diff mbox series

[f2fs-dev,v2,4/7] f2fs-tools: Refactor SIT/NAT block structs

Message ID 20230825224400.2206278-5-drosen@google.com (mailing list archive)
State Superseded
Headers show
Series Add 16K Support for f2fs-tools | expand

Commit Message

Daniel Rosenberg Aug. 25, 2023, 10:43 p.m. UTC
This converts f2fs_nat_block and f2fs_sit_block to be variable length
arrays. This does not change the way they are accessed, but removes a
misleading statment that these sizes are fixed, as opposed to deriving
from F2FS_BLKSIZE

Signed-off-by: Daniel Rosenberg <drosen@google.com>
---
 include/f2fs_fs.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Jaegeuk Kim Aug. 28, 2023, 8:22 p.m. UTC | #1
On 08/25, Daniel Rosenberg wrote:
> This converts f2fs_nat_block and f2fs_sit_block to be variable length
> arrays. This does not change the way they are accessed, but removes a
> misleading statment that these sizes are fixed, as opposed to deriving
> from F2FS_BLKSIZE
> 
> Signed-off-by: Daniel Rosenberg <drosen@google.com>
> ---
>  include/f2fs_fs.h | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> index 13a1c14..b2d479f 100644
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -1119,11 +1119,9 @@ struct f2fs_nat_entry {
>  static_assert(sizeof(struct f2fs_nat_entry) == 9, "");
>  
>  struct f2fs_nat_block {
> -	struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
> +	struct f2fs_nat_entry entries[0]; /* NAT_ENTRY_PER_BLOCK */
>  };
>  
> -static_assert(sizeof(struct f2fs_nat_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 9), "");
> -
>  /*
>   * For SIT entries
>   *
> @@ -1169,12 +1167,14 @@ struct f2fs_sit_entry {
>  
>  static_assert(sizeof(struct f2fs_sit_entry) == 74, "");
>  
> +/*
> + * On disk layout is:
> + * struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
> + */
>  struct f2fs_sit_block {
> -	struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
> +	struct f2fs_sit_entry entries[0];
>  };
>  
> -static_assert(sizeof(struct f2fs_sit_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 74), "");
> -
>  /*
>   * For segment summary
>   *
> @@ -1995,6 +1995,14 @@ static inline void check_block_struct_sizes(void)
>  
>  	/* Check Indirect Block Size */
>  	assert(NIDS_PER_BLOCK * sizeof(__le32) + sizeof(struct node_footer) == F2FS_BLKSIZE);
> +
> +	/* Check NAT Block Size */
> +	assert((NAT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE);
> +	assert(NAT_ENTRY_PER_BLOCK * sizeof(struct f2fs_nat_entry) <= F2FS_BLKSIZE);
> +
> +	/* Check SIT Block Size */
> +	assert((SIT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE);

					sizeof(struct f2fs_sit_entry)?

> +	assert(SIT_ENTRY_PER_BLOCK * sizeof(struct f2fs_sit_entry) <= F2FS_BLKSIZE);
>  }
>  
>  #endif	/*__F2FS_FS_H */
> -- 
> 2.42.0.rc2.253.gd59a3bf2b4-goog
diff mbox series

Patch

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 13a1c14..b2d479f 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1119,11 +1119,9 @@  struct f2fs_nat_entry {
 static_assert(sizeof(struct f2fs_nat_entry) == 9, "");
 
 struct f2fs_nat_block {
-	struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
+	struct f2fs_nat_entry entries[0]; /* NAT_ENTRY_PER_BLOCK */
 };
 
-static_assert(sizeof(struct f2fs_nat_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 9), "");
-
 /*
  * For SIT entries
  *
@@ -1169,12 +1167,14 @@  struct f2fs_sit_entry {
 
 static_assert(sizeof(struct f2fs_sit_entry) == 74, "");
 
+/*
+ * On disk layout is:
+ * struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
+ */
 struct f2fs_sit_block {
-	struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
+	struct f2fs_sit_entry entries[0];
 };
 
-static_assert(sizeof(struct f2fs_sit_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 74), "");
-
 /*
  * For segment summary
  *
@@ -1995,6 +1995,14 @@  static inline void check_block_struct_sizes(void)
 
 	/* Check Indirect Block Size */
 	assert(NIDS_PER_BLOCK * sizeof(__le32) + sizeof(struct node_footer) == F2FS_BLKSIZE);
+
+	/* Check NAT Block Size */
+	assert((NAT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE);
+	assert(NAT_ENTRY_PER_BLOCK * sizeof(struct f2fs_nat_entry) <= F2FS_BLKSIZE);
+
+	/* Check SIT Block Size */
+	assert((SIT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE);
+	assert(SIT_ENTRY_PER_BLOCK * sizeof(struct f2fs_sit_entry) <= F2FS_BLKSIZE);
 }
 
 #endif	/*__F2FS_FS_H */