diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-26 01:30:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-26 01:30:59 +0000 |
commit | c4f623ef2a7980a63de7c9f1d539a656b83f10e7 (patch) | |
tree | a294e28b0112052cb9d58b403554b3390e76f50c /e2fsprogs/lsattr.c | |
parent | 64c54025842f205ad722675105b88044a5b6845a (diff) | |
download | busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.gz busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.bz2 busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.zip |
put small subset of e2fsprogs back in the tree:
lsattr, chattr, fsck. Old e2fsprogs tree is in
e2fsprogs/old_e2fsprogs/*.
Diffstat (limited to 'e2fsprogs/lsattr.c')
-rw-r--r-- | e2fsprogs/lsattr.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c new file mode 100644 index 000000000..f317b047e --- /dev/null +++ b/e2fsprogs/lsattr.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * lsattr.c - List file attributes on an ext2 file system | ||
4 | * | ||
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) | ||
8 | * | ||
9 | * This file can be redistributed under the terms of the GNU General | ||
10 | * Public License | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * History: | ||
15 | * 93/10/30 - Creation | ||
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) | ||
19 | */ | ||
20 | |||
21 | #include "busybox.h" | ||
22 | #include "e2fs_lib.h" | ||
23 | |||
24 | enum { | ||
25 | OPT_RECUR = 0x1, | ||
26 | OPT_ALL = 0x2, | ||
27 | OPT_DIRS_OPT = 0x4, | ||
28 | OPT_PF_LONG = 0x8, | ||
29 | OPT_GENERATION = 0x10, | ||
30 | }; | ||
31 | |||
32 | static void list_attributes(const char *name) | ||
33 | { | ||
34 | unsigned long fsflags; | ||
35 | unsigned long generation; | ||
36 | |||
37 | if (fgetflags(name, &fsflags) == -1) | ||
38 | goto read_err; | ||
39 | |||
40 | if (option_mask32 & OPT_GENERATION) { | ||
41 | if (fgetversion(name, &generation) == -1) | ||
42 | goto read_err; | ||
43 | printf("%5lu ", generation); | ||
44 | } | ||
45 | |||
46 | if (option_mask32 & OPT_PF_LONG) { | ||
47 | printf("%-28s ", name); | ||
48 | print_flags(stdout, fsflags, PFOPT_LONG); | ||
49 | puts(""); | ||
50 | } else { | ||
51 | print_flags(stdout, fsflags, 0); | ||
52 | printf(" %s\n", name); | ||
53 | } | ||
54 | |||
55 | return; | ||
56 | read_err: | ||
57 | bb_perror_msg("reading %s", name); | ||
58 | } | ||
59 | |||
60 | static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | ||
61 | void *private) | ||
62 | { | ||
63 | struct stat st; | ||
64 | char *path; | ||
65 | |||
66 | path = concat_path_file(dir_name, de->d_name); | ||
67 | |||
68 | if (lstat(path, &st) == -1) | ||
69 | bb_perror_msg("stat %s", path); | ||
70 | |||
71 | else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) { | ||
72 | list_attributes(path); | ||
73 | if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR) | ||
74 | && (de->d_name[0] != '.' | ||
75 | || (de->d_name[1] != '\0' && NOT_LONE_CHAR(de->d_name+1, '.'))) | ||
76 | ) { | ||
77 | printf("\n%s:\n", path); | ||
78 | iterate_on_dir(path, lsattr_dir_proc, NULL); | ||
79 | puts(""); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | free(path); | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static void lsattr_args(const char *name) | ||
89 | { | ||
90 | struct stat st; | ||
91 | |||
92 | if (lstat(name, &st) == -1) { | ||
93 | bb_perror_msg("stat %s", name); | ||
94 | } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) { | ||
95 | iterate_on_dir(name, lsattr_dir_proc, NULL); | ||
96 | } else { | ||
97 | list_attributes(name); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | int lsattr_main(int argc, char **argv) | ||
102 | { | ||
103 | getopt32(argc, argv, "Radlv"); | ||
104 | argv += optind; | ||
105 | |||
106 | if (!*argv) | ||
107 | lsattr_args("."); | ||
108 | else { | ||
109 | while (*argv) | ||
110 | lsattr_args(*argv++); | ||
111 | } | ||
112 | |||
113 | return EXIT_SUCCESS; | ||
114 | } | ||