mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	vdubeyko@coreweave.com, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH 5/5] hfsplus: name the constants of the allocation bitmap check
Date: Thu, 19 Nov 2026 15:41:12 -0800	[thread overview]
Message-ID: <20261119234112.720963-6-slava@dubeyko.com> (raw)
In-Reply-To: <20261119234112.720963-1-slava@dubeyko.com>

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@physik.fu-berlin.de>
cc: Yangtao Li <frank.li@vivo.com>
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
---
 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


      parent reply	other threads:[~2026-11-19 23:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 23:41 [PATCH 0/5] hfsplus: fix locking and validation of the special files Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 1/5] hfsplus: reject special files larger than their allocation at mount Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 2/5] hfsplus: map the allocation file without the extents B-tree Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 3/5] hfsplus: give the special files their own extents_lock lockdep class Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 4/5] hfsplus: reject an allocation bitmap that does not cover the volume Viacheslav Dubeyko
2026-11-19 23:41 ` Viacheslav Dubeyko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119234112.720963-6-slava@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vdubeyko@coreweave.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®