Skip to contentSkip to conversation

f2fs-tools: fix incorrect return type of f2fs_max_file_offset

PATCH In review LongPing Wei via Linux-f2fs-devel 1 participant 2 messages Mar 20, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs-tools: fix incorrect return type of f2fs_max_file_offset

An error occurs when the file length exceeds 4 GiB. For example:
touch test.img
truncate -s 10G test.img
mkfs.f2fs test.img
mkdir mnt
mount -t f2fs -o loop test.img mnt
dd if=/dev/zero of=mnt/testfile bs=1G count=5 sync
umount mnt
fsck.f2fs -M test.img

/testfile 1319936-1320447[ASSERT] (dump_data_blk: 285) blkaddr == NULL_ADDR

---
 include/f2fs_fs.h | 2 +-
 lib/libf2fs.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -1
index bb40adc..f206994 100644
@@ -1610,7 +1610,7 @@ extern int utf8_to_utf16(char *, const char *, size_t, size_t);
 extern int utf16_to_utf8(char *, const char *, size_t, size_t);
 extern int log_base_2(uint32_t);
 extern unsigned int addrs_per_page(struct f2fs_inode *, bool);
-extern unsigned int f2fs_max_file_offset(struct f2fs_inode *);
+extern u64 f2fs_max_file_offset(struct f2fs_inode *);
 extern __u32 f2fs_inode_chksum(struct f2fs_node *);
 extern __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *);
 extern int write_inode(struct f2fs_node *, u64, enum rw_hint);
lib/libf2fs.c +1 -1
index ecd22d4..d2579d7 100644
@@ -527,7 +527,7 @@ unsigned int addrs_per_page(struct f2fs_inode *i, bool is_inode)
 	return ALIGN_DOWN(addrs, 1 << i->i_log_cluster_size);
 }
 
-unsigned int f2fs_max_file_offset(struct f2fs_inode *i)
+u64 f2fs_max_file_offset(struct f2fs_inode *i)
 {
 	if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
 			!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
Signature · 8 lines
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
author Reviewed-by Chao Yu on v1 1/1
#1 lore raw
Quoted 12 lines · LongPing Wei

An error occurs when the file length exceeds 4 GiB. For example:
touch test.img
truncate -s 10G test.img
mkfs.f2fs test.img
mkdir mnt
mount -t f2fs -o loop test.img mnt
dd if=/dev/zero of=mnt/testfile bs=1G count=5 sync
umount mnt
fsck.f2fs -M test.img

Quoted 1 line

/testfile 1319936-1320447[ASSERT] (dump_data_blk: 285) blkaddr == NULL_ADDR

Good catch! Seems it will affect several tools including fsck, dump and sload.

Quoted 3 lines

Thanks,

Quoted 23 lines
---
  include/f2fs_fs.h | 2 +-
  lib/libf2fs.c     | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -1
index bb40adc..f206994 100644
@@ -1610,7 +1610,7 @@ extern int utf8_to_utf16(char *, const char *, size_t, size_t);
  extern int utf16_to_utf8(char *, const char *, size_t, size_t);
  extern int log_base_2(uint32_t);
  extern unsigned int addrs_per_page(struct f2fs_inode *, bool);
-extern unsigned int f2fs_max_file_offset(struct f2fs_inode *);
+extern u64 f2fs_max_file_offset(struct f2fs_inode *);
  extern __u32 f2fs_inode_chksum(struct f2fs_node *);
  extern __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *);
  extern int write_inode(struct f2fs_node *, u64, enum rw_hint);
lib/libf2fs.c +0 -0
index ecd22d4..d2579d7 100644

lib/libf2fs.c unsigned int addrs_per_page(struct f2fs_inode *i, bool is_inode) · line 533

Quoted 8 lines
lib/libf2fs.c +1 -1
@@ -527,7 +527,7 @@ unsigned int addrs_per_page(struct f2fs_inode *i, bool is_inode)
  	return ALIGN_DOWN(addrs, 1 << i->i_log_cluster_size);
  }
 
-unsigned int f2fs_max_file_offset(struct f2fs_inode *i)
+u64 f2fs_max_file_offset(struct f2fs_inode *i)
  {
  	if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
  			!(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel