1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* dumpe2fs.c - List the control structures of a second
|
|
|
|
* extended filesystem
|
|
|
|
*
|
|
|
|
* 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-30 00:17:09 +08:00
|
|
|
* Copyright 1995, 1996, 1997 by Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* History:
|
|
|
|
* 94/01/09 - Creation
|
|
|
|
* 94/02/27 - Ported to use the ext2fs library
|
|
|
|
*/
|
|
|
|
|
1997-04-26 22:00:26 +08:00
|
|
|
#ifdef HAVE_GETOPT_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <getopt.h>
|
Many files:
badblocks.c, dumpe2fs.c, e2label.c, mke2fs.c, tune2fs.c, uuidgen.c:
For platforms that don't define optarg.h, manually define optarg and
optind.
ChangeLog, main.c:
main.c: For platforms that don't define optarg.h, manually define
optarg and optind.
ChangeLog, unix.c:
unix.c: For platforms that don't define optarg.h, manually define
optarg and optind.
2000-04-04 00:22:35 +08:00
|
|
|
#else
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
1997-04-26 22:00:26 +08:00
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.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 "ext2fs/ext2fs.h"
|
|
|
|
#include "e2p/e2p.h"
|
2001-01-16 15:47:31 +08:00
|
|
|
#include "jfs_user.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
1997-04-26 22:37:06 +08:00
|
|
|
#define in_use(m, x) (ext2fs_test_bit ((x), (m)))
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
const char * program_name = "dumpe2fs";
|
|
|
|
char * device_name = NULL;
|
2000-08-14 23:32:11 +08:00
|
|
|
int opt_hex = 0;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
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
|
|
|
{
|
2001-05-03 22:43:43 +08:00
|
|
|
fprintf (stderr, _("Usage: %s [-bfhixV] [-ob superblock] "
|
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
|
|
|
"[-oB blocksize] device\n"), program_name);
|
1997-04-26 21:21:57 +08:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_free (unsigned long group, char * bitmap,
|
|
|
|
unsigned long nbytes, unsigned long offset)
|
|
|
|
{
|
|
|
|
int p = 0;
|
|
|
|
unsigned long i;
|
|
|
|
unsigned long j;
|
|
|
|
|
|
|
|
for (i = 0; i < nbytes; i++)
|
|
|
|
if (!in_use (bitmap, i))
|
|
|
|
{
|
|
|
|
if (p)
|
|
|
|
printf (", ");
|
|
|
|
if (i == nbytes - 1 || in_use (bitmap, i + 1))
|
2000-08-14 23:32:11 +08:00
|
|
|
printf (opt_hex ? "0x%04x" : "%lu",
|
|
|
|
group * nbytes + i + offset);
|
1997-04-26 21:21:57 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = i; j < nbytes && !in_use (bitmap, j);
|
|
|
|
j++)
|
|
|
|
;
|
2000-08-14 23:32:11 +08:00
|
|
|
printf (opt_hex ? "0x%04lx-0x%04lx" :
|
|
|
|
"%lu-%lu", group * nbytes + i + offset,
|
1997-04-26 21:21:57 +08:00
|
|
|
group * nbytes + (j - 1) + offset);
|
|
|
|
i = j - 1;
|
|
|
|
}
|
|
|
|
p = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void list_desc (ext2_filsys fs)
|
|
|
|
{
|
|
|
|
unsigned long i;
|
1997-04-30 01:48:10 +08:00
|
|
|
blk_t group_blk, next_blk;
|
1997-04-26 21:34:30 +08:00
|
|
|
char * block_bitmap = fs->block_map->bitmap;
|
|
|
|
char * inode_bitmap = fs->inode_map->bitmap;
|
2000-08-14 23:32:11 +08:00
|
|
|
int inode_blocks_per_group;
|
|
|
|
int group_desc_blocks;
|
|
|
|
|
|
|
|
inode_blocks_per_group = ((fs->super->s_inodes_per_group *
|
|
|
|
EXT2_INODE_SIZE(fs->super)) +
|
|
|
|
EXT2_BLOCK_SIZE(fs->super) - 1) /
|
|
|
|
EXT2_BLOCK_SIZE(fs->super);
|
|
|
|
group_desc_blocks = ((fs->super->s_blocks_count -
|
|
|
|
fs->super->s_first_data_block +
|
|
|
|
EXT2_BLOCKS_PER_GROUP(fs->super) - 1) /
|
|
|
|
EXT2_BLOCKS_PER_GROUP(fs->super) +
|
|
|
|
EXT2_DESC_PER_BLOCK(fs->super) - 1) /
|
|
|
|
EXT2_DESC_PER_BLOCK(fs->super);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
printf ("\n");
|
1997-04-30 01:48:10 +08:00
|
|
|
group_blk = fs->super->s_first_data_block;
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
|
next_blk = group_blk + fs->super->s_blocks_per_group;
|
|
|
|
if (next_blk > fs->super->s_blocks_count)
|
|
|
|
next_blk = fs->super->s_blocks_count;
|
2001-02-08 11:24:18 +08:00
|
|
|
printf (opt_hex ? _("Group %lu: (Blocks 0x%04x -- 0x%04x)\n"):
|
2000-08-14 23:32:11 +08:00
|
|
|
_("Group %lu: (Blocks %u -- %u)\n"), i,
|
1997-04-30 01:48:10 +08:00
|
|
|
group_blk, next_blk -1 );
|
2000-08-14 23:32:11 +08:00
|
|
|
if (ext2fs_bg_has_super (fs, i))
|
|
|
|
printf (opt_hex ? _(" %s Superblock at 0x%04x,"
|
|
|
|
" Group Descriptors at 0x%04x-0x%04x\n"):
|
|
|
|
_(" %s Superblock at %u,"
|
|
|
|
" Group Descriptors at %u-%u\n"),
|
|
|
|
i == 0 ? _("Primary") : _("Backup"),
|
|
|
|
group_blk, group_blk + 1,
|
|
|
|
group_blk + group_desc_blocks);
|
2001-02-08 11:24:18 +08:00
|
|
|
printf (opt_hex ? _(" Block bitmap at 0x%04x (+%d), "
|
|
|
|
"Inode bitmap at 0x%04x (+%d)\n "
|
|
|
|
"Inode table at 0x%04x-0x%04x (+%d)\n"):
|
2000-08-14 23:32:11 +08:00
|
|
|
_(" Block bitmap at %u (+%d), "
|
1997-04-30 01:48:10 +08:00
|
|
|
"Inode bitmap at %u (+%d)\n "
|
2000-09-12 01:01:35 +08:00
|
|
|
"Inode table at %u-%u (+%d)\n"),
|
1997-04-26 21:21:57 +08:00
|
|
|
fs->group_desc[i].bg_block_bitmap,
|
1997-04-30 01:48:10 +08:00
|
|
|
fs->group_desc[i].bg_block_bitmap - group_blk,
|
1997-04-26 21:21:57 +08:00
|
|
|
fs->group_desc[i].bg_inode_bitmap,
|
1997-04-30 01:48:10 +08:00
|
|
|
fs->group_desc[i].bg_inode_bitmap - group_blk,
|
|
|
|
fs->group_desc[i].bg_inode_table,
|
2000-08-14 23:32:11 +08:00
|
|
|
fs->group_desc[i].bg_inode_table +
|
2001-02-08 11:24:18 +08:00
|
|
|
inode_blocks_per_group - 1,
|
1997-04-30 01:48:10 +08:00
|
|
|
fs->group_desc[i].bg_inode_table - group_blk);
|
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
|
|
|
printf (_(" %d free blocks, %d free inodes, %d directories\n"),
|
1997-04-26 21:21:57 +08:00
|
|
|
fs->group_desc[i].bg_free_blocks_count,
|
|
|
|
fs->group_desc[i].bg_free_inodes_count,
|
|
|
|
fs->group_desc[i].bg_used_dirs_count);
|
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
|
|
|
printf (_(" Free blocks: "));
|
1997-04-26 21:21:57 +08:00
|
|
|
print_free (i, block_bitmap, fs->super->s_blocks_per_group,
|
|
|
|
fs->super->s_first_data_block);
|
|
|
|
block_bitmap += fs->super->s_blocks_per_group / 8;
|
|
|
|
printf ("\n");
|
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
|
|
|
printf (_(" Free inodes: "));
|
1997-04-26 21:21:57 +08:00
|
|
|
print_free (i, inode_bitmap, fs->super->s_inodes_per_group, 1);
|
|
|
|
inode_bitmap += fs->super->s_inodes_per_group / 8;
|
|
|
|
printf ("\n");
|
1997-04-30 01:48:10 +08:00
|
|
|
group_blk = next_blk;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void list_bad_blocks(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
badblocks_list bb_list = 0;
|
|
|
|
badblocks_iterate bb_iter;
|
|
|
|
blk_t blk;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
retval = ext2fs_read_bb_inode(fs, &bb_list);
|
|
|
|
if (retval) {
|
|
|
|
com_err("ext2fs_read_bb_inode", retval, "");
|
|
|
|
exit(1);
|
|
|
|
}
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
|
1997-04-26 21:21:57 +08:00
|
|
|
if (retval) {
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
com_err("ext2fs_badblocks_list_iterate_begin", retval,
|
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
|
|
|
_("while printing bad block list"));
|
1997-04-26 21:21:57 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
if (ext2fs_badblocks_list_iterate(bb_iter, &blk))
|
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
|
|
|
printf(_("Bad blocks: %d"), blk);
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
|
1997-04-26 22:00:26 +08:00
|
|
|
printf(", %d", blk);
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
ext2fs_badblocks_list_iterate_end(bb_iter);
|
1997-04-26 21:21:57 +08:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
1997-04-26 21:34:30 +08:00
|
|
|
static void dump_bad_blocks(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
badblocks_list bb_list = 0;
|
|
|
|
badblocks_iterate bb_iter;
|
|
|
|
blk_t blk;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
retval = ext2fs_read_bb_inode(fs, &bb_list);
|
|
|
|
if (retval) {
|
|
|
|
com_err("ext2fs_read_bb_inode", retval, "");
|
|
|
|
exit(1);
|
|
|
|
}
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
|
1997-04-26 21:34:30 +08:00
|
|
|
if (retval) {
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
com_err("ext2fs_badblocks_list_iterate_begin", retval,
|
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
|
|
|
_("while printing bad block list"));
|
1997-04-26 21:34:30 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
|
1997-04-26 22:00:26 +08:00
|
|
|
printf("%d\n", blk);
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
ext2fs_badblocks_list_iterate_end(bb_iter);
|
1997-04-29 22:53:37 +08:00
|
|
|
}
|
1997-04-26 21:34:30 +08:00
|
|
|
|
2001-01-16 15:47:31 +08:00
|
|
|
static void print_journal_information(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
char buf[1024];
|
|
|
|
char str[80];
|
|
|
|
int i;
|
|
|
|
journal_superblock_t *jsb;
|
|
|
|
|
|
|
|
/* Get the journal superblock */
|
2001-01-18 09:44:19 +08:00
|
|
|
if ((retval = io_channel_read_blk(fs->io, fs->super->s_first_data_block+1, -1024, buf))) {
|
2001-01-16 15:47:31 +08:00
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while reading journal superblock"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
jsb = (journal_superblock_t *) buf;
|
|
|
|
if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
|
|
|
|
(jsb->s_header.h_blocktype !=
|
|
|
|
(unsigned) ntohl(JFS_SUPERBLOCK_V2))) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("Couldn't find journal superblock magic numbers"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("\n", stdout);
|
|
|
|
printf("Journal block size: %d\n", ntohl(jsb->s_blocksize));
|
|
|
|
printf("Journal length: %d\n", ntohl(jsb->s_maxlen));
|
|
|
|
printf("Journal first block: %d\n", ntohl(jsb->s_first));
|
|
|
|
printf("Journal sequence: 0x%08x\n", ntohl(jsb->s_sequence));
|
|
|
|
printf("Journal start: %d\n", ntohl(jsb->s_start));
|
|
|
|
printf("Journal number of users: %d\n", ntohl(jsb->s_nr_users));
|
|
|
|
for (i=0; i < ntohl(jsb->s_nr_users); i++) {
|
|
|
|
if (i)
|
|
|
|
printf(" ");
|
|
|
|
else
|
|
|
|
printf("Journal users: ");
|
|
|
|
uuid_unparse(&jsb->s_users[i*16], str);
|
|
|
|
printf("%s\n", str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-09-16 10:13:52 +08:00
|
|
|
int main (int argc, char ** argv)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
ext2_filsys fs;
|
1997-04-26 21:34:30 +08:00
|
|
|
int print_badblocks = 0;
|
1999-06-18 08:48:41 +08:00
|
|
|
int use_superblock = 0;
|
|
|
|
int use_blocksize = 0;
|
2001-05-03 22:43:43 +08:00
|
|
|
int image_dump = 0;
|
1999-09-15 04:11:19 +08:00
|
|
|
int force = 0;
|
2001-01-16 15:47:31 +08:00
|
|
|
int flags;
|
1999-09-15 04:11:19 +08:00
|
|
|
int header_only = 0;
|
1997-04-29 22:53:37 +08:00
|
|
|
int big_endian;
|
1997-10-25 11:49:49 +08:00
|
|
|
int c;
|
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
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
setlocale(LC_MESSAGES, "");
|
|
|
|
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
|
|
|
|
textdomain(NLS_CAT_NAME);
|
|
|
|
#endif
|
1997-04-29 23:29:49 +08:00
|
|
|
initialize_ext2_error_table();
|
2001-08-28 00:44:23 +08:00
|
|
|
fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION,
|
|
|
|
E2FSPROGS_DATE);
|
1997-04-26 21:21:57 +08:00
|
|
|
if (argc && *argv)
|
|
|
|
program_name = *argv;
|
1997-04-26 21:34:30 +08:00
|
|
|
|
2001-05-03 22:43:43 +08:00
|
|
|
while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) {
|
1997-04-26 21:34:30 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
|
|
|
print_badblocks++;
|
|
|
|
break;
|
1999-09-15 04:11:19 +08:00
|
|
|
case 'f':
|
|
|
|
force++;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
header_only++;
|
|
|
|
break;
|
2001-05-03 22:43:43 +08:00
|
|
|
case 'i':
|
|
|
|
image_dump++;
|
|
|
|
break;
|
1999-06-18 08:48:41 +08:00
|
|
|
case 'o':
|
|
|
|
if (optarg[0] == 'b')
|
|
|
|
use_superblock = atoi(optarg+1);
|
|
|
|
else if (optarg[0] == 'B')
|
|
|
|
use_blocksize = atoi(optarg+1);
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
break;
|
1997-04-29 23:29:49 +08:00
|
|
|
case 'V':
|
|
|
|
/* Print version number and exit */
|
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, _("\tUsing %s\n"),
|
1997-04-29 23:29:49 +08:00
|
|
|
error_message(EXT2_ET_BASE));
|
|
|
|
exit(0);
|
2000-08-14 23:32:11 +08:00
|
|
|
case 'x':
|
|
|
|
opt_hex=1;
|
|
|
|
break;
|
1997-04-26 21:34:30 +08:00
|
|
|
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:34:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind > argc - 1)
|
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:34:30 +08:00
|
|
|
device_name = argv[optind++];
|
1999-06-18 08:48:41 +08:00
|
|
|
if (use_superblock && !use_blocksize)
|
|
|
|
use_blocksize = 1024;
|
2001-01-16 15:47:31 +08:00
|
|
|
flags = EXT2_FLAG_JOURNAL_DEV_OK;
|
|
|
|
if (force)
|
|
|
|
flags |= EXT2_FLAG_FORCE;
|
2001-05-03 22:43:43 +08:00
|
|
|
if (image_dump)
|
|
|
|
flags |= EXT2_FLAG_IMAGE_FILE;
|
|
|
|
|
2001-01-16 15:47:31 +08:00
|
|
|
retval = ext2fs_open (device_name, flags, use_superblock,
|
|
|
|
use_blocksize, unix_io_manager, &fs);
|
1997-04-26 21:34:30 +08:00
|
|
|
if (retval) {
|
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, retval, _("while trying to open %s"),
|
1997-04-26 21:21:57 +08:00
|
|
|
device_name);
|
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
|
|
|
printf (_("Couldn't find valid filesystem superblock.\n"));
|
1997-04-26 21:21:57 +08:00
|
|
|
exit (1);
|
|
|
|
}
|
1997-04-26 21:34:30 +08:00
|
|
|
if (print_badblocks) {
|
|
|
|
dump_bad_blocks(fs);
|
|
|
|
} else {
|
1999-09-15 04:11:19 +08:00
|
|
|
big_endian = ((fs->flags & EXT2_FLAG_SWAP_BYTES) != 0);
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 08:12:04 +08:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
big_endian = !big_endian;
|
|
|
|
#endif
|
1999-09-15 04:11:19 +08:00
|
|
|
if (big_endian)
|
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
|
|
|
printf(_("Note: This is a byte-swapped filesystem\n"));
|
1999-09-15 04:11:19 +08:00
|
|
|
list_super (fs->super);
|
2001-01-16 15:47:31 +08:00
|
|
|
if (fs->super->s_feature_incompat &
|
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
|
|
|
|
print_journal_information(fs);
|
|
|
|
ext2fs_close(fs);
|
|
|
|
exit(0);
|
|
|
|
}
|
1999-09-15 04:11:19 +08:00
|
|
|
list_bad_blocks (fs);
|
|
|
|
if (header_only) {
|
|
|
|
ext2fs_close (fs);
|
|
|
|
exit (0);
|
|
|
|
}
|
1997-04-26 21:34:30 +08:00
|
|
|
retval = ext2fs_read_bitmaps (fs);
|
|
|
|
if (retval) {
|
|
|
|
com_err (program_name, retval,
|
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
|
|
|
_("while trying to read the bitmaps"),
|
1997-04-26 21:34:30 +08:00
|
|
|
device_name);
|
|
|
|
ext2fs_close (fs);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
list_desc (fs);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
ext2fs_close (fs);
|
|
|
|
exit (0);
|
|
|
|
}
|