[PATCH v7 14/31] ntfs: report attribute conversion and mapping update failures
From: Xuewen Wang
Date: Fri Dec 04 2026 - 02:51:45 EST
From: Xuewen Wang <wangxuewen@xxxxxxxxxx>
Attribute conversion and mapping updates can detect corruption or fail
to recover modified metadata without reporting it. Cover missing
required attributes, malformed mapping pairs and failed extent cleanup.
Preserve ENOMEM from runlist merges and report invalid merges as
EFSCORRUPTED. Report failed cluster release, mapping restoration and
record cleanup separately from the initiating error. Include failure to
restore the resident record after an unsuccessful conversion.
Report a failed attribute-list update after moving a record to make
room for sparse metadata, unless the list updater already reported it.
Propagate reports from lower corruption checks through the locked list
updater and list-entry removal. Callers that have already changed metadata
still report unreported update failures, including ENOMEM and ENOSPC.
Record synchronous conversion-write errors and report them after cleanup,
retaining the resident value and the original I/O errno.
Apply required-attribute corruption handling to data-size updates as well
as initialized-size updates, preserving named-stream lookup semantics.
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Changes in v7:
Report synchronous internal-attribute conversion-write errors at the
cleanup exit. Classify an invalid conversion runlist as corruption.
Propagate lower corruption reports through attribute-list update error
exits. Keep unreported ENOMEM/ENOSPC failures available to callers that
have changed metadata, and retain independent recovery reports.
Cover missing required attributes in ntfs_attr_set_data_size(), preserving
named-stream absence and lower-level errors. Report local corruption after
releasing the search context.
Validation:
- QEMU size-restoration injections cover missing DATA metadata and retained
EIO, ENOMEM and ENOSPC reports through the completed series.
fs/ntfs/attrib.c | 174 ++++++++++++++++++++++++++++++++++-----------
fs/ntfs/attrlist.c | 40 ++++++++---
fs/ntfs/attrlist.h | 4 +-
3 files changed, 167 insertions(+), 51 deletions(-)
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index d365d339571a..0bea77144b6d 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -2056,7 +2056,7 @@ static int ntfs_attr_write_conversion(struct ntfs_volume *vol, struct folio *fol
int err;
if (!rl->length || rl->lcn < 0)
- return -EIO;
+ return -EFSCORRUPTED;
len = min_t(s64, size, ntfs_cluster_to_bytes(vol, rl->length));
bio = bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE | REQ_SYNC,
GFP_NOIO);
@@ -2107,6 +2107,7 @@ int ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_size)
static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_size,
bool nowait)
{
+ int report_err = 0;
s64 new_size;
struct inode *vi = VFS_I(ni);
struct ntfs_volume *vol = ni->vol;
@@ -2163,8 +2164,10 @@ static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_s
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
- if (err == -ENOENT)
- err = -EIO;
+ if (err == -ENOENT) {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
+ }
goto err_out;
}
m = ctx->mrec;
@@ -2231,12 +2234,15 @@ static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_s
mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0, -1, -1);
if (unlikely(mp_size < 0)) {
err = mp_size;
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_debug("Failed to get size for mapping pairs array, error code %i.\n", err);
goto rl_err_out;
}
if (NInoNonResident(ni) || a->non_resident) {
- err = -EIO;
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
goto rl_err_out;
}
@@ -2278,8 +2284,10 @@ static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_s
*/
if (folio && sync) {
err = ntfs_attr_write_conversion(vol, folio, rl, attr_size);
- if (err)
+ if (err) {
+ report_err = err;
goto rl_err_out;
+ }
}
/* Backup the attribute flag. */
@@ -2322,6 +2330,8 @@ static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_s
err = ntfs_mapping_pairs_build(vol, (u8 *)a + mp_ofs,
arec_size - mp_ofs, rl, 0, -1, NULL, NULL, NULL);
if (unlikely(err)) {
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_error(vol->sb, "Failed to build mapping pairs, error code %i.",
err);
goto undo_err_out;
@@ -2392,6 +2402,7 @@ undo_err_out:
/* Resize the resident part of the attribute record. */
err2 = ntfs_attr_record_resize(m, a, arec_size);
if (unlikely(err2)) {
+ ntfs_report_file_metadata_error(vi, err2);
/*
* This cannot happen (well if memory corruption is at work it
* could happen in theory), but deal with it as well as we can.
@@ -2433,10 +2444,11 @@ undo_err_out:
rl_err_out:
up_write(&ni->runlist.lock);
if (rl) {
- if (ntfs_cluster_free_from_rl(vol, rl) < 0) {
+ err2 = ntfs_cluster_free_from_rl(vol, rl);
+ if (err2 < 0) {
ntfs_error(vol->sb,
"Failed to release allocated cluster(s) in error code path. Run chkdsk to recover the lost cluster(s).");
- NVolSetErrors(vol);
+ ntfs_report_file_metadata_error(vi, err2);
}
kvfree(rl);
folio_err_out:
@@ -2452,6 +2464,8 @@ err_out:
if (err == -EINVAL)
err = -EIO;
+ if (report_err)
+ ntfs_report_file_metadata_error(VFS_I(base_ni), report_err);
return err;
}
@@ -2527,8 +2541,14 @@ int ntfs_attr_set_initialized_size(struct ntfs_inode *ni, loff_t new_size)
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
- if (err)
+ if (err) {
+ if (err == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ err = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(VFS_I(base_ni),
+ -EFSCORRUPTED);
+ }
goto out_ctx;
+ }
ctx->attr->data.non_resident.initialized_size = cpu_to_le64(new_size);
ni->initialized_size = new_size;
@@ -2549,7 +2569,7 @@ int ntfs_attr_set_data_size(struct ntfs_inode *ni, loff_t new_size)
{
struct ntfs_attr_search_ctx *ctx;
struct ntfs_inode *base_ni = ntfs_base_inode(ni);
- int err = 0;
+ int err = 0, report_err = 0;
if (!NInoNonResident(ni) || new_size < ni->initialized_size ||
new_size > ni->allocated_size)
@@ -2561,8 +2581,13 @@ int ntfs_attr_set_data_size(struct ntfs_inode *ni, loff_t new_size)
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
- if (err)
+ if (err) {
+ if (err == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ err = -EFSCORRUPTED;
+ report_err = err;
+ }
goto out_ctx;
+ }
ctx->attr->data.non_resident.data_size = cpu_to_le64(new_size);
ni->data_size = new_size;
@@ -2572,6 +2597,8 @@ int ntfs_attr_set_data_size(struct ntfs_inode *ni, loff_t new_size)
mark_mft_record_dirty(ctx->ntfs_ino);
out_ctx:
ntfs_attr_put_search_ctx(ctx);
+ if (report_err)
+ ntfs_report_file_metadata_error(VFS_I(base_ni), report_err);
return err;
}
@@ -2932,9 +2959,12 @@ int ntfs_attr_record_rm(struct ntfs_attr_search_ctx *ctx)
* delete $ATTRIBUTE_LIST itself.
*/
if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) {
- err = ntfs_attrlist_entry_rm(ctx);
+ bool reported;
+
+ err = ntfs_attrlist_entry_rm(ctx, &reported);
if (err) {
- report_err = err;
+ if (!reported)
+ report_err = err;
ntfs_debug("Couldn't delete record from $ATTRIBUTE_LIST.\n");
goto out;
}
@@ -3923,6 +3953,7 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
struct mft_record *m, struct ntfs_attr_search_ctx *ctx,
struct ntfs_inode *locked_ni, bool defer_attrlist)
{
+ int report_err = 0;
int sparse, err = 0;
struct ntfs_inode *base_ni;
struct super_block *sb = ni->vol->sb;
@@ -3942,7 +3973,8 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
sparse = ntfs_rl_sparse(ni->runlist.rl);
if (sparse < 0) {
- err = -EIO;
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
goto out;
}
@@ -3956,6 +3988,7 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
if ((le32_to_cpu(a->length) -
le16_to_cpu(a->data.non_resident.mapping_pairs_offset) == 8) &&
!(le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use))) {
+ bool reported;
if (defer_attrlist)
return -ENOSPC;
@@ -3972,16 +4005,22 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
goto out;
}
- err = ntfs_attrlist_update_locked(base_ni, locked_ni);
- if (err)
+ err = ntfs_attrlist_update_locked(base_ni, locked_ni,
+ &reported);
+ if (err) {
+ /* The moved record still has its old on-disk list entry. */
+ if (!reported)
+ report_err = err;
goto out;
+ }
err = -EAGAIN;
goto out;
}
if (!(le32_to_cpu(a->length) -
le16_to_cpu(a->data.non_resident.mapping_pairs_offset))) {
- err = -EIO;
+ err = -EFSCORRUPTED;
ntfs_error(sb, "Mapping pairs space is 0");
+ report_err = -EFSCORRUPTED;
goto out;
}
@@ -4025,7 +4064,8 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
new_compr_size = ntfs_rl_get_compressed_size(ni->vol, ni->runlist.rl);
if (new_compr_size < 0) {
- err = new_compr_size;
+ report_err = -EFSCORRUPTED;
+ err = -EFSCORRUPTED;
goto out;
}
@@ -4044,6 +4084,8 @@ static int ntfs_attr_update_meta(struct attr_record *a, struct ntfs_inode *ni,
if (ni->type == AT_DATA && ni->name == AT_UNNAMED)
NInoSetFileNameDirty(ni);
out:
+ if (report_err)
+ ntfs_report_file_metadata_error(VFS_I(ni), report_err);
return err;
}
@@ -4068,12 +4110,14 @@ static int __ntfs_attr_update_mapping_pairs(struct ntfs_inode *ni,
struct ntfs_inode *locked_ni,
bool defer_attrlist)
{
+ int report_err = 0;
struct ntfs_attr_search_ctx *ctx;
struct ntfs_inode *base_ni;
struct mft_record *m;
struct attr_record *a;
s64 stop_vcn;
int err = 0, mp_size, cur_max_mp_size, exp_max_mp_size;
+ int rollback_err;
bool finished_build;
bool first_updated = false;
struct super_block *sb;
@@ -4136,8 +4180,9 @@ retry:
*/
first_lcn = ntfs_rl_vcn_to_lcn(ni->runlist.rl, stop_vcn);
if (first_lcn == LCN_EINVAL) {
- err = -EIO;
+ err = -EFSCORRUPTED;
ntfs_error(sb, "Bad runlist");
+ report_err = -EFSCORRUPTED;
goto put_err_out;
}
if (first_lcn == LCN_ENOENT ||
@@ -4188,6 +4233,8 @@ retry:
stop_vcn, -1, exp_max_mp_size);
if (mp_size <= 0) {
err = mp_size;
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_error(sb, "%s: get MP size failed", __func__);
goto put_err_out;
}
@@ -4209,8 +4256,7 @@ retry:
cur_max_mp_size);
if (err)
return err;
- err = ntfs_attrlist_update_locked(
- base_ni, locked_ni);
+ err = ntfs_attrlist_update_locked(base_ni, locked_ni, NULL);
if (err)
return err;
goto retry;
@@ -4223,9 +4269,10 @@ retry:
goto put_err_out;
}
ntfs_attr_put_search_ctx(ctx);
- if (ntfs_inode_add_attrlist(base_ni)) {
+ err = ntfs_inode_add_attrlist(base_ni);
+ if (err) {
ntfs_error(sb, "Can not add attrlist");
- return -EIO;
+ return err;
}
goto retry;
}
@@ -4242,8 +4289,9 @@ retry:
if (((mp_size + 7) & ~7) != cur_max_mp_size) {
if (ntfs_attr_record_resize(m, a,
le16_to_cpu(a->data.non_resident.mapping_pairs_offset) +
- mp_size)) {
+ mp_size)) {
err = -EIO;
+ report_err = err;
ntfs_error(sb, "Failed to resize attribute");
goto put_err_out;
}
@@ -4263,7 +4311,7 @@ retry:
if ((ctx->ntfs_ino->nr_extents == -1 || NInoAttrList(ctx->ntfs_ino)) &&
ctx->attr->type != AT_ATTRIBUTE_LIST) {
ctx->al_entry->lowest_vcn = cpu_to_le64(stop_vcn);
- err = ntfs_attrlist_update_locked(base_ni, locked_ni);
+ err = ntfs_attrlist_update_locked(base_ni, locked_ni, NULL);
if (err)
goto put_err_out;
}
@@ -4278,6 +4326,8 @@ retry:
if (!err)
finished_build = true;
if (!finished_build && err != -ENOSPC) {
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_error(sb, "Failed to build mapping pairs");
goto put_err_out;
}
@@ -4311,6 +4361,10 @@ retry:
NInoSetFileNameDirty(ni);
mark_mft_record_dirty(ctx->ntfs_ino);
} else {
+ if (err == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
+ }
ntfs_error(sb, "Failed to update sizes in base extent\n");
goto put_err_out;
}
@@ -4364,10 +4418,14 @@ retry:
m = map_mft_record(ext_ni);
if (IS_ERR(m)) {
ntfs_error(sb, "Could not map new MFT record");
- if (ntfs_mft_record_free(ni->vol, ext_ni))
+ rollback_err = ntfs_mft_record_free(ni->vol, ext_ni);
+ if (rollback_err) {
ntfs_error(sb, "Could not free MFT record");
+ ntfs_report_file_metadata_error(VFS_I(base_ni),
+ rollback_err);
+ }
ntfs_inode_close(ext_ni);
- err = -ENOMEM;
+ err = PTR_ERR(m);
ext_ni = NULL;
goto put_err_out;
}
@@ -4389,6 +4447,8 @@ retry:
unmap_mft_record(ext_ni);
ntfs_inode_close(ext_ni);
err = mp_size;
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_error(sb, "%s: get mp size failed", __func__);
goto put_err_out;
}
@@ -4401,8 +4461,12 @@ retry:
if (err < 0) {
ntfs_error(sb, "Could not add attribute extent");
unmap_mft_record(ext_ni);
- if (ntfs_mft_record_free(ni->vol, ext_ni))
+ rollback_err = ntfs_mft_record_free(ni->vol, ext_ni);
+ if (rollback_err) {
ntfs_error(sb, "Could not free MFT record");
+ ntfs_report_file_metadata_error(VFS_I(base_ni),
+ rollback_err);
+ }
ntfs_inode_close(ext_ni);
goto put_err_out;
}
@@ -4413,10 +4477,16 @@ retry:
mp_size, start_rl, stop_vcn, -1, &stop_vcn, &start_rl,
&de_cnt);
if (err < 0 && err != -ENOSPC) {
+ if (err == -EFSCORRUPTED)
+ report_err = -EFSCORRUPTED;
ntfs_error(sb, "Failed to build MP");
unmap_mft_record(ext_ni);
- if (ntfs_mft_record_free(ni->vol, ext_ni))
+ rollback_err = ntfs_mft_record_free(ni->vol, ext_ni);
+ if (rollback_err) {
ntfs_error(sb, "Couldn't free MFT record");
+ ntfs_report_file_metadata_error(VFS_I(base_ni),
+ rollback_err);
+ }
goto put_err_out;
}
a->data.non_resident.highest_vcn = cpu_to_le64(stop_vcn - 1);
@@ -4436,6 +4506,8 @@ out:
put_err_out:
if (ctx)
ntfs_attr_put_search_ctx(ctx);
+ if (report_err)
+ ntfs_report_file_metadata_error(VFS_I(base_ni), report_err);
return err;
}
@@ -4527,7 +4599,8 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc
* already checked that attribute fits MFT record).
*/
ntfs_error(ctx->ntfs_ino->vol->sb, "BUG! Failed to resize attribute record. ");
- return -EIO;
+ ntfs_report_file_metadata_error(VFS_I(ni), -EFSCORRUPTED);
+ return -EFSCORRUPTED;
}
/* Convert the attribute record to describe a resident attribute. */
@@ -4555,6 +4628,7 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc
*/
freed = ntfs_cluster_free(ni, 0, -1, ctx);
if (freed < 0) {
+ ntfs_report_file_metadata_error(VFS_I(ni), freed);
ntfs_error(sb, "Eeek! Failed to release allocated clusters");
ntfs_debug("Ignoring error and leaving behind wasted clusters.\n");
}
@@ -5594,6 +5668,7 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
s64 *lcn_count, s64 max_clu_count, bool *balloc, bool update_mp,
bool skip_holes)
{
+ int report_err = 0;
struct ntfs_inode *base_ni = ntfs_base_inode(ni);
struct ntfs_volume *vol = ni->vol;
struct ntfs_attr_search_ctx *ctx;
@@ -5601,7 +5676,7 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
struct runlist_element *old_rl = NULL;
s64 vcn = vcn_start, lcn, clu_count;
s64 lcn_seek_from = -1;
- int err = 0;
+ int err = 0, err2;
size_t new_rl_count, old_rl_count;
err = ntfs_attr_map_whole_runlist(ni);
@@ -5617,6 +5692,10 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, vcn, NULL, 0, ctx);
if (err) {
+ if (err == -ENOENT && !ntfs_inode_is_named_stream(ni)) {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
+ }
ntfs_error(vol->sb,
"ntfs_attr_lookup failed, ntfs inode(mft_no : %llu) type : 0x%x, err : %d",
ni->mft_no, ni->type, err);
@@ -5642,10 +5721,12 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
}
} else {
WARN_ON(lcn == LCN_RL_NOT_MAPPED);
- if (lcn == LCN_ENOENT)
+ if (lcn == LCN_ENOENT) {
err = -ENOENT;
- else
- err = -EIO;
+ } else {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
+ }
goto out;
}
@@ -5697,10 +5778,11 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
old_rl_count * sizeof(*old_rl), GFP_NOFS);
if (!old_rl) {
err = -ENOMEM;
- if (ntfs_cluster_free_from_rl(vol, rlc)) {
+ err2 = ntfs_cluster_free_from_rl(vol, rlc);
+ if (err2) {
ntfs_error(vol->sb,
"Failed to free cluster allocation after runlist backup failure.");
- NVolSetErrors(vol);
+ ntfs_report_file_metadata_error(VFS_I(ni), err2);
}
kvfree(rlc);
goto out;
@@ -5710,8 +5792,15 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
if (IS_ERR(rl)) {
ntfs_error(vol->sb, "Failed to merge runlists");
err = PTR_ERR(rl);
- if (ntfs_cluster_free_from_rl(vol, rlc))
+ if (err != -ENOMEM) {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
+ }
+ err2 = ntfs_cluster_free_from_rl(vol, rlc);
+ if (err2) {
ntfs_error(vol->sb, "Failed to free hot clusters.");
+ ntfs_report_file_metadata_error(VFS_I(ni), err2);
+ }
kvfree(rlc);
goto out;
}
@@ -5736,7 +5825,10 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
if (freed < 0 || freed != clu_count) {
ntfs_error(vol->sb,
"Failed to free cluster allocation. Leaving inconsistent metadata.\n");
- NVolSetErrors(vol);
+ err2 = freed < 0 ? freed : -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(VFS_I(ni),
+ freed < 0 ?
+ (int)freed : -EFSCORRUPTED);
goto out;
}
@@ -5748,11 +5840,11 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
ni->runlist.rl = old_rl;
ni->runlist.count = old_rl_count;
old_rl = NULL;
- if (ntfs_attr_update_mapping_pairs_locked(
- ni, 0, ni)) {
+ err2 = ntfs_attr_update_mapping_pairs_locked(ni, 0, ni);
+ if (err2) {
ntfs_error(vol->sb,
"Failed to restore mapping pairs after allocation rollback.\n");
- NVolSetErrors(vol);
+ ntfs_report_file_metadata_error(VFS_I(ni), err2);
}
}
} else {
@@ -5767,6 +5859,8 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
out:
kvfree(old_rl);
ntfs_attr_put_search_ctx(ctx);
+ if (report_err)
+ ntfs_report_file_metadata_error(VFS_I(base_ni), report_err);
return err;
}
diff --git a/fs/ntfs/attrlist.c b/fs/ntfs/attrlist.c
index fb081b296ff0..70292d62ab38 100644
--- a/fs/ntfs/attrlist.c
+++ b/fs/ntfs/attrlist.c
@@ -210,14 +210,22 @@ out_free_data:
return err;
}
+/*
+ * Track reports for the returned failure, including lower corruption
+ * checks. Leave unreported failures to callers that have already changed
+ * metadata, including allocation failures.
+ */
int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
- struct ntfs_inode *locked_ni)
+ struct ntfs_inode *locked_ni, bool *reported)
{
struct inode *attr_vi;
struct ntfs_inode *attr_ni;
s64 written;
int err, retry_err;
+ if (reported)
+ *reported = false;
+
/*
* generic_shutdown_super() clears SB_ACTIVE before evicting cached
* inodes. Do not look up the attribute-list inode after SB_ACTIVE has
@@ -235,7 +243,7 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
ntfs_report_file_metadata_error(VFS_I(base_ni),
-EFSCORRUPTED);
}
- return err;
+ goto out_error;
}
attr_ni = NTFS_I(attr_vi);
/* Truncation and page-cache writes can reacquire this runlist lock. */
@@ -253,7 +261,8 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
if (retry_err) {
ntfs_error(base_ni->vol->sb, "Failed to repack attribute list");
iput(attr_vi);
- return retry_err;
+ err = retry_err;
+ goto out_error;
}
retry_err = ntfs_attr_truncate_i_locked(
@@ -263,14 +272,15 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
ntfs_error(base_ni->vol->sb,
"Failed to resize attribute list after repack");
iput(attr_vi);
- return retry_err;
+ err = retry_err;
+ goto out_error;
}
} else if (err) {
iput(attr_vi);
ntfs_error(base_ni->vol->sb,
"Failed to truncate attribute list of inode %#llx",
(long long)base_ni->mft_no);
- return err;
+ goto out_error;
}
/* ntfs_attrlist_repack() below reads the list up to i_size. */
@@ -299,7 +309,8 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
ntfs_error(base_ni->vol->sb,
"Failed to reserve attribute list space");
iput(attr_vi);
- return retry_err;
+ err = retry_err;
+ goto out_error;
}
}
@@ -312,6 +323,8 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
err = written < 0 ? (int)written : -EIO;
if (err != -EFSCORRUPTED)
ntfs_report_file_metadata_error(attr_vi, err);
+ if (reported)
+ *reported = true;
iput(attr_vi);
ntfs_error(base_ni->vol->sb,
"Failed to write attribute list of inode %#llx",
@@ -322,11 +335,17 @@ int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
NInoSetAttrListDirty(base_ni);
iput(attr_vi);
return 0;
+
+out_error:
+ /* Attribute lookup, resize and repack report their own corruption. */
+ if (reported && err == -EFSCORRUPTED)
+ *reported = true;
+ return err;
}
int ntfs_attrlist_update(struct ntfs_inode *base_ni)
{
- return ntfs_attrlist_update_locked(base_ni, NULL);
+ return ntfs_attrlist_update_locked(base_ni, NULL, NULL);
}
/*
@@ -469,18 +488,21 @@ err_out:
/*
* ntfs_attrlist_entry_rm - remove an attribute list attribute entry
* @ctx: attribute search context describing the attribute list entry
+ * @reported: set if the updater or a lower corruption check reported the failure
*
* Remove the attribute list entry @ctx->al_entry from the attribute list.
*
* Return 0 on success and -errno on error.
*/
-int ntfs_attrlist_entry_rm(struct ntfs_attr_search_ctx *ctx)
+int ntfs_attrlist_entry_rm(struct ntfs_attr_search_ctx *ctx, bool *reported)
{
u8 *new_al;
int new_al_len;
struct ntfs_inode *base_ni;
struct attr_list_entry *ale;
+ *reported = false;
+
if (!ctx || !ctx->ntfs_ino || !ctx->al_entry) {
ntfs_debug("Invalid arguments.\n");
return -EINVAL;
@@ -518,5 +540,5 @@ int ntfs_attrlist_entry_rm(struct ntfs_attr_search_ctx *ctx)
base_ni->attr_list = new_al;
base_ni->attr_list_size = new_al_len;
- return ntfs_attrlist_update(base_ni);
+ return ntfs_attrlist_update_locked(base_ni, NULL, reported);
}
diff --git a/fs/ntfs/attrlist.h b/fs/ntfs/attrlist.h
index 10cc2cc8e208..aff3a3ef4dc3 100644
--- a/fs/ntfs/attrlist.h
+++ b/fs/ntfs/attrlist.h
@@ -14,9 +14,9 @@
int ntfs_attrlist_need(struct ntfs_inode *ni);
int ntfs_attrlist_entry_add(struct ntfs_inode *ni, struct attr_record *attr);
-int ntfs_attrlist_entry_rm(struct ntfs_attr_search_ctx *ctx);
+int ntfs_attrlist_entry_rm(struct ntfs_attr_search_ctx *ctx, bool *reported);
int ntfs_attrlist_update(struct ntfs_inode *base_ni);
int ntfs_attrlist_update_locked(struct ntfs_inode *base_ni,
- struct ntfs_inode *locked_ni);
+ struct ntfs_inode *locked_ni, bool *reported);
#endif /* defined _NTFS_ATTRLIST_H */
--
2.51.0