[PATCH 2/2] hfs: remove the dead grow path from hfs_file_truncate()
From: Hengyu Liang
Date: Fri Oct 30 2026 - 00:30:33 EST
hfs_file_truncate() grows the file through hfs_write_begin() when
i_size is larger than phys_size. That case no longer happens.
phys_size is set to i_size when the inode is read. After that, i_size
only grows through hfs_write_begin(), which grows phys_size first, or
through a direct write that ends within phys_size.
"hfs: report errors when extending files with setattr" made
hfs_inode_setattr() extend files with generic_cont_expand_simple(),
and "hfs: fall back to buffered I/O for direct writes past phys_size"
made direct writes past phys_size go through hfs_write_begin() too.
This patch removes the grow path, and warns and returns if i_size is
ever larger than phys_size.
Suggested-by: Viacheslav Dubeyko <slava@xxxxxxxxxxx>
Signed-off-by: Hengyu Liang <hengyul@xxxxxxxxxx>
---
fs/hfs/extent.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c
index 26357086517f..8d04b7c0911e 100644
--- a/fs/hfs/extent.c
+++ b/fs/hfs/extent.c
@@ -491,23 +491,9 @@ void hfs_file_truncate(struct inode *inode)
hfs_dbg("ino %llu, phys_size %llu -> i_size %llu\n",
inode->i_ino, (long long)HFS_I(inode)->phys_size,
inode->i_size);
- if (inode->i_size > HFS_I(inode)->phys_size) {
- struct address_space *mapping = inode->i_mapping;
- void *fsdata = NULL;
- struct folio *folio;
-
- /* XXX: Can use generic_cont_expand? */
- size = inode->i_size - 1;
- res = hfs_write_begin(NULL, mapping, size + 1, 0, &folio,
- &fsdata);
- if (!res) {
- res = generic_write_end(NULL, mapping, size + 1, 0, 0,
- folio, fsdata);
- }
- if (res)
- inode->i_size = HFS_I(inode)->phys_size;
+ if (WARN_ON_ONCE(inode->i_size > HFS_I(inode)->phys_size))
return;
- } else if (inode->i_size == HFS_I(inode)->phys_size)
+ if (inode->i_size == HFS_I(inode)->phys_size)
return;
size = inode->i_size + HFS_SB(sb)->alloc_blksz - 1;
blk_cnt = size / HFS_SB(sb)->alloc_blksz;
--
2.53.0