Add 16K Support for f2fs-tools
cover Add 16K Support for f2fs-tools
This adds support for different block sizes to f2fs-tools.
The first patch redefines all block size based constants to be based on the block size. After this patch, you should be able to compile a version of f2fs-tools that works for a given blocksize by just setting F2FS_BLKSIZE_BITS in f2fs_fs.h. Running fsck on an f2fs filesystem of a different block size will fail early, and should leave the fs untouched.
I was unsure how to handle things under tools/, so I've left them as is.
The rest of the patches refactor the code to allow it to handle different block sizes with the same binary. The final patch puts this under a block size argument in make_f2fs.
The refactor splits apart structs that have components with sizes derived from the blocksize in the middle. If the component is at the end, it's treated as a variable length array. This means that sizeof on affected structs will not work as expected, and should be replaced with F2FS_BLKSIZE where appropriate. The affected static_asserts are replaced with runtime asserts.
It touches a lot of places, but I think it's probably with it to be able to use a single binary, particularly if we're ever going to be able to mount different blocksize f2fs filesystems using the same kernel.
I was unable to get xfstests running on my 16k arm setup, so I wasn't able to test it as thoroughly as I'd like to have, but it behaved the same on a 4k x86_64 system, and fsck/mounted successfully on an arm64 system.
Daniel Rosenberg (7):
f2fs-tools: Define constants in terms of BLKSIZE
f2fs-tools: Refactor Orphan Block struct
f2fs-tools: Refactor f2fs_node struct and friends
f2fs-tools: Refactor SIT/NAT block structs
f2fs-tools: Refactor Summary block struct and friends
f2fs-tools: Refactor f2fs_dentry_block struct
f2fs-tools: Support different block sizes
fsck/dir.c | 46 +++---- fsck/dump.c | 28 ++-- fsck/f2fs.h | 6 +- fsck/fsck.c | 72 +++++------ fsck/fsck.h | 5 +- fsck/main.c | 1 + fsck/mount.c | 93 ++++++++------ fsck/node.c | 12 +- fsck/node.h | 20 +-- fsck/resize.c | 2 +- include/f2fs_fs.h | 271 ++++++++++++++++++++++++++++----------- lib/libf2fs.c | 4 +- man/sload.f2fs.8 | 2 +- mkfs/f2fs_format.c | 90 ++++++------- mkfs/f2fs_format_main.c | 14 +- mkfs/f2fs_format_utils.c | 2 +- 16 files changed, 405 insertions(+), 263 deletions(-)
base-commit: 6ebf6f2967d0a5731af1767d5735f46e30fea0fc
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 1/7 f2fs-tools: Define constants in terms of BLKSIZE
This converts the various block size based constants to be defined in terms of the block size. This makes it possible to change the block size by changing only F2FS_BLKSIZE_BITS in f2fs_fs.h
--- fsck/fsck.h | 2 +- fsck/mount.c | 4 +- include/f2fs_fs.h | 81 +++++++++++++++++++++++------------------ mkfs/f2fs_format.c | 12 +++--- mkfs/f2fs_format_main.c | 2 +- 5 files changed, 55 insertions(+), 46 deletions(-)
fsck/fsck.h +1 -1
@@ -126,7 +126,7 @@ struct f2fs_fsck {struct quota_ctx *qctx; }; -#define BLOCK_SZ 4096 +#define BLOCK_SZ F2FS_BLKSIZEstruct block {unsigned char buf[BLOCK_SZ ]; };
fsck/mount.c +2 -2
@@ -995,8 +995,8 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) blocksize =1 <<get_sb (log_blocksize);if (F2FS_BLKSIZE != blocksize) { -MSG (0 ,"Invalid blocksize (%u), supports only 4KB\n" , - blocksize); +MSG (0 ,"Invalid blocksize (%u), supports only (%u)\n" , + blocksize,F2FS_BLKSIZE );return -1 ; }
include/f2fs_fs.h +45 -36
216 lines not on this page · raw message
mkfs/f2fs_format.c +6 -6
@@ -1372,7 +1372,7 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id)memcpy (filebuf +5136 , &dqblk,sizeof (struct v2r1_disk_dqblk )); -/* Write two blocks */ +/* Write quota blocks */ for (i =0 ; i <QUOTA_DATA ; i++) { blkaddr =alloc_next_free_block (CURSEG_HOT_DATA );
@@ -1385,13 +1385,13 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id)update_sit_journal (CURSEG_HOT_DATA );update_summary_entry (CURSEG_HOT_DATA ,le32_to_cpu (sb->qf_ino[qtype]), i); - } +DBG (1 ,"\tWriting quota data, at offset %08x (%d/%d)\n" , + blkaddr, i +1 ,QUOTA_DATA ); -DBG (1 ,"\tWriting quota data, at offset %08x, %08x\n" , - blkaddr -1 , blkaddr); + }free (filebuf); -return blkaddr -1 ; +return blkaddr +1 -QUOTA_DATA ; }static int f2fs_write_qf_inode (int qtype)
@@ -1426,7 +1426,7 @@ static int f2fs_write_qf_inode(int qtype)else ASSERT (0 ); -/* write two blocks */ +/* write quota blocks */ data_blkaddr =f2fs_write_default_quota (qtype, raw_id);if (data_blkaddr ==0 ) {free (raw_node);
mkfs/f2fs_format_main.c +1 -1
@@ -141,7 +141,7 @@ static void add_default_options(void)/* -d1 -f -w 4096 -R 0:0 */ c.dbg_lv =1 ; force_overwrite =1 ; - c.wanted_sector_size =4096 ; + c.wanted_sector_size = c.blksize; c.root_uid = c.root_gid =0 ;/* RO doesn't need any other features */
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 1/7] f2fs-tools: Define constants in terms of BLKSIZE
Hi Daniel,
f2fs_format_main.c: In function ‘add_default_options’:
f2fs_format_main.c:142:41: error: ‘struct f2fs_configuration’ has no member named ‘blksize’
142 | c.wanted_sector_size = c.blksize;
| ^
make[2]: *** [Makefile:516: f2fs_format_main.o] Error 1
make[2]: *** Waiting for unfinished jobs....f2fs_format_main.c: In function 'add_default_options':
f2fs_format_main.c:142:41: error: 'struct f2fs_configuration' has no member named 'blksize'
142 | c.wanted_sector_size = c.blksize;
|Quoted 333 lines · Daniel Rosenberg
This converts the various block size based constants to be defined in terms of the block size. This makes it possible to change the block size by changing only
F2FS_BLKSIZE_BITSinf2fs_fs.hSigned-off-by Daniel Rosenberg <[email protected]>--- fsck/fsck.h | 2 +- fsck/mount.c | 4 +- include/f2fs_fs.h | 81 +++++++++++++++++++++++------------------ mkfs/f2fs_format.c | 12 +++--- mkfs/f2fs_format_main.c | 2 +- 5 files changed, 55 insertions(+), 46 deletions(-)fsck/fsck.h +1
-1@@ -126,7 +126,7 @@ struct f2fs_fsck {struct quota_ctx *qctx; }; -#define BLOCK_SZ 4096 +#define BLOCK_SZ F2FS_BLKSIZEstruct block {unsigned char buf[BLOCK_SZ ]; };fsck/mount.c +2
-2@@ -995,8 +995,8 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) blocksize =1 <<get_sb (log_blocksize);if (F2FS_BLKSIZE != blocksize) { -MSG (0 ,"Invalid blocksize (%u), supports only 4KB\n" , - blocksize); +MSG (0 ,"Invalid blocksize (%u), supports only (%u)\n" , + blocksize,F2FS_BLKSIZE );return -1 ; }include/f2fs_fs.h +45
-36@@ -385,18 +385,18 @@ static inline uint64_t bswap_64(uint64_t val)#define SECTOR_SHIFT 9#endif #define F2FS_SUPER_MAGIC 0xF2F52010/* F2FS Magic Number */ -#define CP_CHKSUM_OFFSET 4092 +#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32))#define SB_CHKSUM_OFFSET 3068#define MAX_PATH_LEN 64#define MAX_DEVICES 8#define F2FS_BYTES_TO_BLK (bytes) ((bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLKSIZE_BITS 12 +#define F2FS_BLKSIZE_BITS 12/* 4KB block */ /* for mkfs */ #define F2FS_NUMBER_OF_CHECKPOINT_PACK 2#define DEFAULT_SECTOR_SIZE 512 -#define DEFAULT_SECTORS_PER_BLOCK 8 +#define DEFAULT_SECTORS_PER_BLOCK (1 << (F2FS_BLKSIZE_BITS - SECTOR_SHIFT))#define DEFAULT_BLOCKS_PER_SEGMENT 512#define DEFAULT_SEGMENTS_PER_SECTION 1@@ -627,8 +627,8 @@ enum {*/ #define F2FS_SUPER_OFFSET 1024/* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9/* 9 bits for 512 bytes */ -#define F2FS_MAX_LOG_SECTOR_SIZE 12/* 12 bits for 4096 bytes */ -#define F2FS_BLKSIZE 4096/* support only 4KB block */ +#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS/* 12 bits for 4096 bytes */ +#define F2FS_BLKSIZE (1 << F2FS_BLKSIZE_BITS)/* support only 4KB block */ #define F2FS_MAX_EXTENSION 64/* # of extension entries */ #define F2FS_EXTENSION_LEN 8/* max size of extension */ #define F2FS_BLK_ALIGN (x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE)@@ -642,7 +642,7 @@ enum {#define F2FS_META_INO (sbi) (sbi->meta_ino_num)#define F2FS_MAX_QUOTAS 3 -#define QUOTA_DATA 2 +#define QUOTA_DATA (((1024 * 6 - 1) / F2FS_BLKSIZE) + 1)#define QUOTA_INO (sb,t) (le32_to_cpu((sb)->qf_ino[t]))/* @@ -853,7 +853,7 @@ static_assert(sizeof(struct f2fs_checkpoint) == 192, "");/* * For orphan inode management */ -#define F2FS_ORPHANS_PER_BLOCK 1020 +#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32))struct f2fs_orphan_block {__le32 ino[F2FS_ORPHANS_PER_BLOCK ];/* inode numbers */ @@ -864,7 +864,7 @@ struct f2fs_orphan_block {__le32 check_sum;/* CRC32 for orphan inode block */ }; -static_assert (sizeof (struct f2fs_orphan_block ) ==4096 ,"" ); +static_assert (sizeof (struct f2fs_orphan_block ) ==F2FS_BLKSIZE ,"" );/* * For NODE structure @@ -884,13 +884,31 @@ static_assert(sizeof(struct f2fs_extent) == 12, "");/* 200 bytes for inline xattrs by default */ #define DEFAULT_INLINE_XATTR_ADDRS 50 -#define DEF_ADDRS_PER_INODE 923/* Address Pointers in an Inode */ + +struct node_footer { +__le32 nid;/* node id */ +__le32 ino;/* inode number */ +__le32 flag;/* include cold/fsync/dentry marks and offset */ +__le64 cp_ver __attribute__((packed));/* checkpoint version */ +__le32 next_blkaddr;/* next node page block address */ +}; + +static_assert (sizeof (struct node_footer ) ==24 ,"" ); + +#define OFFSET_OF_END_OF_I_EXT 360 +#define SIZE_OF_I_NID 20 +/* Address Pointers in an Inode */ +#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ + - SIZE_OF_I_NID \ + - sizeof(struct node_footer)) / sizeof(__le32))#define CUR_ADDRS_PER_INODE (inode) (DEF_ADDRS_PER_INODE - \ __get_extra_isize(inode))#define ADDRS_PER_INODE (i) addrs_per_inode(i) -#define DEF_ADDRS_PER_BLOCK 1018/* Address Pointers in a Direct Block */ +/* Address Pointers in a Direct Block */ +#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))#define ADDRS_PER_BLOCK (i) addrs_per_block(i) -#define NIDS_PER_BLOCK 1018/* Node IDs in an Indirect Block */ +/* Node IDs in an Indirect Block */ +#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1)#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)@@ -1024,19 +1042,19 @@ struct f2fs_inode {static_assert (offsetof(struct f2fs_inode , i_extra_end) - offsetof(struct f2fs_inode , i_extra_isize) ==36 ,"" ); -static_assert (sizeof (struct f2fs_inode ) ==4072 ,"" ); +static_assert (sizeof (struct f2fs_inode ) ==F2FS_BLKSIZE -24 ,"" );struct direct_node {__le32 addr[DEF_ADDRS_PER_BLOCK ];/* array of data block address */ }; -static_assert (sizeof (struct direct_node ) ==4072 ,"" ); +static_assert (sizeof (struct direct_node ) ==F2FS_BLKSIZE -24 ,"" );struct indirect_node {__le32 nid[NIDS_PER_BLOCK ];/* array of data block address */ }; -static_assert (sizeof (struct indirect_node ) ==4072 ,"" ); +static_assert (sizeof (struct indirect_node ) ==F2FS_BLKSIZE -24 ,"" );enum {COLD_BIT_SHIFT =0 ,@@ -1047,15 +1065,6 @@ enum {#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ >> OFFSET_BIT_SHIFT) -struct node_footer { -__le32 nid;/* node id */ -__le32 ino;/* inode nunmber */ -__le32 flag;/* include cold/fsync/dentry marks and offset */ -__le64 cp_ver __attribute__((packed));/* checkpoint version */ -__le32 next_blkaddr;/* next node page block address */ -}; - -static_assert (sizeof (struct node_footer ) ==24 ,"" );struct f2fs_node {/* can be one of three types: inode, direct, and indirect types */ @@ -1067,7 +1076,7 @@ struct f2fs_node {struct node_footer footer; }; -static_assert (sizeof (struct f2fs_node ) ==4096 ,"" ); +static_assert (sizeof (struct f2fs_node ) ==F2FS_BLKSIZE ,"" );/* * For NAT entries @@ -1089,7 +1098,7 @@ struct f2fs_nat_block {struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK ]; }; -static_assert (sizeof (struct f2fs_nat_block ) ==4095 ,"" ); +static_assert (sizeof (struct f2fs_nat_block ) ==F2FS_BLKSIZE - (F2FS_BLKSIZE %9 ),"" );/* * For SIT entries @@ -1140,13 +1149,13 @@ struct f2fs_sit_block {struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK ]; }; -static_assert (sizeof (struct f2fs_sit_block ) ==4070 ,"" ); +static_assert (sizeof (struct f2fs_sit_block ) ==F2FS_BLKSIZE - (F2FS_BLKSIZE %74 ),"" );/* * For segment summary * -* One summary block contains exactly 512 summary entries, which represents -* exactly 2MB segment by default. Not allow to change the basic units. +* One summary block contains exactly 2048 summary entries, which represents +* exactly 32MB segment by default. Not allow to change the basic units. * * NOTE: For initializing fields, you must use set_summary * @@ -1157,7 +1166,7 @@ static_assert(sizeof(struct f2fs_sit_block) == 4070, "");* from node's page's beginning to get a data block address. * ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node) */ -#define ENTRIES_IN_SUM 512 +#define ENTRIES_IN_SUM (F2FS_BLKSIZE / 8)#define SUMMARY_SIZE (7)/* sizeof(struct summary) */ #define SUM_FOOTER_SIZE (5)/* sizeof(struct summary_footer) */ #define SUM_ENTRIES_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM)@@ -1225,7 +1234,7 @@ struct nat_journal {__u8 reserved[NAT_JOURNAL_RESERVED ]; }; -static_assert (sizeof (struct nat_journal ) ==505 ,"" ); +static_assert (sizeof (struct nat_journal ) == (F2FS_BLKSIZE /8 ) -7 ,"" );struct sit_journal_entry {__le32 segno;@@ -1239,14 +1248,14 @@ struct sit_journal {__u8 reserved[SIT_JOURNAL_RESERVED ]; }; -static_assert (sizeof (struct sit_journal ) ==505 ,"" ); +static_assert (sizeof (struct sit_journal ) == (F2FS_BLKSIZE /8 ) -7 ,"" );struct f2fs_extra_info {__le64 kbytes_written;__u8 reserved[EXTRA_INFO_RESERVED ]; } __attribute__((packed)); -static_assert (sizeof (struct f2fs_extra_info ) ==505 ,"" ); +static_assert (sizeof (struct f2fs_extra_info ) == (F2FS_BLKSIZE /8 ) -7 ,"" ); struct f2fs_journal { union {@@ -1261,7 +1270,7 @@ struct f2fs_journal { }; } __attribute__((packed)); -static_assert (sizeof (struct f2fs_journal ) ==507 ,"" ); +static_assert (sizeof (struct f2fs_journal ) == (F2FS_BLKSIZE /8 ) -5 ,"" );/* 4KB-sized summary block structure */ struct f2fs_summary_block {@@ -1270,7 +1279,7 @@ struct f2fs_summary_block {struct summary_footer footer; }; -static_assert (sizeof (struct f2fs_summary_block ) ==4096 ,"" ); +static_assert (sizeof (struct f2fs_summary_block ) ==F2FS_BLKSIZE ,"" );/* * For directory operations @@ -1289,8 +1298,8 @@ typedef __le32 f2fs_hash_t;#define GET_DENTRY_SLOTS (x) ((x + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS)/* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK 214 - +#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ + ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1))/* MAX level for dir lookup */ #define MAX_DIR_HASH_DEPTH 63mkfs/f2fs_format.c +6
-6@@ -1372,7 +1372,7 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id)memcpy (filebuf +5136 , &dqblk,sizeof (struct v2r1_disk_dqblk )); -/* Write two blocks */ +/* Write quota blocks */ for (i =0 ; i <QUOTA_DATA ; i++) { blkaddr =alloc_next_free_block (CURSEG_HOT_DATA );@@ -1385,13 +1385,13 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id)update_sit_journal (CURSEG_HOT_DATA );update_summary_entry (CURSEG_HOT_DATA ,le32_to_cpu (sb->qf_ino[qtype]), i); - } +DBG (1 ,"\tWriting quota data, at offset %08x (%d/%d)\n" , + blkaddr, i +1 ,QUOTA_DATA ); -DBG (1 ,"\tWriting quota data, at offset %08x, %08x\n" , - blkaddr -1 , blkaddr); + }free (filebuf); -return blkaddr -1 ; +return blkaddr +1 -QUOTA_DATA ; }static int f2fs_write_qf_inode (int qtype)@@ -1426,7 +1426,7 @@ static int f2fs_write_qf_inode(int qtype)else ASSERT (0 ); -/* write two blocks */ +/* write quota blocks */ data_blkaddr =f2fs_write_default_quota (qtype, raw_id);if (data_blkaddr ==0 ) {free (raw_node);mkfs/f2fs_format_main.c +1
-1@@ -141,7 +141,7 @@ static void add_default_options(void)/* -d1 -f -w 4096 -R 0:0 */ c.dbg_lv =1 ; force_overwrite =1 ; - c.wanted_sector_size =4096 ; + c.wanted_sector_size = c.blksize; c.root_uid = c.root_gid =0 ;/* RO doesn't need any other features */ Signature · 1 line
2.41.0.694.ge786442a9b-goog
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 1/7] f2fs-tools: Define constants in terms of BLKSIZE
Quoted 11 lines · Jaegeuk Kim
Hi Daniel,
f2fs_format_main.c: In function ‘add_default_options’:
f2fs_format_main.c:142:41: error: ‘struct f2fs_configuration’ has no member named ‘blksize’
142 | c.wanted_sector_size = c.blksize;
| ^
make[2]: *** [Makefile:516: f2fs_format_main.o] Error 1
make[2]: *** Waiting for unfinished jobs....f2fs_format_main.c: In function 'add_default_options':
f2fs_format_main.c:142:41: error: 'structf2fs_configuration' has no member named 'blksize'
Quoted 3 lines
142 | c.wanted_sector_size = c.blksize;
|Oof... Missed updating the patch files after my last rebase. I'll resend. Took the opportunity to move some changes in the last patch up to the first as well.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 2/7 f2fs-tools: Refactor Orphan Block struct
In reply to Daniel Rosenberg via Linux-f2fs-develThis splits off access to the orphan block's footer into a macro call as its location is dependent on block size. Because of this, you should use F2FS_BLKSIZE instead of sizeof(struct f2fs_orphan_block)
--- fsck/fsck.c | 4 ++-- fsck/main.c | 1 + include/f2fs_fs.h | 23 ++++++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-)
fsck/fsck.c +2 -2
@@ -2058,7 +2058,7 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi)u32 new_entry_count =0 ;ASSERT (ret >=0 ); - entry_count =le32_to_cpu (orphan_blk->entry_count); + entry_count =le32_to_cpu (F2FS_ORPHAN_BLOCK_FOOTER (orphan_blk)->entry_count);for (j =0 ; j < entry_count; j++) {nid_t ino =le32_to_cpu (orphan_blk->ino[j]);
@@ -2094,7 +2094,7 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) }if (f2fs_dev_is_writable () && c.fix_on && entry_count != new_entry_count) { - new_blk->entry_count =cpu_to_le32 (new_entry_count); +F2FS_ORPHAN_BLOCK_FOOTER (new_blk)->entry_count =cpu_to_le32 (new_entry_count); ret =dev_write_block (new_blk, start_blk + i);ASSERT (ret >=0 ); }
fsck/main.c +1 -0
@@ -803,6 +803,7 @@ void f2fs_parse_options(int argc, char *argv[])return ; } +check_block_struct_sizes ();/* print out error */ switch (err) {case EWRONG_OPT :
include/f2fs_fs.h +20 -3
@@ -21,6 +21,7 @@#define __SANE_USERSPACE_TYPES__/* For PPC64, to get LL64 types */ #endif +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h>
@@ -855,8 +856,19 @@ static_assert(sizeof(struct f2fs_checkpoint) == 192, "");*/ #define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32)) +/* +* On disk layout is: +* __le32 ino[F2FS_ORPHANS_PER_BLOCK]; +* struct f2fs_ophan_block_footer +* +* Do NOT use sizeof, use F2FS_BLKSIZE instead +*/ struct f2fs_orphan_block { -__le32 ino[F2FS_ORPHANS_PER_BLOCK ];/* inode numbers */ +__le32 ino[0 ];/* F2FS_ORPHANS_PER_BLOCK inode numbers */ +}; +#define F2FS_ORPHAN_BLOCK_FOOTER (blk) ((struct orphan_block_footer *)&(blk)->ino[F2FS_ORPHANS_PER_BLOCK]) + +struct orphan_block_footer {__le32 reserved;/* reserved */ __le16 blk_addr;/* block index in current CP */ __le16 blk_count;/* Number of orphan inode blocks in CP */
@@ -864,8 +876,6 @@ struct f2fs_orphan_block {__le32 check_sum;/* CRC32 for orphan inode block */ }; -static_assert (sizeof (struct f2fs_orphan_block ) ==F2FS_BLKSIZE ,"" ); -/* * For NODE structure */
@@ -1956,4 +1966,11 @@ extern char *f2fs_encoding2str(const int encoding);extern int f2fs_get_encoding_flags (int encoding);extern int f2fs_str2encoding_flags (char **param,__u16 *flags); +static inline void check_block_struct_sizes (void ) +{ +/* Check Orphan Block Size */ +assert (F2FS_ORPHANS_PER_BLOCK *sizeof (__le32) + +sizeof (struct orphan_block_footer ) ==F2FS_BLKSIZE ); +} +#endif /*__F2FS_FS_H */
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/7 f2fs-tools: Refactor f2fs_node struct and friends
In reply to Daniel Rosenberg via Linux-f2fs-develThis converts inodes, direct nodes, and indirect nodes over to not being based on a 4K page size. f2fs_inode's i_nids field should now be accessed via a macro, as it's location depends on block size.
Access to direct nodes and indirect nodes is unchanged.
The node footer's location is also based on block sized, and accessed via a macro. With these changes, you should use F2FS_BLKSIZE in place of sizeof(struct f2fs_node)
--- fsck/dir.c | 20 ++++++++--------- fsck/dump.c | 24 ++++++++++----------- fsck/f2fs.h | 2 +- fsck/fsck.c | 54 +++++++++++++++++++++++----------------------- fsck/mount.c | 20 ++++++++--------- fsck/node.c | 12 +++++------ fsck/node.h | 20 ++++++++--------- include/f2fs_fs.h | 54 +++++++++++++++++++++++++++++++++------------- lib/libf2fs.c | 2 +- mkfs/f2fs_format.c | 10 ++++----- 10 files changed, 121 insertions(+), 97 deletions(-)
fsck/dir.c +10 -10
@@ -116,7 +116,7 @@ static int find_in_level(struct f2fs_sb_info *sbi, struct f2fs_node *dir,struct dnode_of_data dn;void *dentry_blk;int max_slots =214 ; -nid_t ino =le32_to_cpu (dir->footer.ino); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (dir)->ino);f2fs_hash_t namehash;unsigned int dir_level = dir->i.i_dir_level;int ret =0 ;
@@ -239,7 +239,7 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, dentry_hash =f2fs_dentry_hash (get_encoding (sbi),IS_CASEFOLDED (&parent->i), name, name_len); - pino =le32_to_cpu (parent->footer.ino); + pino =le32_to_cpu (F2FS_NODE_FOOTER (parent)->ino); dir_level = parent->i.i_dir_level;if (!pino) {
@@ -340,7 +340,7 @@ add_dentry:static void make_empty_dir (struct f2fs_sb_info *sbi,struct f2fs_node *inode) {struct f2fs_dentry_block *dent_blk; -nid_t ino =le32_to_cpu (inode->footer.ino); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (inode)->ino);nid_t pino =le32_to_cpu (inode->i.i_pino);struct f2fs_summary sum;struct node_info ni;
@@ -381,7 +381,7 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode)static void page_symlink (struct f2fs_sb_info *sbi,struct f2fs_node *inode,const char *symname,int symlen) { -nid_t ino =le32_to_cpu (inode->footer.ino); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (inode)->ino);struct f2fs_summary sum;struct node_info ni;char *data_blk;
@@ -531,10 +531,10 @@ 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; +F2FS_NODE_FOOTER (node_blk)->ino =cpu_to_le32 (de->ino); +F2FS_NODE_FOOTER (node_blk)->nid =cpu_to_le32 (de->ino); +F2FS_NODE_FOOTER (node_blk)->flag =0 ; +F2FS_NODE_FOOTER (node_blk)->cp_ver = ckpt->checkpoint_ver;set_cold_node (node_blk,S_ISDIR (mode));if (S_ISDIR (mode)) {
@@ -556,7 +556,7 @@ int convert_inline_dentry(struct f2fs_sb_info *sbi, struct f2fs_node *node, {struct f2fs_inode *inode = &(node->i);unsigned int dir_level = node->i.i_dir_level; -nid_t ino =le32_to_cpu (node->footer.ino); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (node)->ino);char inline_data[MAX_INLINE_DATA (node)];struct dnode_of_data dn;struct f2fs_dentry_ptr d;
@@ -751,7 +751,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) ret =f2fs_add_link (sbi, parent, child->i.i_name,le32_to_cpu (child->i.i_namelen), -le32_to_cpu (child->footer.ino), +le32_to_cpu (F2FS_NODE_FOOTER (child)->ino),map_de_type (le16_to_cpu (child->i.i_mode)), ni.blk_addr,1 );if (ret) {
fsck/dump.c +12 -12
@@ -71,7 +71,7 @@ void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat)"nid:%5u\tino:%5u\toffset:%5u" "\tblkaddr:%10u\tpack:%d\n" , ni.nid, ni.ino, -le32_to_cpu (node_block->footer.flag) >> +le32_to_cpu (F2FS_NODE_FOOTER (node_block)->flag) >>OFFSET_BIT_SHIFT , ni.blk_addr, pack); ret =write (fd, buf,strlen (buf));
@@ -92,7 +92,7 @@ void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat)"nid:%5u\tino:%5u\toffset:%5u" "\tblkaddr:%10u\tpack:%d\n" , ni.nid, ni.ino, -le32_to_cpu (node_block->footer.flag) >> +le32_to_cpu (F2FS_NODE_FOOTER (node_block)->flag) >>OFFSET_BIT_SHIFT , ni.blk_addr, pack); ret =write (fd, buf,strlen (buf));
@@ -456,17 +456,17 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,for (i =0 ; i <5 ; i++) {if (i ==0 || i ==1 )dump_node_blk (sbi,TYPE_DIRECT_NODE , -le32_to_cpu (node_blk->i.i_nid[i]), +le32_to_cpu (F2FS_INODE_I_NID (&node_blk->i, i)), addr_per_block, &ofs);else if (i ==2 || i ==3 )dump_node_blk (sbi,TYPE_INDIRECT_NODE , -le32_to_cpu (node_blk->i.i_nid[i]), +le32_to_cpu (F2FS_INODE_I_NID (&node_blk->i, i)), addr_per_block, &ofs);else if (i ==4 )dump_node_blk (sbi,TYPE_DOUBLE_INDIRECT_NODE , -le32_to_cpu (node_blk->i.i_nid[i]), +le32_to_cpu (F2FS_INODE_I_NID (&node_blk->i, i)), addr_per_block, &ofs);else
@@ -570,11 +570,11 @@ void dump_node_scan_disk(struct f2fs_sb_info *sbi, nid_t nid) ret =dev_read_block (node_blk, blkaddr);ASSERT (ret >=0 ); -if (le32_to_cpu (node_blk->footer.ino) != nid || -le32_to_cpu (node_blk->footer.nid) != nid) +if (le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino) != nid || +le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->nid) != nid)continue ;MSG (0 ,"Info: nid: %u, blkaddr: %lu\n" , nid, blkaddr); -MSG (0 ,"node_blk.footer.flag [0x%x]\n" ,le32_to_cpu (node_blk->footer.flag)); +MSG (0 ,"node_blk.footer.flag [0x%x]\n" ,le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->flag));MSG (0 ,"node_blk.footer.cp_ver [%x]\n" , (u32)(cpver_of_node (node_blk)));print_inode_info (sbi, node_blk,0 ); }
@@ -608,11 +608,11 @@ int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)if (!is_sit_bitmap_set (sbi, ni.blk_addr))MSG (force,"Invalid sit bitmap, %u\n\n" , ni.blk_addr); -DBG (1 ,"node_blk.footer.ino [0x%x]\n" ,le32_to_cpu (node_blk->footer.ino)); -DBG (1 ,"node_blk.footer.nid [0x%x]\n" ,le32_to_cpu (node_blk->footer.nid)); +DBG (1 ,"node_blk.footer.ino [0x%x]\n" ,le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino)); +DBG (1 ,"node_blk.footer.nid [0x%x]\n" ,le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->nid)); -if (le32_to_cpu (node_blk->footer.ino) == ni.ino && -le32_to_cpu (node_blk->footer.nid) == ni.nid) { +if (le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino) == ni.ino && +le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->nid) == ni.nid) {if (!c.show_file_map)print_node_info (sbi, node_blk, force);
fsck/f2fs.h +1 -1
@@ -332,7 +332,7 @@ static inline void *inline_data_addr(struct f2fs_node *node_blk)static inline unsigned int ofs_of_node (struct f2fs_node *node_blk) { -unsigned flag =le32_to_cpu (node_blk->footer.flag); +unsigned flag =le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->flag);return flag >>OFFSET_BIT_SHIFT ; }
fsck/fsck.c +27 -27
169 lines not on this page · raw message
fsck/mount.c +10 -10
@@ -364,11 +364,11 @@ void print_inode_info(struct f2fs_sb_info *sbi, blkaddr, blkaddr); } -DISP_u32 (inode, i_nid[0 ]);/* direct */ -DISP_u32 (inode, i_nid[1 ]);/* direct */ -DISP_u32 (inode, i_nid[2 ]);/* indirect */ -DISP_u32 (inode, i_nid[3 ]);/* indirect */ -DISP_u32 (inode, i_nid[4 ]);/* double indirect */ +DISP_u32 (F2FS_INODE_NIDS (inode), i_nid[0 ]);/* direct */ +DISP_u32 (F2FS_INODE_NIDS (inode), i_nid[1 ]);/* direct */ +DISP_u32 (F2FS_INODE_NIDS (inode), i_nid[2 ]);/* indirect */ +DISP_u32 (F2FS_INODE_NIDS (inode), i_nid[3 ]);/* indirect */ +DISP_u32 (F2FS_INODE_NIDS (inode), i_nid[4 ]);/* double indirect */ xattr_addr =read_all_xattrs (sbi, node);if (!xattr_addr)
@@ -393,8 +393,8 @@ out:void print_node_info (struct f2fs_sb_info *sbi,struct f2fs_node *node_block,int verbose) { -nid_t ino =le32_to_cpu (node_block->footer.ino); -nid_t nid =le32_to_cpu (node_block->footer.nid); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (node_block)->ino); +nid_t nid =le32_to_cpu (F2FS_NODE_FOOTER (node_block)->nid);/* Is this inode? */ if (ino == nid) {DBG (verbose,"Node ID [0x%x:%u] is inode\n" , nid, nid);
@@ -2058,7 +2058,7 @@ static void restore_node_summary(struct f2fs_sb_info *sbi,for (i =0 ; i < sbi->blocks_per_seg; i++, sum_entry++) { ret =dev_read_block (node_blk, addr);ASSERT (ret >=0 ); - sum_entry->nid = node_blk->footer.nid; + sum_entry->nid =F2FS_NODE_FOOTER (node_blk)->nid; addr++; }free (node_blk);
@@ -2453,7 +2453,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,/* check extent cache entry */ if (!IS_INODE (node_blk)) { -get_node_info (sbi,le32_to_cpu (node_blk->footer.ino), &ni); +get_node_info (sbi,le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino), &ni);/* read inode block */ ret =dev_read_block (node_blk, ni.blk_addr);
@@ -3568,7 +3568,7 @@ static int loop_node_chain_fix(block_t blkaddr_fast, }while (blkaddr != blkaddr_entry);/* fix the blkaddr of last node with NULL_ADDR. */ - node_blk->footer.next_blkaddr =NULL_ADDR ; +F2FS_NODE_FOOTER (node_blk)->next_blkaddr =NULL_ADDR ;if (IS_INODE (node_blk)) err =write_inode (node_blk, blkaddr_tmp);else
fsck/node.c +6 -6
@@ -66,7 +66,7 @@ int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype)if (is_set_ckpt_flags (ckpt,CP_CRC_RECOVERY_FLAG )) cp_ver |= (cur_cp_crc (ckpt) <<32 ); - raw_node->footer.cp_ver =cpu_to_le64 (cp_ver); +F2FS_NODE_FOOTER (raw_node)->cp_ver =cpu_to_le64 (cp_ver);get_node_info (sbi, ino, &ni);set_summary (&sum, ino,0 , ni.version);
@@ -128,10 +128,10 @@ block_t new_node_block(struct f2fs_sb_info *sbi, 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; +F2FS_NODE_FOOTER (node_blk)->nid =cpu_to_le32 (dn->nid); +F2FS_NODE_FOOTER (node_blk)->ino =F2FS_NODE_FOOTER (f2fs_inode)->ino; +F2FS_NODE_FOOTER (node_blk)->flag =cpu_to_le32 (ofs <<OFFSET_BIT_SHIFT ); +F2FS_NODE_FOOTER (node_blk)->cp_ver = ckpt->checkpoint_ver;set_cold_node (node_blk,S_ISDIR (le16_to_cpu (f2fs_inode->i.i_mode))); type =CURSEG_COLD_NODE ;
@@ -155,7 +155,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi, }/* update nat info */ -update_nat_blkaddr (sbi,le32_to_cpu (f2fs_inode->footer.ino), +update_nat_blkaddr (sbi,le32_to_cpu (F2FS_NODE_FOOTER (f2fs_inode)->ino), dn->nid, blkaddr); dn->node_blk = node_blk;
fsck/node.h +10 -10
@@ -20,13 +20,13 @@static inline bool IS_INODE (struct f2fs_node *node) { -return node->footer.ino == node->footer.nid; +return F2FS_NODE_FOOTER (node)->nid ==F2FS_NODE_FOOTER (node)->ino; }static inline unsigned int ADDRS_PER_PAGE (struct f2fs_sb_info *sbi,struct f2fs_node *node_blk,struct f2fs_node *inode_blk) { -nid_t ino =le32_to_cpu (node_blk->footer.ino); +nid_t ino =le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino);unsigned int nblocks;if (IS_INODE (node_blk))
@@ -71,7 +71,7 @@ static inline block_t datablock_addr(struct f2fs_node *node_page,static inline void set_nid (struct f2fs_node * rn,int off,nid_t nid,int i) {if (i) - rn->i.i_nid[off -NODE_DIR1_BLOCK ] =cpu_to_le32 (nid); +F2FS_INODE_I_NID (&rn->i, off -NODE_DIR1_BLOCK ) =cpu_to_le32 (nid);else rn->in.nid[off] =cpu_to_le32 (nid); }
@@ -79,7 +79,7 @@ static inline void set_nid(struct f2fs_node * rn, int off, nid_t nid, int i)static inline nid_t get_nid (struct f2fs_node * rn,int off,int i) {if (i) -return le32_to_cpu (rn->i.i_nid[off -NODE_DIR1_BLOCK ]); +return le32_to_cpu (F2FS_INODE_I_NID (&rn->i, off -NODE_DIR1_BLOCK ));else return le32_to_cpu (rn->in.nid[off]); }
@@ -127,12 +127,12 @@ static inline int IS_DNODE(struct f2fs_node *node_page)static inline nid_t ino_of_node (struct f2fs_node *node_blk) { -return le32_to_cpu (node_blk->footer.ino); +return le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->ino); }static inline __u64 cpver_of_node (struct f2fs_node *node_blk) { -return le64_to_cpu (node_blk->footer.cp_ver); +return le64_to_cpu (F2FS_NODE_FOOTER (node_blk)->cp_ver); } static inline bool is_recoverable_dnode(struct f2fs_sb_info *sbi,
@@ -153,23 +153,23 @@ static inline bool is_recoverable_dnode(struct f2fs_sb_info *sbi,static inline block_t next_blkaddr_of_node (struct f2fs_node *node_blk) { -return le32_to_cpu (node_blk->footer.next_blkaddr); +return le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->next_blkaddr); }static inline int is_node (struct f2fs_node *node_blk,int type) { -return le32_to_cpu (node_blk->footer.flag) & (1 << type); +return le32_to_cpu (F2FS_NODE_FOOTER (node_blk)->flag) & (1 << type); }static inline void set_cold_node (struct f2fs_node *rn,bool is_dir) { -unsigned int flag =le32_to_cpu (rn->footer.flag); +unsigned int flag =le32_to_cpu (F2FS_NODE_FOOTER (rn)->flag);if (is_dir) flag &= ~(0x1 <<COLD_BIT_SHIFT );else flag |= (0x1 <<COLD_BIT_SHIFT ); - rn->footer.flag =cpu_to_le32 (flag); +F2FS_NODE_FOOTER (rn)->flag =cpu_to_le32 (flag); }#define is_fsync_dnode (node_blk) is_node(node_blk, FSYNC_BIT_SHIFT)
include/f2fs_fs.h +39 -15
105 lines not on this page · raw message
lib/libf2fs.c +1 -1
@@ -574,7 +574,7 @@ int f2fs_crc_valid(uint32_t blk_crc, void *buf, int len)__u32 f2fs_inode_chksum (struct f2fs_node *node) {struct f2fs_inode *ri = &node->i; -__le32 ino = node->footer.ino; +__le32 ino =F2FS_NODE_FOOTER (node)->ino;__le32 gen = ri->i_generation;__u32 chksum, chksum_seed;__u32 dummy_cs =0 ;
mkfs/f2fs_format.c +5 -5
@@ -1106,7 +1106,7 @@ static int f2fs_discard_obsolete_dnode(void)if (c.zoned_mode || c.feature &F2FS_FEATURE_RO )return 0 ; - raw_node =calloc (sizeof (struct f2fs_node ),1 ); + raw_node =calloc (F2FS_BLKSIZE ,1 );if (raw_node ==NULL ) {MSG (1 ,"\tError: Calloc Failed for discard_raw_node!!!\n" );return -1 ;
@@ -1130,7 +1130,7 @@ static int f2fs_discard_obsolete_dnode(void)return -1 ; } - next_blkaddr =le32_to_cpu (raw_node->footer.next_blkaddr); + next_blkaddr =le32_to_cpu (F2FS_NODE_FOOTER (raw_node)->next_blkaddr);memset (raw_node,0 ,F2FS_BLKSIZE );DBG (1 ,"\tDiscard dnode, at offset 0x%08" PRIx64"\n" , offset);
@@ -1297,7 +1297,7 @@ static int f2fs_write_root_inode(void)cpu_to_le32 (data_blkaddr); node_blkaddr =alloc_next_free_block (CURSEG_HOT_NODE ); - raw_node->footer.next_blkaddr =cpu_to_le32 (node_blkaddr +1 ); +F2FS_NODE_FOOTER (raw_node)->next_blkaddr =cpu_to_le32 (node_blkaddr +1 );DBG (1 ,"\tWriting root inode (hot node), offset 0x%x\n" , node_blkaddr);if (write_inode (raw_node, node_blkaddr) <0 ) {
@@ -1415,7 +1415,7 @@ static int f2fs_write_qf_inode(int qtype) raw_node->i.i_flags =F2FS_NOATIME_FL |F2FS_IMMUTABLE_FL ; node_blkaddr =alloc_next_free_block (CURSEG_HOT_NODE ); - raw_node->footer.next_blkaddr =cpu_to_le32 (node_blkaddr +1 ); +F2FS_NODE_FOOTER (raw_node)->next_blkaddr =cpu_to_le32 (node_blkaddr +1 );if (qtype ==0 ) raw_id = raw_node->i.i_uid;
@@ -1550,7 +1550,7 @@ static int f2fs_write_lpf_inode(void)memcpy (raw_node->i.i_name,LPF ,strlen (LPF )); node_blkaddr =alloc_next_free_block (CURSEG_HOT_NODE ); - raw_node->footer.next_blkaddr =cpu_to_le32 (node_blkaddr +1 ); +F2FS_NODE_FOOTER (raw_node)->next_blkaddr =cpu_to_le32 (node_blkaddr +1 ); data_blkaddr =f2fs_add_default_dentry_lpf ();if (data_blkaddr ==0 ) {
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 4/7 f2fs-tools: Refactor SIT/NAT block structs
In reply to Daniel Rosenberg via Linux-f2fs-develThis 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
--- include/f2fs_fs.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
include/f2fs_fs.h +14 -6
@@ -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 */
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 5/7 f2fs-tools: Refactor Summary block struct and friends
In reply to Daniel Rosenberg via Linux-f2fs-develThis splits off access to the summary block's journal and footer into a macro call, as their location is dependent on block size. Because of this you should use F2FS_BLKSIZE instead of sizeof(struct summary_block)
--- fsck/f2fs.h | 4 +-- fsck/fsck.c | 12 +++---- fsck/mount.c | 48 +++++++++++++-------------- fsck/resize.c | 2 +- include/f2fs_fs.h | 83 +++++++++++++++++++++++++++++++++------------- mkfs/f2fs_format.c | 16 ++++----- 6 files changed, 101 insertions(+), 64 deletions(-)
fsck/f2fs.h +2 -2
@@ -608,8 +608,8 @@ static inline int inline_xattr_size(struct f2fs_inode *inode) }extern int lookup_nat_in_journal (struct f2fs_sb_info *sbi,u32 nid,struct f2fs_nat_entry *ne); -#define IS_SUM_NODE_SEG (footer) (footer.entry_type == SUM_TYPE_NODE) -#define IS_SUM_DATA_SEG (footer) (footer.entry_type == SUM_TYPE_DATA) +#define IS_SUM_NODE_SEG (sum) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type == SUM_TYPE_NODE) +#define IS_SUM_DATA_SEG (sum) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type == SUM_TYPE_DATA)static inline unsigned int dir_buckets (unsigned int level,int dir_level) {
fsck/fsck.c +6 -6
@@ -172,7 +172,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid, se =get_seg_entry (sbi, segno);if (IS_NODESEG (se->type)) {ASSERT_MSG ("Summary footer indicates a node segment: 0x%x" , segno); - sum_blk->footer.entry_type =SUM_TYPE_NODE ; +F2FS_SUMMARY_BLOCK_FOOTER (sum_blk)->entry_type =SUM_TYPE_NODE ; }else { ret = -EINVAL ; goto out;
@@ -297,7 +297,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr, se =get_seg_entry (sbi, segno);if (IS_DATASEG (se->type)) {ASSERT_MSG ("Summary footer indicates a data segment: 0x%x" , segno); - sum_blk->footer.entry_type =SUM_TYPE_DATA ; +F2FS_SUMMARY_BLOCK_FOOTER (sum_blk)->entry_type =SUM_TYPE_DATA ; }else { ret = -EINVAL ; goto out;
@@ -3299,16 +3299,16 @@ int fsck_chk_curseg_info(struct f2fs_sb_info *sbi) se->type = i; ret =-1 ; } -if (i <=CURSEG_COLD_DATA &&IS_SUM_DATA_SEG (sum_blk->footer)) { +if (i <=CURSEG_COLD_DATA &&IS_SUM_DATA_SEG (sum_blk)) {continue ; - }else if (i >CURSEG_COLD_DATA &&IS_SUM_NODE_SEG (sum_blk->footer)) { + }else if (i >CURSEG_COLD_DATA &&IS_SUM_NODE_SEG (sum_blk)) {continue ; }else {ASSERT_MSG ("Incorrect curseg [%d]: segno [0x%x] " "type(SSA) [%d]" , i, curseg->segno, - sum_blk->footer.entry_type); +F2FS_SUMMARY_BLOCK_FOOTER (sum_blk)->entry_type);if (c.fix_on || c.preen_mode) - sum_blk->footer.entry_type = +F2FS_SUMMARY_BLOCK_FOOTER (sum_blk)->entry_type = i <=CURSEG_COLD_DATA ?SUM_TYPE_DATA :SUM_TYPE_NODE ; ret =-1 ;
fsck/mount.c +24 -24
174 lines not on this page · raw message
fsck/resize.c +1 -1
@@ -222,7 +222,7 @@ static void move_ssa(struct f2fs_sb_info *sbi, unsigned int segno,ASSERT (ret >=0 );DBG (1 ,"Write summary block: (%d) segno=%x/%x --> (%d) %x\n" , type, segno,GET_SUM_BLKADDR (sbi, segno), -IS_SUM_NODE_SEG (sum_blk->footer), +IS_SUM_NODE_SEG (sum_blk), new_sum_blk_addr); } if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA ||
include/f2fs_fs.h +60 -23
138 lines not on this page · raw message
mkfs/f2fs_format.c +8 -8
@@ -929,8 +929,8 @@ static int f2fs_write_check_point_pack(void) sum_compact_p +=SUM_JOURNAL_SIZE ;/* hot data summary */ -memset (sum,0 ,sizeof (struct f2fs_summary_block )); -SET_SUM_TYPE ((&sum->footer),SUM_TYPE_DATA ); +memset (sum,0 ,F2FS_BLKSIZE ); +SET_SUM_TYPE (sum,SUM_TYPE_DATA ); sum_entry = (struct f2fs_summary *)sum_compact_p; memcpy(sum_entry, c.sum[CURSEG_HOT_DATA],
@@ -948,8 +948,8 @@ static int f2fs_write_check_point_pack(void) }/* Prepare and write Segment summary for HOT_NODE */ -memset (sum,0 ,sizeof (struct f2fs_summary_block )); -SET_SUM_TYPE ((&sum->footer),SUM_TYPE_NODE ); +memset (sum,0 ,F2FS_BLKSIZE ); +SET_SUM_TYPE (sum,SUM_TYPE_NODE );memcpy (sum->entries, c.sum[CURSEG_HOT_NODE ],sizeof (struct f2fs_summary ) *MAX_CACHE_SUMS );
@@ -962,8 +962,8 @@ static int f2fs_write_check_point_pack(void) }/* Fill segment summary for WARM_NODE to zero. */ -memset (sum,0 ,sizeof (struct f2fs_summary_block )); -SET_SUM_TYPE ((&sum->footer),SUM_TYPE_NODE ); +memset (sum,0 ,F2FS_BLKSIZE ); +SET_SUM_TYPE (sum,SUM_TYPE_NODE ); cp_seg_blk++; DBG(1, "\tWriting Segment summary for WARM_NODE, at offset 0x%08"PRIx64"\n",
@@ -974,8 +974,8 @@ static int f2fs_write_check_point_pack(void) }/* Fill segment summary for COLD_NODE to zero. */ -memset (sum,0 ,sizeof (struct f2fs_summary_block )); -SET_SUM_TYPE ((&sum->footer),SUM_TYPE_NODE ); +memset (sum,0 ,F2FS_BLKSIZE ); +SET_SUM_TYPE (sum,SUM_TYPE_NODE ); cp_seg_blk++;DBG (1 ,"\tWriting Segment summary for COLD_NODE, at offset 0x%08" PRIx64"\n" , cp_seg_blk);
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 6/7 f2fs-tools: Refactor f2fs_dentry_block struct
In reply to Daniel Rosenberg via Linux-f2fs-develThis moves access to f2fs_dentry_block's dentry list and filename list behind a macro, as their locations depend on block size.
Since struct f2fs_dentry_block no longer represents the full block, use F2FS_BLKSIZE instead of sizeof(struct f2fs_dentry_block)
--- fsck/dir.c | 26 +++++++++++----------- fsck/fsck.c | 2 +- include/f2fs_fs.h | 30 ++++++++++++++++++++------ mkfs/f2fs_format.c | 54 +++++++++++++++++++++++----------------------- 4 files changed, 65 insertions(+), 47 deletions(-)
fsck/dir.c +13 -13
@@ -43,8 +43,8 @@ void make_dentry_ptr(struct f2fs_dentry_ptr *d, struct f2fs_node *node_blk, d->max =NR_DENTRY_IN_BLOCK ; d->nr_bitmap =SIZE_OF_DENTRY_BITMAP ; d->bitmap = t->dentry_bitmap; - d->dentry = t->dentry; - d->filename = t->filename; + d->dentry =F2FS_DENTRY_BLOCK_DENTRIES (t); + d->filename =F2FS_DENTRY_BLOCK_FILENAMES (t); }else {int entry_cnt =NR_INLINE_DENTRY (node_blk);int bitmap_size =INLINE_DENTRY_BITMAP_SIZE (node_blk);
@@ -352,17 +352,17 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) dent_blk =calloc (BLOCK_SZ ,1 );ASSERT (dent_blk); - dent_blk->dentry[0 ].hash_code =0 ; - dent_blk->dentry[0 ].ino =cpu_to_le32 (ino); - dent_blk->dentry[0 ].name_len =cpu_to_le16 (1 ); - dent_blk->dentry[0 ].file_type =F2FS_FT_DIR ; -memcpy (dent_blk->filename[0 ],"." ,1 ); - - dent_blk->dentry[1 ].hash_code =0 ; - dent_blk->dentry[1 ].ino =cpu_to_le32 (pino); - dent_blk->dentry[1 ].name_len =cpu_to_le16 (2 ); - dent_blk->dentry[1 ].file_type =F2FS_FT_DIR ; -memcpy (dent_blk->filename[1 ],".." ,2 ); +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,0 ).hash_code =0 ; +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,0 ).ino =cpu_to_le32 (ino); +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,0 ).name_len =cpu_to_le16 (1 ); +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,0 ).file_type =F2FS_FT_DIR ; +memcpy (F2FS_DENTRY_BLOCK_FILENAME (dent_blk,0 ),"." ,1 ); + +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,1 ).hash_code =0 ; +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,1 ).ino =cpu_to_le32 (pino); +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,1 ).name_len =cpu_to_le16 (2 ); +F2FS_DENTRY_BLOCK_DENTRY (dent_blk,1 ).file_type =F2FS_FT_DIR ; +memcpy (F2FS_DENTRY_BLOCK_FILENAME (dent_blk,1 ),".." ,2 );test_and_set_bit_le (0 , dent_blk->dentry_bitmap);test_and_set_bit_le (1 , dent_blk->dentry_bitmap);
fsck/fsck.c +1 -1
@@ -1963,7 +1963,7 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, int casefolded, u32 blk_addr, dentries =__chk_dentries (sbi, casefolded, child, de_blk->dentry_bitmap, - de_blk->dentry, de_blk->filename, +F2FS_DENTRY_BLOCK_DENTRIES (de_blk),F2FS_DENTRY_BLOCK_FILENAMES (de_blk),NR_DENTRY_IN_BLOCK , last_blk, enc_name);if (dentries <0 &&f2fs_dev_is_writable ()) {
include/f2fs_fs.h +24 -6
@@ -1365,16 +1365,29 @@ struct f2fs_dir_entry {static_assert (sizeof (struct f2fs_dir_entry ) ==11 ,"" ); -/* 4KB-sized directory entry block */ +/* +* Block-sized directory entry block +* On disk structure: +* struct f2fs_dentry_block; +* __u8 reserved[SIZE_OF_RESERVED]; +* struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; +* __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; +* +* Do NOT use sizeof. Use F2FS_BLKSIZE instead +*/ struct f2fs_dentry_block {/* validity bitmap for directory entries in each block */ -__u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP ]; -__u8 reserved[SIZE_OF_RESERVED ]; -struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK ]; -__u8 filename[NR_DENTRY_IN_BLOCK ][F2FS_SLOT_LEN ]; +__u8 dentry_bitmap[0 ];/* size is SIZE_OF_DENTRY_BITMAP, based on block size */ }; -static_assert (sizeof (struct f2fs_dentry_block ) ==F2FS_BLKSIZE ,"" ); +#define F2FS_DENTRY_BLOCK_DENTRIES (blk) ((struct f2fs_dir_entry *)\ + &((blk)->dentry_bitmap[SIZE_OF_DENTRY_BITMAP + SIZE_OF_RESERVED])) +#define F2FS_DENTRY_BLOCK_DENTRY (blk, i) (F2FS_DENTRY_BLOCK_DENTRIES((blk))[(i)]) + +#define F2FS_DENTRY_BLOCK_FILENAMES (blk) ((__u8(*)[F2FS_SLOT_LEN])&F2FS_DENTRY_BLOCK_DENTRY(blk,\ + NR_DENTRY_IN_BLOCK)) +#define F2FS_DENTRY_BLOCK_FILENAME (blk, i) (&((__u8 *)&F2FS_DENTRY_BLOCK_DENTRY(blk,\ + NR_DENTRY_IN_BLOCK))[(i) * F2FS_SLOT_LEN])/* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1
@@ -2040,6 +2053,11 @@ static inline void check_block_struct_sizes(void)/* Check Info Journal Block Size */ assert (sizeof (struct f2fs_summary ) *ENTRIES_IN_SUM +sizeof (__le64) +EXTRA_INFO_RESERVED +sizeof (struct summary_footer ) ==F2FS_BLKSIZE ); + +/* Check Dentry Block Size */ +assert (sizeof (__u8) * (SIZE_OF_DENTRY_BITMAP +SIZE_OF_RESERVED ) + +NR_DENTRY_IN_BLOCK *sizeof (struct f2fs_dir_entry ) + + NR_DENTRY_IN_BLOCK * F2FS_SLOT_LEN * sizeof(u8) == F2FS_BLKSIZE); }#endif /*__F2FS_FS_H */
mkfs/f2fs_format.c +27 -27
74 lines not on this page · raw message
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 7/7 f2fs-tools: Support different block sizes
In reply to Daniel Rosenberg via Linux-f2fs-develThis adds support for 4K and 16K block size using the same binary. mkfs can choose block size via the -b option, with other tools getting the blocksize from the superblock.
On mount time, we can't rely on block size for the location for the superblock, since that information is in the superblock. If the first superblock is corrupt, we will attempt to find the second superblock at a 4K block offset, and then a 16K block offset if that fails.
--- fsck/dir.c | 2 +- fsck/dump.c | 4 ++-- fsck/fsck.h | 3 --- fsck/mount.c | 27 +++++++++++++++++++++------ include/f2fs_fs.h | 10 +++++++--- lib/libf2fs.c | 2 ++ man/sload.f2fs.8 | 2 +- mkfs/f2fs_format_main.c | 12 +++++++++++- mkfs/f2fs_format_utils.c | 2 +- 9 files changed, 46 insertions(+), 18 deletions(-)
fsck/dir.c +1 -1
@@ -474,7 +474,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi,if (de->file_type ==F2FS_FT_DIR ) { mode |=S_IFDIR ; - size =4096 ; + size =F2FS_BLKSIZE ; links++; blocks++; }else if (de->file_type ==F2FS_FT_REG_FILE ) {
fsck/dump.c +2 -2
@@ -687,8 +687,8 @@ static void dump_data_offset(u32 blk_addr, int ofs_in_node) bidx += ofs_in_node;setlocale (LC_ALL ,"" ); -MSG (0 ," - Data offset : 0x%x (4KB), %'u (bytes)\n" , - bidx, bidx *4096 ); +MSG (0 ," - Data offset : 0x%x (BLOCK), %'u (bytes)\n" , + bidx, bidx *F2FS_BLKSIZE );free (node_blk); }
fsck/fsck.h +0 -3
@@ -127,9 +127,6 @@ struct f2fs_fsck { };#define BLOCK_SZ F2FS_BLKSIZE -struct block { -unsigned char buf[BLOCK_SZ ]; -};enum NODE_TYPE {TYPE_INODE =37 ,
fsck/mount.c +21 -6
@@ -994,11 +994,15 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr)return -1 ; blocksize =1 <<get_sb (log_blocksize); -if (F2FS_BLKSIZE != blocksize) { -MSG (0 ,"Invalid blocksize (%u), supports only (%u)\n" , - blocksize,F2FS_BLKSIZE ); +if (blocksize <F2FS_MIN_BLKSIZE || blocksize >F2FS_MAX_BLKSIZE ) { +MSG (0 ,"Invalid blocksize (%u), must be between 4KB and 16KB\n" , + blocksize);return -1 ; } + c.blksize_bits =get_sb (log_blocksize); + c.blksize = blocksize; + c.sectors_per_blk =F2FS_BLKSIZE / c.sector_size; +check_block_struct_sizes ();/* check log blocks per segment */ if (get_sb (log_blocks_per_seg) !=9 ) {
@@ -1007,7 +1011,7 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr)return -1 ; } -/* Currently, support 512/1024/2048/4096 bytes sector size */ +/* Currently, support powers of 2 from 512 to BLOCK SIZE bytes sector size */ if (get_sb (log_sectorsize) >F2FS_MAX_LOG_SECTOR_SIZE ||get_sb (log_sectorsize) <F2FS_MIN_LOG_SECTOR_SIZE ) {MSG (0 ,"Invalid log sectorsize (%u)\n" ,get_sb (log_sectorsize));
@@ -3854,9 +3858,20 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; ret =validate_super_block (sbi,SB0_ADDR );if (ret) { +/* Assuming 4K Block Size */ + c.blksize_bits =12 ; + c.blksize =1 << c.blksize_bits; +MSG (0 ,"Looking for secondary superblock assuming 4K Block Size\n" ); ret =validate_super_block (sbi,SB1_ADDR ); -if (ret) -return -1 ; +if (ret) { +/* Trying 16K Block Size */ + c.blksize_bits =14 ; + c.blksize =1 << c.blksize_bits; +MSG (0 ,"Looking for secondary superblock assuming 16K Block Size\n" ); + ret =validate_super_block (sbi,SB1_ADDR ); +if (ret) +return -1 ; + } } sb =F2FS_RAW_SUPER (sbi);
include/f2fs_fs.h +7 -3
@@ -392,7 +392,7 @@ static inline uint64_t bswap_64(uint64_t val)#define MAX_DEVICES 8#define F2FS_BYTES_TO_BLK (bytes) ((bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLKSIZE_BITS 12/* 4KB block */ +#define F2FS_BLKSIZE_BITS c.blksize_bits/* for mkfs */ #define F2FS_NUMBER_OF_CHECKPOINT_PACK 2
@@ -400,6 +400,7 @@ static inline uint64_t bswap_64(uint64_t val)#define DEFAULT_SECTORS_PER_BLOCK (1 << (F2FS_BLKSIZE_BITS - SECTOR_SHIFT))#define DEFAULT_BLOCKS_PER_SEGMENT 512#define DEFAULT_SEGMENTS_PER_SECTION 1 +#define DEFAULT_BLKSIZE_BITS 12/* 4096 */ #define VERSION_LEN 256#define VERSION_TIMESTAMP_LEN 4
@@ -628,9 +629,10 @@ enum {*/ #define F2FS_SUPER_OFFSET 1024/* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9/* 9 bits for 512 bytes */ -#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS/* 12 bits for 4096 bytes */ -#define F2FS_BLKSIZE (1 << F2FS_BLKSIZE_BITS)/* support only 4KB block */ +#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS/* max sector size is block size */ +#define F2FS_MIN_BLKSIZE 4096#define F2FS_MAX_BLKSIZE 16384 +#define F2FS_BLKSIZE c.blksize/* support configurable block size */ #define F2FS_MAX_EXTENSION 64/* # of extension entries */ #define F2FS_EXTENSION_LEN 8/* max size of extension */ #define F2FS_BLK_ALIGN (x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE)
@@ -1510,6 +1512,8 @@ struct f2fs_configuration {uint32_t lpf_ino;uint32_t root_uid;uint32_t root_gid; +uint32_t blksize; +uint32_t blksize_bits;/* defragmentation parameters */ int defrag_shrink;
lib/libf2fs.c +2 -0
@@ -689,6 +689,8 @@ void f2fs_init_configuration(void)memset (&c,0 ,sizeof (struct f2fs_configuration )); c.ndevs =1 ; + c.blksize =1 <<DEFAULT_BLKSIZE_BITS ; + c.blksize_bits =DEFAULT_BLKSIZE_BITS ; c.sectors_per_blk =DEFAULT_SECTORS_PER_BLOCK ; c.blks_per_seg =DEFAULT_BLOCKS_PER_SEGMENT ; c.wanted_total_sectors =-1 ;
man/sload.f2fs.8 +1 -1
@@ -82,7 +82,7 @@ independently. Specify cluster size in power of two blocks. The minimum value is 2 (4 blocks, default). The maximum value is 8 (256 blocks). -Note that a block contains 4096 bytes. +Note that a block contains 4096 or 16384 bytes. This option must be used with option \fB\-c\fR. .TP .BI \-a " compression-algorithm"
mkfs/f2fs_format_main.c +11 -1
@@ -52,6 +52,7 @@ static void mkfs_usage()MSG (0 ,"\nUsage: mkfs.f2fs [options] device [sectors]\n" );MSG (0 ,"[options]:\n" );MSG (0 ," -a heap-based allocation [default:0]\n" ); +MSG (0 ," -b filesystem block size [default:4096]\n" );MSG (0 ," -c device1[,device2,...] up to 7 additional devices, except meta device\n" );MSG (0 ," -d debug level [default:0]\n" );MSG (0 ," -e [cold file ext list] e.g. \"mp3,gif,mov\"\n" );
@@ -177,7 +178,7 @@ static void add_default_options(void)static void f2fs_parse_options (int argc,char *argv[]) { -static const char *option_string ="qa:c:C:d:e:E:g:hil:mo:O:rR:s:S:z:t:T:U:Vfw:Z:" ; +static const char *option_string ="qa:b:c:C:d:e:E:g:hil:mo:O:rR:s:S:z:t:T:U:Vfw:Z:" ;static const struct option long_opts[] = { { .name ="help" , .has_arg =0 , .flag =NULL , .val ='h' }, { .name =NULL , .has_arg =0 , .flag =NULL , .val =0 }
@@ -194,6 +195,15 @@ static void f2fs_parse_options(int argc, char *argv[])case 'a' : c.heap =atoi (optarg);break ; +case 'b' : + c.blksize =atoi (optarg); + c.blksize_bits =log_base_2 (c.blksize); + c.sectors_per_blk =DEFAULT_SECTORS_PER_BLOCK ; +if ((1 << c.blksize_bits) != c.blksize) { +MSG (0 ,"Error: Block size must be power of 2" ); +mkfs_usage (); + } +break ;case 'c' :if (c.ndevs >=MAX_DEVICES ) {MSG (0 ,"Error: Too many devices\n" );
mkfs/f2fs_format_utils.c +1 -1
@@ -126,7 +126,7 @@ static bool is_wiped_device(int i)int fd = dev->fd;char *buf, *zero_buf;bool wiped = true; -int nblocks =4096 ;/* 16MB size */ +int nblocks = (4096 *4096 ) /F2FS_BLKSIZE ;/* 16MB size */ int j;/* let's trim the other devices except the first device */
Signature · 8 lines
2.41.0.694.ge786442a9b-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel