[PATCH v7 17/31] ntfs: report inode metadata and eviction cleanup errors

From: Xuewen Wang

Date: Fri Dec 04 2026 - 02:52:53 EST


From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

Report corrupt inode metadata, stale extent references and missing
required attributes as EFSCORRUPTED. During FILE_NAME synchronization,
report missing index entries. Also report unused parents unless the
child is being deleted. Retain best-effort parent lookup handling.

Use volume reports for deletion and eviction cleanup. Report failed
attribute walks even on ENOMEM: deletion still frees the MFT records and
may leave unvisited allocations behind.

At eviction, report dirty base records that the final write failed to
save, using its errno or EIO if none was returned. Also report discarded
dirty runlists and extent records. Normal writeback keeps its ENOMEM
retry behavior; after SB_ACTIVE is cleared, only volume state is updated.

Do not repeat errors already reported by attribute lookup or an attribute
inode loader, including STANDARD_INFORMATION lookup during writeback.
Leave mapping-pairs corruption reports to the update path. Leave missing
MFT runlist reports to the block mapper for both base and extent records.
Keep reports for missing required attributes and locally detected
corruption, including FILE_NAME checks for extended system files.

Pass report ownership through both checks for extended system files.

Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Changes in v7:
Remove obsolete metadata signal-error handling. Avoid repeating lookup
errors in inode, attribute and index loaders, and preserve reports for
missing required attributes and locally detected corruption. Report
attribute-list I/O failures in load_attribute_list().

Track report ownership in inode writeback so STANDARD_INFORMATION
lookup failures are not reported twice; retain the missing-attribute
report and ENOMEM redirty behavior.

Leave missing MFT runlist reports to the block mapper in both base and
extent writeback; preserve its errno without a duplicate file report.

Leave mapping-pairs corruption reports to the update path without
repeating them at the writeback exit; preserve errno and ENOMEM retry.

Validation:
- One-shot STANDARD_INFORMATION corruption: fsync EUCLEAN, one report.
- Missing required attribute reports once; healthy fsync is silent.
- One-shot missing MFT runlist: fsync EUCLEAN, one report; healthy silent.
- One-shot malformed nonresident DATA: fsync EUCLEAN, one report.
- Missing required DATA reports once; healthy buffered writes are silent.
Pass report ownership through the added early $Extend classification call.

fs/ntfs/attrib.c | 4 +-
fs/ntfs/inode.c | 186 ++++++++++++++++++++++++++++++++++-------------
2 files changed, 138 insertions(+), 52 deletions(-)

diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 9ab530d711a0..b8c6fff40349 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -1185,8 +1185,8 @@ int load_attribute_list(struct ntfs_inode *base_ni, u8 *al_start, const s64 size

read = ntfs_inode_attr_pread(attr_vi, 0, size, al_start);
if (read != size) {
- if (read >= 0)
- report_err = -EFSCORRUPTED;
+ if (read >= 0 || read == -EIO)
+ report_err = read < 0 ? (int)read : -EFSCORRUPTED;
iput(attr_vi);
ntfs_error(base_ni->vol->sb,
"Failed to read attribute list, mft = %llu",
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index ab18aeea5654..9e700cdfb14c 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -391,8 +391,10 @@ static int ntfs_non_resident_dealloc_clusters(struct ntfs_inode *ni)
int err = 0;

actx = ntfs_attr_get_search_ctx(ni, NULL);
- if (IS_ERR(actx))
+ if (IS_ERR(actx)) {
+ ntfs_report_metadata_error(ni->vol, PTR_ERR(actx));
return PTR_ERR(actx);
+ }
WARN_ON(actx->mrec->link_count != 0);

/**
@@ -402,9 +404,11 @@ static int ntfs_non_resident_dealloc_clusters(struct ntfs_inode *ni)
*/
if (NInoRunlistDirty(ni)) {
err = ntfs_cluster_free_from_rl(ni->vol, ni->runlist.rl);
- if (err)
+ if (err) {
+ ntfs_report_metadata_error(ni->vol, err);
ntfs_error(sb,
"Failed to free clusters. Leaving inconsistent metadata.\n");
+ }
}

while ((err = ntfs_attrs_walk(actx)) == 0) {
@@ -417,19 +421,27 @@ static int ntfs_non_resident_dealloc_clusters(struct ntfs_inode *ni)
&new_rl_count);
if (IS_ERR(rl)) {
err = PTR_ERR(rl);
+ ntfs_report_metadata_error(ni->vol,
+ err == -ENOMEM ? err : -EFSCORRUPTED);
ntfs_error(sb,
"Failed to decompress runlist. Leaving inconsistent metadata.\n");
continue;
}

err = ntfs_cluster_free_from_rl(ni->vol, rl);
- if (err)
+ if (err) {
+ ntfs_report_metadata_error(ni->vol, err);
ntfs_error(sb,
"Failed to free attribute clusters. Leaving inconsistent metadata.\n");
+ }
kvfree(rl);
}
}

+ /* The caller frees the MFT records even if enumeration ran out of memory. */
+ if (err == -ENOMEM)
+ ntfs_report_metadata_error(ni->vol, err);
+
ntfs_release_dirty_clusters(ni->vol, ni->i_dealloc_clusters);
ntfs_attr_put_search_ctx(actx);
return err;
@@ -587,6 +599,7 @@ inline struct ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
/*
* ntfs_is_extended_system_file - check if a file is in the $Extend directory
* @ctx: initialized attribute search context
+ * @vol_err: cleared when a lookup error has already been reported
*
* Search all file name attributes in the inode described by the attribute
* search context @ctx and check if any of the names are in the $Extend system
@@ -599,7 +612,8 @@ inline struct ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
* 0: file is not in $Extend directory
* -errno: failed to determine if the file is in the $Extend directory
*/
-static int ntfs_is_extended_system_file(struct ntfs_attr_search_ctx *ctx)
+static int ntfs_is_extended_system_file(struct ntfs_attr_search_ctx *ctx,
+ bool *vol_err)
{
int nr_links, err;

@@ -627,22 +641,22 @@ static int ntfs_is_extended_system_file(struct ntfs_attr_search_ctx *ctx)
err_corrupt_attr:
ntfs_error(ctx->ntfs_ino->vol->sb,
"Corrupt file name attribute. You should run chkdsk.");
- return -EIO;
+ return -EFSCORRUPTED;
}
if (attr->non_resident) {
ntfs_error(ctx->ntfs_ino->vol->sb,
"Non-resident file name. You should run chkdsk.");
- return -EIO;
+ return -EFSCORRUPTED;
}
if (attr->flags) {
ntfs_error(ctx->ntfs_ino->vol->sb,
"File name with invalid flags. You should run chkdsk.");
- return -EIO;
+ return -EFSCORRUPTED;
}
if (!(attr->data.resident.flags & RESIDENT_ATTR_IS_INDEXED)) {
ntfs_error(ctx->ntfs_ino->vol->sb,
"Unindexed file name. You should run chkdsk.");
- return -EIO;
+ return -EFSCORRUPTED;
}
file_name_attr = (struct file_name_attr *)((u8 *)attr +
le16_to_cpu(attr->data.resident.value_offset));
@@ -670,12 +684,14 @@ err_corrupt_attr:
return 1; /* YES, it's an extended system file. */
}
}
- if (unlikely(err != -ENOENT))
+ if (unlikely(err != -ENOENT)) {
+ *vol_err = false;
return err;
+ }
if (unlikely(nr_links)) {
ntfs_error(ctx->ntfs_ino->vol->sb,
"Inode hard link count doesn't match number of name attributes. You should run chkdsk.");
- return -EIO;
+ return -EFSCORRUPTED;
}
return 0; /* NO, it is not an extended system file. */
}
@@ -838,6 +854,8 @@ static int ntfs_read_locked_inode(struct inode *vi)
err = ntfs_attr_lookup(AT_STANDARD_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx);
if (unlikely(err)) {
+ /* Lookup reports failures; only absence is diagnosed here. */
+ vol_err = err == -ENOENT;
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$STANDARD_INFORMATION attribute is missing.");
goto unm_err_out;
@@ -878,6 +896,7 @@ static int ntfs_read_locked_inode(struct inode *vi)
err = ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx);
if (err) {
if (unlikely(err != -ENOENT)) {
+ vol_err = false;
ntfs_error(vi->i_sb, "Failed to lookup attribute list attribute.");
goto unm_err_out;
}
@@ -931,6 +950,7 @@ static int ntfs_read_locked_inode(struct inode *vi)
/* Now load the attribute list. */
err = load_attribute_list(ni, ni->attr_list, ni->attr_list_size);
if (err) {
+ vol_err = err != -EFSCORRUPTED && err != -EIO;
ntfs_error(vi->i_sb, "Failed to load attribute list attribute.");
goto unm_err_out;
}
@@ -957,12 +977,13 @@ skip_attr_list_load:
if (err)
goto unm_err_out;
} else if (err != -ENOENT) {
+ vol_err = false;
goto unm_err_out;
}

