summaryrefslogtreecommitdiff
path: root/lib/ext2fs
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2011-09-16 09:21:53 -0400
committerTheodore Ts'o <tytso@mit.edu>2011-09-16 09:28:43 -0400
commit98f4547198b369bef7e41eb7ce4a16855726c393 (patch)
treebcc3905013eb56a8698060ca1c1d375286912e54 /lib/ext2fs
parent65b7a463da3b8f7ce0892be579f34ba4cf66456e (diff)
downloade2fsprogs-98f4547198b369bef7e41eb7ce4a16855726c393.tar.gz
e2fsprogs: add ext2fs_group_blocks_count helper
Code to count the number of blocks in the last partial group is cut and pasted around the e2fsprogs codebase a few times. Making this a helper function should improve matters. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs')
-rw-r--r--lib/ext2fs/alloc_sb.c10
-rw-r--r--lib/ext2fs/blknum.c19
-rw-r--r--lib/ext2fs/closefs.c9
-rw-r--r--lib/ext2fs/ext2fs.h1
4 files changed, 22 insertions, 17 deletions
diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c
index 09786a75..2e323894 100644
--- a/lib/ext2fs/alloc_sb.c
+++ b/lib/ext2fs/alloc_sb.c
@@ -74,15 +74,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
if (new_desc_blk)
ext2fs_mark_block_bitmap2(bmap, new_desc_blk);
- if (group == fs->group_desc_count-1) {
- num_blocks = (ext2fs_blocks_count(fs->super) -
- fs->super->s_first_data_block) %
- fs->super->s_blocks_per_group;
- if (!num_blocks)
- num_blocks = fs->super->s_blocks_per_group;
- } else
- num_blocks = fs->super->s_blocks_per_group;
-
+ num_blocks = ext2fs_group_blocks_count(fs, group);
num_blocks -= 2 + fs->inode_blocks_per_group + used_blks;
return num_blocks ;
diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c
index b3e6dcad..b9ac36cf 100644
--- a/lib/ext2fs/blknum.c
+++ b/lib/ext2fs/blknum.c
@@ -43,6 +43,25 @@ blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group)
}
/*
+ * Return the number of blocks in a group
+ */
+int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group)
+{
+ int num_blocks;
+
+ if (group == fs->group_desc_count - 1) {
+ num_blocks = (ext2fs_blocks_count(fs->super) -
+ fs->super->s_first_data_block) %
+ fs->super->s_blocks_per_group;
+ if (!num_blocks)
+ num_blocks = fs->super->s_blocks_per_group;
+ } else
+ num_blocks = fs->super->s_blocks_per_group;
+
+ return num_blocks;
+}
+
+/*
* Return the inode data block count
*/
blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 952f4966..51ef63cb 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -152,14 +152,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
&ret_new_desc_blk2,
&ret_used_blks);
- if (group == fs->group_desc_count-1) {
- numblocks = (ext2fs_blocks_count(fs->super) -
- (blk64_t) fs->super->s_first_data_block) %
- (blk64_t) fs->super->s_blocks_per_group;
- if (!numblocks)
- numblocks = fs->super->s_blocks_per_group;
- } else
- numblocks = fs->super->s_blocks_per_group;
+ numblocks = ext2fs_group_blocks_count(fs, group);
if (ret_super_blk)
*ret_super_blk = (blk_t)ret_super_blk2;
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index ed1a3ce5..1b9acc30 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -765,6 +765,7 @@ extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
+extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
struct ext2_inode *inode);
extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,