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.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2020-03-19 18:28:49 +08:00 committed by Jaegeuk Kim
parent a64fbe53c3
commit 88d1bd9615

View 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);
}