befs: Large file support and a superblock check fix
Subsystems (2)
v2 cover befs: Large file support and a superblock check fix
Two small befs fixes I originally sent in 2019 [1][2], which never got picked up. Rebased onto v7.3 and resent as v2.
Patch 1 lets befs serve files larger than 2GiB; the on-disk format and the implementation already handle 64-bit file sizes, only s_maxbytes was never raised from the MAX_NON_LFS default.
Patch 2 replaces a superblock consistency check that compares ag_shift against blocks_per_ag, and therefore emits an error message on basically every valid volume, with the check the BFS reference implementation uses. Note that a mismatch now fails the mount, like the other structural superblock checks do.
In v1, patch 2 just removed the check; the corresponding v1 thread is "befs: Removed incorrect check" [2].
Changes since v1:
- Patch 1: rebased; sb_set_blocksize() is now checked for failure, so the assignment moved below the new error path.
- Patch 2: replace the incorrect check with the one from the BFS reference implementation instead of just removing it, limit ag_shift to what a block_run can address, and explain what ag_shift and blocks_per_ag actually mean.
Both patches were build-tested with W=1 and CONFIG_BEFS_DEBUG=y on x86_64 and i386, and tested by mounting a Haiku volume: the bogus ag_shift error is gone, and a file larger than 2GiB can now be read beyond the 2GiB boundary.
[1] https://lore.kernel.org/lkml/?q=s:%22befs:+Allow+file+sizes+beyond+2GiB%22
[2] https://lore.kernel.org/lkml/?q=s:%22befs:+Removed+incorrect+check%22
Axel Dörfler (2):
befs: Allow file sizes beyond 2GiB
befs: Fix allocation group consistency check
fs/befs/linuxvfs.c | 1 + fs/befs/super.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
Signature · 1 line
2.56.0
PATCH v2 1/2 befs: Allow file sizes beyond 2GiB
This just enables LFS support in the VFS. The implementation already supports large files.
---
Notes:
v2:
- Rebased onto v7.3; sb_set_blocksize() is now checked for failure, so the assignment moved below the new error path.
fs/befs/linuxvfs.c | 1 + 1 file changed, 1 insertion(+)
fs/befs/linuxvfs.c +1 -0
@@ -862,6 +862,7 @@ befs_fill_super(struct super_block *sb, struct fs_context *fc)/* Set real blocksize of fs */ if (!sb_set_blocksize (sb, (ulong ) befs_sb->block_size)) goto unacquire_priv_sbp; + sb->s_maxbytes =MAX_LFS_FILESIZE ; sb->s_op = &befs_sops; sb->s_export_op = &befs_export_operations; sb->s_time_min =0 ;
Signature · 1 line
2.56.0
PATCH v2 2/2 befs: Fix allocation group consistency check
In reply to Axel Dörflerbefs_check_sb() complains if (1 << ag_shift) != blocks_per_ag, but the two fields do not describe the same thing: ag_shift is the log2 of the number of blocks in an allocation group (which is also how befs uses it to convert between inode addresses and block numbers), while blocks_per_ag is the number of bitmap blocks per allocation group.
As a result, the check triggers on basically every valid volume.
Replace it with the check the BFS reference implementation uses: the number of allocation groups must match the number of blocks divided by the allocation group size, rounded up. Also reject ag_shift values larger than 16: the start of a block_run within an allocation group is only 16 bits wide, so larger allocation groups cannot be addressed, and such values could otherwise make the shifts in iaddr2blockno() and blockno2iaddr(), and the division in the new check, misbehave.
Like the other structural checks in befs_check_sb(), a mismatch now fails the mount instead of only printing an error.
---
Notes:
v2:
- Replace the incorrect check with the one from the BFS reference implementation instead of just removing it, and limit ag_shift to what a block_run can address.
- Explain what ag_shift and blocks_per_ag actually mean.
fs/befs/super.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
fs/befs/super.c +17 -5
@@ -99,12 +99,24 @@ befs_check_sb(struct super_block *sb)return BEFS_ERR ; } - -/* ag_shift also encodes the same information as blocks_per_ag in a -* different way, non-fatal consistency check +/* +* ag_shift is the log2 of the number of blocks in an allocation +* group, so it determines how many allocation groups are needed to +* cover all blocks of the file system. Since the start of a block +* run within an allocation group is only 16 bits wide, an allocation +* group cannot have more than 65536 blocks. */ -if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag) -befs_error (sb,"ag_shift disagrees with blocks_per_ag." ); + +if (befs_sb->ag_shift <1 || befs_sb->ag_shift >16 ) { +befs_error (sb,"invalid ag_shift: %u" , befs_sb->ag_shift); +return BEFS_ERR ; + } + +if (DIV_ROUND_UP_ULL (befs_sb->num_blocks,1ULL << befs_sb->ag_shift) != + befs_sb->num_ags) { +befs_error (sb,"num_ags disagrees with num_blocks and ag_shift" ); +return BEFS_ERR ; + }if (befs_sb->log_start != befs_sb->log_end || befs_sb->flags ==BEFS_DIRTY ) {
Signature · 1 line
2.56.0
Quoted 8 lines · Axel Dörfler
Two small befs fixes I originally sent in 2019 [1][2], which never got picked up. Rebased onto v7.3 and resent as v2.
Patch 1 lets befs serve files larger than 2GiB; the on-disk format and the implementation already handle 64-bit file sizes, only
s_maxbyteswas never raised from theMAX_NON_LFSdefault.[...]
Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.5.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.5.misc
[1/2] befs: Allow file sizes beyond 2GiB
https://git.kernel.org/vfs/vfs/c/cd1fb89d09f9 [2/2] befs: Fix allocation group consistency check https://git.kernel.org/vfs/vfs/c/f51cd637b410