/* Classify $Extend children regardless of their data or index layout. */
if (ni->mft_no >= FILE_first_user) {
- err = ntfs_is_extended_system_file(ctx);
+ err = ntfs_is_extended_system_file(ctx, &vol_err);
if (err < 0)
goto unm_err_out;
if (err > 0)
@@ -1019,6 +1040,7 @@ view_index_meta:
err = ntfs_attr_lookup(AT_INDEX_ROOT, name, name_len, CASE_SENSITIVE,
0, NULL, 0, ctx);
if (unlikely(err)) {
+ vol_err = err == -ENOENT;
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is missing.");
goto unm_err_out;
@@ -1153,6 +1175,7 @@ view_index_meta:
vi->i_size = ni->initialized_size =
ni->allocated_size = 0;
if (err != -ENOENT) {
+ vol_err = false;
ntfs_error(vi->i_sb, "Failed to lookup $DATA attribute.");
goto unm_err_out;
}
@@ -1171,7 +1194,7 @@ view_index_meta:
* name of this inode from the mft record as the name
* contains the back reference to the parent directory.
*/
- extend_sys = ntfs_is_extended_system_file(ctx);
+ extend_sys = ntfs_is_extended_system_file(ctx, &vol_err);
if (extend_sys > 0) {
if (m->flags & MFT_RECORD_IS_VIEW_INDEX) {
if (extend_sys == 2) {
@@ -1348,19 +1371,18 @@ no_data_attr_special_case:
ntfs_debug("Done.");
return 0;
unm_err_out:
- if (!err)
- err = -EIO;
+ if (!err || (err == -ENOENT && vol_err))
+ err = -EFSCORRUPTED;
if (ctx)
ntfs_attr_put_search_ctx(ctx);
if (m)
unmap_mft_record(ni);
err_out:
- if (err != -EOPNOTSUPP && err != -ENOMEM &&
- err != -EINTR && err != -ERESTARTSYS && vol_err == true) {
+ if (err != -EOPNOTSUPP && err != -ENOMEM && vol_err) {
ntfs_error(vol->sb,
"Failed with error code %i. Marking corrupt inode 0x%llx as bad. Run chkdsk.",
err, ni->mft_no);
- NVolSetErrors(vol);
+ ntfs_report_file_metadata_error(vi, err);
}
return err;
}
@@ -1394,6 +1416,7 @@ static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi)
struct attr_record *a;
struct ntfs_attr_search_ctx *ctx;
int err = 0;
+ bool report_error = true;
u32 ic;

ntfs_debug("Entering for i_ino 0x%llx.", ni->mft_no);
@@ -1431,8 +1454,10 @@ static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi)
ic = ntfs_inode_is_named_stream(ni) ? IGNORE_CASE : CASE_SENSITIVE;
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
ic, 0, NULL, 0, ctx);
- if (unlikely(err))
+ if (unlikely(err)) {
+ report_error = false;
goto unm_err_out;
+ }
a = ctx->attr;
if (ntfs_inode_is_named_stream(ni)) {
__le16 *disk_name = (__le16 *)((u8 *)a +
@@ -1607,19 +1632,19 @@ static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi)

unm_err_out:
if (!err)
- err = -EIO;
+ err = -EFSCORRUPTED;
if (ctx)
ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(base_ni);
err_out:
- if (err != -ENOENT && err != -EINTR && err != -ERESTARTSYS)
+ if (err != -ENOENT)
ntfs_error(vol->sb,
"Failed with error code %i while reading attribute inode (mft_no 0x%llx, type 0x%x, name_len %i). Marking corrupt inode and base inode 0x%llx as bad. Run chkdsk.",
err, ni->mft_no, ni->type, ni->name_len,
base_ni->mft_no);
- if (err != -ENOENT && err != -ENOMEM &&
- err != -EINTR && err != -ERESTARTSYS)
- NVolSetErrors(vol);
+ if (report_error && err != -ENOENT && err != -ENOMEM &&
+ err != -EOPNOTSUPP)
+ ntfs_report_file_metadata_error(base_vi, err);
return err;
}

@@ -1666,6 +1691,7 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
struct ntfs_attr_search_ctx *ctx;
struct index_root *ir;
int err = 0;
+ bool report_error = true;

ntfs_debug("Entering for i_ino 0x%llx.", ni->mft_no);
lockdep_assert_held(&base_ni->mrec_lock);
@@ -1697,6 +1723,7 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
err = ntfs_attr_lookup(AT_INDEX_ROOT, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
+ report_error = err == -ENOENT;
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is missing.");
goto unm_err_out;
@@ -1770,8 +1797,9 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
m = NULL;
ctx = NULL;
goto skip_large_index_stuff;
- } else
- ntfs_error(vi->i_sb, "Failed to lookup $INDEX_ALLOCATION attribute.");
+ }
+ report_error = false;
+ ntfs_error(vi->i_sb, "Failed to lookup $INDEX_ALLOCATION attribute.");
goto unm_err_out;
}
NInoSetIndexAllocPresent(ni);
@@ -1827,8 +1855,8 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
bvi = ntfs_attr_iget(base_vi, AT_BITMAP, ni->name, ni->name_len);
if (IS_ERR(bvi)) {
err = PTR_ERR(bvi);
- if (err != -EINTR && err != -ERESTARTSYS)
- ntfs_error(vi->i_sb, "Failed to get bitmap attribute.");
+ report_error = err == -ENOENT;
+ ntfs_error(vi->i_sb, "Failed to get bitmap attribute.");
goto unm_err_out;
}
bni = NTFS_I(bvi);
@@ -1855,8 +1883,10 @@ skip_large_index_stuff:
* Make sure the base inode doesn't go away and attach it to the
* index inode.
*/
- if (!igrab(base_vi))
+ if (!igrab(base_vi)) {
+ err = -EIO;
goto unm_err_out;
+ }
ni->ext.base_ntfs_ino = base_ni;
ni->nr_extents = -1;

