ext4: introduce ext4_get_group_number()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / ext4 / balloc.c
index 2f2e0da1a6b7774d45e1886c4d22d5a48cc00032..9e8d8ffb063f8d7b7346391bcc9fe7c552b44a35 100644 (file)
@@ -29,6 +29,23 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
  * balloc.c contains the blocks allocation and deallocation routines
  */
 
+/*
+ * Calculate block group number for a given block number
+ */
+ext4_group_t ext4_get_group_number(struct super_block *sb,
+                                  ext4_fsblk_t block)
+{
+       ext4_group_t group;
+
+       if (test_opt2(sb, STD_GROUP_SIZE))
+               group = (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) +
+                        block) >>
+                       (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3);
+       else
+               ext4_get_group_no_and_offset(sb, block, &group, NULL);
+       return group;
+}
+
 /*
  * Calculate the block group number and offset into the block/cluster
  * allocation bitmap, given a block number
@@ -49,14 +66,18 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
 
 }
 
-static int ext4_block_in_group(struct super_block *sb, ext4_fsblk_t block,
-                       ext4_group_t block_group)
+/*
+ * Check whether the 'block' lives within the 'block_group'. Returns 1 if so
+ * and 0 otherwise.
+ */
+static inline int ext4_block_in_group(struct super_block *sb,
+                                     ext4_fsblk_t block,
+                                     ext4_group_t block_group)
 {
        ext4_group_t actual_group;
-       ext4_get_group_no_and_offset(sb, block, &actual_group, NULL);
-       if (actual_group == block_group)
-               return 1;
-       return 0;
+
+       actual_group = ext4_get_group_number(sb, block);
+       return (actual_group == block_group) ? 1 : 0;
 }
 
 /* Return the number of clusters used for file system metadata; this
@@ -635,7 +656,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
        brelse(bitmap_bh);
        printk(KERN_DEBUG "ext4_count_free_clusters: stored = %llu"
               ", computed = %llu, %llu\n",
-              EXT4_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)),
+              EXT4_NUM_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)),
               desc_count, bitmap_count);
        return bitmap_count;
 #else