source: MondoRescue/branches/3.2/mindi-busybox/e2fsprogs/lsattr.c@ 3232

Last change on this file since 3232 was 3232, checked in by Bruno Cornec, 10 years ago
  • Update mindi-busybox to 1.21.1
File size: 2.8 KB
RevLine 
[1765]1/* vi: set sw=4 ts=4: */
[821]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
[3232]21//usage:#define lsattr_trivial_usage
22//usage: "[-Radlv] [FILE]..."
23//usage:#define lsattr_full_usage "\n\n"
24//usage: "List file attributes on an ext2 fs\n"
25//usage: "\n -R Recurse"
26//usage: "\n -a Don't hide entries starting with ."
27//usage: "\n -d List directory entries instead of contents"
28//usage: "\n -l List long flag names"
29//usage: "\n -v List the file's version/generation number"
30
[1765]31#include "libbb.h"
32#include "e2fs_lib.h"
[821]33
[1765]34enum {
35 OPT_RECUR = 0x1,
36 OPT_ALL = 0x2,
37 OPT_DIRS_OPT = 0x4,
38 OPT_PF_LONG = 0x8,
39 OPT_GENERATION = 0x10,
40};
[821]41
42static void list_attributes(const char *name)
43{
44 unsigned long fsflags;
45 unsigned long generation;
46
[1765]47 if (fgetflags(name, &fsflags) != 0)
[821]48 goto read_err;
[1765]49
50 if (option_mask32 & OPT_GENERATION) {
51 if (fgetversion(name, &generation) != 0)
[821]52 goto read_err;
53 printf("%5lu ", generation);
54 }
55
[1765]56 if (option_mask32 & OPT_PF_LONG) {
[821]57 printf("%-28s ", name);
[2725]58 print_e2flags(stdout, fsflags, PFOPT_LONG);
59 bb_putchar('\n');
[821]60 } else {
[2725]61 print_e2flags(stdout, fsflags, 0);
[821]62 printf(" %s\n", name);
63 }
64
65 return;
[1765]66 read_err:
[821]67 bb_perror_msg("reading %s", name);
68}
69
[2725]70static int FAST_FUNC lsattr_dir_proc(const char *dir_name,
71 struct dirent *de,
72 void *private UNUSED_PARAM)
[821]73{
[1765]74 struct stat st;
[821]75 char *path;
76
77 path = concat_path_file(dir_name, de->d_name);
78
[1765]79 if (lstat(path, &st) != 0)
80 bb_perror_msg("stat %s", path);
81 else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) {
82 list_attributes(path);
83 if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR)
84 && !DOT_OR_DOTDOT(de->d_name)
85 ) {
86 printf("\n%s:\n", path);
87 iterate_on_dir(path, lsattr_dir_proc, NULL);
[2725]88 bb_putchar('\n');
[821]89 }
90 }
91
92 free(path);
93 return 0;
94}
95
[1765]96static void lsattr_args(const char *name)
97{
98 struct stat st;
99
100 if (lstat(name, &st) == -1) {
101 bb_perror_msg("stat %s", name);
102 } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
103 iterate_on_dir(name, lsattr_dir_proc, NULL);
104 } else {
105 list_attributes(name);
106 }
107}
108
[2725]109int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
110int lsattr_main(int argc UNUSED_PARAM, char **argv)
[821]111{
[1765]112 getopt32(argv, "Radlv");
113 argv += optind;
[821]114
[1765]115 if (!*argv)
[2725]116 *--argv = (char*)".";
117 do lsattr_args(*argv++); while (*argv);
[821]118
119 return EXIT_SUCCESS;
120}
Note: See TracBrowser for help on using the repository browser.