@@ -1865,20 +1895,18 @@ skip_large_index_stuff:
iput_unm_err_out:
iput(bvi);
unm_err_out:
- if (!err)
- err = -EIO;
+ if (!err || err == -ENOENT)
+ err = -EFSCORRUPTED;
if (ctx)
ntfs_attr_put_search_ctx(ctx);
if (m)
unmap_mft_record(base_ni);
err_out:
- if (err != -EINTR && err != -ERESTARTSYS)
- ntfs_error(vi->i_sb,
- "Failed with error code %i while reading index inode (mft_no 0x%llx, name_len %i.",
- err, ni->mft_no, ni->name_len);
- if (err != -EOPNOTSUPP && err != -ENOMEM &&
- err != -EINTR && err != -ERESTARTSYS)
- NVolSetErrors(vol);
+ ntfs_error(vi->i_sb,
+ "Failed with error code %i while reading index inode (mft_no 0x%llx, name_len %i.",
+ err, ni->mft_no, ni->name_len);
+ if (report_error && err != -EOPNOTSUPP && err != -ENOMEM)
+ ntfs_report_file_metadata_error(base_vi, err);
return err;
}

@@ -2450,16 +2478,20 @@ static int ntfs_delete_base_inode(struct ntfs_inode *ni)
*/
while (ni->nr_extents) {
err = ntfs_mft_record_free(ni->vol, *(ni->ext.extent_ntfs_inos));
- if (err)
+ if (err) {
+ ntfs_report_metadata_error(ni->vol, err);
ntfs_error(sb,
"Failed to free extent MFT record. Leaving inconsistent metadata.\n");
+ }
ntfs_inode_close(*(ni->ext.extent_ntfs_inos));
}

/* Deallocate base mft record */
err = ntfs_mft_record_free(ni->vol, ni);
- if (err)
+ if (err) {
+ ntfs_report_metadata_error(ni->vol, err);
ntfs_error(sb, "Failed to free base MFT record. Leaving inconsistent metadata.\n");
+ }
return err;
}

@@ -2490,9 +2522,11 @@ void ntfs_evict_big_inode(struct inode *vi)

