[PATCH 5/8][e2fsprogs] add new inline functions to get blocks counters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Valerie Clement <valerie.clement@xxxxxxxx>

In preparation for 64-bit support, this patch introduces new inline functions
to get block counts in the on-disk superblock.

If the EXT4_FEATURE_INCOMPAT_64BIT flag is not set, the functions return the
low 32 bits of block counters.

Changes from the previous version:
Replace macros definition by inline functions because some previous macros
evaluate their argument more than once.

Signed-off-by: Valerie Clement <valerie.clement@xxxxxxxx>
---

 lib/ext2fs/ext2fs.h |   72 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 3aa9c8f..b60318c 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1011,6 +1011,13 @@ extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
 				      struct ext2_inode *inode);
 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
+extern blk_t ext2_blocks_count(struct ext2_super_block *super);
+extern blk_t ext2_r_blocks_count(struct ext2_super_block *super);
+extern blk_t ext2_free_blocks_count(struct ext2_super_block *super);
+extern void ext2_blocks_count_set(struct ext2_super_block *super, blk_t blk);
+extern void ext2_r_blocks_count_set(struct ext2_super_block *super, blk_t blk);
+extern void ext2_free_blocks_count_set(struct ext2_super_block *super,
+					blk_t blk);
 
 /*
  * The actual inlined functions definitions themselves...
@@ -1184,17 +1191,6 @@ _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
 		(group * fs->super->s_blocks_per_group);
 }
 
-/*
- * Return the last block (inclusive) in a group
- */
-_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
-{
-	return (group == fs->group_desc_count - 1 ?
-		fs->super->s_blocks_count - 1 :
-		ext2fs_group_first_block(fs, group) +
-			(fs->super->s_blocks_per_group - 1));
-}
-
 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
 					struct ext2_inode *inode)
 {
@@ -1211,6 +1207,60 @@ _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
 		return 0;
 	return ((a - 1) / b) + 1;
 }
+
+_INLINE_ blk_t ext2_blocks_count(struct ext2_super_block *super)
+{
+	return super->s_blocks_count +
+		(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+		(__u64)super->s_blocks_count_hi << 32 : 0);
+}
+
+_INLINE_ blk_t ext2_r_blocks_count(struct ext2_super_block *super)
+{
+	return super->s_r_blocks_count +
+		(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+		(__u64)super->s_r_blocks_count_hi << 32 : 0);
+}
+
+_INLINE_ blk_t ext2_free_blocks_count(struct ext2_super_block *super)
+{
+	return super->s_free_blocks_count +
+		(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+		(__u64)super->s_free_blocks_hi << 32 : 0);
+}
+
+_INLINE_ void ext2_blocks_count_set(struct ext2_super_block *super, blk_t blk)
+{
+	super->s_blocks_count = blk;
+	if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+		super->s_blocks_count_hi = (__u64) blk >> 32;
+}
+
+_INLINE_ void ext2_r_blocks_count_set(struct ext2_super_block *super, blk_t blk)
+{
+	super->s_r_blocks_count = blk;
+	if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+		super->s_r_blocks_count_hi = (__u64) blk >> 32;
+}
+
+_INLINE_ void ext2_free_blocks_count_set(struct ext2_super_block *super,
+					 blk_t blk)
+{
+	super->s_free_blocks_count = blk;
+	if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+		super->s_free_blocks_hi = (__u64) blk >> 32;
+}
+
+/*
+ * Return the last block (inclusive) in a group
+ */
+_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
+{
+	return (group == fs->group_desc_count - 1 ?
+		fs->super->s_blocks_count - 1 :
+		ext2fs_group_first_block(fs, group) +
+			(fs->super->s_blocks_per_group - 1));
+}
 #undef _INLINE_
 #endif
 


-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux