1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* ls.c - List the contents of an ext2fs superblock
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
|
|
|
|
* Laboratoire MASI, Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* Copyright (C) 1995, 1996, 1997 Theodore Ts'o <tytso@mit.edu>
|
|
|
|
*
|
1997-04-26 17:21:57 +04:00
|
|
|
* This file can be redistributed under the terms of the GNU Library General
|
|
|
|
* Public License
|
|
|
|
*/
|
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
#include <stdio.h>
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <sys/types.h>
|
1997-04-29 18:53:37 +04:00
|
|
|
#include <string.h>
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "e2p.h"
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
static void print_user (unsigned short uid, FILE *f)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "%u ", uid);
|
1997-04-26 17:34:30 +04:00
|
|
|
pw = getpwuid (uid);
|
|
|
|
if (pw == NULL)
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "(user unknown)\n");
|
1997-04-26 17:34:30 +04:00
|
|
|
else
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "(user %s)\n", pw->pw_name);
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
static void print_group (unsigned short gid, FILE *f)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
|
|
|
struct group *gr;
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "%u ", gid);
|
1997-04-26 17:34:30 +04:00
|
|
|
gr = getgrgid (gid);
|
|
|
|
if (gr == NULL)
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "(group unknown)\n");
|
1997-04-26 17:34:30 +04:00
|
|
|
else
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "(group %s)\n", gr->gr_name);
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
#define MONTH_INT (86400 * 30)
|
|
|
|
#define WEEK_INT (86400 * 7)
|
|
|
|
#define DAY_INT (86400)
|
|
|
|
#define HOUR_INT (60 * 60)
|
|
|
|
#define MINUTE_INT (60)
|
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
static const char *interval_string(unsigned int secs)
|
1997-04-29 18:53:37 +04:00
|
|
|
{
|
|
|
|
static char buf[256], tmp[80];
|
|
|
|
int hr, min, num;
|
|
|
|
|
|
|
|
buf[0] = 0;
|
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
if (secs == 0)
|
|
|
|
return "<none>";
|
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
if (secs >= MONTH_INT) {
|
|
|
|
num = secs / MONTH_INT;
|
|
|
|
secs -= num*MONTH_INT;
|
|
|
|
sprintf(buf, "%d month%s", num, (num>1) ? "s" : "");
|
|
|
|
}
|
|
|
|
if (secs >= WEEK_INT) {
|
|
|
|
num = secs / WEEK_INT;
|
|
|
|
secs -= num*WEEK_INT;
|
|
|
|
sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "",
|
|
|
|
num, (num>1) ? "s" : "");
|
|
|
|
strcat(buf, tmp);
|
|
|
|
}
|
|
|
|
if (secs >= DAY_INT) {
|
|
|
|
num = secs / DAY_INT;
|
|
|
|
secs -= num*DAY_INT;
|
|
|
|
sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "",
|
|
|
|
num, (num>1) ? "s" : "");
|
|
|
|
strcat(buf, tmp);
|
|
|
|
}
|
|
|
|
if (secs > 0) {
|
|
|
|
hr = secs / HOUR_INT;
|
|
|
|
secs -= hr*HOUR_INT;
|
|
|
|
min = secs / MINUTE_INT;
|
|
|
|
secs -= min*MINUTE_INT;
|
|
|
|
sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "",
|
|
|
|
hr, min, secs);
|
|
|
|
strcat(buf, tmp);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
static void print_features(struct ext2_super_block * s, FILE *f)
|
1999-09-15 00:17:38 +04:00
|
|
|
{
|
|
|
|
#ifdef EXT2_DYNAMIC_REV
|
|
|
|
int i, j, printed=0;
|
|
|
|
__u32 *mask = &s->s_feature_compat, m;
|
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Filesystem features: ");
|
1999-09-15 00:17:38 +04:00
|
|
|
for (i=0; i <3; i++,mask++) {
|
|
|
|
for (j=0,m=1; j < 32; j++, m<<=1) {
|
|
|
|
if (*mask & m) {
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, " %s", e2p_feature2string(i, m));
|
1999-09-15 00:17:38 +04:00
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (printed == 0)
|
2001-05-14 02:14:53 +04:00
|
|
|
fprintf(f, " (none)");
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "\n");
|
1999-09-15 00:17:38 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-10-16 01:43:43 +04:00
|
|
|
static void print_mntopts(struct ext2_super_block * s, FILE *f)
|
|
|
|
{
|
|
|
|
#ifdef EXT2_DYNAMIC_REV
|
|
|
|
int i, printed=0;
|
|
|
|
__u32 mask = s->s_default_mount_opts, m;
|
|
|
|
|
|
|
|
fprintf(f, "Default mount options: ");
|
2002-10-20 09:52:52 +04:00
|
|
|
if (mask & EXT3_DEFM_JMODE) {
|
|
|
|
fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE));
|
|
|
|
printed++;
|
|
|
|
}
|
2002-10-16 01:43:43 +04:00
|
|
|
for (i=0,m=1; i < 32; i++, m<<=1) {
|
2002-10-20 09:52:52 +04:00
|
|
|
if (m & EXT3_DEFM_JMODE)
|
|
|
|
continue;
|
2002-10-16 01:43:43 +04:00
|
|
|
if (mask & m) {
|
2002-10-20 09:52:52 +04:00
|
|
|
fprintf(f, " %s", e2p_mntopt2string(m));
|
2002-10-16 01:43:43 +04:00
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (printed == 0)
|
|
|
|
fprintf(f, " (none)");
|
|
|
|
fprintf(f, "\n");
|
|
|
|
#endif
|
|
|
|
}
|
1999-09-15 00:17:38 +04:00
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
|
1997-04-26 18:48:50 +04:00
|
|
|
#ifndef EXT2_INODE_SIZE
|
|
|
|
#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
|
|
|
|
#endif
|
|
|
|
|
1997-04-30 01:26:48 +04:00
|
|
|
#ifndef EXT2_GOOD_OLD_REV
|
|
|
|
#define EXT2_GOOD_OLD_REV 0
|
|
|
|
#endif
|
|
|
|
|
2001-01-01 18:54:58 +03:00
|
|
|
void list_super2(struct ext2_super_block * sb, FILE *f)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
1997-04-26 18:48:50 +04:00
|
|
|
int inode_blocks_per_group;
|
1997-04-29 18:53:37 +04:00
|
|
|
char buf[80];
|
|
|
|
const char *os;
|
1997-04-29 20:15:03 +04:00
|
|
|
time_t tm;
|
1997-04-26 18:48:50 +04:00
|
|
|
|
2001-01-01 18:54:58 +03:00
|
|
|
inode_blocks_per_group = (((sb->s_inodes_per_group *
|
|
|
|
EXT2_INODE_SIZE(sb)) +
|
|
|
|
EXT2_BLOCK_SIZE(sb) - 1) /
|
|
|
|
EXT2_BLOCK_SIZE(sb));
|
1997-04-29 18:53:37 +04:00
|
|
|
if (sb->s_volume_name[0]) {
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name));
|
1997-04-29 20:15:03 +04:00
|
|
|
} else
|
|
|
|
strcpy(buf, "<none>");
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Filesystem volume name: %s\n", buf);
|
1997-04-29 18:53:37 +04:00
|
|
|
if (sb->s_last_mounted[0]) {
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted));
|
1997-04-29 20:15:03 +04:00
|
|
|
} else
|
|
|
|
strcpy(buf, "<not available>");
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Last mounted on: %s\n", buf);
|
2002-08-24 08:04:03 +04:00
|
|
|
fprintf(f, "Filesystem UUID: %s\n", e2p_uuid2str(sb->s_uuid));
|
2001-01-01 18:54:58 +03:00
|
|
|
fprintf(f, "Filesystem magic number: 0x%04X\n", sb->s_magic);
|
|
|
|
fprintf(f, "Filesystem revision #: %d", sb->s_rev_level);
|
|
|
|
if (sb->s_rev_level == EXT2_GOOD_OLD_REV) {
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, " (original)\n");
|
1997-04-29 21:48:10 +04:00
|
|
|
#ifdef EXT2_DYNAMIC_REV
|
2001-01-01 18:54:58 +03:00
|
|
|
} else if (sb->s_rev_level == EXT2_DYNAMIC_REV) {
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, " (dynamic)\n");
|
1997-04-29 21:48:10 +04:00
|
|
|
#endif
|
|
|
|
} else
|
2001-05-14 02:14:53 +04:00
|
|
|
fprintf(f, " (unknown)\n");
|
2001-01-01 18:54:58 +03:00
|
|
|
print_features(sb, f);
|
2002-10-16 01:43:43 +04:00
|
|
|
print_mntopts(sb, f);
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Filesystem state: ");
|
2001-01-01 18:54:58 +03:00
|
|
|
print_fs_state (f, sb->s_state);
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "\n");
|
|
|
|
fprintf(f, "Errors behavior: ");
|
2001-01-01 18:54:58 +03:00
|
|
|
print_fs_errors(f, sb->s_errors);
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "\n");
|
2001-01-01 18:54:58 +03:00
|
|
|
switch (sb->s_creator_os) {
|
1997-04-29 18:53:37 +04:00
|
|
|
case EXT2_OS_LINUX: os = "Linux"; break;
|
ChangeLog, problem.c, problem.h, super.c:
problem.c, problem.h (PR_0_HURD_CLEAR_FILETYPE): Add new problem code.
super.c (check_super_block): If the OS type in the superblock is the
Hurd, check to see if the filetype feature is set, and offer to clear
it if so. This needs to be done since the Hurd doesn't properly
support the filetype feature. (And since the hurd allows the
transmogrification of files to special files and vice versa --- for no
good reason that I can understand --- it can't support the filetype
feature for the forseeable future, either.)
ChangeLog, mke2fs.c:
mke2fs.c (main): We forcibly turn off the filetype feature if the OS
is the hurd, since the hurd doesn't support it. (And since the hurd
allows the transmogrification of files to special files and vice versa
--- for no good reason that I can understand --- it can't support the
filetype feature for the forseeable future, either.)
mke2fs.c (proceed_question): Fix reversed sense of proceed_question
that was busted due to the internationalization patch. Fixed bug
where if proceed_question was called twice, the input buffer wasn't
cleared of the previous question's newline.
ChangeLog, expect.1, expect.2, image.gz, name:
f_hurd: Add test for Hurd-specific features (right now, just checks to
make sure the filetype feature is cleared)
ChangeLog, ls.c:
ls.c (list_super): Change the string displayed for the Hurd to be
GNU/Hurd, instead of just "GNU".
2000-05-08 17:33:17 +04:00
|
|
|
case EXT2_OS_HURD: os = "GNU/Hurd"; break;
|
1997-04-29 18:53:37 +04:00
|
|
|
case EXT2_OS_MASIX: os = "Masix"; break;
|
|
|
|
default: os = "unknown"; break;
|
|
|
|
}
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Filesystem OS type: %s\n", os);
|
2001-01-01 18:54:58 +03:00
|
|
|
fprintf(f, "Inode count: %u\n", sb->s_inodes_count);
|
|
|
|
fprintf(f, "Block count: %u\n", sb->s_blocks_count);
|
|
|
|
fprintf(f, "Reserved block count: %u\n", sb->s_r_blocks_count);
|
|
|
|
fprintf(f, "Free blocks: %u\n", sb->s_free_blocks_count);
|
|
|
|
fprintf(f, "Free inodes: %u\n", sb->s_free_inodes_count);
|
|
|
|
fprintf(f, "First block: %u\n", sb->s_first_data_block);
|
|
|
|
fprintf(f, "Block size: %u\n", EXT2_BLOCK_SIZE(sb));
|
|
|
|
fprintf(f, "Fragment size: %u\n", EXT2_FRAG_SIZE(sb));
|
|
|
|
fprintf(f, "Blocks per group: %u\n", sb->s_blocks_per_group);
|
|
|
|
fprintf(f, "Fragments per group: %u\n", sb->s_frags_per_group);
|
|
|
|
fprintf(f, "Inodes per group: %u\n", sb->s_inodes_per_group);
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Inode blocks per group: %u\n", inode_blocks_per_group);
|
2002-10-20 08:38:57 +04:00
|
|
|
if (sb->s_first_meta_bg)
|
|
|
|
fprintf(f, "First meta block group: %u\n",
|
|
|
|
sb->s_first_meta_bg);
|
2002-10-26 01:29:55 +04:00
|
|
|
if (sb->s_mkfs_time) {
|
|
|
|
tm = sb->s_mkfs_time;
|
|
|
|
fprintf(f, "Filesystem created: %s", ctime(&tm));
|
|
|
|
}
|
|
|
|
tm = sb->s_mtime;
|
|
|
|
fprintf(f, "Last mount time: %s",
|
|
|
|
sb->s_mtime ? ctime(&tm) : "n/a\n");
|
2001-01-01 18:54:58 +03:00
|
|
|
tm = sb->s_wtime;
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Last write time: %s", ctime(&tm));
|
2001-01-01 18:54:58 +03:00
|
|
|
fprintf(f, "Mount count: %u\n", sb->s_mnt_count);
|
|
|
|
fprintf(f, "Maximum mount count: %d\n", sb->s_max_mnt_count);
|
|
|
|
tm = sb->s_lastcheck;
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Last checked: %s", ctime(&tm));
|
2001-01-01 18:54:58 +03:00
|
|
|
fprintf(f, "Check interval: %u (%s)\n", sb->s_checkinterval,
|
|
|
|
interval_string(sb->s_checkinterval));
|
|
|
|
if (sb->s_checkinterval)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
time_t next;
|
|
|
|
|
2001-01-01 18:54:58 +03:00
|
|
|
next = sb->s_lastcheck + sb->s_checkinterval;
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Next check after: %s", ctime(&next));
|
1997-04-26 17:21:57 +04:00
|
|
|
}
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Reserved blocks uid: ");
|
2001-01-01 18:54:58 +03:00
|
|
|
print_user(sb->s_def_resuid, f);
|
2000-08-15 00:13:32 +04:00
|
|
|
fprintf(f, "Reserved blocks gid: ");
|
2001-01-01 18:54:58 +03:00
|
|
|
print_group(sb->s_def_resgid, f);
|
|
|
|
if (sb->s_rev_level >= EXT2_DYNAMIC_REV) {
|
|
|
|
fprintf(f, "First inode: %d\n", sb->s_first_ino);
|
|
|
|
fprintf(f, "Inode size: %d\n", sb->s_inode_size);
|
1997-04-26 18:48:50 +04:00
|
|
|
}
|
2003-03-17 21:53:38 +03:00
|
|
|
if (!e2p_is_null_uuid(sb->s_journal_uuid))
|
2002-08-24 08:04:03 +04:00
|
|
|
fprintf(f, "Journal UUID: %s\n",
|
|
|
|
e2p_uuid2str(sb->s_journal_uuid));
|
2003-03-17 21:53:38 +03:00
|
|
|
if (sb->s_journal_inum)
|
|
|
|
fprintf(f, "Journal inode: %u\n",
|
|
|
|
sb->s_journal_inum);
|
|
|
|
if (sb->s_journal_dev)
|
|
|
|
fprintf(f, "Journal device: 0x%04x\n",
|
|
|
|
sb->s_journal_dev);
|
|
|
|
if (sb->s_last_orphan)
|
|
|
|
fprintf(f, "First orphan inode: %u\n",
|
|
|
|
sb->s_last_orphan);
|
|
|
|
if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) ||
|
|
|
|
sb->s_def_hash_version)
|
2002-08-24 08:04:03 +04:00
|
|
|
fprintf(f, "Default directory hash: %s\n",
|
|
|
|
e2p_hash2string(sb->s_def_hash_version));
|
2003-03-17 21:53:38 +03:00
|
|
|
if (!e2p_is_null_uuid(sb->s_hash_seed))
|
2002-08-24 08:04:03 +04:00
|
|
|
fprintf(f, "Directory Hash Seed: %s\n",
|
|
|
|
e2p_uuid2str(sb->s_hash_seed));
|
2003-08-21 08:40:26 +04:00
|
|
|
if (sb->s_jnl_backup_type) {
|
|
|
|
fprintf(f, "Journal backup: ");
|
|
|
|
switch (sb->s_jnl_backup_type) {
|
|
|
|
case 1:
|
|
|
|
fprintf(f, "inode blocks\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(f, "type %u\n", sb->s_jnl_backup_type);
|
|
|
|
}
|
|
|
|
}
|
1997-04-26 17:21:57 +04:00
|
|
|
}
|
1997-04-29 18:53:37 +04:00
|
|
|
|
2000-08-15 00:13:32 +04:00
|
|
|
void list_super (struct ext2_super_block * s)
|
|
|
|
{
|
|
|
|
list_super2(s, stdout);
|
|
|
|
}
|
1997-04-29 18:53:37 +04:00
|
|
|
|