[PATCH v7 00/31] Report NTFS metadata errors and shutdown through FAN_FS_ERROR

From: Xuewen Wang

Date: Fri Dec 04 2026 - 02:50:13 EST


From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

Report NTFS metadata corruption, failed recovery and shutdown through
FAN_FS_ERROR. File events identify the affected base file; volume events
cover errors without a safe file reference. Preserve the volume error bit
and errors= policy. Before SB_ACTIVE, metadata reporting helpers record
the volume error state without queuing an event.

Use -EFSCORRUPTED (-EUCLEAN) for confirmed corruption in the updated error
paths, both in reports and in failing NTFS operations. Preserve genuine
I/O, allocation and unsupported-format errors. Ordinary EOF and missing
names or streams are not corruption. Partial-I/O and best-effort
operations retain their return semantics; independent recovery failures
can report a different errno from the initiating operation.

Based on ntfs-next commit 660cb7022966 ("ntfs: map a read past the end
of the runlist as a hole").

Changes in this refreshed v7:
- Rebase onto the updated ntfs-next, preserving the upstream short-write,
LZNT1 input-boundary, directory-size, case-insensitive lookup and
named-stream locking fixes.
- Adapt both extended-system-file checks to carry lower-level report
ownership. Preserve the upstream protection of $Extend metadata.
- Report non-root directory self-references from locked named-stream
lookups as EUCLEAN. Keep the root self-entry and unlocked revalidation
from generating corruption reports.
- Cover missing required metadata in the new data-size setter. Move
failed size-restoration reports to the short-write cleanup exit, and
avoid repeating corruption already reported below. Keep notifications
for other recovery failures, including ENOMEM and ENOSPC.
- Drop six patches already merged into ntfs-next: mapping-pairs writeback
error propagation, cluster-free count handling, source-record removal
failure handling, search-context error propagation, buffered fallback
writeback errors, and export-parent locking. The series now contains
31 patches. Keep the maintainer's versions of these changes.
- Adapt EA creation-cleanup reporting to the upstream tri-state lookup
code, preserving its errno diagnostics and deferring our reports until
after cleanup and unlocking. Reconcile the EA lookup comment.
- Preserve upstream's system-record-only MFT mirror comparison, index
buffer kvfree(), and FILE_NAME flexible-array allocation changes.
- Retain the v6 review fix for obsolete EINTR/ERESTARTSYS handling after
upstream commit 136760737a76 ("ntfs: don't let a fatal signal interrupt
metadata reads"). Keep valid signal handling for named-stream payload
I/O, preallocation and other interruptible data paths.
- Retain single-report handling for inode/attribute/index loading,
external extent lookup, attribute-list reads, EA and reparse decoding.
Missing required metadata and locally detected corruption still report.
- Avoid reporting STANDARD_INFORMATION lookup failures again from inode
writeback. Keep the local report for a missing required attribute,
preserve fsync errno and ENOMEM redirty behavior, and introduce the
ownership tracking in patch 17 before extending it in patch 26.
- Leave missing MFT runlist reports to the block mapper. Base-record
and extent-record writeback propagate its error without repeating
the volume report at the inode writeback exit.
- Avoid repeating mapping-pairs corruption at the inode writeback exit.
Keep the original errno, dirty-runlist state and ENOMEM retry behavior.
- Propagate already-reported corruption through attribute-list updates and
avoid reporting it again after attribute writes. Preserve notifications
for unreported failures after metadata changes and independent recovery
failures. Fold these corrections into patches 13 and 14.
- Retain the MFT writeback correction: report a failed synchronous write
in the lower writeback path, without repeating it at the inode writeback
exit. Preserve fsync errno and ENOMEM redirty behavior.

Earlier review changes retained:
- The standalone Fixes-tagged fixes and search-context changes are now
upstream; they do not depend on this series' new reporting helpers.
Keep reporting integration for the attribute-move fix in the last patch.
- Cover the directory lookup, index-block read and nonresident iomap
corruption paths identified in v3. Use ntfs_inode_base() for base-file
attribution and test_and_set_bit() for each shutdown transition.
- ntfs_attr_exist() preserves lookup failures instead of reporting them
as absence. Preserve the inner ntfs_read_inode_mount() errno instead
of returning -1. Keep local reports at the affected cleanup exits.
- Distinguish malformed or missing required EA metadata from lower-level
read failures, and recheck HasEA under mrec_lock in listxattr().
- Preserve ntfs_icx_ia_ensure() errors, clear failed allocation pointers
before cleanup, and report missing required INDEX_ALLOCATION metadata.
Treat invalid child VCNs as corruption in lookup and readdir.

Series organization:
- 1-3: remaining read/compression/readdir error propagation.
- 4: file and volume metadata reporting helpers.
- 5-10: boot/system metadata, logfile, runlists, iomap and compression.
- 11-17: attribute metadata, failed updates and inode cleanup.
- 18-23: index/directory operations, namespace recovery and exportfs.
- 24-29: MFT, EA/ACL, named-stream and reparse/ObjectID reporting.
- 30: atomic shutdown reporting.
- 31: reporting integration for the upstream attribute-move fix.

Validation on the refreshed base:
- Built NTFS with W=1 at all 31 intermediate stages and checked all 31
NTFS translation units with Sparse C=2, without NTFS diagnostics.
- Passed 18 QEMU runtime cases covering normal file/namespace/stream
operations, corruption reports, readdir, shutdown, ustat selftests,
fsync/remount/data verification, O_TMPFILE, ACL inheritance and large EAs.
- Passed 24 focused QEMU cases checking exact event counts for malformed
or missing inode, attribute, index, extent, EA and reparse metadata.
Required-metadata corruption reports once; absent streams and healthy
operations remain silent. These include directory self-reference checks
and a healthy short write with preallocated space.
- Injected missing attributes during initialized-size and data-size
restoration each report EUCLEAN once. EIO, ENOMEM and ENOSPC recovery
failures each report once; the write retains its positive short count.
- A single injected synchronous MFT BIO failure returns EIO from fsync
and reports one error. The healthy control succeeds without an event.
- A single malformed STANDARD_INFORMATION value returns EUCLEAN from
fsync and reports one error. Missing required metadata still reports
once, and the healthy control succeeds without an event.
- A one-shot failure of MFT block mapping returns EUCLEAN from fsync
with one error count; the healthy control succeeds without an event.
- A one-shot malformed nonresident DATA attribute during mapping-pairs
writeback returns EUCLEAN from fsync and reports once. Missing required
DATA metadata still reports once; healthy buffered writes remain silent.
- Runtime configurations enable non-strict KCSAN and lockdep. No KCSAN
or lockdep diagnostics were detected in the checked runtime logs.

The v7 patches are available at:
https://github.com/liubaolin-murphy/liubaolin-ntfs/tree/main/ntfs_notify/ntfs_notify_patch_v7

Thanks to Hyunchul and Namjae for reviewing the earlier versions.

Baolin Liu (8):
ntfs: add filesystem metadata error reporting helpers
ntfs: report runlist and cluster allocation metadata errors
ntfs: report attribute lookup and validation errors
ntfs: report attribute list update and recovery failures
ntfs: report MFT record validation and lifecycle errors
ntfs: report MFT bitmap and data growth recovery failures
ntfs: report MFT writeback errors to fsnotify
ntfs: report each shutdown transition once

Dandan Wu (9):
ntfs: report required system file and volume metadata errors
ntfs: report logfile metadata and emptying errors
ntfs: report LZNT1 and WOF compressed stream errors
ntfs: report attribute resize and relocation recovery failures
ntfs: report incomplete attribute range updates
ntfs: report index validation and block I/O errors
ntfs: preserve and report index traversal errors
ntfs: report directory lookup and metadata corruption
ntfs: report index update and recovery failures

Xuewen Wang (14):
ntfs: preserve synchronous buffered read errors
ntfs: preserve compressed I/O preparation errors
ntfs: retain directory iteration state after errors
ntfs: report boot geometry and MFT bootstrap errors
ntfs: report iomap metadata corruption
ntfs: report attribute record update and cleanup failures
ntfs: report attribute conversion and mapping update failures
ntfs: report inode metadata and eviction cleanup errors
ntfs: report namespace and file recovery errors
ntfs: report export parent reconstruction errors
ntfs: report EA metadata and restoration errors
ntfs: report named stream metadata and recovery errors
ntfs: report reparse and object ID metadata errors
ntfs: report attribute move removal and cleanup failures

fs/ntfs/aops.c | 20 +-
fs/ntfs/attrib.c | 754 +++++++++++++++++++++++++++++++----------
fs/ntfs/attrib.h | 4 +-
fs/ntfs/attrlist.c | 79 +++--
fs/ntfs/attrlist.h | 4 +-
fs/ntfs/bitmap.c | 2 +-
fs/ntfs/compress.c | 35 +-
fs/ntfs/dir.c | 97 ++++--
fs/ntfs/ea.c | 163 +++++----
fs/ntfs/file.c | 25 +-
fs/ntfs/index.c | 356 ++++++++++++-------
fs/ntfs/inode.c | 302 ++++++++++++-----
fs/ntfs/inode.h | 10 +-
fs/ntfs/iomap.c | 56 ++-
fs/ntfs/lcnalloc.c | 17 +-
fs/ntfs/logfile.c | 58 ++--
fs/ntfs/mft.c | 333 +++++++++++-------
fs/ntfs/named_stream.c | 58 +++-
fs/ntfs/namei.c | 165 ++++++---
fs/ntfs/object_id.c | 50 ++-
fs/ntfs/reparse.c | 114 +++++--
fs/ntfs/reparse.h | 2 +-
fs/ntfs/runlist.c | 23 +-
fs/ntfs/runlist.h | 4 +-
fs/ntfs/stream.h | 2 +-
fs/ntfs/super.c | 296 +++++++++++-----
fs/ntfs/volume.h | 4 +
fs/ntfs/wof.c | 39 ++-
28 files changed, 2219 insertions(+), 853 deletions(-)


base-commit: 660cb70229665c241b4ea5537491d7cd01c25ad8
--
2.51.0