1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* lsattr.c - List file attributes on an ext2 file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
|
|
|
* Laboratoire MASI, Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
|
|
|
* This file can be redistributed under the terms of the GNU General
|
|
|
|
* Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* History:
|
|
|
|
* 93/10/30 - Creation
|
|
|
|
* 93/11/13 - Replace stat() calls by lstat() to avoid loops
|
|
|
|
* 94/02/27 - Integrated in Ted's distribution
|
1999-01-05 15:02:39 +08:00
|
|
|
* 98/12/29 - Display version info only when -V specified (G M Sipe)
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
|
|
|
|
2001-02-08 11:06:43 +08:00
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
1997-04-26 22:00:26 +08:00
|
|
|
#include <sys/types.h>
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <dirent.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#ifdef HAVE_ERRNO_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <errno.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <fcntl.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#ifdef HAVE_GETOPT_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <getopt.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#else
|
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#include <stdlib.h>
|
1997-04-30 00:17:09 +08:00
|
|
|
#include <string.h>
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2image.c, findsuper.c, lsattr.c,
mke2fs.c, mklost+found.c, tune2fs.c, util.c: Change location of
ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, resize2fs.h:
resize2fs.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, debugfs.h:
debugfs.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, e2fsck.h, scantest.c:
e2fsck.h, scantest.c: Change location of ext2_fs.h to be
ext2fs/ext2_fs.h
ChangeLog, Makefile.in, tst_uuid.c, uuid_time.c:
tst_uuid.c, uuid_time.c: Remove unneeded #include of ext2_fs.h
ChangeLog, Makefile.in, e2p.h:
e2p.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, test_icount.c, test_rel.c:
test_icount.c, test_rel.c: Change location of ext2_fs.h to be
ext2fs/ext2_fs.h
2001-05-14 19:45:38 +08:00
|
|
|
#include "ext2fs/ext2_fs.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include "et/com_err.h"
|
|
|
|
#include "e2p/e2p.h"
|
|
|
|
|
|
|
|
#include "../version.h"
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
#include "nls-enable.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2003-12-07 14:28:50 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define EXT2FS_ATTR(x) __attribute__(x)
|
|
|
|
#else
|
|
|
|
#define EXT2FS_ATTR(x)
|
|
|
|
#endif
|
|
|
|
|
2000-02-11 13:00:19 +08:00
|
|
|
static const char * program_name = "lsattr";
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2000-12-31 21:55:14 +08:00
|
|
|
static int all;
|
|
|
|
static int dirs_opt;
|
|
|
|
static unsigned pf_options;
|
|
|
|
static int recursive;
|
|
|
|
static int verbose;
|
|
|
|
static int generation_opt;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2001-06-08 10:53:20 +08:00
|
|
|
#ifdef _LFS64_LARGEFILE
|
|
|
|
#define LSTAT lstat64
|
|
|
|
#define STRUCT_STAT struct stat64
|
|
|
|
#else
|
|
|
|
#define LSTAT lstat
|
|
|
|
#define STRUCT_STAT struct stat
|
|
|
|
#endif
|
|
|
|
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
static void usage(void)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name);
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
exit(1);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void list_attributes (const char * name)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2000-02-11 13:00:19 +08:00
|
|
|
unsigned long generation;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2000-12-31 21:55:14 +08:00
|
|
|
if (fgetflags (name, &flags) == -1) {
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
com_err (program_name, errno, _("While reading flags on %s"),
|
1997-04-26 21:21:57 +08:00
|
|
|
name);
|
2000-12-31 21:55:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (generation_opt) {
|
|
|
|
if (fgetversion (name, &generation) == -1) {
|
|
|
|
com_err (program_name, errno,
|
|
|
|
_("While reading version on %s"),
|
|
|
|
name);
|
|
|
|
return;
|
2000-02-11 13:00:19 +08:00
|
|
|
}
|
2000-12-31 21:55:14 +08:00
|
|
|
printf ("%5lu ", generation);
|
|
|
|
}
|
|
|
|
if (pf_options & PFOPT_LONG) {
|
|
|
|
printf("%-28s ", name);
|
|
|
|
print_flags(stdout, flags, pf_options);
|
|
|
|
fputc('\n', stdout);
|
|
|
|
} else {
|
|
|
|
print_flags(stdout, flags, pf_options);
|
|
|
|
printf(" %s\n", name);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lsattr_dir_proc (const char *, struct dirent *, void *);
|
|
|
|
|
|
|
|
static void lsattr_args (const char * name)
|
|
|
|
{
|
2001-06-08 10:53:20 +08:00
|
|
|
STRUCT_STAT st;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2001-06-08 10:53:20 +08:00
|
|
|
if (LSTAT (name, &st) == -1)
|
2000-02-11 13:00:19 +08:00
|
|
|
com_err (program_name, errno, _("while trying to stat %s"),
|
|
|
|
name);
|
|
|
|
else {
|
|
|
|
if (S_ISDIR(st.st_mode) && !dirs_opt)
|
|
|
|
iterate_on_dir (name, lsattr_dir_proc, NULL);
|
1997-04-26 21:21:57 +08:00
|
|
|
else
|
|
|
|
list_attributes (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-07 14:28:50 +08:00
|
|
|
static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
|
|
|
|
void * private EXT2FS_ATTR((unused)))
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
2001-06-08 10:53:20 +08:00
|
|
|
STRUCT_STAT st;
|
1997-04-26 22:00:26 +08:00
|
|
|
char *path;
|
2004-09-25 00:16:17 +08:00
|
|
|
int dir_len = strlen(dir_name);
|
1997-04-26 22:00:26 +08:00
|
|
|
|
2004-09-25 00:16:17 +08:00
|
|
|
path = malloc(dir_len + strlen (de->d_name) + 2);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2004-09-25 00:16:17 +08:00
|
|
|
if (dir_len && dir_name[dir_len-1] == '/')
|
|
|
|
sprintf (path, "%s%s", dir_name, de->d_name);
|
|
|
|
else
|
|
|
|
sprintf (path, "%s/%s", dir_name, de->d_name);
|
2001-06-08 10:53:20 +08:00
|
|
|
if (LSTAT (path, &st) == -1)
|
1997-04-26 21:21:57 +08:00
|
|
|
perror (path);
|
1997-04-26 22:00:26 +08:00
|
|
|
else {
|
|
|
|
if (de->d_name[0] != '.' || all) {
|
1997-04-26 21:21:57 +08:00
|
|
|
list_attributes (path);
|
|
|
|
if (S_ISDIR(st.st_mode) && recursive &&
|
1997-04-26 22:00:26 +08:00
|
|
|
strcmp(de->d_name, ".") &&
|
|
|
|
strcmp(de->d_name, "..")) {
|
1997-04-26 21:21:57 +08:00
|
|
|
printf ("\n%s:\n", path);
|
2000-02-11 13:00:19 +08:00
|
|
|
iterate_on_dir (path, lsattr_dir_proc, NULL);
|
1997-04-26 21:21:57 +08:00
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-04-26 22:00:26 +08:00
|
|
|
free(path);
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-09-16 10:13:52 +08:00
|
|
|
int main (int argc, char ** argv)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
1997-10-25 11:49:49 +08:00
|
|
|
int c;
|
1997-04-26 21:21:57 +08:00
|
|
|
int i;
|
|
|
|
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
setlocale(LC_MESSAGES, "");
|
2002-03-05 16:26:52 +08:00
|
|
|
setlocale(LC_CTYPE, "");
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
|
|
|
|
textdomain(NLS_CAT_NAME);
|
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
if (argc && *argv)
|
|
|
|
program_name = *argv;
|
1999-01-05 15:02:39 +08:00
|
|
|
while ((c = getopt (argc, argv, "RVadlv")) != EOF)
|
1997-04-26 21:21:57 +08:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'R':
|
|
|
|
recursive = 1;
|
|
|
|
break;
|
1999-01-05 15:02:39 +08:00
|
|
|
case 'V':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
1997-04-26 21:21:57 +08:00
|
|
|
case 'a':
|
|
|
|
all = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2000-02-11 13:00:19 +08:00
|
|
|
dirs_opt = 1;
|
1997-04-26 21:21:57 +08:00
|
|
|
break;
|
1997-04-26 21:34:30 +08:00
|
|
|
case 'l':
|
2000-02-11 13:00:19 +08:00
|
|
|
pf_options = PFOPT_LONG;
|
1997-04-26 21:34:30 +08:00
|
|
|
break;
|
1997-04-26 21:21:57 +08:00
|
|
|
case 'v':
|
2000-02-11 13:00:19 +08:00
|
|
|
generation_opt = 1;
|
1997-04-26 21:21:57 +08:00
|
|
|
break;
|
|
|
|
default:
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
usage();
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
1999-01-05 15:02:39 +08:00
|
|
|
if (verbose)
|
2001-08-28 00:44:23 +08:00
|
|
|
fprintf (stderr, "lsattr %s (%s)\n",
|
|
|
|
E2FSPROGS_VERSION, E2FSPROGS_DATE);
|
1997-04-26 21:21:57 +08:00
|
|
|
if (optind > argc - 1)
|
|
|
|
lsattr_args (".");
|
|
|
|
else
|
|
|
|
for (i = optind; i < argc; i++)
|
|
|
|
lsattr_args (argv[i]);
|
1997-09-16 10:13:52 +08:00
|
|
|
exit(0);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|