mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hfs: report errors when extending files with setattr
@ 2026-10-17 16:06 hengyul
  2026-10-19 22:45 ` Viacheslav Dubeyko
  0 siblings, 1 reply; 2+ messages in thread
From: hengyul @ 2026-10-17 16:06 UTC (permalink / raw)
  To: slava; +Cc: glaubitz, frank.li, linux-fsdevel, linux-kernel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-19 22:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17 16:06 [PATCH] hfs: report errors when extending files with setattr hengyul
2026-10-19 22:45 ` Viacheslav Dubeyko

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®