1 /* vi: set sw=4 ts=4: */
3 * lsattr.c - List file attributes on an ext2 file system
5 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
6 * Laboratoire MASI, Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
9 * This file can be redistributed under the terms of the GNU General
16 * 93/11/13 - Replace stat() calls by lstat() to avoid loops
17 * 94/02/27 - Integrated in Ted's distribution
18 * 98/12/29 - Display version info only when -V specified (G M Sipe)
21 #include <sys/types.h>
30 #include <sys/param.h>
33 #include "ext2fs/ext2_fs.h"
39 #define OPT_DIRS_OPT 4
41 #define OPT_GENERATION 16
44 static void list_attributes(const char *name)
46 unsigned long fsflags;
47 unsigned long generation;
49 if (fgetflags(name, &fsflags) == -1)
51 if (flags & OPT_GENERATION) {
52 if (fgetversion(name, &generation) == -1)
54 printf("%5lu ", generation);
57 if (flags & OPT_PF_LONG) {
58 printf("%-28s ", name);
59 print_e2flags(stdout, fsflags, PFOPT_LONG);
62 print_e2flags(stdout, fsflags, 0);
63 printf(" %s\n", name);
68 bb_perror_msg("reading %s", name);
71 static int lsattr_dir_proc(const char *, struct dirent *, void *);
73 static void lsattr_args(const char *name)
77 if (lstat(name, &st) == -1) {
78 bb_perror_msg("stating %s", name);
80 if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
81 iterate_on_dir(name, lsattr_dir_proc, NULL);
83 list_attributes(name);
87 static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
93 path = concat_path_file(dir_name, de->d_name);
95 if (lstat(path, &st) == -1)
98 if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
99 list_attributes(path);
100 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
101 (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
102 (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
103 printf("\n%s:\n", path);
104 iterate_on_dir(path, lsattr_dir_proc, NULL);
115 int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
116 int lsattr_main(int argc, char **argv)
120 flags = getopt32(argv, "Radlv");
122 if (optind > argc - 1)
125 for (i = optind; i < argc; i++)
126 lsattr_args(argv[i]);