Skip to contentSkip to conversation

mkfs.f2fs: fix to calculate left space of checkpoint page correctly

PATCH New Chao Yu 1 participant 1 message Dec 14, 2015

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 mkfs.f2fs: fix to calculate left space of checkpoint page correctly

We reserved one segment for NAT region at least, so when formatting fs, calculated maximum size of left space in CP page should be:
CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 1 - 64 (size of reserved NAT bitmap).

Fix the incorrect calculated size to avoid potential overflow bug here.

---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +1 -1
index c4b17de..a2f33f9 100644
@@ -220,7 +220,7 @@ static int f2fs_prepare_super_block(void)
 	 * When sit is too large, we should expand cp area. It requires more pages for cp.
 	 */
 	if (max_sit_bitmap_size >
-			(CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 65)) {
+			(CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 1 - 64)) {
 		max_nat_bitmap_size = CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 1;
 		set_sb(cp_payload, F2FS_BLK_ALIGN(max_sit_bitmap_size));
 	} else {
Signature · 5 lines
2.6.3



------------------------------------------------------------------------------