From: hengyul@cs.unc.edu
To: slava@dubeyko.com
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] hfs: report errors when extending files with setattr
Date: Sat, 17 Oct 2026 12:06:12 -0400 [thread overview]
Message-ID: <20261017160612.3740256-1-hengyul@cs.unc.edu> (raw)
From: Hengyu Liang <hengyul@cs.unc.edu>
hfs_inode_setattr() sets i_size and calls hfs_file_truncate() to change
the allocation. If expansion fails, hfs_file_truncate() restores i_size
to the allocated size, but its void return type leaves setattr reporting
success.
On a freshly formatted 64 MiB HFS volume, ftruncate() to 128 MiB returns
zero while the file remains empty. When the requested size fits within
the volume but exceeds the free space, it also returns zero, leaving
the file only partially extended.
Call generic_cont_expand_simple() before truncate_setsize() when growing
a file, and propagate its error. This makes failed extensions report
EFBIG or ENOSPC.
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
Compared unpatched and patched v7.3-rc7 in KVM with GCC 10.5 and
identical KASAN configurations:
- 36 growth/shrink/error cases per kernel on 32/64/128 MiB HFS volumes;
content, zeroing and read-only remount checks passed.
- fsx (10,000 operations) and generic/736 (10 runs) passed on both
kernels; post-test fsck.hfs -fn was clean.
- fsck.hfs -fn was also clean for ordinary and recovery cases.
No kernel BUG, WARN or KASAN report was observed.
fs/hfs/inode.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index 2aef3c36a150..44b1735a54c2 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -684,6 +684,12 @@ int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (error)
return error;
+ if (attr->ia_size > inode->i_size) {
+ error = generic_cont_expand_simple(inode, attr->ia_size);
+ if (error)
+ return error;
+ }
+
truncate_setsize(inode, attr->ia_size);
hfs_file_truncate(inode);
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
--
2.53.0
next reply other threads:[~2026-10-17 16:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 16:06 hengyul [this message]
2026-10-19 22:45 ` 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=20261017160612.3740256-1-hengyul@cs.unc.edu \
--to=hengyul@cs.unc.edu \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.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®