[PATCH v7 23/31] ntfs: report export parent reconstruction errors
From: Xuewen Wang
Date: Fri Dec 04 2026 - 02:52:29 EST
From: Xuewen Wang <wangxuewen@xxxxxxxxxx>
Report missing required or malformed FILE_NAME attributes during export
parent reconstruction, while continuing past malformed candidates as
before. Report an unused parent as EFSCORRUPTED only for a linked,
non-deleting child. The preceding locking fix stabilizes these checks
against rename and rmdir.
Preserve ordinary stale-handle behavior. NTFS returns EFSCORRUPTED for a
confirmed corrupt parent reference; generic open_by_handle_at() decoding
still converts that error to ESTALE.
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Changes in v7:
Rebase onto ntfs-next 660cb7022966; retain the v6 logical change.
fs/ntfs/namei.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index f54c3d0ba2b1..4833ce7a0df3 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -1924,6 +1924,7 @@ const struct inode_operations ntfs_dir_inode_ops = {
*/
static struct dentry *ntfs_get_parent(struct dentry *child_dent)
{
+ int report_err = 0;
struct inode *vi = d_inode(child_dent);
struct inode *parent;
struct ntfs_inode *ni = NTFS_I(vi);
@@ -1947,6 +1948,7 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
if (IS_ERR(ctx)) {
unmap_mft_record(ni);
err = PTR_ERR(ctx);
+ ctx = NULL;
goto unlock_err;
}
try_next:
@@ -1955,20 +1957,27 @@ try_next:
if (unlikely(err)) {
ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(ni);
- if (err == -ENOENT)
+ if (err == -ENOENT && vi->i_nlink) {
+ err = -EFSCORRUPTED;
+ report_err = -EFSCORRUPTED;
ntfs_error(vi->i_sb,
"Inode 0x%llx does not have a file name attribute. Run chkdsk.",
ni->mft_no);
+ }
goto unlock_err;
}
attr = ctx->attr;
- if (unlikely(attr->non_resident))
+ if (unlikely(attr->non_resident)) {
+ report_err = -EFSCORRUPTED;
goto try_next;
+ }
fn = (struct file_name_attr *)((u8 *)attr +
le16_to_cpu(attr->data.resident.value_offset));
if (unlikely((u8 *)fn + le32_to_cpu(attr->data.resident.value_length) >
- (u8 *)attr + le32_to_cpu(attr->length)))
+ (u8 *)attr + le32_to_cpu(attr->length))) {
+ report_err = -EFSCORRUPTED;
goto try_next;
+ }
/* Get the inode number of the parent directory. */
parent_ino = MREF_LE(fn->parent_directory);
/* Release the search context and the mft record of the child. */
@@ -1976,11 +1985,18 @@ try_next:
unmap_mft_record(ni);
parent = ntfs_iget(vi->i_sb, parent_ino);
+ if (IS_ERR(parent) && PTR_ERR(parent) == -ENOENT &&
+ vi->i_nlink && !NInoBeingDeleted(ni)) {
+ report_err = -EFSCORRUPTED;
+ parent = ERR_PTR(-EFSCORRUPTED);
+ }
goto out;
unlock_err:
parent = ERR_PTR(err);
out:
+ if (report_err)
+ ntfs_report_file_metadata_error(vi, report_err);
mutex_unlock(&ni->mrec_lock);
return d_obtain_alias(parent);
}
--
2.51.0