[PATCH v4 01/12] ntfs: return zero after removing nonresident attributes

From: Baolin Liu

Date: Sun Nov 15 2026 - 08:27:12 EST


From: Dandan Wu <wudandan@xxxxxxxxxx>

ntfs_cluster_free() returns the number of freed clusters on success.
ntfs_attr_rm() retains that positive value after removing the attribute
records. ntfs_attr_remove() treats it as an error and skips invalidating
the cached attribute inode.

Store the cluster count in an s64 and propagate only negative errors,
so successful removal returns zero and the caller invalidates the inode.

Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Dandan Wu <wudandan@xxxxxxxxxx>
---
New in v4.

Tested 1536 injected creation failures with small/large inherited ACLs
and 512-byte/4 KiB clusters. Free-cluster/free-MFT counts and offline
reclamation checks passed.

fs/ntfs/attrib.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 9266a3ea3b0f..a18d74a9f685 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -5515,6 +5515,7 @@ int ntfs_attr_rm(struct ntfs_inode *ni)
/* Free cluster allocation. */
if (NInoNonResident(ni)) {
struct ntfs_attr_search_ctx *ctx;
+ s64 freed;

err = ntfs_attr_map_whole_runlist(ni);
if (err)
@@ -5525,10 +5526,12 @@ int ntfs_attr_rm(struct ntfs_inode *ni)
return -ENOMEM;
}

- ret = ntfs_cluster_free(ni, 0, -1, ctx);
- if (ret < 0)
+ freed = ntfs_cluster_free(ni, 0, -1, ctx);
+ if (freed < 0) {
+ ret = freed;
ntfs_error(sb,
"Failed to free cluster allocation. Leaving inconstant metadata.\n");
+ }
ntfs_attr_put_search_ctx(ctx);
}