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 #define _LARGEFILE64_SOURCE
21 #define _FILE_OFFSET_BITS 64
23 #include <sys/types.h>
39 #include <sys/param.h>
41 #include <linux/ext2_fs.h>
43 #include "et/com_err.h"
46 #include "../version.h"
47 #include "nls-enable.h"
49 static const char * program_name = "lsattr";
53 static unsigned pf_options;
56 static int generation_opt;
58 static void usage(void)
60 fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name);
64 static void list_attributes (const char * name)
67 unsigned long generation;
69 if (fgetflags (name, &flags) == -1) {
70 com_err (program_name, errno, _("While reading flags on %s"),
75 if (fgetversion (name, &generation) == -1) {
76 com_err (program_name, errno,
77 _("While reading version on %s"),
81 printf ("%5lu ", generation);
83 if (pf_options & PFOPT_LONG) {
84 printf("%-28s ", name);
85 print_flags(stdout, flags, pf_options);
88 print_flags(stdout, flags, pf_options);
89 printf(" %s\n", name);
93 static int lsattr_dir_proc (const char *, struct dirent *, void *);
95 static void lsattr_args (const char * name)
99 if (lstat (name, &st) == -1)
100 com_err (program_name, errno, _("while trying to stat %s"),
103 if (S_ISDIR(st.st_mode) && !dirs_opt)
104 iterate_on_dir (name, lsattr_dir_proc, NULL);
106 list_attributes (name);
110 static int lsattr_dir_proc (const char * dir_name, struct dirent * de, void * private)
115 path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1);
117 sprintf (path, "%s/%s", dir_name, de->d_name);
118 if (lstat (path, &st) == -1)
121 if (de->d_name[0] != '.' || all) {
122 list_attributes (path);
123 if (S_ISDIR(st.st_mode) && recursive &&
124 strcmp(de->d_name, ".") &&
125 strcmp(de->d_name, "..")) {
126 printf ("\n%s:\n", path);
127 iterate_on_dir (path, lsattr_dir_proc, NULL);
136 int main (int argc, char ** argv)
142 setlocale(LC_MESSAGES, "");
143 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
144 textdomain(NLS_CAT_NAME);
147 program_name = *argv;
148 while ((c = getopt (argc, argv, "RVadlv")) != EOF)
164 pf_options = PFOPT_LONG;
174 fprintf (stderr, _("lsattr %s, %s for EXT2 FS %s, %s\n"),
175 E2FSPROGS_VERSION, E2FSPROGS_DATE,
176 EXT2FS_VERSION, EXT2FS_DATE);
177 if (optind > argc - 1)
180 for (i = optind; i < argc; i++)
181 lsattr_args (argv[i]);