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
45 # define LSTAT lstat64
46 # define STRUCT_STAT struct stat64
49 # define STRUCT_STAT struct stat
52 static void list_attributes(const char *name)
54 unsigned long fsflags;
55 unsigned long generation;
57 if (fgetflags(name, &fsflags) == -1)
59 if (flags & OPT_GENERATION) {
60 if (fgetversion(name, &generation) == -1)
62 printf("%5lu ", generation);
65 if (flags & OPT_PF_LONG) {
66 printf("%-28s ", name);
67 print_flags(stdout, fsflags, PFOPT_LONG);
70 print_flags(stdout, fsflags, 0);
71 printf(" %s\n", name);
76 bb_perror_msg("reading %s", name);
79 static int lsattr_dir_proc(const char *, struct dirent *, void *);
81 static void lsattr_args(const char *name)
85 if (LSTAT(name, &st) == -1) {
86 bb_perror_msg("stating %s", name);
88 if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
89 iterate_on_dir(name, lsattr_dir_proc, NULL);
91 list_attributes(name);
95 static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
101 path = concat_path_file(dir_name, de->d_name);
103 if (LSTAT(path, &st) == -1)
106 if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
107 list_attributes(path);
108 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
109 (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
110 (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
111 printf("\n%s:\n", path);
112 iterate_on_dir(path, lsattr_dir_proc, NULL);
123 int lsattr_main(int argc, char **argv)
127 flags = bb_getopt_ulflags(argc, argv, "Radlv");
129 if (optind > argc - 1)
132 for (i = optind; i < argc; i++)
133 lsattr_args(argv[i]);