Imported reiserfsprogs-3.6.19
This commit is contained in:
1 parent
3078c83c48
commit
0ed773997f
34 files changed
+724
-560
No files matched your search
+353
-332
@@ -45,6 +45,7 @@ Options:\n\
|
||||
-J\tsearch block numbers in the journal\n\
|
||||
-t\tstat the device\n\
|
||||
-v\tverboes unpack, prints the block number of every block being unpacked\n\
|
||||
-Z\tzero all data.
|
||||
|
||||
To build a map of a file blocks by name:
|
||||
debugreiserfs device -a mapfile -n filename
|
||||
@@ -73,55 +74,59 @@ static void print_disk_tree (reiserfs_filsys_t * fs, unsigned long block_nr)
|
||||
static int level = -1;
|
||||
|
||||
if (level == -1)
|
||||
level = get_sb_tree_height (fs->fs_ondisk_sb);
|
||||
level = get_sb_tree_height (fs->fs_ondisk_sb);
|
||||
|
||||
bh = bread (fs->fs_dev, block_nr, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
die ("Could not read block %lu\n", block_nr);
|
||||
die ("Could not read block %lu\n", block_nr);
|
||||
}
|
||||
level --;
|
||||
|
||||
if (level < 1)
|
||||
die ("level too small");
|
||||
die ("level too small");
|
||||
|
||||
if (level != get_blkh_level (B_BLK_HEAD (bh))) {
|
||||
printf ("%d expected, %d found in %lu\n", level, get_blkh_level (B_BLK_HEAD (bh)),
|
||||
bh->b_blocknr);
|
||||
printf ("%d expected, %d found in %lu\n", level,
|
||||
get_blkh_level (B_BLK_HEAD (bh)), bh->b_blocknr);
|
||||
}
|
||||
|
||||
if (is_internal_node (bh)) {
|
||||
struct disk_child * dc;
|
||||
struct disk_child * dc;
|
||||
|
||||
g_stat_info.nr_internals ++;
|
||||
print_block (stdout, fs, bh, data (fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
g_stat_info.nr_internals ++;
|
||||
print_block (stdout, fs, bh,
|
||||
data(fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
|
||||
dc = B_N_CHILD (bh, 0);
|
||||
count = B_NR_ITEMS(bh);
|
||||
for (i = 0; i <= count; i++, dc++)
|
||||
print_disk_tree (fs, get_dc_child_blocknr (dc));
|
||||
|
||||
dc = B_N_CHILD (bh, 0);
|
||||
count = B_NR_ITEMS(bh);
|
||||
for (i = 0; i <= count; i++, dc++)
|
||||
print_disk_tree (fs, get_dc_child_blocknr (dc));
|
||||
} else if (is_leaf_node (bh)) {
|
||||
struct item_head *ih;
|
||||
|
||||
g_stat_info.nr_leaves ++;
|
||||
print_block (stdout, fs, bh, data (fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
count = leaf_item_number_estimate(bh);
|
||||
for (i = 0; i < count; i++, ih++) {
|
||||
if (is_indirect_ih(ih)) {
|
||||
__u32 * ind_item = (__u32 *)B_I_PITEM (bh, ih);
|
||||
|
||||
for (j = 0; j < (int)I_UNFM_NUM (ih); j ++) {
|
||||
if (d32_get (ind_item, j)) {
|
||||
g_stat_info.nr_unformatted += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
struct item_head *ih;
|
||||
|
||||
g_stat_info.nr_leaves ++;
|
||||
print_block (stdout, fs, bh,
|
||||
data (fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
count = leaf_item_number_estimate(bh);
|
||||
for (i = 0; i < count; i++, ih++) {
|
||||
if (is_indirect_ih(ih)) {
|
||||
__u32 * ind_item = (__u32 *)B_I_PITEM (bh, ih);
|
||||
|
||||
for (j = 0; j < (int)I_UNFM_NUM (ih); j ++) {
|
||||
if (d32_get (ind_item, j)) {
|
||||
g_stat_info.nr_unformatted += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_block (stdout, fs, bh, data (fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
reiserfs_warning (stdout, "print_disk_tree: bad block type (%b)\n", bh);
|
||||
print_block (stdout, fs, bh,
|
||||
data (fs)->options & PRINT_TREE_DETAILS, -1, -1);
|
||||
|
||||
reiserfs_warning (stdout, "print_disk_tree: bad block "
|
||||
"type (%b)\n", bh);
|
||||
}
|
||||
brelse (bh);
|
||||
level ++;
|
||||
@@ -149,8 +154,12 @@ static void print_disk_blocks (reiserfs_filsys_t * fs)
|
||||
}
|
||||
|
||||
type = who_is_this (bh->b_data, bh->b_size);
|
||||
if (type != THE_UNKNOWN)
|
||||
print_block (stdout, fs, bh, PRINT_TREE_DETAILS | PRINT_DIRECT_ITEMS, -1, -1);
|
||||
if (type != THE_UNKNOWN) {
|
||||
print_block (stdout, fs, bh,
|
||||
PRINT_TREE_DETAILS | PRINT_DIRECT_ITEMS,
|
||||
-1, -1);
|
||||
}
|
||||
|
||||
if (type == THE_INTERNAL)
|
||||
g_stat_info.nr_internals ++;
|
||||
else if (type == THE_LEAF || type == HAS_IH_ARRAY)
|
||||
@@ -172,44 +181,52 @@ static void print_one_block (reiserfs_filsys_t * fs, unsigned long block)
|
||||
unsigned long bm_block;
|
||||
|
||||
if (spread_bitmaps (fs))
|
||||
bm_block = ( block / (fs->fs_blocksize * 8) ) ?
|
||||
(block / (fs->fs_blocksize * 8)) * (fs->fs_blocksize * 8) :
|
||||
bm_block =
|
||||
( block / (fs->fs_blocksize * 8) ) ?
|
||||
(block / (fs->fs_blocksize * 8)) *
|
||||
(fs->fs_blocksize * 8) :
|
||||
fs->fs_super_bh->b_blocknr + 1;
|
||||
else
|
||||
bm_block = fs->fs_super_bh->b_blocknr + 1 + (block / (fs->fs_blocksize * 8));
|
||||
|
||||
bm_block = fs->fs_super_bh->b_blocknr + 1 +
|
||||
(block / (fs->fs_blocksize * 8));
|
||||
|
||||
bm_bh = bread (fs->fs_dev, bm_block, fs->fs_blocksize);
|
||||
if (bm_bh) {
|
||||
if ( misc_test_bit((block % (fs->fs_blocksize * 8)), bm_bh->b_data) )
|
||||
fprintf (stderr, "%lu is used in ondisk bitmap\n", block);
|
||||
else
|
||||
fprintf (stderr, "%lu is free in ondisk bitmap\n", block);
|
||||
if (misc_test_bit((block % (fs->fs_blocksize * 8)),
|
||||
bm_bh->b_data))
|
||||
{
|
||||
fprintf (stderr, "%lu is used in "
|
||||
"ondisk bitmap\n", block);
|
||||
} else {
|
||||
fprintf (stderr, "%lu is free in "
|
||||
"ondisk bitmap\n", block);
|
||||
}
|
||||
|
||||
brelse (bm_bh);
|
||||
}
|
||||
} else {
|
||||
if (reiserfs_bitmap_test_bit (fs->fs_bitmap2, block))
|
||||
fprintf (stderr, "%lu is used in ondisk bitmap\n", block);
|
||||
fprintf (stderr, "%lu is used in ondisk bitmap\n", block);
|
||||
else
|
||||
fprintf (stderr, "%lu is free in ondisk bitmap\n", block);
|
||||
fprintf (stderr, "%lu is free in ondisk bitmap\n", block);
|
||||
}
|
||||
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("print_one_block: bread failed\n");
|
||||
return;
|
||||
printf ("print_one_block: bread failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (debug_mode (fs) == DO_PACK) {
|
||||
pack_one_block (fs, bh->b_blocknr);
|
||||
brelse (bh);
|
||||
return;
|
||||
pack_one_block (fs, bh->b_blocknr);
|
||||
brelse (bh);
|
||||
return;
|
||||
}
|
||||
|
||||
if (who_is_this (bh->b_data, bh->b_size) != THE_UNKNOWN)
|
||||
print_block (stdout, fs, bh, PRINT_TREE_DETAILS, -1, -1);
|
||||
print_block (stdout, fs, bh, PRINT_TREE_DETAILS, -1, -1);
|
||||
else
|
||||
printf ("Looks like unformatted\n");
|
||||
printf ("Looks like unformatted\n");
|
||||
brelse (bh);
|
||||
return;
|
||||
}
|
||||
@@ -225,7 +242,8 @@ char * badblocks_file;
|
||||
char * corruption_list_file;
|
||||
char *program_name;
|
||||
|
||||
static char * parse_options (struct debugreiserfs_data * data, int argc, char * argv [])
|
||||
static char * parse_options (struct debugreiserfs_data * data,
|
||||
int argc, char * argv [])
|
||||
{
|
||||
int c;
|
||||
char * tmp;
|
||||
@@ -240,161 +258,166 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
|
||||
else
|
||||
program_name = argv[ 0 ];
|
||||
|
||||
while ((c = getopt (argc, argv, "a:b:C:F:SU1:pkn:Nfr:dDomj:JqtZl:LVB:uv")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a': /* -r will read this, -n and -N will write to it */
|
||||
asprintf (&data->map_file, "%s", optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
/* will load bitmap from a file and read only blocks
|
||||
marked in it. This is for -p and -k */
|
||||
asprintf (&data->input_bitmap, "%s", optarg);
|
||||
data->scan_area = EXTERN_BITMAP;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
/* have debugreiserfs -p or -k to read all the device */
|
||||
data->scan_area = ALL_BLOCKS;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
/* have debugreiserfs -p or -k to read unused blocks only */
|
||||
data->scan_area = UNUSED_BLOCKS;
|
||||
break;
|
||||
|
||||
case '1': /* print a single node */
|
||||
data->block = strtol (optarg, &tmp, 0);
|
||||
if (*tmp)
|
||||
die ("parse_options: bad block number");
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
data->mode = DO_CORRUPT_ONE;
|
||||
data->block = strtol (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
die ("parse_options: bad block number");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
data->mode = DO_CORRUPT_FILE;
|
||||
if (asprintf (&corruption_list_file, "%s", optarg) == -1 ) {
|
||||
die ("parse_options: bad list corruption file");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
data->mode = DO_PACK;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
data->mode = DO_UNPACK;
|
||||
break;
|
||||
while ((c = getopt (argc, argv, "a:b:C:F:SU1:pkn:Nfr:dDomj:JqtZl:LVB:uv"))
|
||||
!= EOF)
|
||||
{
|
||||
switch (c) {
|
||||
case 'a': /* -r will read this, -n and -N will write to it */
|
||||
asprintf (&data->map_file, "%s", optarg);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
data->mode = DO_STAT;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
/* read the device and print reiserfs blocks which contain defined key */
|
||||
data->mode = DO_SCAN;
|
||||
break;
|
||||
|
||||
case 'n': /* scan for names matching a specified pattern */
|
||||
data->mode = DO_SCAN_FOR_NAME;
|
||||
data->pattern = optarg;
|
||||
/*asprintf (&data->pattern, "%s", optarg);*/
|
||||
break;
|
||||
|
||||
case 'N': /* search name in the tree */
|
||||
data->mode = DO_LOOK_FOR_NAME;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
data->mode = DO_FILE_MAP;
|
||||
break;
|
||||
case 'b':
|
||||
/* will load bitmap from a file and read only blocks
|
||||
marked in it. This is for -p and -k */
|
||||
asprintf (&data->input_bitmap, "%s", optarg);
|
||||
data->scan_area = EXTERN_BITMAP;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
asprintf (&data->recovery_file, "%s", optarg);
|
||||
data->mode = DO_RECOVER;
|
||||
break;
|
||||
case 'S':
|
||||
/* have debugreiserfs -p or -k to read all the device */
|
||||
data->scan_area = ALL_BLOCKS;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
/* print leaf details from internal tree */
|
||||
data->options |= PRINT_TREE_DETAILS;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
/* print leaf details accordingly the bitmap - can be used with -S */
|
||||
data->options |= PRINT_DETAILS;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
/* print objectid map */
|
||||
data->options |= PRINT_OBJECTID_MAP;
|
||||
break;
|
||||
|
||||
case 'm': /* print a block map */
|
||||
case 'M': /* print a block map with details */
|
||||
data->options |= PRINT_BITMAP;
|
||||
break;
|
||||
|
||||
case 'j': /* -j must have a parameter */
|
||||
data->options |= PRINT_JOURNAL;
|
||||
data->journal_device_name = optarg;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
data->options |= PRINT_JOURNAL_HEADER;
|
||||
break;
|
||||
|
||||
case 'R': /* read block numbers from stdin and look for them in the
|
||||
journal */
|
||||
data->mode = DO_SCAN_JOURNAL;
|
||||
data->JJ ++;
|
||||
break;
|
||||
|
||||
case 'B': /*disabled for a while*/
|
||||
asprintf (&badblocks_file, "%s", optarg);
|
||||
data->mode = DO_EXTRACT_BADBLOCKS;
|
||||
break;
|
||||
case 'q':
|
||||
/* this makes packing to not show speed info during -p or -P */
|
||||
data->options |= BE_QUIET;
|
||||
break;
|
||||
case 'Z':
|
||||
data->mode = DO_ZERO_BITMAP;
|
||||
break;
|
||||
|
||||
case 'l': /* --logfile */
|
||||
data->log_file_name = optarg;
|
||||
data->log = fopen (optarg, "w");
|
||||
if (!data->log)
|
||||
fprintf (stderr, "debugreiserfs: Cannot not open \'%s\': %s",
|
||||
optarg, strerror(errno));
|
||||
break;
|
||||
case 'L' :
|
||||
/* random fs corruption */
|
||||
data->mode = DO_RANDOM_CORRUPTION;
|
||||
break;
|
||||
case 'V':
|
||||
data->mode = DO_NOTHING;
|
||||
break;
|
||||
case 'v':
|
||||
data->options |= BE_VERBOSE;
|
||||
break;
|
||||
}
|
||||
case 'U':
|
||||
/* have debugreiserfs -p or -k to read unused blocks only */
|
||||
data->scan_area = UNUSED_BLOCKS;
|
||||
break;
|
||||
|
||||
case '1': /* print a single node */
|
||||
data->block = strtol (optarg, &tmp, 0);
|
||||
if (*tmp)
|
||||
die ("parse_options: bad block number");
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
data->mode = DO_CORRUPT_ONE;
|
||||
data->block = strtol (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
die ("parse_options: bad block number");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
data->mode = DO_CORRUPT_FILE;
|
||||
if (asprintf (&corruption_list_file, "%s", optarg) == -1 ) {
|
||||
die ("parse_options: bad list corruption file");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
data->mode = DO_PACK;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
data->mode = DO_UNPACK;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
data->mode = DO_STAT;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
/* read the device and print reiserfs blocks which contain
|
||||
defined key */
|
||||
data->mode = DO_SCAN;
|
||||
break;
|
||||
|
||||
case 'n': /* scan for names matching a specified pattern */
|
||||
data->mode = DO_SCAN_FOR_NAME;
|
||||
data->pattern = optarg;
|
||||
/*asprintf (&data->pattern, "%s", optarg);*/
|
||||
break;
|
||||
|
||||
case 'N': /* search name in the tree */
|
||||
data->mode = DO_LOOK_FOR_NAME;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
data->mode = DO_FILE_MAP;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
asprintf (&data->recovery_file, "%s", optarg);
|
||||
data->mode = DO_RECOVER;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
/* print leaf details from internal tree */
|
||||
data->options |= PRINT_TREE_DETAILS;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
/* print leaf details accordingly the bitmap - can be used
|
||||
with -S */
|
||||
data->options |= PRINT_DETAILS;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
/* print objectid map */
|
||||
data->options |= PRINT_OBJECTID_MAP;
|
||||
break;
|
||||
|
||||
case 'm': /* print a block map */
|
||||
case 'M': /* print a block map with details */
|
||||
data->options |= PRINT_BITMAP;
|
||||
break;
|
||||
|
||||
case 'j': /* -j must have a parameter */
|
||||
data->options |= PRINT_JOURNAL;
|
||||
data->journal_device_name = optarg;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
data->options |= PRINT_JOURNAL_HEADER;
|
||||
break;
|
||||
|
||||
case 'R': /* read block numbers from stdin and look for them in the
|
||||
journal */
|
||||
data->mode = DO_SCAN_JOURNAL;
|
||||
data->JJ ++;
|
||||
break;
|
||||
|
||||
case 'B': /*disabled for a while*/
|
||||
asprintf (&badblocks_file, "%s", optarg);
|
||||
data->mode = DO_EXTRACT_BADBLOCKS;
|
||||
break;
|
||||
case 'q':
|
||||
/* this makes packing to not show speed info during -p or -P */
|
||||
data->options |= BE_QUIET;
|
||||
break;
|
||||
case 'Z':
|
||||
data->mode = DO_ZERO;
|
||||
break;
|
||||
|
||||
case 'l': /* --logfile */
|
||||
data->log_file_name = optarg;
|
||||
data->log = fopen (optarg, "w");
|
||||
if (!data->log) {
|
||||
fprintf (stderr, "debugreiserfs: Cannot not open "
|
||||
"\'%s\': %s", optarg, strerror(errno));
|
||||
}
|
||||
break;
|
||||
case 'L' :
|
||||
/* random fs corruption */
|
||||
data->mode = DO_RANDOM_CORRUPTION;
|
||||
break;
|
||||
case 'V':
|
||||
data->mode = DO_NOTHING;
|
||||
break;
|
||||
case 'v':
|
||||
data->options |= BE_VERBOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (data->mode == DO_NOTHING) {
|
||||
print_banner(program_name);
|
||||
exit(0);
|
||||
print_banner(program_name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (optind != argc - 1)
|
||||
/* only one non-option argument is permitted */
|
||||
print_usage_and_exit();
|
||||
/* only one non-option argument is permitted */
|
||||
print_usage_and_exit();
|
||||
|
||||
print_banner(program_name);
|
||||
|
||||
@@ -407,9 +430,9 @@ void pack_partition (reiserfs_filsys_t * fs);
|
||||
static void do_pack (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (certain_block (fs))
|
||||
pack_one_block (fs, certain_block (fs));
|
||||
pack_one_block (fs, certain_block (fs));
|
||||
else
|
||||
pack_partition (fs);
|
||||
pack_partition (fs);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -434,51 +457,49 @@ static void init_bitmap (reiserfs_filsys_t * fs)
|
||||
|
||||
|
||||
if (reiserfs_open_ondisk_bitmap (fs) < 0)
|
||||
reiserfs_panic ("Could not open ondisk bitmap");
|
||||
reiserfs_exit (1, "Could not open ondisk bitmap");
|
||||
|
||||
block_count = get_sb_block_count (fs->fs_ondisk_sb);
|
||||
|
||||
switch (scan_area (fs)) {
|
||||
case ALL_BLOCKS:
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_fill (input_bitmap (fs));
|
||||
reiserfs_warning (stderr, "Whole device (%d blocks) is to be scanned\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_fill (input_bitmap (fs));
|
||||
reiserfs_warning (stderr, "Whole device (%d blocks) is to be scanned\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
case USED_BLOCKS:
|
||||
reiserfs_warning (stderr, "Loading on-disk bitmap .. ");
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_copy (input_bitmap (fs), fs->fs_bitmap2);
|
||||
reiserfs_warning (stderr, "%d bits set - done\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
|
||||
reiserfs_warning (stderr, "Loading on-disk bitmap .. ");
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_copy (input_bitmap (fs), fs->fs_bitmap2);
|
||||
reiserfs_warning (stderr, "%d bits set - done\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
case UNUSED_BLOCKS:
|
||||
reiserfs_warning (stderr, "Loading on-disk bitmap .. ");
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_copy (input_bitmap (fs), fs->fs_bitmap2);
|
||||
reiserfs_bitmap_invert (input_bitmap (fs));
|
||||
reiserfs_warning (stderr, "%d bits set - done\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
|
||||
reiserfs_warning (stderr, "Loading on-disk bitmap .. ");
|
||||
input_bitmap (fs) = reiserfs_create_bitmap (block_count);
|
||||
reiserfs_bitmap_copy (input_bitmap (fs), fs->fs_bitmap2);
|
||||
reiserfs_bitmap_invert (input_bitmap (fs));
|
||||
reiserfs_warning (stderr, "%d bits set - done\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
break;
|
||||
case EXTERN_BITMAP:
|
||||
fp = fopen (input_bitmap_file_name(fs), "r");
|
||||
if (!fp)
|
||||
reiserfs_panic ("init_bitmap: could not load bitmap: %m\n");
|
||||
|
||||
input_bitmap (fs) = reiserfs_bitmap_load (fp);
|
||||
if (!input_bitmap (fs))
|
||||
reiserfs_panic ("could not load fitmap from \"%s\"",
|
||||
input_bitmap_file_name(fs));
|
||||
reiserfs_warning (stderr, "%d blocks marked in the given bitmap\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
fclose (fp);
|
||||
break;
|
||||
|
||||
fp = fopen (input_bitmap_file_name(fs), "r");
|
||||
if (!fp) {
|
||||
reiserfs_exit (1, "init_bitmap: could not load bitmap: %m\n");
|
||||
}
|
||||
|
||||
input_bitmap (fs) = reiserfs_bitmap_load (fp);
|
||||
if (!input_bitmap (fs)) {
|
||||
reiserfs_exit (1, "could not load fitmap from \"%s\"",
|
||||
input_bitmap_file_name(fs));
|
||||
}
|
||||
reiserfs_warning (stderr, "%d blocks marked in the given bitmap\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
fclose (fp);
|
||||
break;
|
||||
default:
|
||||
reiserfs_panic ("No area to scan specified");
|
||||
reiserfs_panic ("No area to scan specified");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,17 +507,20 @@ static void init_bitmap (reiserfs_filsys_t * fs)
|
||||
static void do_dump_tree (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (certain_block (fs)) {
|
||||
print_one_block (fs, certain_block (fs));
|
||||
return;
|
||||
print_one_block (fs, certain_block (fs));
|
||||
return;
|
||||
}
|
||||
|
||||
if (data (fs)->options & PRINT_JOURNAL || data (fs)->options & PRINT_JOURNAL_HEADER) {
|
||||
if (!reiserfs_journal_opened (fs) &&
|
||||
reiserfs_open_journal (fs, data (fs)->journal_device_name, O_RDONLY))
|
||||
{
|
||||
printf ("Could not open journal\n");
|
||||
return;
|
||||
}
|
||||
if (((data (fs)->options & PRINT_JOURNAL) ||
|
||||
(data (fs)->options & PRINT_JOURNAL_HEADER)) &&
|
||||
!reiserfs_journal_opened (fs))
|
||||
{
|
||||
if (reiserfs_open_journal (fs, data(fs)->journal_device_name,
|
||||
O_RDONLY))
|
||||
{
|
||||
printf ("Could not open journal\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_filesystem_state (stdout, fs);
|
||||
@@ -517,19 +541,24 @@ static void do_dump_tree (reiserfs_filsys_t * fs)
|
||||
if (data (fs)->options & PRINT_DETAILS)
|
||||
init_bitmap (fs);
|
||||
|
||||
if (data (fs)->options & PRINT_DETAILS || data (fs)->options & PRINT_TREE_DETAILS) {
|
||||
if (data (fs)->options & PRINT_DETAILS) {
|
||||
print_disk_blocks (fs);
|
||||
printf("The '%s' device with reiserfs has:\n", fs->fs_file_name);
|
||||
} else {
|
||||
print_disk_tree (fs, get_sb_root_block (fs->fs_ondisk_sb));
|
||||
printf("The internal reiserfs tree has:\n");
|
||||
}
|
||||
|
||||
/* print the statistic */
|
||||
printf ("\t%d internal + %d leaves + %d unformatted nodes = %d blocks\n",
|
||||
g_stat_info.nr_internals, g_stat_info.nr_leaves, g_stat_info.nr_unformatted,
|
||||
g_stat_info.nr_internals + g_stat_info.nr_leaves + g_stat_info.nr_unformatted);
|
||||
if (data (fs)->options & PRINT_DETAILS ||
|
||||
data (fs)->options & PRINT_TREE_DETAILS)
|
||||
{
|
||||
if (data (fs)->options & PRINT_DETAILS) {
|
||||
print_disk_blocks (fs);
|
||||
printf("The '%s' device with reiserfs has:\n",
|
||||
fs->fs_file_name);
|
||||
} else {
|
||||
print_disk_tree (fs, get_sb_root_block(fs->fs_ondisk_sb));
|
||||
printf("The internal reiserfs tree has:\n");
|
||||
}
|
||||
|
||||
/* print the statistic */
|
||||
printf ("\t%d internal + %d leaves + %d "
|
||||
"unformatted nodes = %d blocks\n",
|
||||
g_stat_info.nr_internals, g_stat_info.nr_leaves,
|
||||
g_stat_info.nr_unformatted, g_stat_info.nr_internals +
|
||||
g_stat_info.nr_leaves + g_stat_info.nr_unformatted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,9 +584,8 @@ void extract_badblock_list () {
|
||||
FILE *fd;
|
||||
|
||||
if (!(fd = fopen (badblocks_file, "w"))) {
|
||||
reiserfs_warning (stderr, "debugreiserfs: could not open badblock file %s\n",
|
||||
badblocks_file);
|
||||
exit (1);
|
||||
reiserfs_exit(1, "debugreiserfs: could not open badblock file %s\n",
|
||||
badblocks_file);
|
||||
}
|
||||
|
||||
badblock_list(fs, callback_badblock_print, fd);
|
||||
@@ -586,9 +614,8 @@ void do_corrupt_blocks (reiserfs_filsys_t * fs)
|
||||
|
||||
fd = fopen (corruption_list_file, "r");
|
||||
if (fd == NULL) {
|
||||
reiserfs_warning (stderr, "debugreiserfs: could not open corruption_list_file %s\n",
|
||||
corruption_list_file);
|
||||
exit (1);
|
||||
reiserfs_exit(1, "debugreiserfs: could not open corruption "
|
||||
"list file %s\n", corruption_list_file);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
@@ -615,7 +642,7 @@ void do_corrupt_blocks (reiserfs_filsys_t * fs)
|
||||
return;
|
||||
}
|
||||
|
||||
void zero_bitmap_blocks(reiserfs_filsys_t * fs) {
|
||||
void debugreiserfs_zero_reiserfs(reiserfs_filsys_t * fs) {
|
||||
unsigned long done, total, i;
|
||||
struct buffer_head * bh;
|
||||
|
||||
@@ -647,6 +674,7 @@ void zero_bitmap_blocks(reiserfs_filsys_t * fs) {
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: need to open reiserfs filesystem first */
|
||||
int main (int argc, char * argv[])
|
||||
{
|
||||
@@ -666,93 +694,86 @@ int main (int argc, char * argv[])
|
||||
fs = reiserfs_open (file_name, O_RDONLY, &error, data, 0);
|
||||
|
||||
if (no_reiserfs_found (fs)) {
|
||||
fprintf (stderr, "\n\ndebugreiserfs: can not open reiserfs on \"%s\": %s\n\n",
|
||||
file_name, error ? strerror (error) : "no filesystem found");
|
||||
exit(1) ;
|
||||
reiserfs_exit (1, "\n\ndebugreiserfs: can not open reiserfs on "
|
||||
"\"%s\": %s\n\n", file_name, error ? strerror(error)
|
||||
: "no filesystem found");
|
||||
exit(1) ;
|
||||
}
|
||||
|
||||
if (reiserfs_open_journal (fs, data (fs)->journal_device_name, O_RDONLY)) {
|
||||
fprintf(stderr, "\ndebugreiserfs: Failed to open the fs journal.\n");
|
||||
fprintf(stderr,"\ndebugreiserfs: Failed to open the fs journal.\n");
|
||||
}
|
||||
|
||||
switch (debug_mode (fs)) {
|
||||
case DO_STAT:
|
||||
init_bitmap (fs);
|
||||
do_stat (fs);
|
||||
break;
|
||||
|
||||
init_bitmap (fs);
|
||||
do_stat (fs);
|
||||
break;
|
||||
|
||||
case DO_PACK:
|
||||
init_bitmap (fs);
|
||||
do_pack (fs);
|
||||
break;
|
||||
|
||||
init_bitmap (fs);
|
||||
do_pack (fs);
|
||||
break;
|
||||
|
||||
case DO_CORRUPT_ONE:
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
do_corrupt_one_block (fs, (char *)NULL);
|
||||
break;
|
||||
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
do_corrupt_one_block (fs, (char *)NULL);
|
||||
break;
|
||||
|
||||
case DO_CORRUPT_FILE:
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
do_corrupt_blocks (fs);
|
||||
break;
|
||||
case DO_RANDOM_CORRUPTION:
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
/*
|
||||
do_leaves_corruption (fs);
|
||||
do_bitmap_corruption (fs);
|
||||
*/
|
||||
do_fs_random_corrupt (fs);
|
||||
break;
|
||||
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
do_corrupt_blocks (fs);
|
||||
break;
|
||||
case DO_RANDOM_CORRUPTION:
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
/*
|
||||
do_leaves_corruption (fs);
|
||||
do_bitmap_corruption (fs);
|
||||
*/
|
||||
do_fs_random_corrupt (fs);
|
||||
break;
|
||||
|
||||
case DO_DUMP:
|
||||
do_dump_tree (fs);
|
||||
break;
|
||||
|
||||
do_dump_tree (fs);
|
||||
break;
|
||||
|
||||
case DO_SCAN:
|
||||
case DO_SCAN_FOR_NAME:
|
||||
case DO_LOOK_FOR_NAME:
|
||||
case DO_SCAN_JOURNAL:
|
||||
init_bitmap (fs);
|
||||
do_scan (fs);
|
||||
break;
|
||||
|
||||
init_bitmap (fs);
|
||||
do_scan (fs);
|
||||
break;
|
||||
|
||||
case DO_FILE_MAP:
|
||||
print_map(fs);
|
||||
break;
|
||||
|
||||
|
||||
print_map(fs);
|
||||
break;
|
||||
|
||||
|
||||
case DO_RECOVER:
|
||||
do_recover (fs);
|
||||
break;
|
||||
|
||||
do_recover (fs);
|
||||
break;
|
||||
|
||||
case DO_TEST:
|
||||
/*do_test (fs);*/
|
||||
break;
|
||||
/*do_test (fs);*/
|
||||
break;
|
||||
case DO_EXTRACT_BADBLOCKS:
|
||||
reiserfs_warning (stderr, "Will try to extract list of bad blocks and "
|
||||
"save it to '%s' file\n", badblocks_file);
|
||||
|
||||
extract_badblock_list ();
|
||||
reiserfs_warning (stderr, "Done\n\n");
|
||||
break;
|
||||
reiserfs_warning (stderr, "Will try to extract list of bad blocks "
|
||||
"and save it to '%s' file\n", badblocks_file);
|
||||
|
||||
extract_badblock_list ();
|
||||
reiserfs_warning (stderr, "Done\n\n");
|
||||
break;
|
||||
case DO_ZERO:
|
||||
init_bitmap (fs);
|
||||
debugreiserfs_zero_reiserfs(fs);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
reiserfs_close (fs);
|
||||
if (data(fs)->log) {
|
||||
fclose (data(fs)->log);
|
||||
fclose (data(fs)->log);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Local variables:
|
||||
c-indentation-style: "K&R"
|
||||
mode-name: "LC"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
fill-column: 80
|
||||
End:
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user