[PATCH 5/5] hfsplus: name the constants of the allocation bitmap check
From: Viacheslav Dubeyko
Date: Thu Nov 19 2026 - 18:41:56 EST
hfsplus_file_extend() refuses to allocate when the allocation bitmap
has fewer than eight bits beyond the blocks in use, written as
i_size * 8 < total_blocks - free_blocks + 8
where the first 8 is the number of bits per byte and the second one is
a margin. Use BITS_PER_BYTE for the first and a new constant,
HFSPLUS_ALLOC_BITMAP_SPARE_BITS, for the second, and name the two sides
of the comparison. The number of blocks in use plus the margin is now
computed in 64 bits, as the bitmap size already was; there is no other
functional change.
Tested on a KASAN and lockdep kernel: filling a volume whose allocation
file is exactly as large as the volume needs fails with -ENOSPC at 0
free blocks and fsck.hfsplus reports the volume as OK; generic/001,
002, 013, 075 and 112 pass.
cc: John Paul Adrian Glaubitz <glaubitz@xxxxxxxxxxxxxxxxxxx>
cc: Yangtao Li <frank.li@xxxxxxxx>
cc: linux-fsdevel@xxxxxxxxxxxxxxx
Signed-off-by: Viacheslav Dubeyko <slava@xxxxxxxxxxx>
---
fs/hfsplus/extents.c | 9 +++++----
fs/hfsplus/hfsplus_fs.h | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
index da6ab85a64ae..f910699338e5 100644
--- a/fs/hfsplus/extents.c
+++ b/fs/hfsplus/extents.c
@@ -552,15 +552,16 @@ int hfsplus_file_extend(struct inode *inode, bool zeroout)
struct super_block *sb = inode->i_sb;
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+ u64 bitmap_bits = (u64)sbi->alloc_file.inode->i_size * BITS_PER_BYTE;
+ u32 used_blocks = sbi->total_blocks - sbi->free_blocks;
u32 start, len, goal;
int res;
- if (sbi->alloc_file.inode->i_size * 8 <
- sbi->total_blocks - sbi->free_blocks + 8) {
+ if (bitmap_bits < (u64)used_blocks + HFSPLUS_ALLOC_BITMAP_SPARE_BITS) {
/* extend alloc file */
pr_err_ratelimited("extend alloc file! (%llu,%u,%u)\n",
- sbi->alloc_file.inode->i_size * 8,
- sbi->total_blocks, sbi->free_blocks);
+ bitmap_bits, sbi->total_blocks,
+ sbi->free_blocks);
return -ENOSPC;
}
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 9a304d946297..4f604c664cb9 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -120,6 +120,12 @@ struct hfsplus_alloc_file {
struct hfsplus_overflow_extents overflow;
};
+/*
+ * Bits the allocation bitmap must have beyond the blocks in use for
+ * hfsplus_file_extend() to allocate more blocks.
+ */
+#define HFSPLUS_ALLOC_BITMAP_SPARE_BITS 8
+
struct hfsplus_sb_info {
void *s_vhdr_buf;
struct hfsplus_vh *s_vhdr;
--
2.53.0