1. 程式人生 > >f2fs系列文章fsck(二)

f2fs系列文章fsck(二)

    fsck_chk_node_blk完成對所有型別的node進行檢查。

    node型別有:TYPE_INODE,TYPE_DIRECT_NODE,TYPE_INDIRECT_NODE,TYPE_DOUBLE_INDIRECT_NODE,TYPE_XATTR。但是呼叫這個函式不會是TYPE_XATTR。

    檔案型別有:F2FS_FT_UNKNOWN、F2FS_FT_REG_FILE、F2FS_FT_DIR、F2FS_FT_CHRDEV、F2FS_FT_BLKDEV、F2FS_FT_FIFO、F2FS_FT_SOCK、F2FS_FT_SYMLINK、F2FS_FT_MAX、F2FS_FT_ORPHAN、F2FS_FT_XATTR。這裡面重點關注的是F2FS_FT_DIR和F2FS_FT_ORPHAN。

    fsck_chk_node_blk首先通過sanity_check_nid對nid進行基本的檢查,如果是TYPE_INODE就對inode的i_mode進行檢查來選擇是否將inode刪掉。然後就呼叫fsck_chk_inode_blk對inode下的所有的node和data進行檢查。如果是TYPE_DIRECT_NODE就呼叫fsck_chk_dnode_blk對direct node進行檢查,如果是TYPE_INDIRECT_NODE就呼叫fsck_chk_idnode_blk對indirect node進行檢查,如果是TYPE_DINDIRECT_NODE就呼叫fsck_chk_didnode_blk對dindirect node進行檢查。

int fsck_chk_node_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
		u32 nid, enum FILE_TYPE ftype, enum NODE_TYPE ntype,
		u32 *blk_cnt, struct child_info *child)
{
	struct node_info ni;
	struct f2fs_node *node_blk = NULL;
	node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
	ASSERT(node_blk != NULL);
	if (sanity_check_nid(sbi, nid, node_blk, ftype, ntype, &ni))
		goto err;

	if (ntype == TYPE_INODE) {
		struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
		if (sanity_check_inode(sbi, node_blk))
			goto err;
		fsck_chk_inode_blk(sbi, nid, ftype, node_blk, blk_cnt, &ni, child);
		quota_add_inode_usage(fsck->qctx, nid, &node_blk->i);
	} else {
		switch (ntype) {
		case TYPE_DIRECT_NODE:
			f2fs_set_main_bitmap(sbi, ni.blk_addr, CURSEG_WARM_NODE);
			fsck_chk_dnode_blk(sbi, inode, nid, ftype, node_blk,
					blk_cnt, child, &ni);
			break;
		case TYPE_INDIRECT_NODE:
			f2fs_set_main_bitmap(sbi, ni.blk_addr, CURSEG_COLD_NODE);
			fsck_chk_idnode_blk(sbi, inode, ftype, node_blk, blk_cnt, child);
			break;
		case TYPE_DOUBLE_INDIRECT_NODE:
			f2fs_set_main_bitmap(sbi, ni.blk_addr, CURSEG_COLD_NODE);
			fsck_chk_didnode_blk(sbi, inode, ftype, node_blk, blk_cnt, child);
			break;
		default:
			ASSERT(0);
		}
	}
	free(node_blk);
	return 0;
err:
	free(node_blk);
	return -EINVAL;
}