diff mbox series

[f2fs-dev] f2fs-tools: clean up addrs_per_{inode,block}()

Message ID 20240717085856.2154901-1-chao@kernel.org (mailing list archive)
State New
Headers show
Series [f2fs-dev] f2fs-tools: clean up addrs_per_{inode,block}() | expand

Commit Message

Chao Yu July 17, 2024, 8:58 a.m. UTC
Introduce a new help addrs_per_page() to wrap common code
from addrs_per_inode() and addrs_per_block() for cleanup.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 include/f2fs_fs.h |  7 +++----
 lib/libf2fs.c     | 13 +++----------
 2 files changed, 6 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 75cbf22..d71a2d7 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -927,10 +927,10 @@  static_assert(sizeof(struct node_footer) == 24, "");
 				- sizeof(struct node_footer)) / sizeof(__le32))
 #define CUR_ADDRS_PER_INODE(inode)	(DEF_ADDRS_PER_INODE - \
 					__get_extra_isize(inode))
-#define ADDRS_PER_INODE(i)	addrs_per_inode(i)
+#define ADDRS_PER_INODE(i)	addrs_per_page(i, true)
 /* Address Pointers in a Direct Block */
 #define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))
-#define ADDRS_PER_BLOCK(i)	addrs_per_block(i)
+#define ADDRS_PER_BLOCK(i)	addrs_per_page(i, false)
 /* Node IDs in an Indirect Block */
 #define NIDS_PER_BLOCK    ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))
 
@@ -1565,8 +1565,7 @@  struct f2fs_configuration {
 extern int utf8_to_utf16(char *, const char *, size_t, size_t);
 extern int utf16_to_utf8(char *, const char *, size_t, size_t);
 extern int log_base_2(uint32_t);
-extern unsigned int addrs_per_inode(struct f2fs_inode *);
-extern unsigned int addrs_per_block(struct f2fs_inode *);
+extern unsigned int addrs_per_page(struct f2fs_inode *, bool);
 extern unsigned int f2fs_max_file_offset(struct f2fs_inode *);
 extern __u32 f2fs_inode_chksum(struct f2fs_node *);
 extern __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 03d900e..d179c3c 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -516,9 +516,10 @@  opaque_seq:
 	return __f2fs_dentry_hash(name, len);
 }
 
-unsigned int addrs_per_inode(struct f2fs_inode *i)
+unsigned int addrs_per_page(struct f2fs_inode *i, bool is_inode)
 {
-	unsigned int addrs = CUR_ADDRS_PER_INODE(i) - get_inline_xattr_addrs(i);
+	unsigned int addrs = is_inode ? CUR_ADDRS_PER_INODE(i) -
+		get_inline_xattr_addrs(i) : DEF_ADDRS_PER_BLOCK;
 
 	if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
 			!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
@@ -526,14 +527,6 @@  unsigned int addrs_per_inode(struct f2fs_inode *i)
 	return ALIGN_DOWN(addrs, 1 << i->i_log_cluster_size);
 }
 
-unsigned int addrs_per_block(struct f2fs_inode *i)
-{
-	if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
-			!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
-		return DEF_ADDRS_PER_BLOCK;
-	return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1 << i->i_log_cluster_size);
-}
-
 unsigned int f2fs_max_file_offset(struct f2fs_inode *i)
 {
 	if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||