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)
29 OPT_GENERATION = 0x10,
32 static void list_attributes(const char *name)
34 unsigned long fsflags;
35 unsigned long generation;
37 if (fgetflags(name, &fsflags) != 0)
40 if (option_mask32 & OPT_GENERATION) {
41 if (fgetversion(name, &generation) != 0)
43 printf("%5lu ", generation);
46 if (option_mask32 & OPT_PF_LONG) {
47 printf("%-28s ", name);
48 print_e2flags(stdout, fsflags, PFOPT_LONG);
51 print_e2flags(stdout, fsflags, 0);
52 printf(" %s\n", name);
57 bb_perror_msg("reading %s", name);
60 static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
61 void *private UNUSED_PARAM)
66 path = concat_path_file(dir_name, de->d_name);
68 if (lstat(path, &st) != 0)
69 bb_perror_msg("stat %s", path);
70 else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) {
71 list_attributes(path);
72 if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR)
73 && !DOT_OR_DOTDOT(de->d_name)
75 printf("\n%s:\n", path);
76 iterate_on_dir(path, lsattr_dir_proc, NULL);
85 static void lsattr_args(const char *name)
89 if (lstat(name, &st) == -1) {
90 bb_perror_msg("stat %s", name);
91 } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
92 iterate_on_dir(name, lsattr_dir_proc, NULL);
94 list_attributes(name);
98 int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
99 int lsattr_main(int argc UNUSED_PARAM, char **argv)
101 getopt32(argv, "Radlv");
105 *--argv = (char*)".";
106 do lsattr_args(*argv++); while (*argv);