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
12
//config:config LSATTR
13
//config: bool "lsattr (5.5 kb)"
15
//config: select PLATFORM_LINUX
17
//config: lsattr lists the file attributes on a second extended file system.
19
//applet:IF_LSATTR(APPLET_NOEXEC(lsattr, lsattr, BB_DIR_BIN, BB_SUID_DROP, lsattr))
20
/* ls is NOEXEC, so we should be too! ;) */
22
//kbuild:lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
24
//usage:#define lsattr_trivial_usage
25
//usage: "[-Radlv] [FILE]..."
26
//usage:#define lsattr_full_usage "\n\n"
27
//usage: "List ext2 file attributes\n"
28
//usage: "\n -R Recurse"
29
//usage: "\n -a Don't hide entries starting with ."
30
//usage: "\n -d List directory entries instead of contents"
31
//usage: "\n -l List long flag names"
32
//usage: "\n -v List version/generation number"
42
OPT_GENERATION = 0x10,
45
static void list_attributes(const char *name)
47
unsigned long fsflags;
48
unsigned long generation;
50
if (fgetflags(name, &fsflags) != 0)
53
if (option_mask32 & OPT_GENERATION) {
54
if (fgetversion(name, &generation) != 0)
56
printf("%5lu ", generation);
59
if (option_mask32 & OPT_PF_LONG) {
60
printf("%-28s ", name);
61
print_e2flags(stdout, fsflags, PFOPT_LONG);
64
print_e2flags(stdout, fsflags, 0);
65
printf(" %s\n", name);
70
bb_perror_msg("reading %s", name);
73
static int FAST_FUNC lsattr_dir_proc(const char *dir_name,
75
void *private UNUSED_PARAM)
80
path = concat_path_file(dir_name, de->d_name);
82
if (lstat(path, &st) != 0)
83
bb_perror_msg("stat %s", path);
84
else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) {
85
list_attributes(path);
86
if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR)
87
&& !DOT_OR_DOTDOT(de->d_name)
89
printf("\n%s:\n", path);
90
iterate_on_dir(path, lsattr_dir_proc, NULL);
99
static void lsattr_args(const char *name)
103
if (lstat(name, &st) == -1) {
104
bb_perror_msg("stat %s", name);
105
} else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
106
iterate_on_dir(name, lsattr_dir_proc, NULL);
108
list_attributes(name);
112
int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
113
int lsattr_main(int argc UNUSED_PARAM, char **argv)
115
getopt32(argv, "Radlv");
119
*--argv = (char*)".";
120
do lsattr_args(*argv++); while (*argv);