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 1/2] hfsplus: set s_maxbytes from the volume capacity
Date: Thu,  5 Nov 2026 16:49:22 -0800	[thread overview]
Message-ID: <20261106004923.1844283-2-slava@dubeyko.com> (raw)
In-Reply-To: <20261106004923.1844283-1-slava@dubeyko.com>

The xfstests' test-case generic/564 expects -EFBIG when
copy_file_range() targets a destination offset near 8EiB.
hfsplus_fill_super() sets s_maxbytes to MAX_LFS_FILESIZE,
so the VFS limit checks (generic_write_check_limits())
only trim the length instead of failing, and the request
reaches the file system. Because HFS+ does not support
holes, the driver then tries to zero-fill the whole gap
up to the target offset, and the operation fails with
-ENOSPC instead of -EFBIG.

This was previously worked around by a local check
against the volume capacity in hfsplus_write_begin().
That check only covered the write path and only the
start offset: truncate up, copy_file_range() and writes
that straddle the limit were not handled.

Every byte of an HFS+ file up to end-of-file must be
backed by an allocated block, so a file can never be
larger than the volume. Set s_maxbytes to the volume
capacity (total_blocks << alloc_blksz_shift, capped by
MAX_LFS_FILESIZE). The VFS then returns -EFBIG for
write(), copy_file_range(), truncate and fallocate
beyond that limit, and trims writes that straddle it.
Drop the now redundant local check from
hfsplus_write_begin().

Fixes: 56a4dbc90601 ("hfsplus: fix error code when writing beyond volume capacity")
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
cc: Yangtao Li <frank.li@vivo.com>
cc: linux-fsdevel@vger.kernel.org
---
 fs/hfsplus/inode.c |  7 -------
 fs/hfsplus/super.c | 10 +++++++++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index aed0866499b2..5fa72b465922 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -44,15 +44,8 @@ int hfsplus_write_begin(const struct kiocb *iocb,
 			void **fsdata)
 {
 	struct inode *inode = mapping->host;
-	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
-	loff_t total_capacity;
 	int ret;
 
-	total_capacity = (loff_t)sbi->total_blocks << sbi->alloc_blksz_shift;
-
-	if (pos >= total_capacity)
-		return -EFBIG;
-
 	ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata,
 				hfsplus_get_block,
 				&HFSPLUS_I(inode)->phys_size);
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 4e878641fb59..f3283e9b42c8 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -672,7 +672,15 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	/* Set up operations so we can load metadata */
 	sb->s_op = &hfsplus_sops;
-	sb->s_maxbytes = MAX_LFS_FILESIZE;
+
+	/*
+	 * HFS+ does not support sparse files, so every byte up to
+	 * the end-of-file has to be backed by an allocated block.
+	 * Therefore, a file can never be larger than the volume.
+	 */
+	sb->s_maxbytes = min_t(loff_t, MAX_LFS_FILESIZE,
+			       (loff_t)sbi->total_blocks <<
+					sbi->alloc_blksz_shift);
 
 	if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
 		pr_warn("Filesystem was not cleanly unmounted, running fsck.hfsplus is recommended.  mounting read-only.\n");
-- 
2.43.0


  reply	other threads:[~2026-11-06  0:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  0:49 [PATCH 0/2] hfs/hfsplus: " Viacheslav Dubeyko
2026-11-06  0:49 ` Viacheslav Dubeyko [this message]
2026-11-06  0:49 ` [PATCH 2/2] hfs: " Viacheslav Dubeyko

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=20261106004923.1844283-2-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®