[PATCH v6 29/37] ntfs: report export parent reconstruction errors

From: Xuewen Wang

Date: Wed Nov 18 2026 - 04:11:15 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 v6:
Keep parent-corruption reporting here; locking is now a preceding patch.

Validation:
- Compiled and linked the NTFS module object with W=1 at this stage.

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 5a497807dda0..b66b82ba1646 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -1740,6 +1740,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);
@@ -1763,6 +1764,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:
@@ -1771,20 +1773,27 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
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. */
@@ -1792,11 +1801,18 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
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