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
19 #include <sys/types.h>
35 #include <sys/param.h>
37 #include <linux/ext2_fs.h>
39 #include "et/com_err.h"
42 #include "../version.h"
44 const char * program_name = "lsattr";
52 static void volatile usage (void)
54 fprintf (stderr, "Usage: %s [-Radlv] [files...]\n", program_name);
58 static void list_attributes (const char * name)
61 unsigned long version;
63 if (fgetflags (name, &flags) == -1)
64 com_err (program_name, errno, "While reading flags on %s",
66 else if (fgetversion (name, &version) == -1)
67 com_err (program_name, errno, "While reading version on %s",
72 printf ("%5lu ", version);
73 print_flags (stdout, flags, l_opt);
74 printf (" %s\n", name);
78 static int lsattr_dir_proc (const char *, struct dirent *, void *);
80 static void lsattr_args (const char * name)
84 if (lstat (name, &st) == -1)
85 com_err (program_name, errno, "while stating %s", name);
88 if (S_ISDIR(st.st_mode) && !d_opt)
89 iterate_on_dir (name, lsattr_dir_proc, (void *) NULL);
91 list_attributes (name);
95 static int lsattr_dir_proc (const char * dir_name, struct dirent * de, void * private)
100 path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1);
102 sprintf (path, "%s/%s", dir_name, de->d_name);
103 if (lstat (path, &st) == -1)
106 if (de->d_name[0] != '.' || all) {
107 list_attributes (path);
108 if (S_ISDIR(st.st_mode) && recursive &&
109 strcmp(de->d_name, ".") &&
110 strcmp(de->d_name, "..")) {
111 printf ("\n%s:\n", path);
112 iterate_on_dir (path, lsattr_dir_proc,
122 void main (int argc, char ** argv)
127 fprintf (stderr, "lsattr %s, %s for EXT2 FS %s, %s\n",
128 E2FSPROGS_VERSION, E2FSPROGS_DATE,
129 EXT2FS_VERSION, EXT2FS_DATE);
131 program_name = *argv;
132 while ((c = getopt (argc, argv, "Radlv")) != EOF)
154 if (optind > argc - 1)
157 for (i = optind; i < argc; i++)
158 lsattr_args (argv[i]);