]>
git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - misc/lsattr.c
2 * lsattr.c - List file attributes on an ext2 file system
4 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
8 * This file can be redistributed under the terms of the GNU General
15 * 93/11/13 - Replace stat() calls by lstat() to avoid loops
16 * 94/02/27 - Integrated in Ted's distribution
17 * 98/12/29 - Display version info only when -V specified (G M Sipe)
20 #include <sys/types.h>
36 #include <sys/param.h>
38 #include <linux/ext2_fs.h>
40 #include "et/com_err.h"
43 #include "../version.h"
44 #include "nls-enable.h"
46 static const char * program_name
= "lsattr";
49 static int dirs_opt
= 0;
50 static unsigned pf_options
= 0;
51 static int recursive
= 0;
52 static int verbose
= 0;
53 static int generation_opt
= 0;
55 static void usage(void)
57 fprintf(stderr
, _("Usage: %s [-RVadlv] [files...]\n"), program_name
);
61 static void list_attributes (const char * name
)
64 unsigned long generation
;
66 if (fgetflags (name
, &flags
) == -1)
67 com_err (program_name
, errno
, _("While reading flags on %s"),
69 else if (fgetversion (name
, &generation
) == -1)
70 com_err (program_name
, errno
, _("While reading version on %s"),
75 printf ("%5lu ", generation
);
76 if (pf_options
& PFOPT_LONG
) {
77 printf("%-28s ", name
);
78 print_flags(stdout
, flags
, pf_options
);
81 print_flags(stdout
, flags
, pf_options
);
82 printf(" %s\n", name
);
87 static int lsattr_dir_proc (const char *, struct dirent
*, void *);
89 static void lsattr_args (const char * name
)
93 if (lstat (name
, &st
) == -1)
94 com_err (program_name
, errno
, _("while trying to stat %s"),
97 if (S_ISDIR(st
.st_mode
) && !dirs_opt
)
98 iterate_on_dir (name
, lsattr_dir_proc
, NULL
);
100 list_attributes (name
);
104 static int lsattr_dir_proc (const char * dir_name
, struct dirent
* de
, void * private)
109 path
= malloc(strlen (dir_name
) + 1 + strlen (de
->d_name
) + 1);
111 sprintf (path
, "%s/%s", dir_name
, de
->d_name
);
112 if (lstat (path
, &st
) == -1)
115 if (de
->d_name
[0] != '.' || all
) {
116 list_attributes (path
);
117 if (S_ISDIR(st
.st_mode
) && recursive
&&
118 strcmp(de
->d_name
, ".") &&
119 strcmp(de
->d_name
, "..")) {
120 printf ("\n%s:\n", path
);
121 iterate_on_dir (path
, lsattr_dir_proc
, NULL
);
130 int main (int argc
, char ** argv
)
136 setlocale(LC_MESSAGES
, "");
137 bindtextdomain(NLS_CAT_NAME
, LOCALEDIR
);
138 textdomain(NLS_CAT_NAME
);
141 program_name
= *argv
;
142 while ((c
= getopt (argc
, argv
, "RVadlv")) != EOF
)
158 pf_options
= PFOPT_LONG
;
168 fprintf (stderr
, _("lsattr %s, %s for EXT2 FS %s, %s\n"),
169 E2FSPROGS_VERSION
, E2FSPROGS_DATE
,
170 EXT2FS_VERSION
, EXT2FS_DATE
);
171 if (optind
> argc
- 1)
174 for (i
= optind
; i
< argc
; i
++)
175 lsattr_args (argv
[i
]);