Skip to contentSkip to conversation

fsck.f2fs: fix wrong addrs_per_{inode,block}

PATCH New Chao Yu 1 participant 1 message Mar 19, 2020 Library code

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 fsck.f2fs: fix wrong addrs_per_{inode,block}

generic/339 reports below assertion on image w/ compression feature enabled.

[ASSERT] (f2fs_check_dirent_position:1366) -->
Wrong position of dirent pino:4521, name:"....", level:9, dir_level:0, pgofs:1880, correct range:[1882, 1883]

The root cause is we calculate blkaddr number in direct node incorrectly for directory inode, since during calculation, we only need align blkaddr number to cluster size for regular inode rather than directory inode, let's fix it.

---
 lib/libf2fs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/libf2fs.c +4 -2
index 5c064c8..c2960fd 100644
@@ -504,14 +504,16 @@ unsigned int addrs_per_inode(struct f2fs_inode *i)
 {
 	unsigned int addrs = CUR_ADDRS_PER_INODE(i) - get_inline_xattr_addrs(i);
 
-	if (!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
+	if (!S_ISREG(le16_to_cpu(i->i_mode)) ||
+			!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
 		return addrs;
 	return ALIGN_DOWN(addrs, 1 << i->i_log_cluster_size);
 }
 
 unsigned int addrs_per_block(struct f2fs_inode *i)
 {
-	if (!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
+	if (!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);
 }
Signature · 8 lines
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel