fsck.f2fs: fix wrong addrs_per_{inode,block}
authorChao Yu <yuchao0@huawei.com>
Thu, 19 Mar 2020 10:28:49 +0000 (18:28 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 6 May 2020 14:41:06 +0000 (07:41 -0700)
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.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
lib/libf2fs.c

index 5c064c8..c2960fd 100644 (file)
@@ -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);
 }