reiserfs: fix usage of signed ints for block numbers
[powerpc.git] / fs / reiserfs / bitmap.c
index b286ccb..f727517 100644 (file)
@@ -47,7 +47,9 @@
     test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
 
 static inline void get_bit_address(struct super_block *s,
-                                  b_blocknr_t block, int *bmap_nr, int *offset)
+                                  b_blocknr_t block,
+                                  unsigned int *bmap_nr,
+                                  unsigned int *offset)
 {
        /* It is in the bitmap block number equal to the block
         * number divided by the number of bits in a block. */
@@ -56,10 +58,9 @@ static inline void get_bit_address(struct super_block *s,
        *offset = block & ((s->s_blocksize << 3) - 1);
 }
 
-#ifdef CONFIG_REISERFS_CHECK
 int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 {
-       int bmap, offset;
+       unsigned int bmap, offset;
 
        if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
                reiserfs_warning(s,
@@ -106,12 +107,11 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 
        return 1;
 }
-#endif                         /* CONFIG_REISERFS_CHECK */
 
 /* searches in journal structures for a given block number (bmap, off). If block
    is found in reiserfs journal it suggests next free block candidate to test. */
-static inline int is_block_in_journal(struct super_block *s, int bmap, int
-                                     off, int *next)
+static inline int is_block_in_journal(struct super_block *s, unsigned int bmap,
+                                     int off, int *next)
 {
        b_blocknr_t tmp;
 
@@ -132,8 +132,8 @@ static inline int is_block_in_journal(struct super_block *s, int bmap, int
 /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap
  * block; */
 static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
-                            int bmap_n, int *beg, int boundary, int min,
-                            int max, int unfm)
+                            unsigned int bmap_n, int *beg, int boundary,
+                            int min, int max, int unfm)
 {
        struct super_block *s = th->t_super;
        struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
@@ -309,16 +309,16 @@ __le32 reiserfs_choose_packing(struct inode * dir)
  * bitmap and place new blocks there. Returns number of allocated blocks. */
 static int scan_bitmap(struct reiserfs_transaction_handle *th,
                       b_blocknr_t * start, b_blocknr_t finish,
-                      int min, int max, int unfm, unsigned long file_block)
+                      int min, int max, int unfm, sector_t file_block)
 {
        int nr_allocated = 0;
        struct super_block *s = th->t_super;
        /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr
         * - Hans, it is not a block number - Zam. */
 
-       int bm, off;
-       int end_bm, end_off;
-       int off_max = s->s_blocksize << 3;
+       unsigned int bm, off;
+       unsigned int end_bm, end_off;
+       unsigned int off_max = s->s_blocksize << 3;
 
        BUG_ON(!th->t_trans_id);
 
@@ -385,7 +385,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
        struct reiserfs_super_block *rs;
        struct buffer_head *sbh, *bmbh;
        struct reiserfs_bitmap_info *apbi;
-       int nr, offset;
+       unsigned int nr, offset;
 
        BUG_ON(!th->t_trans_id);
 
@@ -434,12 +434,19 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th,
                         int for_unformatted)
 {
        struct super_block *s = th->t_super;
-
        BUG_ON(!th->t_trans_id);
 
        RFALSE(!s, "vs-4061: trying to free block on nonexistent device");
-       RFALSE(is_reusable(s, block, 1) == 0,
-              "vs-4071: can not free such block");
+       if (!is_reusable(s, block, 1))
+               return;
+
+       if (block > sb_block_count(REISERFS_SB(s)->s_rs)) {
+               reiserfs_panic(th->t_super, "bitmap-4072",
+                              "Trying to free block outside file system "
+                              "boundaries (%lu > %lu)",
+                              block, sb_block_count(REISERFS_SB(s)->s_rs));
+               return;
+       }
        /* mark it before we clear it, just in case */
        journal_mark_freed(th, s, block);
        _reiserfs_free_block(th, inode, block, for_unformatted);
@@ -449,11 +456,11 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th,
 static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th,
                                         struct inode *inode, b_blocknr_t block)
 {
+       BUG_ON(!th->t_trans_id);
        RFALSE(!th->t_super,
               "vs-4060: trying to free block on nonexistent device");
-       RFALSE(is_reusable(th->t_super, block, 1) == 0,
-              "vs-4070: can not free such block");
-       BUG_ON(!th->t_trans_id);
+       if (!is_reusable(th->t_super, block, 1))
+               return;
        _reiserfs_free_block(th, inode, block, 1);
 }
 
@@ -1201,63 +1208,6 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t * hint, b_blocknr_t * new
        return ret;
 }
 
-/* These 2 functions are here to provide blocks reservation to the rest of kernel */
-/* Reserve @blocks amount of blocks in fs pointed by @sb. Caller must make sure
-   there are actually this much blocks on the FS available */
-void reiserfs_claim_blocks_to_be_allocated(struct super_block *sb,     /* super block of
-                                                                          filesystem where
-                                                                          blocks should be
-                                                                          reserved */
-                                          int blocks   /* How much to reserve */
-    )
-{
-
-       /* Fast case, if reservation is zero - exit immediately. */
-       if (!blocks)
-               return;
-
-       spin_lock(&REISERFS_SB(sb)->bitmap_lock);
-       REISERFS_SB(sb)->reserved_blocks += blocks;
-       spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
-}
-
-/* Unreserve @blocks amount of blocks in fs pointed by @sb */
-void reiserfs_release_claimed_blocks(struct super_block *sb,   /* super block of
-                                                                  filesystem where
-                                                                  blocks should be
-                                                                  reserved */
-                                    int blocks /* How much to unreserve */
-    )
-{
-
-       /* Fast case, if unreservation is zero - exit immediately. */
-       if (!blocks)
-               return;
-
-       spin_lock(&REISERFS_SB(sb)->bitmap_lock);
-       REISERFS_SB(sb)->reserved_blocks -= blocks;
-       spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
-       RFALSE(REISERFS_SB(sb)->reserved_blocks < 0,
-              "amount of blocks reserved became zero?");
-}
-
-/* This function estimates how much pages we will be able to write to FS
-   used for reiserfs_file_write() purposes for now. */
-int reiserfs_can_fit_pages(struct super_block *sb      /* superblock of filesystem
-                                                          to estimate space */ )
-{
-       int space;
-
-       spin_lock(&REISERFS_SB(sb)->bitmap_lock);
-       space =
-           (SB_FREE_BLOCKS(sb) -
-            REISERFS_SB(sb)->reserved_blocks) >> (PAGE_CACHE_SHIFT -
-                                                  sb->s_blocksize_bits);
-       spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
-
-       return space > 0 ? space : 0;
-}
-
 void reiserfs_cache_bitmap_metadata(struct super_block *sb,
                                     struct buffer_head *bh,
                                     struct reiserfs_bitmap_info *info)