2 * lsattr.c - List file attributes on an ext2 file system
4 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
8 * This file can be redistributed under the terms of the GNU General
15 * 93/11/13 - Replace stat() calls by lstat() to avoid loops
16 * 94/02/27 - Integrated in Ted's distribution
17 * 98/12/29 - Display version info only when -V specified (G M Sipe)
20 #include <sys/types.h>
29 #include <sys/param.h>
32 #include "ext2fs/ext2_fs.h"
37 # define EXT2FS_ATTR(x) __attribute__(x)
39 # define EXT2FS_ATTR(x)
44 #define OPT_DIRS_OPT 4
46 #define OPT_GENERATION 16
50 # define LSTAT lstat64
51 # define STRUCT_STAT struct stat64
54 # define STRUCT_STAT struct stat
57 static void list_attributes(const char *name)
59 unsigned long fsflags;
60 unsigned long generation;
62 if (fgetflags(name, &fsflags) == -1)
64 if (flags & OPT_GENERATION) {
65 if (fgetversion(name, &generation) == -1)
67 printf("%5lu ", generation);
70 if (flags & OPT_PF_LONG) {
71 printf("%-28s ", name);
72 print_flags(stdout, fsflags, PFOPT_LONG);
75 print_flags(stdout, fsflags, 0);
76 printf(" %s\n", name);
81 bb_perror_msg("reading %s", name);
84 static int lsattr_dir_proc(const char *, struct dirent *, void *);
86 static void lsattr_args(const char *name)
90 if (LSTAT(name, &st) == -1) {
91 bb_perror_msg("stating %s", name);
93 if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
94 iterate_on_dir(name, lsattr_dir_proc, NULL);
96 list_attributes(name);
100 static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
101 void *private EXT2FS_ATTR((unused)))
106 path = concat_path_file(dir_name, de->d_name);
108 if (LSTAT(path, &st) == -1)
111 if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
112 list_attributes(path);
113 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
114 (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
115 (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
116 printf("\n%s:\n", path);
117 iterate_on_dir(path, lsattr_dir_proc, NULL);
128 int lsattr_main(int argc, char **argv)
132 flags = bb_getopt_ulflags(argc, argv, "Radlv");
134 if (optind > argc - 1)
137 for (i = optind; i < argc; i++)
138 lsattr_args(argv[i]);