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>
34 #include <sys/param.h>
36 #include <linux/ext2_fs.h>
38 #include "et/com_err.h"
41 #include "../version.h"
43 const char * program_name = "lsattr";
51 static void volatile usage (void)
53 fprintf (stderr, "Usage: %s [-Radlv] [files...]\n", program_name);
57 static void list_attributes (const char * name)
60 unsigned long version;
62 if (fgetflags (name, &flags) == -1)
63 com_err (program_name, errno, "While reading flags on %s",
65 else if (fgetversion (name, &version) == -1)
66 com_err (program_name, errno, "While reading version on %s",
71 printf ("%5lu ", version);
72 print_flags (stdout, flags, l_opt);
73 printf (" %s\n", name);
77 static int lsattr_dir_proc (const char *, struct dirent *, void *);
79 static void lsattr_args (const char * name)
83 if (lstat (name, &st) == -1)
84 com_err (program_name, errno, "while stating %s", name);
87 if (S_ISDIR(st.st_mode) && !d_opt)
88 iterate_on_dir (name, lsattr_dir_proc, (void *) NULL);
90 list_attributes (name);
94 static int lsattr_dir_proc (const char * dir_name, struct dirent * de, void * private)
99 path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1);
101 sprintf (path, "%s/%s", dir_name, de->d_name);
102 if (lstat (path, &st) == -1)
105 if (de->d_name[0] != '.' || all) {
106 list_attributes (path);
107 if (S_ISDIR(st.st_mode) && recursive &&
108 strcmp(de->d_name, ".") &&
109 strcmp(de->d_name, "..")) {
110 printf ("\n%s:\n", path);
111 iterate_on_dir (path, lsattr_dir_proc,
121 void main (int argc, char ** argv)
126 fprintf (stderr, "lsattr %s, %s for EXT2 FS %s, %s\n",
127 E2FSPROGS_VERSION, E2FSPROGS_DATE,
128 EXT2FS_VERSION, EXT2FS_DATE);
130 program_name = *argv;
131 while ((c = getopt (argc, argv, "Radlv")) != EOF)
153 if (optind > argc - 1)
156 for (i = optind; i < argc; i++)
157 lsattr_args (argv[i]);