if (NInoDirty(ni)) {
/* Committing the inode also commits all extent inodes. */
- ntfs_commit_inode(vi);
+ int err = __ntfs_write_inode(vi, 1);

if (NInoDirty(ni)) {
+ /* Eviction discards the dirty record, so it cannot be retried. */
+ ntfs_report_metadata_error(ni->vol, err ? err : -EIO);
ntfs_debug("Failed to commit dirty inode 0x%llx. Losing data!",
ni->mft_no);
NInoClearAttrListDirty(ni);
@@ -2500,13 +2534,20 @@ void ntfs_evict_big_inode(struct inode *vi)
}
}

+ /* A deferred mapping update can outlive the base record's dirty bit. */
+ if (NInoRunlistDirty(ni))
+ ntfs_report_metadata_error(ni->vol, -EIO);
+
/* No need to lock at this stage as no one else has a reference. */
if (ni->nr_extents > 0) {
int i;

for (i = 0; i < ni->nr_extents; i++) {
- if (ni->ext.extent_ntfs_inos[i])
+ if (ni->ext.extent_ntfs_inos[i]) {
+ if (NInoDirty(ni->ext.extent_ntfs_inos[i]))
+ ntfs_report_metadata_error(ni->vol, -EIO);
ntfs_clear_extent_inode(ni->ext.extent_ntfs_inos[i]);
+ }
}
ni->nr_extents = 0;
kvfree(ni->ext.extent_ntfs_inos);
@@ -2808,11 +2849,15 @@ int ntfs_inode_sync_filename(struct ntfs_inode *ni)
/* Collect the reparse tag, if any */
reparse_tag = cpu_to_le32(0);
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
- if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL,
- 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) {
+ err = ntfs_attr_lookup(AT_REPARSE_POINT, NULL, 0,
+ CASE_SENSITIVE, 0, NULL, 0, ctx);
+ if (!err) {
rpp = (struct reparse_point *)((u8 *)ctx->attr +
le16_to_cpu(ctx->attr->data.resident.value_offset));
reparse_tag = rpp->reparse_tag;
+ } else if (err == -ENOENT) {
+ ntfs_report_file_metadata_error(VFS_I(ni),
+ -EFSCORRUPTED);
}
ntfs_attr_reinit_search_ctx(ctx);
}
@@ -2826,6 +2871,9 @@ int ntfs_inode_sync_filename(struct ntfs_inode *ni)

index_vi = ntfs_iget(sb, MREF_LE(fn->parent_directory));
if (IS_ERR(index_vi)) {
+ if (PTR_ERR(index_vi) == -ENOENT && !NInoBeingDeleted(ni))
+ ntfs_report_file_metadata_error(VFS_I(ni),
+ -EFSCORRUPTED);
ntfs_error(sb, "Failed to open inode %lld with index",
(long long)MREF_LE(fn->parent_directory));
continue;
@@ -2851,6 +2899,11 @@ int ntfs_inode_sync_filename(struct ntfs_inode *ni)

err = ntfs_index_lookup(fn, sizeof(struct file_name_attr), ictx);
if (err) {
+ if (err == -ENOENT) {
+ err = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(index_vi,
+ -EFSCORRUPTED);
+ }
ntfs_debug("Index lookup failed, inode %llu",
index_ni->mft_no);
ntfs_index_ctx_put(ictx);
@@ -2921,7 +2974,8 @@ int ntfs_get_block_mft_record(struct ntfs_inode *mft_ni, struct ntfs_inode *ni)
rl = mft_ni->runlist.rl;
if (!rl) {
ntfs_error(mft_ni->vol->sb, "$MFT runlist is not present");
- return -EIO;
+ ntfs_report_metadata_error(mft_ni->vol, -EFSCORRUPTED);
+ return -EFSCORRUPTED;
}

/* Seek to element containing target vcn. */
@@ -2961,6 +3015,7 @@ int __ntfs_write_inode(struct inode *vi, int sync)
struct mft_record *m;
int err = 0;
bool need_iput = false;
+ bool report_error = true;

ntfs_debug("Entering for %sinode 0x%llx.", NInoAttr(ni) ? "attr " : "",
ni->mft_no);
@@ -3002,13 +3057,22 @@ int __ntfs_write_inode(struct inode *vi, int sync)
if (!err)
NInoClearRunlistDirty(ni);
up_write(&ni->runlist.lock);
- if (err)
+ if (err) {
+ /* Mapping-pairs corruption is reported at its source. */
+ report_error = err != -EFSCORRUPTED;
goto unm_err_out;
+ }
}

err = ntfs_inode_sync_standard_information(vi, m);
- if (err)
+ if (err) {
+ /* Lookup reports its errors; a missing required attribute is local. */
+ if (err == -ENOENT)
+ err = -EFSCORRUPTED;
+ else
+ report_error = false;
goto unm_err_out;
+ }

/*
* when being umounted and inodes are evicted, write_inode()
@@ -3026,8 +3090,11 @@ int __ntfs_write_inode(struct inode *vi, int sync)
down_read(&mft_ni->runlist.lock);
err = ntfs_get_block_mft_record(mft_ni, ni);
up_read(&mft_ni->runlist.lock);
- if (err)
+ if (err) {
+ /* The block mapper already reported this error. */
+ report_error = false;
goto unm_err_out;
+ }

