@@ -278,7 +278,8 @@ static void dump_data_blk(struct f2fs_sb_info *sbi, __u64 offset, u32 blkaddr)
return;
/* get data */
- if (blkaddr == NEW_ADDR || !IS_VALID_BLK_ADDR(sbi, blkaddr)) {
+ if (blkaddr == NEW_ADDR ||
+ !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC)) {
memset(buf, 0, F2FS_BLKSIZE);
} else {
int ret;
@@ -588,7 +589,7 @@ int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)
DBG(1, "nat_entry.version [0x%x]\n", ni.version);
DBG(1, "nat_entry.ino [0x%x]\n", ni.ino);
- if (!IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
+ if (!f2fs_is_valid_blkaddr(sbi, ni.blk_addr, DATA_GENERIC)) {
MSG(force, "Invalid node blkaddr: %u\n\n", ni.blk_addr);
goto out;
}
@@ -108,6 +108,7 @@ enum {
META_SSA,
META_MAX,
META_POR,
+ DATA_GENERIC,
};
#define MAX_RA_BLOCKS 64
@@ -520,20 +521,6 @@ static inline bool IS_VALID_NID(struct f2fs_sb_info *sbi, u32 nid)
<< (sbi->log_blocks_per_seg - 1)));
}
-static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
-{
- if (addr == NULL_ADDR || addr == NEW_ADDR)
- return 1;
-
- if (addr >= le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count) ||
- addr < SM_I(sbi)->main_blkaddr) {
- DBG(1, "block addr [0x%x]\n", addr);
- return 0;
- }
- /* next block offset will be checked at the end of fsck. */
- return 1;
-}
-
static inline bool is_valid_data_blkaddr(block_t blkaddr)
{
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR ||
@@ -236,7 +236,7 @@ static int is_valid_summary(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
get_node_info(sbi, nid, &ni);
- if (!IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+ if (!f2fs_is_valid_blkaddr(sbi, ni.blk_addr, DATA_GENERIC))
goto out;
/* read node_block */
@@ -405,12 +405,12 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
return -EINVAL;
}
- if (ni->blk_addr == NEW_ADDR) {
- ASSERT_MSG("nid is NEW_ADDR. [0x%x]", nid);
+ if (!is_valid_data_blkaddr(ni->blk_addr)) {
+ ASSERT_MSG("nid->blk_addr is 0x%x. [0x%x]", ni->blk_addr, nid);
return -EINVAL;
}
- if (!IS_VALID_BLK_ADDR(sbi, ni->blk_addr)) {
+ if (!f2fs_is_valid_blkaddr(sbi, ni->blk_addr, DATA_GENERIC)) {
ASSERT_MSG("blkaddress is not valid. [0x%x]", ni->blk_addr);
return -EINVAL;
}
@@ -676,7 +676,7 @@ void fsck_reada_node_block(struct f2fs_sb_info *sbi, u32 nid)
if (nid != 0 && IS_VALID_NID(sbi, nid)) {
get_node_info(sbi, nid, &ni);
- if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+ if (f2fs_is_valid_blkaddr(sbi, ni.blk_addr, DATA_GENERIC))
dev_reada_block(ni.blk_addr);
}
}
@@ -1612,7 +1612,8 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, int casefolded,
struct node_info ni;
get_node_info(sbi, ino, &ni);
- if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
+ if (f2fs_is_valid_blkaddr(sbi, ni.blk_addr,
+ DATA_GENERIC)) {
dev_reada_block(ni.blk_addr);
name_len = le16_to_cpu(dentry[i].name_len);
if (name_len > 0)
@@ -1867,7 +1868,7 @@ int fsck_chk_data_blk(struct f2fs_sb_info *sbi, int casefolded,
return 0;
}
- if (!IS_VALID_BLK_ADDR(sbi, blk_addr)) {
+ if (!f2fs_is_valid_blkaddr(sbi, blk_addr, DATA_GENERIC)) {
ASSERT_MSG("blkaddress is not valid. [0x%x]", blk_addr);
return -EINVAL;
}
@@ -1939,7 +1940,8 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
if (c.preen_mode == PREEN_MODE_1 && !c.fix_on) {
get_node_info(sbi, ino, &ni);
if (!IS_VALID_NID(sbi, ino) ||
- !IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
+ !f2fs_is_valid_blkaddr(sbi, ni.blk_addr,
+ DATA_GENERIC)) {
free(orphan_blk);
free(new_blk);
return -EINVAL;
@@ -1997,7 +1999,8 @@ int fsck_chk_quota_node(struct f2fs_sb_info *sbi)
if (c.preen_mode == PREEN_MODE_1 && !c.fix_on) {
get_node_info(sbi, ino, &ni);
if (!IS_VALID_NID(sbi, ino) ||
- !IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+ !f2fs_is_valid_blkaddr(sbi, ni.blk_addr,
+ DATA_GENERIC))
return -EINVAL;
continue;
}
@@ -2136,7 +2139,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
*/
continue;
- if (!IS_VALID_BLK_ADDR(sbi, blk)) {
+ if (!f2fs_is_valid_blkaddr(sbi, blk, DATA_GENERIC)) {
MSG(0, "\tError: nat entry[ino %u block_addr 0x%x]"
" is in valid\n",
ino, blk);
@@ -216,6 +216,8 @@ extern int f2fs_set_sit_bitmap(struct f2fs_sb_info *, u32);
extern void fsck_init(struct f2fs_sb_info *);
extern int fsck_verify(struct f2fs_sb_info *);
extern void fsck_free(struct f2fs_sb_info *);
+extern bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
+ block_t blkaddr, int type);
extern int f2fs_ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
extern int f2fs_do_mount(struct f2fs_sb_info *);
extern void f2fs_do_umount(struct f2fs_sb_info *);
@@ -767,6 +767,7 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
return 0;
break;
case META_POR:
+ case DATA_GENERIC:
if (blkaddr >= MAX_BLKADDR(sbi) ||
blkaddr < MAIN_BLKADDR(sbi))
return 0;
@@ -1596,7 +1597,8 @@ static int f2fs_early_init_nid_bitmap(struct f2fs_sb_info *sbi)
block_t addr;
addr = le32_to_cpu(nat_in_journal(journal, i).block_addr);
- if (!IS_VALID_BLK_ADDR(sbi, addr)) {
+ if (addr != NULL_ADDR &&
+ !f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC)) {
MSG(0, "\tError: f2fs_init_nid_bitmap: addr(%u) is invalid!!!\n", addr);
journal->n_nats = cpu_to_le16(i);
c.fix_on = 1;
use f2fs_is_valid_blkaddr() instead of IS_VALID_BLK_ADDR() to check validity of data/node's block address. use is_valid_data_blkaddr() in sanity_check_nid() to check NULL_ADDR as NEW_ADDR, and print the value in error path explicitly. Signed-off-by: Chao Yu <chao@kernel.org> --- fsck/dump.c | 5 +++-- fsck/f2fs.h | 15 +-------------- fsck/fsck.c | 23 +++++++++++++---------- fsck/fsck.h | 2 ++ fsck/mount.c | 4 +++- 5 files changed, 22 insertions(+), 27 deletions(-)