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 //usage:#define lsattr_trivial_usage
22 //usage: "[-Radlv] [FILE]..."
23 //usage:#define lsattr_full_usage "\n\n"
24 //usage: "List file attributes on an ext2 fs\n"
26 //usage: "\n -R Recurse"
27 //usage: "\n -a Don't hide entries starting with ."
28 //usage: "\n -d List directory entries instead of contents"
29 //usage: "\n -l List long flag names"
30 //usage: "\n -v List the file's version/generation number"
40 OPT_GENERATION = 0x10,
43 static void list_attributes(const char *name)
45 unsigned long fsflags;
46 unsigned long generation;
48 if (fgetflags(name, &fsflags) != 0)
51 if (option_mask32 & OPT_GENERATION) {
52 if (fgetversion(name, &generation) != 0)
54 printf("%5lu ", generation);
57 if (option_mask32 & 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 FAST_FUNC lsattr_dir_proc(const char *dir_name,
73 void *private UNUSED_PARAM)
78 path = concat_path_file(dir_name, de->d_name);
80 if (lstat(path, &st) != 0)
81 bb_perror_msg("stat %s", path);
82 else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) {
83 list_attributes(path);
84 if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR)
85 && !DOT_OR_DOTDOT(de->d_name)
87 printf("\n%s:\n", path);
88 iterate_on_dir(path, lsattr_dir_proc, NULL);
97 static void lsattr_args(const char *name)
101 if (lstat(name, &st) == -1) {
102 bb_perror_msg("stat %s", name);
103 } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
104 iterate_on_dir(name, lsattr_dir_proc, NULL);
106 list_attributes(name);
110 int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
111 int lsattr_main(int argc UNUSED_PARAM, char **argv)
113 getopt32(argv, "Radlv");
117 *--argv = (char*)".";
118 do lsattr_args(*argv++); while (*argv);