Skip to contentSkip to conversation

fsck.f2fs add a simple check orphan inodes in -p 1 mode

PATCH New Yunlei He 1 participant 2 messages Nov 19, 2016

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/2 fsck.f2fs add a simple check orphan inodes in -p 1 mode

This patch add a simple check orphan inodes in -p 1 mode

---
 fsck/fsck.c | 21 +++++++++++++++++++--
 fsck/fsck.h |  2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)
fsck/fsck.c +19 -2
index 0009ea4..fd28d94 100644
@@ -1494,7 +1494,7 @@ int fsck_chk_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 	return 0;
 }
 
-void fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
+int fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
 {
 	u32 blk_cnt = 0;
 	block_t start_blk, orphan_blkaddr, i, j;
@@ -1503,7 +1503,7 @@ void fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
 	u32 entry_count;
 
 	if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG))
-		return;
+		return 0;
 
 	start_blk = __start_cp_addr(sbi) + 1 + get_sb(cp_payload);
 	orphan_blkaddr = __start_sum_addr(sbi) - 1 - get_sb(cp_payload);
@@ -1524,7 +1524,18 @@ void fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
 		for (j = 0; j < entry_count; j++) {
 			nid_t ino = le32_to_cpu(orphan_blk->ino[j]);
 			DBG(1, "[%3d] ino [0x%x]\n", i, ino);
+			struct node_info ni;
 			blk_cnt = 1;
+
+			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))
+					return -EINVAL;
+
+				continue;
+			}
+
 			ret = fsck_chk_node_blk(sbi, NULL, ino, NULL,
 					F2FS_FT_ORPHAN, TYPE_INODE, &blk_cnt,
 					NULL);
@@ -1547,6 +1558,8 @@ void fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
 	}
 	free(orphan_blk);
 	free(new_blk);
+
+	return 0;
 }
 
 int fsck_chk_meta(struct f2fs_sb_info *sbi)
@@ -1605,6 +1618,10 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
 		return -EINVAL;
 	}
 
+	/* 4. check orphan inode simply */
+	if (fsck_chk_orphan_node(sbi))
+		return -EINVAL;
+
 	if (fsck->nat_valid_inode_cnt != le32_to_cpu(cp->valid_inode_count)) {
 		ASSERT_MSG("valid inode does not match: nat_valid_inode_cnt %u,"
 				" valid_inode_count %u",
fsck/fsck.h +1 -1
index 412e7b7..8785de8 100644
@@ -109,7 +109,7 @@ enum seg_type {
 
 struct selabel_handle;
 
-extern void fsck_chk_orphan_node(struct f2fs_sb_info *);
+extern int fsck_chk_orphan_node(struct f2fs_sb_info *);
 extern int fsck_chk_node_blk(struct f2fs_sb_info *, struct f2fs_inode *, u32,
 		u8 *, enum FILE_TYPE, enum NODE_TYPE, u32 *,
 		struct child_info *);
Signature · 4 lines
2.10.1


------------------------------------------------------------------------------
author
#1 lore raw

PATCH 2/2 dump.f2fs: fix an error in dump nat pack num

This patch fix an error in dump nat pack num

---
 fsck/dump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fsck/dump.c +2 -2
index 8e7c85c..5d0d3d9 100644
@@ -34,7 +34,7 @@ void nat_dump(struct f2fs_sb_info *sbi)
 	pgoff_t block_addr;
 	char buf[BUF_SZ];
 	int seg_off;
-	int fd, ret, pack = 1;
+	int fd, ret, pack;
 	unsigned int i;
 
 	nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1);
@@ -47,7 +47,7 @@ void nat_dump(struct f2fs_sb_info *sbi)
 	fd = open("dump_nat", O_CREAT|O_WRONLY|O_TRUNC, 0666);
 	ASSERT(fd >= 0);
 
-	for (block_off = 0; block_off < nr_nat_blks; block_off++) {
+	for (block_off = 0; block_off < nr_nat_blks; pack = 1, block_off++) {
 
 		seg_off = block_off >> sbi->log_blocks_per_seg;
 		block_addr = (pgoff_t)(nm_i->nat_blkaddr +
Signature · 4 lines
2.10.1


------------------------------------------------------------------------------