Skip to contentSkip to conversation

mkfs.f2fs: fix to align RO image layout w/ block size

PATCH New Chao Yu 1 participant 1 message Oct 22

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 mkfs.f2fs: fix to align RO image layout w/ block size

From: Chao Yu <[email protected]>

f2fs/015 fails w/ 16k block size, mounting an image formatted w/ "-O ro" fails as below:

mkfs.f2fs -f -b 16384 -O ro /dev/vdd
mount -t f2fs -o ro /dev/vdd /mnt/f2fs
mount: /mnt/f2fs: mount() failed: Structure needs cleaning.

F2FS-fs (vdd): invalid crc_offset: 0
F2FS-fs (vdd): Skip to start discard thread for readonly image F2FS-fs (vdd): SIT is corrupted node# 0 vs 1
F2FS-fs (vdd): Failed to initialize F2FS segment manager (-117)

and fsck.f2fs reports:

[ASSERT] (fsck_chk_curseg_info:3747) --> Incorrect curseg [3]: segno [0x38] type(SIT) [0]

For RO image, f2fs_prepare_super_block() hardcodes the start offset of segment0 to 8192 bytes, i.e. two 4k blocks for the two superblocks, but w/ 16k block size, 8192 bytes is only half of a block, so segment0_blkaddr and cp_blkaddr become 0, then the 1st checkpoint pack shares block #0 w/ the superblock and is overwritten by it, so kernel and fsck can not find valid SIT journal entries in the compacted summary.

Let's use 2 * F2FS_BLKSIZE as the start offset instead.

Fixes 50fd00b ("f2fs-tools: Support different block sizes")
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +1 -1
index 33d3da9..7390fa4 100644
@@ -316,7 +316,7 @@ static int f2fs_prepare_super_block(void)
 		(uint64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	if (c.feature & F2FS_FEATURE_RO)
-		zone_align_start_offset = 8192;
+		zone_align_start_offset = 2 * F2FS_BLKSIZE;
 
 	if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
Signature · 1 line
2.49.0