diff options
author | Jeff Mahoney <jeffm@suse.com> | 2012-10-11 11:31:31 -0400 |
---|---|---|
committer | Jeff Mahoney <jeffm@suse.com> | 2012-10-11 11:31:31 -0400 |
commit | 0ed773997fc833a8a8eb3b598c70ddfd22d97b6f (patch) | |
tree | f687dd5a44cc50662625c61bea09b635db95e976 | |
parent | 3078c83c48bdf4691d6d2ce3818dfe82d5dc2c3b (diff) | |
download | reiserfsprogs-0ed773997fc833a8a8eb3b598c70ddfd22d97b6f.tar.gz |
Imported reiserfsprogs-3.6.19v3.6.19
34 files changed, 727 insertions, 563 deletions
@@ -1,3 +1,20 @@ +2004-10-13 + 3.6.19 release. +2004-09-22 + Some bug fixes: + - stop handling directory item if it has been removed on fsck pass0 + - handle correctly cases when hash functions return 0 + - additional check for wrong order of hashes when generation counters + differ. +2004-08-18 + {get|set}_unaligned macroses fix for broken powerpc linux kernel + headers. +2004-08-18 + Patches from Jeff Mahoney: + - warnings cleanups + - sd_blocks check fix for quota + - make fsck -a works quitely + - fix the definition of BLKGETSIZE64 2004-08-03 3.6.18 release. 2004-06-18 @@ -1605,7 +1605,7 @@ fi # Define the identity of the package. PACKAGE=reiserfsprogs - VERSION=3.6.18 + VERSION=3.6.19 cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index 7968634..bcb4789 100644 --- a/configure.in +++ b/configure.in @@ -6,7 +6,7 @@ AC_PREREQ(2.50) AH_TEMPLATE([HAVE_LIBUUID], [Define for enable libuuid using.]) AH_TEMPLATE([ENABLE_DEBUG], [Define for enable debug info.]) -AM_INIT_AUTOMAKE(reiserfsprogs, 3.6.18) +AM_INIT_AUTOMAKE(reiserfsprogs, 3.6.19) AM_MAINTAINER_MODE dnl We install in /sbin, the utils are to be available on boot diff --git a/debugreiserfs/corruption.c b/debugreiserfs/corruption.c index eb77345..d584130 100644 --- a/debugreiserfs/corruption.c +++ b/debugreiserfs/corruption.c @@ -728,7 +728,7 @@ void do_leaves_corruption (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"); for (i = 0; (i < get_sb_block_count (fs->fs_ondisk_sb)) && nr_leaves < nr_leaves_cr; i ++) { @@ -853,7 +853,7 @@ void do_ih_random_corrupt (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"); for (i = 0; (i < get_sb_block_count (fs->fs_ondisk_sb)) && nr_leaves < nr_leaves_cr; i ++) { @@ -960,7 +960,7 @@ void do_dir_random_corrupt (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"); for (i = 0; (i < get_sb_block_count (fs->fs_ondisk_sb)) && nr_leaves < nr_leaves_cr; i ++) { @@ -1041,7 +1041,7 @@ void do_sd_random_corrupt (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"); for (i = 0; (i < get_sb_block_count (fs->fs_ondisk_sb)) && nr_leaves < nr_leaves_cr; i ++) { @@ -1122,7 +1122,7 @@ void do_ind_random_corrupt (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"); for (i = 0; (i < get_sb_block_count (fs->fs_ondisk_sb)) && nr_leaves < nr_leaves_cr; i ++) { diff --git a/debugreiserfs/debugreiserfs.8 b/debugreiserfs/debugreiserfs.8 index 80ddb7d..0f89591 100644 --- a/debugreiserfs/debugreiserfs.8 +++ b/debugreiserfs/debugreiserfs.8 @@ -1,7 +1,7 @@ .\" -*- nroff -*- .\" Copyright 1996-2004 Hans Reiser. .\" -.TH DEBUGREISERFS 8 "February 2004" "Reiserfsprogs 3.6.18" +.TH DEBUGREISERFS 8 "February 2004" "Reiserfsprogs 3.6.19" .SH NAME debugreiserfs \- The debugging tool for the ReiserFS filesystem. .SH SYNOPSIS diff --git a/debugreiserfs/debugreiserfs.c b/debugreiserfs/debugreiserfs.c index 5a5f74f..3435626 100644 --- a/debugreiserfs/debugreiserfs.c +++ b/debugreiserfs/debugreiserfs.c @@ -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; - - 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_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; - } + 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; + + 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: -*/ - - - diff --git a/debugreiserfs/debugreiserfs.h b/debugreiserfs/debugreiserfs.h index c60a99d..58e58e6 100644 --- a/debugreiserfs/debugreiserfs.h +++ b/debugreiserfs/debugreiserfs.h @@ -39,7 +39,7 @@ extern reiserfs_filsys_t * fs; #define DO_SCAN_JOURNAL 13 /* -J */ #define DO_EXTRACT_BADBLOCKS 14 #define DO_FILE_MAP 15 -#define DO_ZERO_BITMAP 16 +#define DO_ZERO 16 #define DO_NOTHING 17 diff --git a/debugreiserfs/scan.c b/debugreiserfs/scan.c index ab39f3e..8ed9d03 100644 --- a/debugreiserfs/scan.c +++ b/debugreiserfs/scan.c @@ -792,8 +792,9 @@ static void make_map(const void *nodep, VISIT value, int level) { if (fp == 0) { fp = fopen (file_name, "w+"); - if (!fp) - reiserfs_panic ("could open %s: %m", file_name); + if (!fp) { + reiserfs_exit (1, "could open %s: %m", file_name); + } } } diff --git a/debugreiserfs/stat.c b/debugreiserfs/stat.c index 5cbab4e..6e8ff96 100644 --- a/debugreiserfs/stat.c +++ b/debugreiserfs/stat.c @@ -241,11 +241,13 @@ void do_stat (reiserfs_filsys_t * fs) return; fp = fopen (input_bitmap_file_name(fs), "w"); - if (!fp) - reiserfs_panic ("stat: could not open %s to save bitmap: %m\n", - input_bitmap_file_name(fs)); + if (!fp) { + reiserfs_exit (1, "could not open %s to save bitmap: %m\n", + input_bitmap_file_name(fs)); + } reiserfs_warning (stderr, "Updated bitmap contains %d blocks marked\n", reiserfs_bitmap_ones (input_bitmap (fs))); + reiserfs_bitmap_save (fp, input_bitmap (fs)); fclose (fp); return; diff --git a/debugreiserfs/unpack.c b/debugreiserfs/unpack.c index c58e2ca..fb93b6b 100644 --- a/debugreiserfs/unpack.c +++ b/debugreiserfs/unpack.c @@ -128,8 +128,7 @@ static void unpack_direntry (struct packed_item * pi, struct buffer_head * bh, /* old or new ".." */ set_deh_offset (deh, DOT_DOT_OFFSET); else if (hash_func) - set_deh_offset (deh, GET_HASH_VALUE (hash_func (item + location, - namelen))); + set_deh_offset (deh, hash_value(hash_func, item + location, namelen)); if (mask & HAS_GEN_COUNTER) { fread_le16 (&gen_counter); set_deh_offset (deh, get_deh_offset (deh) | gen_counter); diff --git a/fsck/check_tree.c b/fsck/check_tree.c index 237dc35..8a53d37 100644 --- a/fsck/check_tree.c +++ b/fsck/check_tree.c @@ -541,8 +541,8 @@ static int bad_directory_item (reiserfs_filsys_t * fs, struct buffer_head * bh, struct item_head * ih) { - char * name; - int namelen; + char *name, *prev_name; + __u32 off, prev_off; unsigned int count, i; struct reiserfs_de_head * deh = B_I_DEH (bh, ih); int min_entry_size = 1;/* We have no way to understand whether the @@ -550,6 +550,7 @@ static int bad_directory_item (reiserfs_filsys_t * fs, converted to it. So, we assume that minimal name length is 1 */ __u16 state; + int namelen; count = get_ih_entry_count (ih); @@ -580,17 +581,34 @@ static int bad_directory_item (reiserfs_filsys_t * fs, } /* check name hashing */ + prev_name = B_I_PITEM(bh, ih) + get_ih_item_len(ih); + prev_off = 0; + for (i = 0; i < count; i ++, deh ++) { namelen = name_in_entry_length (ih, deh, i); name = name_in_entry (deh, i); - if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh))) { + off = get_deh_offset (deh); + + if (namelen > (int)REISERFS_MAX_NAME_LEN(fs->fs_blocksize) || + name >= prev_name || off <= prev_off) + { + fsck_log ("%s: block %lu: The directory item %k has a broken entry " + "(%d)\n", __FUNCTION__, bh->b_blocknr, &ih->ih_key, i); + one_more_corruption (fs, FATAL); + return 1; + } + + if (!is_properly_hashed (fs, name, namelen, off)) { fsck_log ("%s: block %lu: The directory item %k has a not properly " "hashed entry (%d)\n", __FUNCTION__, bh->b_blocknr, &ih->ih_key, i); - one_more_corruption (fs, FATAL); + one_more_corruption (fs, FATAL); return 1; } + + prev_name = name; + prev_off = off; } deh = B_I_DEH (bh, ih); diff --git a/fsck/main.c b/fsck/main.c index 9c179d7..ab3342a 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -228,6 +228,7 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv []) case 'a': case 'p': + data->options |= OPT_QUIET; mode = FSCK_AUTO; break; @@ -673,7 +674,8 @@ static void mark_filesystem_consistent (reiserfs_filsys_t * fs) if (!reiserfs_journal_opened (fs)) { /* make sure journal is not standard */ if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) - die ("Filesystem with default journal must be opened."); + reiserfs_exit(EXIT_OPER, "Filesystem with default journal " + "must be opened."); fsck_progress ("WARNING: You must use reiserfstune to specify a new " "journal before mounting it.\n"); @@ -785,13 +787,17 @@ static void prepare_fs_for_check(reiserfs_filsys_t * fs) { /* If not CHECK mode, lock the process in the memory. */ if (fsck_mode (fs) != FSCK_CHECK) { if (mlockall(MCL_CURRENT)) { - reiserfs_warning (stderr, "Failed to lock the process to " - "fsck the mounted ro partition. %s.\n", - strerror(errno)); - exit(EXIT_OPER); + reiserfs_exit(EXIT_OPER, "Failed to lock the process to " + "fsck the mounted ro partition. %s.\n", + strerror(errno)); } } + if (fsck_skip_journal (fs)) { + reiserfs_exit(EXIT_USER, "Jounrnal of the mounted " + "filesystem must be specified.\n"); + } + if (!reiserfs_journal_opened (fs)) { /* just to make sure */ reiserfs_panic ("Journal is not opened"); @@ -879,7 +885,7 @@ static void clean_attributes (reiserfs_filsys_t * fs) { time (&t); if (get_sb_umount_state (fs->fs_ondisk_sb) != FS_CLEANLY_UMOUNTED) { - fsck_progress ("Filesystem does not look cleanly umounted\n" + fsck_progress ("Filesystem is not clean\n" "Check consistency of the partition first.\n"); exit(EXIT_USER); } @@ -1227,8 +1233,9 @@ int main (int argc, char * argv []) 'fsck.run'. Logs get there if log file was not specified*/ data->options |= OPT_QUIET; data->progress = fopen ("fsck.run", "a+"); - if (!data->progress) - reiserfs_panic ("reiserfsck: Cannot not open \"fsck.run\""); + if (!data->progress) { + reiserfs_exit(EXIT_OPER, "reiserfsck: Cannot not open \"fsck.run\""); + } if (data->log == stdout) /* no log file specifed - redirect log into 'fsck.run' */ @@ -1255,19 +1262,20 @@ int main (int argc, char * argv []) } else { fs = reiserfs_open (file_name, O_RDONLY, &error, data, data->mode != FSCK_SB); - + + if (error) { + reiserfs_exit(EXIT_OPER, "Failed to open the device " + "'%s': %s\n\n", file_name, strerror(error)); + } + if (data->mode != FSCK_SB) { if (no_reiserfs_found (fs)) { - if (error) { - die ("Failed to open the device '%s': %s\n\n", - file_name, strerror(error)); - } else { - die ("Failed to open the filesystem.\n\n" - "If the partition table has not been changed, and the partition is\n" - "valid and it really contains a reiserfs partition, then the\n" - "superblock is corrupted and you need to run this utility with\n" - "--rebuild-sb.\n"); - } + reiserfs_exit(EXIT_OPER, "Failed to open the filesystem.\n\n" + "If the partition table has not been changed, " + "and the partition is\nvalid and it really " + "contains a reiserfs partition, then the\n" + "superblock is corrupted and you need to run " + "this utility with\n--rebuild-sb.\n"); } if (fsck_skip_journal (fs) && !is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) diff --git a/fsck/pass0.c b/fsck/pass0.c index 3e4b9e3..8d91cc4 100644 --- a/fsck/pass0.c +++ b/fsck/pass0.c @@ -365,8 +365,7 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b hash_code = 0; for (j = min_length; j <= max_length; j ++) { - hash_code = find_hash_in_use (name, j, - GET_HASH_VALUE (get_deh_offset (deh + i)), + hash_code = find_hash_in_use (name, j, get_deh_offset (deh + i), get_sb_hash_code (fs->fs_ondisk_sb)); /* add_hash_hit (fs, hash_code);*/ if (code2func (hash_code) != 0) { @@ -527,9 +526,11 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b } } - if (bad == get_ih_entry_count (&tmp) && lost_found != bad) { - fsck_log ("%s: block %lu, item %H: All entries were deleted from the directory\n", - __FUNCTION__, bh->b_blocknr, &tmp); + if (bad == get_ih_entry_count (&tmp)) { + if (lost_found != bad) { + fsck_log ("%s: block %lu, item %H: All entries were deleted from the directory\n", + __FUNCTION__, bh->b_blocknr, &tmp); + } return -1; } @@ -586,6 +587,9 @@ int leaf_structure_check (reiserfs_filsys_t * fs, struct buffer_head * bh) { return 1; } + if (get_blkh_nr_items (blkh) == 0) + return 0; + counted = leaf_count_ih(bh->b_data, bh->b_size); if (counted < get_blkh_nr_items (blkh)) { @@ -1770,12 +1774,19 @@ static void init_source_bitmap (reiserfs_filsys_t * fs) case EXTERN_BITMAP: fp = fopen (fsck_data (fs)->rebuild.bitmap_file_name, "r"); - if (!fp) - reiserfs_panic ("Could not load bitmap: %s\n", strerror(errno)); + + if (!fp) { + reiserfs_exit (EXIT_OPER, "Could not load bitmap: %s\n", + strerror(errno)); + } + fsck_source_bitmap (fs) = reiserfs_bitmap_load (fp); - if (!fsck_source_bitmap (fs)) - reiserfs_panic ("Could not load fitmap from \"%s\"", - fsck_data (fs)->rebuild.bitmap_file_name); + + if (!fsck_source_bitmap (fs)) { + reiserfs_exit (EXIT_OPER, "Could not load fitmap from \"%s\"", + fsck_data (fs)->rebuild.bitmap_file_name); + } + fsck_progress ("%d blocks marked used in extern bitmap\n", reiserfs_bitmap_ones (fsck_source_bitmap (fs))); fclose (fp); @@ -1967,7 +1978,10 @@ void pass_0 (reiserfs_filsys_t * fs) { if (get_reiserfs_format (fs->fs_ondisk_sb) != fs->fs_format || get_reiserfs_format (fs->fs_ondisk_sb) == REISERFS_FORMAT_UNKNOWN) - reiserfs_panic ("pass 0: ReiserFS format version mismatch found, you should run --rebuild-sb"); + { + reiserfs_exit (EXIT_OPER, "pass 0: ReiserFS format version mismatch " + "found, you should run --rebuild-sb"); + } fsck_progress ("\nPass 0:\n"); if (fsck_log_file (fs) != stderr) diff --git a/fsck/pass1.c b/fsck/pass1.c index 15a338b..d27fbb6 100644 --- a/fsck/pass1.c +++ b/fsck/pass1.c @@ -349,11 +349,13 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs, for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) { if (is_direntry_ih (ih)) { struct reiserfs_de_head * deh; + __u32 offset; char * name; int name_len; unsigned int hash_code; deh = B_I_DEH (bh, ih); + offset = 0; for (j = 0; j < get_ih_entry_count (ih); j ++) { name = name_in_entry (deh + j, j); name_len = name_in_entry_length (ih, deh + j, j); @@ -363,8 +365,7 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs, continue; } - hash_code = find_hash_in_use (name, name_len, - GET_HASH_VALUE (get_deh_offset (deh + j)), + hash_code = find_hash_in_use (name, name_len, get_deh_offset (deh + j), get_sb_hash_code (fs->fs_ondisk_sb)); if (hash_code != get_sb_hash_code (fs->fs_ondisk_sb)) { fsck_log ("pass1: block %lu, item %d, entry %d: The entry \"%.*s\" of the %k is hashed with %s " @@ -381,8 +382,24 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs, fsck_log(" - deleted\n"); j --; deh = B_I_DEH (bh, ih); + continue; } } + + if (j && offset >= get_deh_offset (deh + j)) { + fsck_log ("pass1: block %lu, item %d, entry %d: The entry " + "\"%.*s\" of the %k has hash offset %lu not " + "larger smaller than the previous one %lu. The " + "entry is deleted.\n", bh->b_blocknr, + i, j, name_len, name, &ih->ih_key, + get_deh_offset(deh + j), offset); + cut_entry (fs, bh, i, j, 1); + j --; + deh = B_I_DEH (bh, ih); + continue; + } + + offset = get_deh_offset (deh + j); } continue; } diff --git a/fsck/reiserfsck.8 b/fsck/reiserfsck.8 index 078fc86..43d4669 100644 --- a/fsck/reiserfsck.8 +++ b/fsck/reiserfsck.8 @@ -1,7 +1,7 @@ .\" -*- nroff -*- .\" Copyright 1996-2004 Hans Reiser. .\" -.TH REISERFSCK 8 "February 2004" "Reiserfsprogs-3.6.18" +.TH REISERFSCK 8 "February 2004" "Reiserfsprogs-3.6.19" .SH NAME reiserfsck \- The checking tool for the ReiserFS filesystem. .SH SYNOPSIS diff --git a/fsck/semantic_rebuild.c b/fsck/semantic_rebuild.c index 05e977d..551a2e6 100644 --- a/fsck/semantic_rebuild.c +++ b/fsck/semantic_rebuild.c @@ -172,7 +172,8 @@ int wrong_st_blocks (struct key * key, __u32 * blocks, __u32 sd_blocks, __u16 mo int ret = 0; if (S_ISREG (mode) || S_ISLNK (mode) || S_ISDIR (mode)) { - if (*blocks != sd_blocks) { + if ((!S_ISLNK(mode) && *blocks != sd_blocks) || + (S_ISLNK(mode) && *blocks != sd_blocks && (ROUND_UP(*blocks) != sd_blocks))) { fsck_log ("vpf-10680: The %s %K has the wrong block count in the StatData " "(%u)%s(%u)\n", S_ISDIR (mode) ? "directory" : S_ISREG (mode) ? "file" : "link", key, sd_blocks, fsck_mode(fs) == FSCK_CHECK ? ", should be " : " - corrected to ", *blocks); diff --git a/fsck/super.c b/fsck/super.c index 2870d4e..86ffd90 100644 --- a/fsck/super.c +++ b/fsck/super.c @@ -220,7 +220,8 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat fs->fs_blocksize = retval; } - block_count = count_blocks (filename, fs->fs_blocksize); + if (!(block_count = count_blocks (filename, fs->fs_blocksize))) + exit(EXIT_OPER); /* save ondisk_sb somewhere and work in temp area */ ondisk_sb = fs->fs_ondisk_sb; @@ -358,7 +359,8 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat retval = 4096; } - block_count = count_blocks (filename, retval); + if (!(block_count = count_blocks (filename, retval))) + exit(EXIT_OPER); switch(version){ case 1: @@ -601,8 +603,8 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat } if (!reiserfs_journal_opened(fs)) { - fsck_log ("Journal cannot be opened, assuming specified journal device " - "is correct\n"); + fsck_log ("Journal cannot be opened, assuming specified " + "journal device is correct\n"); } } @@ -629,7 +631,9 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat } else set_jp_journal_1st_block (sb_jp(sb), default_value); - p_jp_dev_size = count_blocks (journal_dev_name, fs->fs_blocksize); + if (!(p_jp_dev_size = count_blocks (journal_dev_name, fs->fs_blocksize))) + exit(EXIT_OPER); + /* some checks for journal offset */ if (strcmp(fs->fs_file_name, journal_dev_name) != 0) { if (p_jp_dev_size < get_jp_journal_1st_block (sb_jp(sb)) + 1) diff --git a/include/reiserfs_fs.h b/include/reiserfs_fs.h index d108dde..41046df 100644 --- a/include/reiserfs_fs.h +++ b/include/reiserfs_fs.h @@ -40,6 +40,14 @@ #include <asm/unaligned.h> +#ifndef get_unaligned +#if defined(__ppc__) || defined(ppc) || defined(__ppc) || \ + defined(__PPC) || defined(powerpc) || defined(__powerpc__) +# define get_unaligned(ptr) (*(ptr)) +# define put_unaligned(val,ptr) ((void)(*(ptr) = (val))) +#endif +#endif + #define get_leXX(xx,p,field) (le##xx##_to_cpu ((p)->field)) #define set_leXX(xx,p,field,val) do { (p)->field = cpu_to_le##xx(val); } while (0) diff --git a/include/reiserfs_lib.h b/include/reiserfs_lib.h index 4f15cf1..2ad8034 100644 --- a/include/reiserfs_lib.h +++ b/include/reiserfs_lib.h @@ -135,6 +135,8 @@ int comp_keys_3 (const void * k1, const void * k2); int comp_short_keys (const void * p_s_key1, const void * p_s_key2); int comp_items (struct item_head * p_s_ih, struct path * p_s_path); +__u32 hash_value (hashf_t func, char * name, int namelen); + int create_dir_sd (reiserfs_filsys_t * fs, struct path * path, struct key * key, void (*modify_item)(struct item_head *, void *)); @@ -279,7 +281,7 @@ char *code2name (unsigned int code); int func2code (hashf_t func); hashf_t code2func (unsigned int code); hashf_t name2func (char * hash); -int find_hash_in_use (char * name, int namelen, __u32 hash_value_masked, unsigned int code_to_try_first); +int find_hash_in_use (char * name, int namelen, __u32 deh_offset, unsigned int code_to_try_first); int entry_length (struct item_head * ih, struct reiserfs_de_head * deh, int pos_in_item); @@ -385,7 +387,6 @@ int can_we_format_it (char * device_name, int force); #define reiserfs_exit(val, fmt, list...) \ {\ fflush (stdout);\ - fprintf (stderr, "%s %d %s\n", __FILE__, __LINE__, __FUNCTION__);\ reiserfs_warning (stderr, (const char *)fmt, ## list);\ reiserfs_warning (stderr, "\n" );\ exit (val);\ @@ -408,7 +408,8 @@ struct buffer_head * getblk (int dev, unsigned long block, int size) if (buffers_memory >= buffer_soft_limit) { if (sync_buffers (&Buffer_list_head, dev, 32) == 0) { grow_buffers(size); - buffer_soft_limit = buffers_memory + GROW_BUFFERS__NEW_BUFERS_PER_CALL * size; + buffer_soft_limit = buffers_memory + + GROW_BUFFERS__NEW_BUFERS_PER_CALL * size; } } else { if (grow_buffers(size) == 0) @@ -418,7 +419,8 @@ struct buffer_head * getblk (int dev, unsigned long block, int size) bh = get_free_buffer (&g_free_buffers, size); if (bh == NULL) { show_buffers (dev, size); - die ("getblk: no free buffers after grow_buffers and refill (%d)", g_nr_buffers); + die ("getblk: no free buffers after grow_buffers " + "and refill (%d)", g_nr_buffers); } } @@ -499,19 +501,20 @@ struct buffer_head * bread (int dev, unsigned long block, size_t size) ret = f_read(bh); - if (ret > 0) - die ("%s: End of file, cannot read the block (%lu).\n", __FUNCTION__, block); - else if (ret < 0) { + if (ret > 0) { + die ("%s: End of file, cannot read the block (%lu).\n", + __FUNCTION__, block); + } else if (ret < 0) { /* BAD BLOCK LIST SUPPORT * die ("%s: Cannot read a block # %lu. Specify list of badblocks\n",*/ if (errno == EIO) { check_hd_msg(); - die ("%s: Cannot read the block (%lu): (%s).\n", __FUNCTION__, - block, strerror(errno)); + die ("%s: Cannot read the block (%lu): (%s).\n", + __FUNCTION__, block, strerror(errno)); } else { - fprintf (stderr, "%s: Cannot read the block (%lu): (%s).\n", __FUNCTION__, - block, strerror(errno)); + fprintf (stderr, "%s: Cannot read the block (%lu): (%s).\n", + __FUNCTION__, block, strerror(errno)); return NULL; } } @@ -904,11 +907,14 @@ static void check_and_free_buffer_mem (void) count += _check_and_free_buffer_list(g_free_buffers); if (count != g_nr_buffers) - die ("check_and_free_buffer_mem: found %d buffers, must be %d", count, g_nr_buffers); + die ("check_and_free_buffer_mem: found %d buffers, must be %d", + count, g_nr_buffers); /* free buffer heads */ while ((next = g_buffer_heads)) { - g_buffer_heads = *(struct buffer_head **)(next + GROW_BUFFERS__NEW_BUFERS_PER_CALL); + g_buffer_heads = *(struct buffer_head **) + (next + GROW_BUFFERS__NEW_BUFERS_PER_CALL); + freemem (next); } @@ -462,7 +462,13 @@ void print_how_far (FILE * fp, } #if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) -# define BLKGETSIZE64 _IOR(0x12, 114, __u64) +/* Note! Despite this call being called with *64, it must be encoded to + * return only sizeof(size_t), since in earlier kernel versions it was + * declared _IOR(0x12, 114, sizeof(u64)), making it use sizeof(sizeof(u64)). + * + * However, the call itself does always return 64bit! + */ +# define BLKGETSIZE64 _IOR(0x12, 114, size_t) #endif /* To not have problem with last sectors on the block device when switching @@ -500,8 +506,10 @@ unsigned long count_blocks (char * filename, int blocksize) return 0; fd = open (filename, O_RDONLY); - if (fd == -1) - die ("count_blocks: open failed (%s)", strerror (errno)); + if (fd == -1) { + fprintf(stderr, "Failed to open '%s': %s.\n", filename, strerror(errno)); + return 0; + } #ifdef BLKGETSIZE64 { diff --git a/mkreiserfs/mkreiserfs.8 b/mkreiserfs/mkreiserfs.8 index 506076b..f6b45ae 100644 --- a/mkreiserfs/mkreiserfs.8 +++ b/mkreiserfs/mkreiserfs.8 @@ -1,7 +1,7 @@ .\" -*- nroff -*- .\" Copyright 1996-2004 Hans Reiser. .\" -.TH MKREISERFS 8 "February 2004" "Reiserfsprogs-3.6.18" +.TH MKREISERFS 8 "February 2004" "Reiserfsprogs-3.6.19" .SH NAME mkreiserfs \- The create tool for the Linux ReiserFS filesystem. .SH SYNOPSIS diff --git a/mkreiserfs/mkreiserfs.c b/mkreiserfs/mkreiserfs.c index 37e6571..8a49317 100644 --- a/mkreiserfs/mkreiserfs.c +++ b/mkreiserfs/mkreiserfs.c @@ -149,8 +149,9 @@ static void invalidate_other_formats (int dev) struct buffer_head * bh; bh = bread (dev, 0, 64 * 1024); - if (!bh) - die ("Unable to read first blocks of the device"); + if (!bh) { + reiserfs_exit(1, "Unable to read first blocks of the device"); + } #if defined(__sparc__) || defined(__sparc_v9__) memset (bh->b_data + 1024, 0, bh->b_size - 1024); #else @@ -178,8 +179,9 @@ void zero_journal (reiserfs_filsys_t * fs) for (i = 0; i < len; i ++) { print_how_far (stdout, &done, len, 1, 1/*be quiet*/); bh = getblk (fs->fs_journal_dev, start + i, fs->fs_blocksize); - if (!bh) - die ("zero_journal: getblk failed"); + if (!bh) { + reiserfs_exit(1, "zero_journal: getblk failed"); + } memset (bh->b_data, 0, bh->b_size); mark_buffer_dirty (bh); mark_buffer_uptodate (bh, 1); @@ -194,8 +196,7 @@ void zero_journal (reiserfs_filsys_t * fs) /* this only sets few first bits in bitmap block. Fills not initialized fields of super block (root block and bitmap block numbers) */ -static void make_bitmap (reiserfs_filsys_t * fs) -{ +static void make_bitmap (reiserfs_filsys_t * fs) { struct reiserfs_super_block * sb = fs->fs_ondisk_sb; unsigned int i; unsigned long block; @@ -222,31 +223,31 @@ static void make_bitmap (reiserfs_filsys_t * fs) block = fs->fs_super_bh->b_blocknr + 1; for (i = 0; i < get_sb_bmap_nr (sb); i ++) { - reiserfs_bitmap_set_bit (fs->fs_bitmap2, block); - marked ++; - if (spread_bitmaps (fs)) - block = (block / (fs->fs_blocksize * 8) + 1) * - (fs->fs_blocksize * 8); - else - block ++; + reiserfs_bitmap_set_bit (fs->fs_bitmap2, block); + marked ++; + if (spread_bitmaps (fs)) + block = (block / (fs->fs_blocksize * 8) + 1) * + (fs->fs_blocksize * 8); + else + block ++; } - if (!get_size_of_journal_or_reserved_area (fs->fs_ondisk_sb)) - /* root block follows directly super block and first bitmap */ - block = fs->fs_super_bh->b_blocknr + 1 + 1; + if (!get_size_of_journal_or_reserved_area (fs->fs_ondisk_sb)) + /* root block follows directly super block and first bitmap */ + block = fs->fs_super_bh->b_blocknr + 1 + 1; else { - /* makr journal blocks as used */ - for (i = 0; i <= get_jp_journal_size (sb_jp (sb)); i ++) { - reiserfs_bitmap_set_bit (fs->fs_bitmap2, - i + get_jp_journal_1st_block (sb_jp (sb))); - marked ++; - } - block = get_jp_journal_1st_block (sb_jp (sb)) + i; + /* makr journal blocks as used */ + for (i = 0; i <= get_jp_journal_size (sb_jp (sb)); i ++) { + reiserfs_bitmap_set_bit (fs->fs_bitmap2, + i + get_jp_journal_1st_block (sb_jp (sb))); + marked ++; + } + block = get_jp_journal_1st_block (sb_jp (sb)) + i; } /*get correct block - not journal nor bitmap*/ while (block_of_journal (fs, block) || block_of_bitmap (fs, block)) { - block++; + block++; } while ((block < get_sb_block_count (sb)) && @@ -256,7 +257,7 @@ static void make_bitmap (reiserfs_filsys_t * fs) } if (block >= get_sb_block_count (sb)) - die ("mkreiserfs: too many bad blocks"); + reiserfs_exit(1, "mkreiserfs: too many bad blocks"); reiserfs_bitmap_set_bit (fs->fs_bitmap2, block); marked ++; @@ -286,8 +287,10 @@ static void make_root_block (reiserfs_filsys_t * fs) sb = fs->fs_ondisk_sb; /* get memory for root block */ bh = getblk (fs->fs_dev, get_sb_root_block (sb), get_sb_block_size (sb)); - if (!bh) - die ("make_root_block: getblk failed"); + + if (!bh) { + reiserfs_exit(1, "getblk failed"); + } mark_buffer_uptodate (bh, 1); @@ -295,7 +298,6 @@ static void make_root_block (reiserfs_filsys_t * fs) make_sure_root_dir_exists (fs, set_root_dir_nlink, 0); brelse (bh); - /**/ mark_objectid_used (fs, REISERFS_ROOT_PARENT_OBJECTID); mark_objectid_used (fs, REISERFS_ROOT_OBJECTID); } @@ -312,74 +314,78 @@ static void report (reiserfs_filsys_t * fs, char * j_filename) dev_t rdev; if (!is_any_reiserfs_magic_string (sb)) - return; + return; if (fstat (fs->fs_super_bh->b_dev, &st) == -1) { - /*reiserfs_warning (stderr, "fstat failed: %s\n", strerror(errno));*/ - rdev = 0; + /*reiserfs_warning (stderr, "fstat failed: %s\n", strerror(errno));*/ + rdev = 0; } else - rdev = st.st_rdev; + rdev = st.st_rdev; if (mode & DEBUG_MODE) { - reiserfs_warning (stdout, "Block %lu (0x%x) contains super block. ", - fs->fs_super_bh->b_blocknr, rdev); + reiserfs_warning (stdout, "Block %lu (0x%x) contains super block. ", + fs->fs_super_bh->b_blocknr, rdev); } switch (get_reiserfs_format (sb)) { case REISERFS_FORMAT_3_5: - reiserfs_warning (stdout, " Format 3.5 with "); - break; + reiserfs_warning (stdout, " Format 3.5 with "); + break; case REISERFS_FORMAT_3_6: - reiserfs_warning (stdout, "Format 3.6 with "); - break; + reiserfs_warning (stdout, "Format 3.6 with "); + break; } if (is_reiserfs_jr_magic_string (sb)) - reiserfs_warning (stdout, "non-"); + reiserfs_warning (stdout, "non-"); reiserfs_warning (stdout, "standard journal\n"); reiserfs_warning (stdout, "Count of blocks on the device: %u\n", - get_sb_block_count (sb)); + get_sb_block_count (sb)); reiserfs_warning (stdout, "Number of blocks consumed by mkreiserfs " - "formatting process: %u\n", get_sb_block_count (sb) - get_sb_free_blocks (sb)); + "formatting process: %u\n", get_sb_block_count (sb) + - get_sb_free_blocks (sb)); if (mode & DEBUG_MODE) - reiserfs_warning (stdout, "Free blocks: %u\n", get_sb_free_blocks (sb)); + reiserfs_warning (stdout, "Free blocks: %u\n", + get_sb_free_blocks (sb)); reiserfs_warning (stdout, "Blocksize: %d\n", get_sb_block_size (sb)); reiserfs_warning (stdout, "Hash function used to sort names: %s\n", - code2name (get_sb_hash_code (sb))); + code2name (get_sb_hash_code (sb))); if (mode & DEBUG_MODE) { reiserfs_warning (stdout, "Number of bitmaps: %u\n", get_sb_bmap_nr (sb)); reiserfs_warning (stdout, "Root block: %u\n", get_sb_root_block (sb)); reiserfs_warning (stdout, "Tree height: %d\n", get_sb_tree_height (sb)); reiserfs_warning (stdout, "Objectid map size %d, max %d\n", - get_sb_oid_cursize (sb), get_sb_oid_maxsize (sb)); + get_sb_oid_cursize (sb), get_sb_oid_maxsize (sb)); reiserfs_warning (stdout, "Journal parameters:\n"); print_journal_params (stdout, sb_jp (sb)); } else { if (j_filename && strcmp (j_filename, fs->fs_file_name)) - reiserfs_warning (stdout, "Journal Device [0x%x]\n", - get_jp_journal_dev (sb_jp (sb))); + reiserfs_warning (stdout, "Journal Device [0x%x]\n", + get_jp_journal_dev (sb_jp (sb))); reiserfs_warning (stdout, "Journal Size %u blocks (first block %u)\n", - get_jp_journal_size (sb_jp (sb)) + 1, - get_jp_journal_1st_block (sb_jp (sb))); + get_jp_journal_size (sb_jp (sb)) + 1, + get_jp_journal_1st_block (sb_jp (sb))); reiserfs_warning (stdout, "Journal Max transaction length %u\n", - get_jp_journal_max_trans_len (sb_jp (sb))); + get_jp_journal_max_trans_len (sb_jp (sb))); } if (j_filename && strcmp (j_filename, fs->fs_file_name)) { - reiserfs_warning (stdout, "Space on this device reserved by journal: %u\n", - get_sb_reserved_for_journal (sb)); + reiserfs_warning (stdout, "Space on this device reserved by journal: " + "%u\n", get_sb_reserved_for_journal (sb)); } if (mode & DEBUG_MODE) { - reiserfs_warning (stdout, "Filesystem state 0x%x\n", get_sb_fs_state (sb)); - reiserfs_warning (stdout, "sb_version %u\n", get_sb_version (sb)); + reiserfs_warning (stdout, "Filesystem state 0x%x\n", + get_sb_fs_state (sb)); + reiserfs_warning (stdout, "sb_version %u\n", + get_sb_version (sb)); } if (get_reiserfs_format (sb) == REISERFS_FORMAT_3_6) { reiserfs_warning (stdout, "inode generation number: %u\n", - get_sb_v2_inode_generation (sb)); + get_sb_v2_inode_generation (sb)); reiserfs_warning (stdout, "UUID: %U\n", sb->s_uuid); if (strcmp (sb->s_label, "")) - reiserfs_warning (stdout, "LABEL: %s\n", sb->s_label); + reiserfs_warning (stdout, "LABEL: %s\n", sb->s_label); } return; @@ -391,24 +397,25 @@ static void report (reiserfs_filsys_t * fs, char * j_filename) static void set_hash_function (char * str) { if (!strcmp (str, "tea")) - Hash = TEA_HASH; + Hash = TEA_HASH; else if (!strcmp (str, "rupasov")) - Hash = YURA_HASH; + Hash = YURA_HASH; else if (!strcmp (str, "r5")) - Hash = R5_HASH; + Hash = R5_HASH; else - message("wrong hash type specified. Using default"); + message("wrong hash type specified. Using default"); } static void set_reiserfs_version (char * str) { if (!strcmp (str, "3.5")) - Format = "3.5"; + Format = "3.5"; else { - Format = "3.6"; - if (strcmp (str, "3.6")) - message("wrong reiserfs version specified. Using default 3.6 format"); + Format = "3.6"; + if (strcmp (str, "3.6")) + message("wrong reiserfs version specified. " + "Using default 3.6 format"); } } @@ -418,8 +425,12 @@ static int str2int (char * str) char * tmp; val = (int) strtol (str, &tmp, 0); - if (*tmp) - die ("%s: strtol is unable to make an integer of %s\n", program_name, str); + + if (*tmp) { + reiserfs_exit (1, "%s: strtol is unable to make an integer of %s\n", + program_name, str); + } + return val; } @@ -429,8 +440,9 @@ static void set_block_size (char * str, int *b_size) *b_size = str2int (str); if (!is_blocksize_correct (*b_size)) - die ("%s: wrong blocksize %s specified, only power of 2 from 512-8192 " - "interval are supported", program_name, str); + reiserfs_exit (1, "%s: wrong blocksize %s specified, " + "only power of 2 from 512-8192 interval " + "are supported", program_name, str); } @@ -466,7 +478,8 @@ static int is_journal_default (char * name, char * jname, int blocksize) return 0; if (Journal_size && Journal_size != - journal_default_size(REISERFS_DISK_OFFSET_IN_BYTES / blocksize, blocksize) + 1) + journal_default_size(REISERFS_DISK_OFFSET_IN_BYTES / blocksize, + blocksize) + 1) /* journal size is set and it is not default size */ return 0; @@ -484,7 +497,6 @@ static int select_format (void) { struct utsname sysinfo; - if (Format) { if (!strcmp (Format, "3.5")) return REISERFS_FORMAT_3_5; @@ -661,7 +673,8 @@ int main (int argc, char **argv) fs_size = str2int (argv[optind + 1]); } else if (optind == argc - 1) { /* number of blocks is not specified */ - fs_size = count_blocks (device_name, Block_size); + if (!(fs_size = count_blocks (device_name, Block_size))) + exit(1); } else { print_usage_and_exit (); } diff --git a/reiserfscore/bitmap.c b/reiserfscore/bitmap.c index 4de8461..771b037 100644 --- a/reiserfscore/bitmap.c +++ b/reiserfscore/bitmap.c @@ -253,9 +253,13 @@ static int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys if (!bh) { reiserfs_warning (stderr, "reiserfs_fetch_ondisk_bitmap: " "bread failed reading bitmap (%lu)\n", block); + bh = getblk (fs->fs_dev, block, fs->fs_blocksize); - if (!bh) - reiserfs_panic ("reiserfs_fetch_ondisk_bitmap: getblk failed"); + if (!bh) { + reiserfs_exit (1, "reiserfs_fetch_ondisk_bitmap: " + "getblk failed"); + } + memset (bh->b_data, 0xff, bh->b_size); mark_buffer_uptodate (bh, 1); } @@ -341,9 +345,10 @@ int reiserfs_flush_to_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t * while (to_copy) { /* we bread to make sure that filesystem contains enough blocks */ bh = getblk (fs->fs_dev, block, fs->fs_blocksize); - if (!bh) - reiserfs_panic ("reiserfs_flush_to_ondisk_bitmap: " - "getblk failed for (%lu)\n", block); + if (!bh) { + reiserfs_exit (1, "Getblk failed for (%lu)\n", block); + } + memset (bh->b_data, 0xff, bh->b_size); mark_buffer_uptodate (bh, 1); @@ -685,7 +690,8 @@ void reiserfs_free_ondisk_bitmap (reiserfs_filsys_t * fs) int reiserfs_open_ondisk_bitmap (reiserfs_filsys_t * fs) { if (fs->fs_bitmap2) - reiserfs_panic ("%s: bitmap is initiaized already", __FUNCTION__); + reiserfs_panic ("bitmap is initiaized already"); + fs->fs_bitmap2 = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb)); if (!fs->fs_bitmap2) return -1; @@ -705,7 +711,8 @@ int reiserfs_open_ondisk_bitmap (reiserfs_filsys_t * fs) int reiserfs_create_ondisk_bitmap (reiserfs_filsys_t * fs) { if (fs->fs_bitmap2) - reiserfs_panic ("create: bitmap is initiaized already"); + reiserfs_panic ("bitmap is initiaized already"); + fs->fs_bitmap2 = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb)); if (!fs->fs_bitmap2) return 0; diff --git a/reiserfscore/journal.c b/reiserfscore/journal.c index 5a4fab4..3803599 100644 --- a/reiserfscore/journal.c +++ b/reiserfscore/journal.c @@ -501,25 +501,37 @@ int reiserfs_open_journal (reiserfs_filsys_t * fs, char * j_filename, int flags) "specified journal device %s.\nMust be not less than (%lu).\n", get_jp_journal_size (sb_jp (sb)) + 1, j_filename, JOURNAL_MIN_SIZE + 1); + close(fs->fs_journal_dev); return 1; } - count = count_blocks (j_filename, fs->fs_blocksize); - if (get_jp_journal_1st_block (sb_jp (sb)) + get_jp_journal_size (sb_jp (sb)) + 1 > count) { - reiserfs_warning (stderr, "Detected journal on specified device %s does not fit to " - "the device.\nStart block (%lu) + size (%lu) less than device size (%lu).\n", - j_filename, get_jp_journal_1st_block(sb_jp (sb)), - get_jp_journal_size(sb_jp (sb)) + 1, count); + if (!(count = count_blocks (j_filename, fs->fs_blocksize))) { + close(fs->fs_journal_dev); + return -1; + } + + if (get_jp_journal_1st_block (sb_jp (sb)) + + get_jp_journal_size (sb_jp (sb)) + 1 > count) + { + reiserfs_warning (stderr, "Detected journal on specified device %s " + "does not fit to the device.\nStart block (%lu) + " + "size (%lu) less than device size (%lu).\n", + j_filename, get_jp_journal_1st_block(sb_jp (sb)), + get_jp_journal_size(sb_jp (sb)) + 1, count); + close(fs->fs_journal_dev); return 1; } /* read journal header */ - fs->fs_jh_bh = bread (fs->fs_journal_dev, get_jp_journal_1st_block (sb_jp (sb)) - + get_jp_journal_size (sb_jp (sb)), fs->fs_blocksize); + fs->fs_jh_bh = bread (fs->fs_journal_dev, + get_jp_journal_1st_block (sb_jp (sb)) + + get_jp_journal_size (sb_jp (sb)), + fs->fs_blocksize); if (!fs->fs_jh_bh) { - reiserfs_warning (stderr, "reiserfs_open_journal: bread failed reading " - "journal header.\n"); + reiserfs_warning (stderr, "reiserfs_open_journal: bread failed " + "reading journal header.\n"); + close(fs->fs_journal_dev); return -1; } @@ -574,7 +586,9 @@ int reiserfs_create_journal( st.st_rdev = 0; } else { /* journal is to be on separate device */ - blocks = count_blocks (j_device, fs->fs_blocksize); + if (!(blocks = count_blocks (j_device, fs->fs_blocksize))) + return 0; + if (!len) { /* default size of a journal on a separate device is whole device */ if (blocks < offset) { diff --git a/reiserfscore/node_formats.c b/reiserfscore/node_formats.c index c17a5c5..59697be 100644 --- a/reiserfscore/node_formats.c +++ b/reiserfscore/node_formats.c @@ -528,7 +528,7 @@ int known_hashes (void) #define good_name(hashfn,name,namelen,deh_offset) \ -(GET_HASH_VALUE ((hashfn) (name, namelen)) == GET_HASH_VALUE (deh_offset)) +(hash_value (hashfn, name, namelen) == GET_HASH_VALUE (deh_offset)) /* this also sets hash function */ @@ -579,7 +579,7 @@ int is_properly_hashed (reiserfs_filsys_t * fs, } -int find_hash_in_use (char * name, int namelen, __u32 hash_value_masked, unsigned int code_to_try_first) +int find_hash_in_use (char * name, int namelen, __u32 offset, unsigned int code_to_try_first) { unsigned int i; @@ -587,14 +587,14 @@ int find_hash_in_use (char * name, int namelen, __u32 hash_value_masked, unsigne return UNSET_HASH; if (code_to_try_first) { - if (hash_value_masked == GET_HASH_VALUE (hashes [code_to_try_first].func (name, namelen))) + if (good_name (hashes [code_to_try_first].func, name, namelen, offset)) return code_to_try_first; } for (i = 1; i < HASH_AMOUNT; i ++) { if (i == code_to_try_first) continue; - if (hash_value_masked == GET_HASH_VALUE (hashes [i].func (name, namelen))) + if (good_name (hashes [i].func, name, namelen, offset)) return i; } @@ -1051,17 +1051,18 @@ char * name_in_entry (struct reiserfs_de_head * deh, int pos_in_item) int name_in_entry_length (struct item_head * ih, struct reiserfs_de_head * deh, int pos_in_item) { - int len; + int len, i; char * name; len = entry_length (ih, deh, pos_in_item); name = name_in_entry (deh, pos_in_item); // name might be padded with 0s - while (!name [len - 1] && len > 0) - len --; + i = 0; + while (name[i] && i < len) + i++; - return len; + return i; } int name_length (char * name, int key_format) diff --git a/reiserfscore/prints.c b/reiserfscore/prints.c index 0f7aadb..c2522e4 100644 --- a/reiserfscore/prints.c +++ b/reiserfscore/prints.c @@ -332,8 +332,7 @@ void print_directory_item (FILE * fp, reiserfs_filsys_t * fs, GET_HASH_VALUE (get_deh_offset (deh)), GET_GENERATION_NUMBER (get_deh_offset (deh)), get_deh_location (deh), get_deh_state (deh), - code2name (find_hash_in_use (name, namelen, - GET_HASH_VALUE (get_deh_offset (deh)), + code2name (find_hash_in_use (name, namelen, get_deh_offset (deh), fs ? get_sb_hash_code (fs->fs_ondisk_sb) : UNSET_HASH))); /*fs ? (is_properly_hashed (fs, name, namelen, deh_offset (deh)) ? "" : "(BROKEN)") : "??");*/ } @@ -648,7 +647,7 @@ int print_super_block (FILE * fp, reiserfs_filsys_t * fs, char * file_name, "bitmaps, data, reserved] blocks): %u\n", get_sb_free_blocks (sb)); reiserfs_warning (fp, "Root block: %u\n", get_sb_root_block (sb)); } - reiserfs_warning (fp, "Filesystem marked as %scleanly umounted\n", + reiserfs_warning (fp, "Filesystem is %sclean\n", (get_sb_umount_state (sb) == FS_CLEANLY_UMOUNTED) ? "" : "NOT "); if (short_print) diff --git a/reiserfscore/reiserfslib.c b/reiserfscore/reiserfslib.c index a54f72f..d904b5b 100644 --- a/reiserfscore/reiserfslib.c +++ b/reiserfscore/reiserfslib.c @@ -52,7 +52,8 @@ int is_block_count_correct (unsigned long journal_offset, unsigned int block_siz /* read super block. fixme: only 4k blocks, pre-journaled format is refused. Journal and bitmap are to be opened separately. skip_check is set to 1 if checks of openned SB should be omitted.*/ -reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int *error, void * vp, int check) +reiserfs_filsys_t * reiserfs_open (char * filename, int flags, + int *error, void * vp, int check) { reiserfs_filsys_t * fs; struct buffer_head * bh; @@ -838,16 +839,11 @@ void reiserfs_insert_item (reiserfs_filsys_t * fs, struct path * path, /*===========================================================================*/ -static __u32 hash_value (reiserfs_filsys_t * fs, char * name) +__u32 hash_value (hashf_t func, char * name, int namelen) { __u32 res; - if (!strcmp (name, ".")) - return DOT_OFFSET; - if (!strcmp (name, "..")) - return DOT_DOT_OFFSET; - - res = reiserfs_hash (fs) (name, strlen (name)); + res = func (name, namelen); res = GET_HASH_VALUE(res); if (res == 0) res = 128; @@ -864,14 +860,12 @@ int reiserfs_locate_entry (reiserfs_filsys_t * fs, struct key * dir, char * name struct key entry_key; struct item_head * ih; struct reiserfs_de_head * deh; - __u32 hash; int i, retval; struct key * rdkey; set_key_dirid (&entry_key, get_key_dirid (dir)); set_key_objectid (&entry_key, get_key_objectid (dir)); - hash = hash_value (fs, name); - set_key_offset_v1 (&entry_key, hash); + set_key_offset_v1 (&entry_key, 0); set_key_uniqueness (&entry_key, DIRENTRY_UNIQUENESS); @@ -884,12 +878,6 @@ int reiserfs_locate_entry (reiserfs_filsys_t * fs, struct key * dir, char * name ih = get_ih (path); deh = B_I_DEH (get_bh (path), ih) + path->pos_in_item; for (i = path->pos_in_item; i < get_ih_entry_count (ih); i ++, deh ++) { - if (GET_HASH_VALUE (get_deh_offset (deh)) != GET_HASH_VALUE (hash)) { - /* all entries having the same hash were scanned */ - pathrelse (path); - return 0; - } - /* the name in directory has the same hash as the given name */ if ((name_in_entry_length (ih, deh, i) == (int)strlen (name)) && !memcmp (name_in_entry (deh, i), name, strlen (name))) { @@ -907,13 +895,6 @@ int reiserfs_locate_entry (reiserfs_filsys_t * fs, struct key * dir, char * name if (!is_direntry_key (rdkey)) reiserfs_panic ("reiserfs_locate_entry: can not find name in broken directory yet"); - /* next item is the item of the directory we are looking name in */ - if (GET_HASH_VALUE (get_offset (rdkey)) != hash) { - /* but there is no names with given hash */ - pathrelse (path); - return 0; - } - /* first name of that item may be a name we are looking for */ entry_key = *rdkey; pathrelse (path); @@ -947,7 +928,12 @@ int reiserfs_find_entry (reiserfs_filsys_t * fs, struct key * dir, char * name, set_key_dirid (&entry_key, get_key_dirid (dir)); set_key_objectid (&entry_key, get_key_objectid (dir)); - hash = hash_value (fs, name); + if (!strcmp (name, ".")) + hash = DOT_OFFSET; + else if (!strcmp (name, "..")) + hash = DOT_DOT_OFFSET; + else + hash = hash_value (reiserfs_hash (fs), name, strlen (name)); set_key_offset_v1 (&entry_key, hash); set_key_uniqueness (&entry_key, DIRENTRY_UNIQUENESS); @@ -1059,11 +1045,12 @@ int reiserfs_add_entry (reiserfs_filsys_t * fs, struct key * dir, char * name, i /* compose entry key to look for its place in the tree */ set_key_dirid (&(entry_ih.ih_key), get_key_dirid (dir)); set_key_objectid (&(entry_ih.ih_key), get_key_objectid (dir)); - hash = hash_value (fs, name) + gen_counter; if (!strcmp (name, ".")) hash = DOT_OFFSET; - if (!strcmp (name, "..")) + else if (!strcmp (name, "..")) hash = DOT_DOT_OFFSET; + else + hash = hash_value (reiserfs_hash (fs), name, strlen (name)) + gen_counter; set_key_offset_v1 (&(entry_ih.ih_key), hash); set_key_uniqueness (&(entry_ih.ih_key), DIRENTRY_UNIQUENESS); diff --git a/reiserfsprogs.spec b/reiserfsprogs.spec index 895b17a..f824b91 100644 --- a/reiserfsprogs.spec +++ b/reiserfsprogs.spec @@ -1,4 +1,4 @@ -%define reiserfsprogsversion 3.6.18 +%define reiserfsprogsversion 3.6.19 Vendor: Hans Reiser Distribution: Hans Reiser diff --git a/resize_reiserfs/do_shrink.c b/resize_reiserfs/do_shrink.c index 8e38173..b1854c8 100644 --- a/resize_reiserfs/do_shrink.c +++ b/resize_reiserfs/do_shrink.c @@ -25,19 +25,24 @@ static void quit_resizer(reiserfs_filsys_t * fs) /* save changes to bitmap blocks */ reiserfs_close (fs); /* leave fs in ERROR state */ - DIE ("fs shrinking was not completed successfully, run reiserfsck."); + reiserfs_exit(1, "fs shrinking was not completed successfully, " + "run reiserfsck."); } /* block moving */ -static unsigned long move_generic_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h) +static unsigned long move_generic_block(reiserfs_filsys_t * fs, + unsigned long block, + unsigned long bnd, int h) { struct buffer_head * bh, * bh2; /* primitive fsck */ if (block > get_sb_block_count(ondisk_sb)) { - fprintf(stderr, "resize_reiserfs: invalid block number (%lu) found.\n", block); + fprintf(stderr, "resize_reiserfs: invalid block number " + "(%lu) found.\n", block); quit_resizer(fs); } + /* progress bar, 3D style :) */ if (opt_verbose) print_how_far(stderr, &total_node_cnt, blocks_used, 1, 0); @@ -57,7 +62,7 @@ static unsigned long move_generic_block(reiserfs_filsys_t * fs, unsigned long bl bh = bread(fs->fs_dev, block, fs->fs_blocksize); if (!bh) - reiserfs_panic ("move_generic_block: bread failed.\n"); + reiserfs_exit (1, "move_generic_block: bread failed.\n"); reiserfs_bitmap_find_zero_bit(bmp, &unused_block); if (unused_block == 0 || unused_block >= bnd) { @@ -103,7 +108,7 @@ static unsigned long move_formatted_block(reiserfs_filsys_t * fs, unsigned long bh = bread(fs->fs_dev, block, fs->fs_blocksize); if (!bh) - reiserfs_panic ("move_formatted_block: bread failed"); + reiserfs_exit (1, "move_formatted_block: bread failed"); if (is_leaf_node (bh)) { @@ -208,7 +213,7 @@ int shrink_fs(reiserfs_filsys_t * fs, long long int blocks) reiserfs_reopen(fs, O_RDWR); if (reiserfs_open_ondisk_bitmap (fs)) - DIE("cannot open ondisk bitmap"); + reiserfs_exit(1, "cannot open ondisk bitmap"); bmp = fs->fs_bitmap2; ondisk_sb = fs->fs_ondisk_sb; diff --git a/resize_reiserfs/resize_reiserfs.8 b/resize_reiserfs/resize_reiserfs.8 index 10cdce5..7db59bf 100644 --- a/resize_reiserfs/resize_reiserfs.8 +++ b/resize_reiserfs/resize_reiserfs.8 @@ -1,7 +1,7 @@ .\" -*- nroff -*- .\" Copyright 1996-2004 Hans Reiser. .\" -.TH RESIZE_REISERFS 8 "January 2004" "Reiserfsprogs-3.6.18" +.TH RESIZE_REISERFS 8 "January 2004" "Reiserfsprogs-3.6.19" .SH NAME resize_reiserfs \- resizer tool for the ReiserFS filesystem .SH SYNOPSIS diff --git a/resize_reiserfs/resize_reiserfs.c b/resize_reiserfs/resize_reiserfs.c index e5d774d..691d855 100644 --- a/resize_reiserfs/resize_reiserfs.c +++ b/resize_reiserfs/resize_reiserfs.c @@ -99,7 +99,7 @@ static int expand_fs (reiserfs_filsys_t * fs, long long int block_count_new) { reiserfs_reopen(fs, O_RDWR); if (reiserfs_open_ondisk_bitmap (fs)) - DIE("cannot open ondisk bitmap"); + reiserfs_exit(1, "cannot open ondisk bitmap"); sb = fs->fs_ondisk_sb; @@ -109,7 +109,7 @@ static int expand_fs (reiserfs_filsys_t * fs, long long int block_count_new) { if (reiserfs_expand_bitmap(fs->fs_bitmap2, block_count_new)) - DIE("cannot expand bitmap\n"); + reiserfs_exit(1, "cannot expand bitmap\n"); /* count bitmap blocks in new fs */ @@ -201,12 +201,12 @@ int main(int argc, char *argv[]) { switch (c) { case 's' : if (!optarg) - DIE("Missing argument to -s option"); + reiserfs_exit(1, "Missing argument to -s option"); bytes_count_str = optarg; break; case 'j' : if (!optarg) - DIE("Missing argument to -j option"); + reiserfs_exit(1, "Missing argument to -j option"); jdevice_name = optarg; case 'f': opt_force = 1; @@ -244,26 +244,38 @@ int main(int argc, char *argv[]) { devname = argv[optind]; fs = reiserfs_open(devname, O_RDONLY, &error, 0, 1); - if (!fs) - DIE ("cannot open '%s': %s", devname, strerror(error)); + if (!fs) { + if (error) { + reiserfs_exit(1, "cannot open '%s': %s", + devname, strerror(error)); + } else { + exit(1); + } + } - if (reiserfs_open_journal (fs, jdevice_name, O_RDWR | O_LARGEFILE)) - DIE ("Failed to open the journal device (%s).", jdevice_name); + if (reiserfs_open_journal (fs, jdevice_name, O_RDWR | O_LARGEFILE)) { + reiserfs_exit(1, "Failed to open the journal device (%s).", + jdevice_name); + } if (reiserfs_journal_params_check(fs)) { - if (!opt_skipj) - DIE ("Wrong journal parameters detected on (%s)", jdevice_name); - else + if (!opt_skipj) { + reiserfs_exit(1, "Wrong journal parameters detected on (%s)", + jdevice_name); + } else { reiserfs_close_journal(fs); + } } /* forced to continue without journal available/specified */ if (no_reiserfs_found (fs)) { - DIE ("no reiserfs found on the device."); + reiserfs_exit(1, "no reiserfs found on the device."); } + if (!spread_bitmaps (fs)) { - DIE ("cannot resize reiserfs in old (not spread bitmap) format."); + reiserfs_exit(1, "cannot resize reiserfs in old (not spread " + "bitmap) format."); } sb = fs->fs_ondisk_sb; @@ -295,7 +307,7 @@ int main(int argc, char *argv[]) { if (get_sb_umount_state(sb) != FS_CLEANLY_UMOUNTED) /* fixme: shouldn't we check for something like: fsck guarantees: fs is ok */ - DIE ("the file system isn't in valid state."); + reiserfs_exit(1, "the file system isn't in valid state."); /* Needed to keep idiot compiler from issuing false warning */ sb_old = 0; diff --git a/tune/reiserfstune.8 b/tune/reiserfstune.8 index ac75992..38ad85b 100644 --- a/tune/reiserfstune.8 +++ b/tune/reiserfstune.8 @@ -1,7 +1,7 @@ .\" -*- nroff -*- .\" Copyright 1996-2004 Hans Reiser. .\" -.TH REISERFSTUNE 8 "February 2004" "Reiserfsprogs-3.6.18" +.TH REISERFSTUNE 8 "February 2004" "Reiserfsprogs-3.6.19" .SH NAME reiserfstune \- The tunning tool for the ReiserFS filesystem. .SH SYNOPSIS diff --git a/tune/tune.c b/tune/tune.c index 2c789d9..869c7ba 100644 --- a/tune/tune.c +++ b/tune/tune.c @@ -525,7 +525,8 @@ int main (int argc, char **argv) #if defined(O_LARGEFILE) | O_LARGEFILE #endif - )) { + )) + { message ("Failed to open the journal device (%s).", jdevice_name); return 1; } @@ -577,10 +578,10 @@ int main (int argc, char **argv) } else { #if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H) if (!uuid_is_null(UUID)) - reiserfs_panic ("UUID cannot be specified for 3.5 format\n"); + reiserfs_exit (1, "UUID cannot be specified for 3.5 format\n"); #endif if (LABEL) - reiserfs_panic ("LABEL cannot be specified for 3.5 format\n"); + reiserfs_exit (1, "LABEL cannot be specified for 3.5 format\n"); } if (!j_new_device_name) { |