]> git.hungrycats.org Git - linux/commitdiff
[PATCH] reiserfs: small filesystem fix
authorChris Mason <mason@suse.com>
Mon, 18 Oct 2004 15:55:00 +0000 (08:55 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 18 Oct 2004 15:55:00 +0000 (08:55 -0700)
On small filesystems (<128M), make sure not to reference bitmap blocks that
don't exist.

Thanks to Jan Kara for finding this bug.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/reiserfs/bitmap.c

index b5e4498fcfebffab88fb6be62577c29825f25ea8..1dae6c8270adfb15eb3a74b52f1b156238a96758 100644 (file)
@@ -236,6 +236,9 @@ static int bmap_hash_id(struct super_block *s, u32 id) {
        if (!bm)
            bm = 1;
     }
+    /* this can only be true when SB_BMAP_NR = 1 */
+    if (bm >= SB_BMAP_NR(s))
+       bm = 0;
     return bm;
 }
 
@@ -293,6 +296,10 @@ static int scan_bitmap (struct reiserfs_transaction_handle *th,
 
     get_bit_address (s, *start, &bm, &off);
     get_bit_address (s, finish, &end_bm, &end_off);
+    if (bm > SB_BMAP_NR(s))
+        return 0;
+    if (end_bm > SB_BMAP_NR(s))
+        end_bm = SB_BMAP_NR(s);
 
     /* When the bitmap is more than 10% free, anyone can allocate.
      * When it's less than 10% free, only files that already use the
@@ -313,6 +320,7 @@ static int scan_bitmap (struct reiserfs_transaction_handle *th,
            if (nr_allocated)
                goto ret;
         }
+       /* we know from above that start is a reasonable number */
        get_bit_address (s, *start, &bm, &off);
     }
 
@@ -1050,9 +1058,10 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint,
 {
     int initial_amount_needed = amount_needed;
     int ret;
+    struct super_block *s = hint->th->t_super;
 
     /* Check if there is enough space, taking into account reserved space */
-    if ( SB_FREE_BLOCKS(hint->th->t_super) - REISERFS_SB(hint->th->t_super)->reserved_blocks <
+    if ( SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks <
         amount_needed - reserved_by_us)
         return NO_DISK_SPACE;
     /* should this be if !hint->inode &&  hint->preallocate? */
@@ -1072,6 +1081,8 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint,
 
     /* find search start and save it in hint structure */
     determine_search_start(hint, amount_needed);
+    if (hint->search_start >= SB_BLOCK_COUNT(s))
+        hint->search_start = SB_BLOCK_COUNT(s) - 1;
 
     /* allocation itself; fill new_blocknrs and preallocation arrays */
     ret = blocknrs_and_prealloc_arrays_from_search_start