[PATCH v5 1/6] ntfs: mark the record dirtied by a resident write in iomap_end
From: Hongling Zeng
Date: Tue Dec 01 2026 - 06:13:57 EST
A buffered write to a resident attribute is copied straight into the
mft record found by the search in ntfs_write_iomap_begin_resident().
With an attribute list that record can be an extent record, while
ntfs_write_iomap_end_resident() only marks the base inode dirty, so
the record holding the copied data is never written out and the write
is lost on a clean unmount.
Carry the inode of the record the lookup found in iomap->private, so
ntfs_write_iomap_end_resident() can mark that record dirty once the
data has been copied into it. The base inode the mrec_lock was taken
on follows from the extent link. Marking the record after the copy
also keeps a write that failed before copying anything from writing
back an unchanged extent record.
Keep marking the base record in iomap_end. The base record also
holds the standard information, which the write's timestamp update
modifies and which is likewise only written out when the record is
marked dirty.
Fixes: 5aec1efb11ab ("ntfs: use direct pointer for inline data to avoid redundant allocation")
Suggested-by: Hyunchul Lee <hyc.lee@xxxxxxxxx>
Signed-off-by: Hongling Zeng <zenghongling@xxxxxxxxxx>
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
---
fs/ntfs/iomap.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index ce916707f69b..920a1aa917fe 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -691,7 +691,8 @@ static int ntfs_write_iomap_begin_resident(struct inode *inode, loff_t offset,
iomap->inline_data = kattr;
iomap->offset = 0;
iomap->length = attr_len;
- iomap->private = mrec_ni;
+ /* The record can be an extent record: let iomap_end mark it dirty. */
+ iomap->private = ctx->ntfs_ino;
out:
if (ctx)
@@ -755,8 +756,14 @@ static int ntfs_write_iomap_end_resident(struct inode *inode, loff_t pos,
loff_t length, ssize_t written,
unsigned int flags, struct iomap *iomap)
{
- struct ntfs_inode *base_ni = iomap->private;
-
+ struct ntfs_inode *rec_ni = iomap->private;
+ struct ntfs_inode *base_ni = rec_ni->nr_extents >= 0 ? rec_ni :
+ rec_ni->ext.base_ntfs_ino;
+
+ /* Mark the record the data was copied into, if anything was. */
+ if (written && rec_ni != base_ni)
+ mark_mft_record_dirty(rec_ni);
+ /* The timestamp update dirties the base record regardless. */
mark_mft_record_dirty(base_ni);
mutex_unlock(&base_ni->mrec_lock);
return written;
--
2.25.1