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"
38 #define OPT_DIRS_OPT 4
40 #define OPT_GENERATION 16
44 # define LSTAT lstat64
45 # define STRUCT_STAT struct stat64
48 # define STRUCT_STAT struct stat
51 static void list_attributes(const char *name)
53 unsigned long fsflags;
54 unsigned long generation;
56 if (fgetflags(name, &fsflags) == -1)
58 if (flags & OPT_GENERATION) {
59 if (fgetversion(name, &generation) == -1)
61 printf("%5lu ", generation);
64 if (flags & OPT_PF_LONG) {
65 printf("%-28s ", name);
66 print_flags(stdout, fsflags, PFOPT_LONG);
69 print_flags(stdout, fsflags, 0);
70 printf(" %s\n", name);
75 bb_perror_msg("reading %s", name);
78 static int lsattr_dir_proc(const char *, struct dirent *, void *);
80 static void lsattr_args(const char *name)
84 if (LSTAT(name, &st) == -1) {
85 bb_perror_msg("stating %s", name);
87 if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
88 iterate_on_dir(name, lsattr_dir_proc, NULL);
90 list_attributes(name);
94 static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
100 path = concat_path_file(dir_name, de->d_name);
102 if (LSTAT(path, &st) == -1)
105 if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
106 list_attributes(path);
107 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
108 (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
109 (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
110 printf("\n%s:\n", path);
111 iterate_on_dir(path, lsattr_dir_proc, NULL);
122 int lsattr_main(int argc, char **argv)
126 flags = bb_getopt_ulflags(argc, argv, "Radlv");
128 if (optind > argc - 1)
131 for (i = optind; i < argc; i++)
132 lsattr_args(argv[i]);