All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 6/6] f2fs-tools: use f2fs_init_inode() to clean up codes
Date: Mon, 8 May 2023 12:42:06 -0700	[thread overview]
Message-ID: <ZFlQjq/nLX16rZYB@google.com> (raw)
In-Reply-To: <20230505100205.1921708-6-chao@kernel.org>

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


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2023-05-08 19:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 10:02 [f2fs-dev] [PATCH 1/6] f2fs-tools: add packed attribute for struct f2fs_super_block Chao Yu
2023-05-05 10:02 ` [f2fs-dev] [PATCH 2/6] f2fs-tools: rename i_padding to i_compress_flag Chao Yu
2023-05-05 10:02 ` [f2fs-dev] [PATCH 3/6] f2fs-tools: fix typo in f2fs_inode structure Chao Yu
2023-05-05 10:02 ` [f2fs-dev] [PATCH 4/6] f2fs-tools: add DISP_u8() macro Chao Yu
2023-05-05 10:02 ` [f2fs-dev] [PATCH 5/6] f2fs-tools: print more raw sb info Chao Yu
2023-05-05 10:02 ` [f2fs-dev] [PATCH 6/6] f2fs-tools: use f2fs_init_inode() to clean up codes Chao Yu
2023-05-08 19:42   ` Jaegeuk Kim [this message]
2023-05-17  2:02     ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZFlQjq/nLX16rZYB@google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.