From: Wuyun Zhao <zhaowu...@wingtech.com> the filesystem will use the cold flag, so deal with it to avoid potential issue of inconsistency
Signed-off-by: Wuyun Zhao <zhaowu...@wingtech.com> --- fsck/dir.c | 6 +----- fsck/node.c | 9 +++++---- include/f2fs_fs.h | 20 ++++++++++++++++++++ mkfs/f2fs_format.c | 14 +++++--------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/fsck/dir.c b/fsck/dir.c index 5f4f75e..64aa539 100644 --- a/fsck/dir.c +++ b/fsck/dir.c @@ -517,11 +517,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi, } set_file_temperature(sbi, node_blk, de->name); - - node_blk->footer.ino = cpu_to_le32(de->ino); - node_blk->footer.nid = cpu_to_le32(de->ino); - node_blk->footer.flag = 0; - node_blk->footer.cp_ver = ckpt->checkpoint_ver; + set_node_footer(node_blk, de->ino, de->ino, 0, le64_to_cpu(ckpt->checkpoint_ver), S_ISDIR(mode)); if (S_ISDIR(mode)) { make_empty_dir(sbi, node_blk); diff --git a/fsck/node.c b/fsck/node.c index 229a99c..66e8a81 100644 --- a/fsck/node.c +++ b/fsck/node.c @@ -69,16 +69,17 @@ block_t new_node_block(struct f2fs_sb_info *sbi, block_t blkaddr = NULL_ADDR; int type; int ret; + u32 ino; + u64 cp_ver; f2fs_inode = dn->inode_blk; node_blk = calloc(BLOCK_SZ, 1); ASSERT(node_blk); - node_blk->footer.nid = cpu_to_le32(dn->nid); - node_blk->footer.ino = f2fs_inode->footer.ino; - node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT); - node_blk->footer.cp_ver = ckpt->checkpoint_ver; + ino = le32_to_cpu(f2fs_inode->footer.ino); + cp_ver = le64_to_cpu(ckpt->checkpoint_ver); + set_node_footer(node_blk, dn->nid, ino, ofs, cp_ver, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode))); type = CURSEG_COLD_NODE; if (IS_DNODE(node_blk)) { diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 709bfd8..3583df4 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -923,6 +923,26 @@ struct f2fs_node { struct node_footer footer; } __attribute__((packed)); +static inline void set_cold_node(struct f2fs_node *rn, bool is_dir) +{ + unsigned int flag = le32_to_cpu(rn->footer.flag); + + if (is_dir) + flag &= ~(0x1 << COLD_BIT_SHIFT); + else + flag |= (0x1 << COLD_BIT_SHIFT); + rn->footer.flag = cpu_to_le32(flag); +} + +static inline void set_node_footer(struct f2fs_node *rn, u32 nid, u32 ino, u32 ofs, u64 ver, bool is_dir) +{ + rn->footer.nid = cpu_to_le32(nid); + rn->footer.ino = cpu_to_le32(ino); + rn->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT); + rn->footer.cp_ver = cpu_to_le64(ver); + set_cold_node(rn, is_dir); +} + /* * For NAT entries */ diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 44575e0..b371adf 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1101,9 +1101,7 @@ static int f2fs_write_root_inode(void) return -1; } - raw_node->footer.nid = sb->root_ino; - raw_node->footer.ino = sb->root_ino; - raw_node->footer.cp_ver = cpu_to_le64(1); + set_node_footer(raw_node, le32_to_cpu(sb->root_ino), le32_to_cpu(sb->root_ino), 0, 1, 1); raw_node->footer.next_blkaddr = cpu_to_le32( get_sb(main_blkaddr) + c.cur_seg[CURSEG_HOT_NODE] * @@ -1256,6 +1254,7 @@ static int f2fs_write_qf_inode(int qtype) u_int64_t main_area_node_seg_blk_offset = 0; __le32 raw_id; int i; + u32 qf_ino; raw_node = calloc(F2FS_BLKSIZE, 1); if (raw_node == NULL) { @@ -1263,9 +1262,8 @@ static int f2fs_write_qf_inode(int qtype) return -1; } - raw_node->footer.nid = sb->qf_ino[qtype]; - raw_node->footer.ino = sb->qf_ino[qtype]; - raw_node->footer.cp_ver = cpu_to_le64(1); + qf_ino = le32_to_cpu(sb->qf_ino[qtype]); + set_node_footer(raw_node, qf_ino, qf_ino, 0, 1, 0); raw_node->footer.next_blkaddr = cpu_to_le32( get_sb(main_blkaddr) + c.cur_seg[CURSEG_HOT_NODE] * @@ -1457,9 +1455,7 @@ static int f2fs_write_lpf_inode(void) return -1; } - raw_node->footer.nid = cpu_to_le32(c.lpf_ino); - raw_node->footer.ino = raw_node->footer.nid; - raw_node->footer.cp_ver = cpu_to_le64(1); + set_node_footer(raw_node, c.lpf_ino, c.lpf_ino, 0, 1, 1); raw_node->footer.next_blkaddr = cpu_to_le32( get_sb(main_blkaddr) + c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg + -- 2.7.4