f2fs_iget checks if i_mode is valid. If it is not, the file cannot be accessed as well as deleted. To make sure such files can be removed, fsck adds the same check, and removes incorrect inode blocks.
Signed-off-by: Sheng Yong <shengyo...@huawei.com> --- fsck/fsck.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fsck/fsck.c b/fsck/fsck.c index 56a47be..77490d8 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -458,6 +458,25 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid, return 0; } +static int sanity_check_inode(struct f2fs_sb_info *sbi, struct f2fs_node *node) +{ + struct f2fs_fsck *fsck = F2FS_FSCK(sbi); + struct f2fs_inode *fi = &node->i; + + if (!(le16_to_cpu(fi->i_mode) & S_IFMT)) { + ASSERT_MSG("i_mode is not valid. [0x%x]", le16_to_cpu(fi->i_mode)); + goto remove_node; + } + + return 0; + +remove_node: + f2fs_set_bit(le32_to_cpu(node->footer.ino), fsck->nat_area_bitmap); + fsck->chk.valid_blk_cnt--; + fsck->chk.valid_node_cnt--; + return -EINVAL; +} + static int fsck_chk_xattr_blk(struct f2fs_sb_info *sbi, u32 ino, u32 x_nid, u32 *blk_cnt) { @@ -500,6 +519,8 @@ int fsck_chk_node_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode, goto err; if (ntype == TYPE_INODE) { + if (sanity_check_inode(sbi, node_blk)) + goto err; fsck_chk_inode_blk(sbi, nid, ftype, node_blk, blk_cnt, &ni); } else { switch (ntype) { -- 2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel