diff mbox series

[f2fs-dev,6/6] f2fs-tools: use f2fs_init_inode() to clean up codes

Message ID 20230505100205.1921708-6-chao@kernel.org (mailing list archive)
State New
Headers show
Series [f2fs-dev,1/6] f2fs-tools: add packed attribute for struct f2fs_super_block | expand

Commit Message

Chao Yu May 5, 2023, 10:02 a.m. UTC
No logic changes.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fsck/node.c        |   7 ++-
 include/f2fs_fs.h  |  36 +++++++++-----
 mkfs/f2fs_format.c | 118 ++++++++-------------------------------------
 3 files changed, 50 insertions(+), 111 deletions(-)

Comments

Jaegeuk Kim May 8, 2023, 7:42 p.m. UTC | #1
Added this to avoid android build failure.

--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -23,6 +23,7 @@

 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/stat.h>
 #include <stddef.h>
 #include <string.h>
 #include <time.h>

On 05/05, Chao Yu wrote:
> No logic changes.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>  fsck/node.c        |   7 ++-
>  include/f2fs_fs.h  |  36 +++++++++-----
>  mkfs/f2fs_format.c | 118 ++++++++-------------------------------------
>  3 files changed, 50 insertions(+), 111 deletions(-)
> 
> diff --git a/fsck/node.c b/fsck/node.c
> index c3e383b..9ce8a72 100644
> --- a/fsck/node.c
> +++ b/fsck/node.c
> @@ -57,7 +57,12 @@ int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype)
>  		MSG(1, "\tError: Calloc Failed for raw_node!!!\n");
>  		return -ENOMEM;
>  	}
> -	f2fs_init_qf_inode(sb, raw_node, qtype, time(NULL));
> +	f2fs_init_inode(sb, raw_node,
> +			le32_to_cpu(sb->qf_ino[qtype]), time(NULL), 0x8180);
> +
> +	raw_node->i.i_size = cpu_to_le64(1024 * 6);
> +	raw_node->i.i_blocks = cpu_to_le64(1);
> +	raw_node->i.i_flags = FS_IMMUTABLE_FL;
>  
>  	if (is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
>  		cp_ver |= (cur_cp_crc(ckpt) << 32);
> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> index 4accade..cab452d 100644
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -1741,20 +1741,16 @@ static inline void show_version(const char *prog)
>  #endif
>  }
>  
> -static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
> -		struct f2fs_node *raw_node, int qtype, time_t mtime)
> +static inline void f2fs_init_inode(struct f2fs_super_block *sb,
> +		struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode)
>  {
> -	raw_node->footer.nid = sb->qf_ino[qtype];
> -	raw_node->footer.ino = sb->qf_ino[qtype];
> +	raw_node->footer.nid = cpu_to_le32(ino);
> +	raw_node->footer.ino = cpu_to_le32(ino);
>  	raw_node->footer.cp_ver = cpu_to_le64(1);
> -	raw_node->i.i_mode = cpu_to_le16(0x8180);
> -	raw_node->i.i_links = cpu_to_le32(1);
> +
>  	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
>  	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
>  
> -	raw_node->i.i_size = cpu_to_le64(1024 * 6); /* Hard coded */
> -	raw_node->i.i_blocks = cpu_to_le64(1);
> -
>  	raw_node->i.i_atime = cpu_to_le32(mtime);
>  	raw_node->i.i_atime_nsec = 0;
>  	raw_node->i.i_ctime = cpu_to_le32(mtime);
> @@ -1763,9 +1759,15 @@ static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
>  	raw_node->i.i_mtime_nsec = 0;
>  	raw_node->i.i_generation = 0;
>  	raw_node->i.i_xattr_nid = 0;
> -	raw_node->i.i_flags = FS_IMMUTABLE_FL;
> -	raw_node->i.i_current_depth = cpu_to_le32(0);
> +	raw_node->i.i_flags = 0;
> +	raw_node->i.i_current_depth = cpu_to_le32(S_ISDIR(mode) ? 1 : 0);
>  	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
> +	raw_node->i.i_mode = cpu_to_le16(mode);
> +	raw_node->i.i_links = cpu_to_le32(S_ISDIR(mode) ? 2 : 1);
> +
> +	/* for dentry block in directory */
> +	raw_node->i.i_size = cpu_to_le64(1 << get_sb(log_blocksize));
> +	raw_node->i.i_blocks = cpu_to_le64(2);
>  
>  	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
>  		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
> @@ -1775,6 +1777,18 @@ static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
>  	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
>  		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
>  
> +	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
> +		raw_node->i.i_crtime = cpu_to_le32(mtime);
> +		raw_node->i.i_crtime_nsec = 0;
> +	}
> +
> +	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
> +		raw_node->i.i_compr_blocks = 0;
> +		raw_node->i.i_compress_algorithm = 0;
> +		raw_node->i.i_log_cluster_size = 0;
> +		raw_node->i.i_compress_flag = 0;
> +	}
> +
>  	raw_node->i.i_ext.fofs = 0;
>  	raw_node->i.i_ext.blk_addr = 0;
>  	raw_node->i.i_ext.len = 0;
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 666af45..6d02a57 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -1233,7 +1233,7 @@ static int f2fs_discard_obsolete_dnode(void)
>  static int f2fs_write_root_inode(void)
>  {
>  	struct f2fs_node *raw_node = NULL;
> -	uint64_t blk_size_bytes, data_blk_nor;
> +	uint64_t data_blk_nor;
>  	uint64_t main_area_node_seg_blk_offset = 0;
>  
>  	raw_node = calloc(F2FS_BLKSIZE, 1);
> @@ -1242,65 +1242,21 @@ 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);
> -	raw_node->footer.next_blkaddr = cpu_to_le32(
> -			get_sb(main_blkaddr) +
> -			c.cur_seg[CURSEG_HOT_NODE] *
> -			c.blks_per_seg + 1);
> +	f2fs_init_inode(sb, raw_node, le32_to_cpu(sb->root_ino),
> +						mkfs_time, 0x41ed);
>  
> -	raw_node->i.i_mode = cpu_to_le16(0x41ed);
>  	if (c.lpf_ino)
>  		raw_node->i.i_links = cpu_to_le32(3);
> -	else
> -		raw_node->i.i_links = cpu_to_le32(2);
> -	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
> -	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
> -
> -	blk_size_bytes = 1 << get_sb(log_blocksize);
> -	raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes); /* dentry */
> -	raw_node->i.i_blocks = cpu_to_le64(2);
> -
> -	raw_node->i.i_atime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_atime_nsec = 0;
> -	raw_node->i.i_ctime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_ctime_nsec = 0;
> -	raw_node->i.i_mtime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_mtime_nsec = 0;
> -	raw_node->i.i_generation = 0;
> -	raw_node->i.i_xattr_nid = 0;
> -	raw_node->i.i_flags = 0;
> -	raw_node->i.i_current_depth = cpu_to_le32(1);
> -	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
> -		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
> -		raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
> -	}
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
> -		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
>  
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
> -		raw_node->i.i_crtime = cpu_to_le32(mkfs_time);
> -		raw_node->i.i_crtime_nsec = 0;
> -	}
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
> -		raw_node->i.i_compress_algorithm = 0;
> -		raw_node->i.i_log_cluster_size = 0;
> -		raw_node->i.i_compress_flag = 0;
> -	}
> +	raw_node->footer.next_blkaddr = cpu_to_le32(
> +			get_sb(main_blkaddr) +
> +			c.cur_seg[CURSEG_HOT_NODE] *
> +			c.blks_per_seg + 1);
>  
>  	data_blk_nor = get_sb(main_blkaddr) +
>  		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg;
>  	raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blk_nor);
>  
> -	raw_node->i.i_ext.fofs = 0;
> -	raw_node->i.i_ext.blk_addr = 0;
> -	raw_node->i.i_ext.len = 0;
> -
>  	main_area_node_seg_blk_offset = get_sb(main_blkaddr);
>  	main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
>  					c.blks_per_seg;
> @@ -1403,13 +1359,17 @@ static int f2fs_write_qf_inode(int qtype, int offset)
>  		MSG(1, "\tError: Calloc Failed for raw_node!!!\n");
>  		return -1;
>  	}
> -	f2fs_init_qf_inode(sb, raw_node, qtype, mkfs_time);
> +	f2fs_init_inode(sb, raw_node,
> +			le32_to_cpu(sb->qf_ino[qtype]), mkfs_time, 0x8180);
> +
> +	raw_node->i.i_size = cpu_to_le64(1024 * 6);
> +	raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
> +	raw_node->i.i_flags = FS_IMMUTABLE_FL;
>  
>  	raw_node->footer.next_blkaddr = cpu_to_le32(
>  			get_sb(main_blkaddr) +
>  			c.cur_seg[CURSEG_HOT_NODE] *
>  			c.blks_per_seg + 1 + qtype + 1);
> -	raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
>  
>  	data_blk_nor = get_sb(main_blkaddr) +
>  		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1
> @@ -1552,7 +1512,7 @@ static block_t f2fs_add_default_dentry_lpf(void)
>  static int f2fs_write_lpf_inode(void)
>  {
>  	struct f2fs_node *raw_node;
> -	uint64_t blk_size_bytes, main_area_node_seg_blk_offset;
> +	uint64_t main_area_node_seg_blk_offset;
>  	block_t data_blk_nor;
>  	int err = 0;
>  
> @@ -1564,56 +1524,16 @@ 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);
> -	raw_node->footer.next_blkaddr = cpu_to_le32(
> -			get_sb(main_blkaddr) +
> -			c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg +
> -			1 + c.quota_inum + 1);
> -
> -	raw_node->i.i_mode = cpu_to_le16(0x41c0); /* 0700 */
> -	raw_node->i.i_links = cpu_to_le32(2);
> -	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
> -	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
> +	f2fs_init_inode(sb, raw_node, c.lpf_ino, mkfs_time, 0x41c0);
>  
> -	blk_size_bytes = 1 << get_sb(log_blocksize);
> -	raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes);
> -	raw_node->i.i_blocks = cpu_to_le64(2);
> -
> -	raw_node->i.i_atime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_atime_nsec = 0;
> -	raw_node->i.i_ctime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_ctime_nsec = 0;
> -	raw_node->i.i_mtime = cpu_to_le32(mkfs_time);
> -	raw_node->i.i_mtime_nsec = 0;
> -	raw_node->i.i_generation = 0;
> -	raw_node->i.i_xattr_nid = 0;
> -	raw_node->i.i_flags = 0;
>  	raw_node->i.i_pino = le32_to_cpu(sb->root_ino);
>  	raw_node->i.i_namelen = le32_to_cpu(strlen(LPF));
>  	memcpy(raw_node->i.i_name, LPF, strlen(LPF));
> -	raw_node->i.i_current_depth = cpu_to_le32(1);
> -	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
>  
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
> -		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
> -		raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
> -	}
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
> -		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
> -		raw_node->i.i_crtime = cpu_to_le32(mkfs_time);
> -		raw_node->i.i_crtime_nsec = 0;
> -	}
> -
> -	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
> -		raw_node->i.i_compress_algorithm = 0;
> -		raw_node->i.i_log_cluster_size = 0;
> -		raw_node->i.i_compress_flag = 0;
> -	}
> +	raw_node->footer.next_blkaddr = cpu_to_le32(
> +			get_sb(main_blkaddr) +
> +			c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg +
> +			1 + c.quota_inum + 1);
>  
>  	data_blk_nor = f2fs_add_default_dentry_lpf();
>  	if (data_blk_nor == 0) {
> -- 
> 2.25.1
Chao Yu May 17, 2023, 2:02 a.m. UTC | #2
On 2023/5/9 3:42, Jaegeuk Kim wrote:
> Added this to avoid android build failure.
> 
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -23,6 +23,7 @@
> 
>   #include <stdio.h>
>   #include <stdlib.h>
> +#include <sys/stat.h>
>   #include <stddef.h>
>   #include <string.h>
>   #include <time.h>

Thank you for the fix, :)

Thanks,
diff mbox series

Patch

diff --git a/fsck/node.c b/fsck/node.c
index c3e383b..9ce8a72 100644
--- a/fsck/node.c
+++ b/fsck/node.c
@@ -57,7 +57,12 @@  int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype)
 		MSG(1, "\tError: Calloc Failed for raw_node!!!\n");
 		return -ENOMEM;
 	}
-	f2fs_init_qf_inode(sb, raw_node, qtype, time(NULL));
+	f2fs_init_inode(sb, raw_node,
+			le32_to_cpu(sb->qf_ino[qtype]), time(NULL), 0x8180);
+
+	raw_node->i.i_size = cpu_to_le64(1024 * 6);
+	raw_node->i.i_blocks = cpu_to_le64(1);
+	raw_node->i.i_flags = FS_IMMUTABLE_FL;
 
 	if (is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
 		cp_ver |= (cur_cp_crc(ckpt) << 32);
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 4accade..cab452d 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1741,20 +1741,16 @@  static inline void show_version(const char *prog)
 #endif
 }
 
-static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
-		struct f2fs_node *raw_node, int qtype, time_t mtime)
+static inline void f2fs_init_inode(struct f2fs_super_block *sb,
+		struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode)
 {
-	raw_node->footer.nid = sb->qf_ino[qtype];
-	raw_node->footer.ino = sb->qf_ino[qtype];
+	raw_node->footer.nid = cpu_to_le32(ino);
+	raw_node->footer.ino = cpu_to_le32(ino);
 	raw_node->footer.cp_ver = cpu_to_le64(1);
-	raw_node->i.i_mode = cpu_to_le16(0x8180);
-	raw_node->i.i_links = cpu_to_le32(1);
+
 	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
 	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
 
-	raw_node->i.i_size = cpu_to_le64(1024 * 6); /* Hard coded */
-	raw_node->i.i_blocks = cpu_to_le64(1);
-
 	raw_node->i.i_atime = cpu_to_le32(mtime);
 	raw_node->i.i_atime_nsec = 0;
 	raw_node->i.i_ctime = cpu_to_le32(mtime);
@@ -1763,9 +1759,15 @@  static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
 	raw_node->i.i_mtime_nsec = 0;
 	raw_node->i.i_generation = 0;
 	raw_node->i.i_xattr_nid = 0;
-	raw_node->i.i_flags = FS_IMMUTABLE_FL;
-	raw_node->i.i_current_depth = cpu_to_le32(0);
+	raw_node->i.i_flags = 0;
+	raw_node->i.i_current_depth = cpu_to_le32(S_ISDIR(mode) ? 1 : 0);
 	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
+	raw_node->i.i_mode = cpu_to_le16(mode);
+	raw_node->i.i_links = cpu_to_le32(S_ISDIR(mode) ? 2 : 1);
+
+	/* for dentry block in directory */
+	raw_node->i.i_size = cpu_to_le64(1 << get_sb(log_blocksize));
+	raw_node->i.i_blocks = cpu_to_le64(2);
 
 	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
 		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
@@ -1775,6 +1777,18 @@  static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
 	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
 		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
 
+	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
+		raw_node->i.i_crtime = cpu_to_le32(mtime);
+		raw_node->i.i_crtime_nsec = 0;
+	}
+
+	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
+		raw_node->i.i_compr_blocks = 0;
+		raw_node->i.i_compress_algorithm = 0;
+		raw_node->i.i_log_cluster_size = 0;
+		raw_node->i.i_compress_flag = 0;
+	}
+
 	raw_node->i.i_ext.fofs = 0;
 	raw_node->i.i_ext.blk_addr = 0;
 	raw_node->i.i_ext.len = 0;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 666af45..6d02a57 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -1233,7 +1233,7 @@  static int f2fs_discard_obsolete_dnode(void)
 static int f2fs_write_root_inode(void)
 {
 	struct f2fs_node *raw_node = NULL;
-	uint64_t blk_size_bytes, data_blk_nor;
+	uint64_t data_blk_nor;
 	uint64_t main_area_node_seg_blk_offset = 0;
 
 	raw_node = calloc(F2FS_BLKSIZE, 1);
@@ -1242,65 +1242,21 @@  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);
-	raw_node->footer.next_blkaddr = cpu_to_le32(
-			get_sb(main_blkaddr) +
-			c.cur_seg[CURSEG_HOT_NODE] *
-			c.blks_per_seg + 1);
+	f2fs_init_inode(sb, raw_node, le32_to_cpu(sb->root_ino),
+						mkfs_time, 0x41ed);
 
-	raw_node->i.i_mode = cpu_to_le16(0x41ed);
 	if (c.lpf_ino)
 		raw_node->i.i_links = cpu_to_le32(3);
-	else
-		raw_node->i.i_links = cpu_to_le32(2);
-	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
-	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
-
-	blk_size_bytes = 1 << get_sb(log_blocksize);
-	raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes); /* dentry */
-	raw_node->i.i_blocks = cpu_to_le64(2);
-
-	raw_node->i.i_atime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_atime_nsec = 0;
-	raw_node->i.i_ctime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_ctime_nsec = 0;
-	raw_node->i.i_mtime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_mtime_nsec = 0;
-	raw_node->i.i_generation = 0;
-	raw_node->i.i_xattr_nid = 0;
-	raw_node->i.i_flags = 0;
-	raw_node->i.i_current_depth = cpu_to_le32(1);
-	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
-		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
-		raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
-	}
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
-		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
 
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
-		raw_node->i.i_crtime = cpu_to_le32(mkfs_time);
-		raw_node->i.i_crtime_nsec = 0;
-	}
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
-		raw_node->i.i_compress_algorithm = 0;
-		raw_node->i.i_log_cluster_size = 0;
-		raw_node->i.i_compress_flag = 0;
-	}
+	raw_node->footer.next_blkaddr = cpu_to_le32(
+			get_sb(main_blkaddr) +
+			c.cur_seg[CURSEG_HOT_NODE] *
+			c.blks_per_seg + 1);
 
 	data_blk_nor = get_sb(main_blkaddr) +
 		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg;
 	raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blk_nor);
 
-	raw_node->i.i_ext.fofs = 0;
-	raw_node->i.i_ext.blk_addr = 0;
-	raw_node->i.i_ext.len = 0;
-
 	main_area_node_seg_blk_offset = get_sb(main_blkaddr);
 	main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
 					c.blks_per_seg;
@@ -1403,13 +1359,17 @@  static int f2fs_write_qf_inode(int qtype, int offset)
 		MSG(1, "\tError: Calloc Failed for raw_node!!!\n");
 		return -1;
 	}
-	f2fs_init_qf_inode(sb, raw_node, qtype, mkfs_time);
+	f2fs_init_inode(sb, raw_node,
+			le32_to_cpu(sb->qf_ino[qtype]), mkfs_time, 0x8180);
+
+	raw_node->i.i_size = cpu_to_le64(1024 * 6);
+	raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
+	raw_node->i.i_flags = FS_IMMUTABLE_FL;
 
 	raw_node->footer.next_blkaddr = cpu_to_le32(
 			get_sb(main_blkaddr) +
 			c.cur_seg[CURSEG_HOT_NODE] *
 			c.blks_per_seg + 1 + qtype + 1);
-	raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
 
 	data_blk_nor = get_sb(main_blkaddr) +
 		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1
@@ -1552,7 +1512,7 @@  static block_t f2fs_add_default_dentry_lpf(void)
 static int f2fs_write_lpf_inode(void)
 {
 	struct f2fs_node *raw_node;
-	uint64_t blk_size_bytes, main_area_node_seg_blk_offset;
+	uint64_t main_area_node_seg_blk_offset;
 	block_t data_blk_nor;
 	int err = 0;
 
@@ -1564,56 +1524,16 @@  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);
-	raw_node->footer.next_blkaddr = cpu_to_le32(
-			get_sb(main_blkaddr) +
-			c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg +
-			1 + c.quota_inum + 1);
-
-	raw_node->i.i_mode = cpu_to_le16(0x41c0); /* 0700 */
-	raw_node->i.i_links = cpu_to_le32(2);
-	raw_node->i.i_uid = cpu_to_le32(c.root_uid);
-	raw_node->i.i_gid = cpu_to_le32(c.root_gid);
+	f2fs_init_inode(sb, raw_node, c.lpf_ino, mkfs_time, 0x41c0);
 
-	blk_size_bytes = 1 << get_sb(log_blocksize);
-	raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes);
-	raw_node->i.i_blocks = cpu_to_le64(2);
-
-	raw_node->i.i_atime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_atime_nsec = 0;
-	raw_node->i.i_ctime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_ctime_nsec = 0;
-	raw_node->i.i_mtime = cpu_to_le32(mkfs_time);
-	raw_node->i.i_mtime_nsec = 0;
-	raw_node->i.i_generation = 0;
-	raw_node->i.i_xattr_nid = 0;
-	raw_node->i.i_flags = 0;
 	raw_node->i.i_pino = le32_to_cpu(sb->root_ino);
 	raw_node->i.i_namelen = le32_to_cpu(strlen(LPF));
 	memcpy(raw_node->i.i_name, LPF, strlen(LPF));
-	raw_node->i.i_current_depth = cpu_to_le32(1);
-	raw_node->i.i_dir_level = DEF_DIR_LEVEL;
 
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
-		raw_node->i.i_inline = F2FS_EXTRA_ATTR;
-		raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
-	}
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
-		raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME)) {
-		raw_node->i.i_crtime = cpu_to_le32(mkfs_time);
-		raw_node->i.i_crtime_nsec = 0;
-	}
-
-	if (c.feature & cpu_to_le32(F2FS_FEATURE_COMPRESSION)) {
-		raw_node->i.i_compress_algorithm = 0;
-		raw_node->i.i_log_cluster_size = 0;
-		raw_node->i.i_compress_flag = 0;
-	}
+	raw_node->footer.next_blkaddr = cpu_to_le32(
+			get_sb(main_blkaddr) +
+			c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg +
+			1 + c.quota_inum + 1);
 
 	data_blk_nor = f2fs_add_default_dentry_lpf();
 	if (data_blk_nor == 0) {