err = write_mft_record(ni, m, sync);
if (err)
@@ -3045,6 +3112,7 @@ int __ntfs_write_inode(struct inode *vi, int sync)
err = ntfs_get_block_mft_record(mft_ni,
ni->ext.extent_ntfs_inos[i]);
if (err) {
+ report_error = false;
mutex_unlock(&ni->extent_lock);
up_read(&mft_ni->runlist.lock);
mutex_unlock(&ni->mrec_lock);
@@ -3106,7 +3174,8 @@ err_out:
mark_inode_dirty(vi);
else {
ntfs_error(vi->i_sb, "Failed (error %i): Run chkdsk.", -err);
- NVolSetErrors(ni->vol);
+ if (report_error)
+ ntfs_report_file_metadata_error(vi, err);
}
if (need_iput)
iput(vi);
@@ -3175,8 +3244,10 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
seq_no != le16_to_cpu(ni_mrec->sequence_number)) {
ntfs_error(sb, "Found stale extent mft reference mft=%llu",
ni->mft_no);
+ ntfs_report_file_metadata_error(VFS_I(base_ni),
+ -EFSCORRUPTED);
unmap_mft_record(ni);
- return ERR_PTR(-EIO);
+ return ERR_PTR(-EFSCORRUPTED);
}
unmap_mft_record(ni);
goto out;
@@ -3239,8 +3310,9 @@ int ntfs_inode_attach_all_extents(struct ntfs_inode *ni)
return 0;

if (!ni->attr_list) {
+ ntfs_report_file_metadata_error(VFS_I(ni), -EFSCORRUPTED);
ntfs_debug("Corrupt in-memory struct.\n");
- return -EINVAL;
+ return -EFSCORRUPTED;
}

/* Walk through attribute list and attach all extents. */
@@ -3817,6 +3889,11 @@ s64 ntfs_inode_attr_pread(struct inode *vi, s64 pos, s64 count, u8 *buf)
CASE_SENSITIVE,
0, NULL, 0, ctx);
if (err) {
+ if (err == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ err = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(vi,
+ -EFSCORRUPTED);
+ }
ntfs_error(vi->i_sb, "Failed to look up attr %#x", ni->type);
ntfs_attr_put_search_ctx(ctx);
mutex_unlock(&mrec_ni->mrec_lock);
@@ -3898,6 +3975,11 @@ static inline int ntfs_enlarge_attribute(struct inode *vi, s64 pos, s64 count,
CASE_SENSITIVE,
0, NULL, 0, ctx);
if (ret) {
+ if (ret == -ENOENT) {
+ ret = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(vi,
+ -EFSCORRUPTED);
+ }
ntfs_error(sb, "Failed to look up attr %#x", ni->type);
return ret;
}
@@ -4167,6 +4249,10 @@ s64 ntfs_inode_attr_pwrite(struct inode *vi, s64 pos, s64 count, u8 *buf, bool s
CASE_SENSITIVE,
0, NULL, 0, ctx);
if (ret) {
+ if (ret == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ ret = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(vi, -EFSCORRUPTED);
+ }
ntfs_attr_put_search_ctx(ctx);
ntfs_error(vi->i_sb, "Failed to look up attr %#x", ni->type);
goto out_unlock;
--
2.51.0