source: MondoRescue/branches/2.2.9/mindi-busybox/e2fsprogs/lsattr.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 2.4 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
[1765]21#include "libbb.h"
22#include "e2fs_lib.h"
[821]23
[1765]24enum {
25 OPT_RECUR = 0x1,
26 OPT_ALL = 0x2,
27 OPT_DIRS_OPT = 0x4,
28 OPT_PF_LONG = 0x8,
29 OPT_GENERATION = 0x10,
30};
[821]31
32static void list_attributes(const char *name)
33{
34 unsigned long fsflags;
35 unsigned long generation;
36
[1765]37 if (fgetflags(name, &fsflags) != 0)
[821]38 goto read_err;
[1765]39
40 if (option_mask32 & OPT_GENERATION) {
41 if (fgetversion(name, &generation) != 0)
[821]42 goto read_err;
43 printf("%5lu ", generation);
44 }
45
[1765]46 if (option_mask32 & OPT_PF_LONG) {
[821]47 printf("%-28s ", name);
[2725]48 print_e2flags(stdout, fsflags, PFOPT_LONG);
49 bb_putchar('\n');
[821]50 } else {
[2725]51 print_e2flags(stdout, fsflags, 0);
[821]52 printf(" %s\n", name);
53 }
54
55 return;
[1765]56 read_err:
[821]57 bb_perror_msg("reading %s", name);
58}
59
[2725]60static int FAST_FUNC lsattr_dir_proc(const char *dir_name,
61 struct dirent *de,
62 void *private UNUSED_PARAM)
[821]63{
[1765]64 struct stat st;
[821]65 char *path;
66
67 path = concat_path_file(dir_name, de->d_name);
68
[1765]69 if (lstat(path, &st) != 0)
70 bb_perror_msg("stat %s", path);
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 && !DOT_OR_DOTDOT(de->d_name)
75 ) {
76 printf("\n%s:\n", path);
77 iterate_on_dir(path, lsattr_dir_proc, NULL);
[2725]78 bb_putchar('\n');
[821]79 }
80 }
81
82 free(path);
83 return 0;
84}
85
[1765]86static void lsattr_args(const char *name)
87{
88 struct stat st;
89
90 if (lstat(name, &st) == -1) {
91 bb_perror_msg("stat %s", name);
92 } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
93 iterate_on_dir(name, lsattr_dir_proc, NULL);
94 } else {
95 list_attributes(name);
96 }
97}
98
[2725]99int lsattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
100int lsattr_main(int argc UNUSED_PARAM, char **argv)
[821]101{
[1765]102 getopt32(argv, "Radlv");
103 argv += optind;
[821]104
[1765]105 if (!*argv)
[2725]106 *--argv = (char*)".";
107 do lsattr_args(*argv++); while (*argv);
[821]108
109 return EXIT_SUCCESS;
110}
Note: See TracBrowser for help on using the repository browser.