mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuewen Wang <wangxuewen_ky@163.com>
To: linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: wangxuewen_ky@163.com, ntfs@lists.linux.dev,
	linux-kernel@vger.kernel.org, Dandan Wu <wudandan@kylinos.cn>
Subject: [PATCH v5 07/31] ntfs: report logfile metadata and emptying errors
Date: Mon,  2 Nov 2026 15:35:08 +0800	[thread overview]
Message-ID: <20261102073532.98873-8-wangxuewen_ky@163.com> (raw)
In-Reply-To: <20261102073532.98873-1-wangxuewen_ky@163.com>

From: Dandan Wu <wudandan@kylinos.cn>

Logfile validation and emptying can detect corruption or I/O failures
without recording them. Report an unusable nonempty log after trying
alternate restart pages, keeping unsupported versions distinct from
corrupt restart metadata.

Report a missing required logfile, read failures, and write failures or
corrupt runlists when emptying it, including on remount. Retain the
existing read-only fallback.

Signed-off-by: Dandan Wu <wudandan@kylinos.cn>
---
 fs/ntfs/logfile.c | 58 +++++++++++++++++++++++++++--------------------
 fs/ntfs/super.c   |  2 +-
 2 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/fs/ntfs/logfile.c b/fs/ntfs/logfile.c
index 2f27ae7a3927..0b60c6b0479d 100644
--- a/fs/ntfs/logfile.c
+++ b/fs/ntfs/logfile.c
@@ -17,14 +17,14 @@
  * @rp:		restart page header to check
  * @pos:	position in @vi at which the restart page header resides
  *
- * Check the restart page header @rp for consistency and return 'true' if it is
- * consistent and 'false' otherwise.
+ * Check the restart page header @rp for consistency. Return 0 on success,
+ * -EOPNOTSUPP for an unsupported version, or -EINVAL for corruption.
  *
  * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
  * require the full restart page.
  */
-static bool ntfs_check_restart_page_header(struct inode *vi,
-		struct restart_page_header *rp, s64 pos)
+static int ntfs_check_restart_page_header(struct inode *vi,
+					  struct restart_page_header *rp, s64 pos)
 {
 	u32 logfile_system_page_size, logfile_log_page_size;
 	u32 ra_ofs, usa_count, usa_ofs, usa_end = 0;
@@ -43,7 +43,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 			(logfile_system_page_size - 1) ||
 			!is_power_of_2(logfile_log_page_size)) {
 		ntfs_error(vi->i_sb, "LogFile uses unsupported page size.");
-		return false;
+		return -EINVAL;
 	}
 	/*
 	 * We must be either at !pos (1st restart page) or at pos = system page
@@ -51,7 +51,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 	 */
 	if (pos && pos != logfile_system_page_size) {
 		ntfs_error(vi->i_sb, "Found restart area in incorrect position in LogFile.");
-		return false;
+		return -EINVAL;
 	}
 	/* We only know how to handle version 1.1. */
 	if (le16_to_cpu(rp->major_ver) != 1 ||
@@ -60,7 +60,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 			"LogFile version %i.%i is not supported.  (This driver supports version 1.1 only.)",
 			(int)le16_to_cpu(rp->major_ver),
 			(int)le16_to_cpu(rp->minor_ver));
-		return false;
+		return -EOPNOTSUPP;
 	}
 	/*
 	 * If chkdsk has been run the restart page may not be protected by an
@@ -75,7 +75,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 	if (usa_count != le16_to_cpu(rp->usa_count)) {
 		ntfs_error(vi->i_sb,
 			"LogFile restart page specifies inconsistent update sequence array count.");
-		return false;
+		return -EINVAL;
 	}
 	/* Verify the position of the update sequence array. */
 	usa_ofs = le16_to_cpu(rp->usa_ofs);
@@ -84,7 +84,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 			usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) {
 		ntfs_error(vi->i_sb,
 			"LogFile restart page specifies inconsistent update sequence array offset.");
-		return false;
+		return -EINVAL;
 	}
 skip_usa_checks:
 	/*
@@ -99,7 +99,7 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 			ra_ofs > logfile_system_page_size) {
 		ntfs_error(vi->i_sb,
 			"LogFile restart page specifies inconsistent restart area offset.");
-		return false;
+		return -EINVAL;
 	}
 	/*
 	 * Only restart pages modified by chkdsk are allowed to have chkdsk_lsn
@@ -108,10 +108,10 @@ static bool ntfs_check_restart_page_header(struct inode *vi,
 	if (!ntfs_is_chkd_record(rp->magic) && le64_to_cpu(rp->chkdsk_lsn)) {
 		ntfs_error(vi->i_sb,
 			"LogFile restart page is not modified by chkdsk but a chkdsk LSN is specified.");
-		return false;
+		return -EINVAL;
 	}
 	ntfs_debug("Done.");
-	return true;
+	return 0;
 }
 
 /*
@@ -315,6 +315,7 @@ static bool ntfs_check_log_client_array(struct inode *vi,
  *
  * The following error codes are defined:
  *	-EINVAL	- The restart page is inconsistent.
+ *	-EOPNOTSUPP - The logfile version is unsupported.
  *	-ENOMEM	- Not enough memory to load the restart page.
  *	-EIO	- Failed to reading from LogFile.
  */
@@ -328,10 +329,9 @@ static int ntfs_check_and_load_restart_page(struct inode *vi,
 
 	ntfs_debug("Entering.");
 	/* Check the restart page header for consistency. */
-	if (!ntfs_check_restart_page_header(vi, rp, pos)) {
-		/* Error output already done inside the function. */
-		return -EINVAL;
-	}
+	err = ntfs_check_restart_page_header(vi, rp, pos);
+	if (err)
+		return err;
 	/* Check the restart area for consistency. */
 	if (!ntfs_check_restart_area(vi, rp)) {
 		/* Error output already done inside the function. */
@@ -372,8 +372,6 @@ static int ntfs_check_and_load_restart_page(struct inode *vi,
 				ntfs_error(vi->i_sb, "Error mapping LogFile page (index %lu).",
 						idx);
 				err = PTR_ERR(folio);
-				if (err != -EIO && err != -ENOMEM)
-					err = -EIO;
 				goto err_out;
 			}
 			size = min_t(int, to_read, PAGE_SIZE);
@@ -452,6 +450,7 @@ static int ntfs_check_and_load_restart_page(struct inode *vi,
  */
 bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 {
+	int report_err = 0;
 	s64 size, pos;
 	s64 rstr1_lsn, rstr2_lsn;
 	struct ntfs_volume *vol = NTFS_SB(log_vi->i_sb);
@@ -461,7 +460,7 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 	struct restart_page_header *rstr1_ph = NULL;
 	struct restart_page_header *rstr2_ph = NULL;
 	int log_page_size, err;
-	bool logfile_is_empty = true;
+	bool logfile_is_empty = true, unsupported_version = false;
 	u8 log_page_bits;
 
 	ntfs_debug("Entering.");
@@ -495,8 +494,9 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 	 */
 	if (size < log_page_size * 2 || (size - log_page_size * 2) >>
 			log_page_bits < MinLogRecordPages) {
+		report_err = -EFSCORRUPTED;
 		ntfs_error(vol->sb, "LogFile is too small.");
-		return false;
+		goto err_out;
 	}
 	/*
 	 * Read through the file looking for a restart page.  Since the restart
@@ -516,6 +516,8 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 			}
 			folio = read_mapping_folio(mapping, idx, NULL);
 			if (IS_ERR(folio)) {
+				if (PTR_ERR(folio) == -EIO)
+					report_err = -EIO;
 				ntfs_error(vol->sb, "Error mapping LogFile page (index %lu).",
 						idx);
 				goto err_out;
@@ -574,7 +576,11 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 		 * not abort if the restart page was invalid as we might still
 		 * find a valid one further in the file.
 		 */
-		if (err != -EINVAL) {
+		if (err == -EOPNOTSUPP)
+			unsupported_version = true;
+		else if (err != -EINVAL) {
+			if (err == -EIO)
+				report_err = err;
 			kunmap_local(kbase);
 			folio_put(folio);
 			goto err_out;
@@ -594,9 +600,11 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 		return true;
 	}
 	if (!rstr1_ph) {
+		if (!unsupported_version)
+			report_err = -EFSCORRUPTED;
 		ntfs_error(vol->sb,
 			"Did not find any restart pages in LogFile and it was not empty.");
-		return false;
+		goto err_out;
 	}
 	/* If both restart pages were found, use the more recent one. */
 	if (rstr2_ph) {
@@ -624,6 +632,8 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
 	return true;
 err_out:
 	kvfree(rstr1_ph);
+	if (report_err)
+		ntfs_report_file_metadata_error(log_vi, report_err);
 	return false;
 }
 
@@ -767,10 +777,10 @@ bool ntfs_empty_logfile(struct inode *log_vi)
 	ntfs_error(sb, "Failed to write buffer.  Unmount and run chkdsk.");
 	goto dirty_err;
 rl_err:
+	err = -EFSCORRUPTED;
 	ntfs_error(sb, "Runlist is corrupt.  Unmount and run chkdsk.");
 dirty_err:
-	NVolSetErrors(vol);
-	err = -EIO;
+	ntfs_report_file_metadata_error(log_vi, err);
 err:
 	kvfree(empty_buf);
 	kfree(ra);
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index dff04972e9ec..481d528884ad 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -1365,7 +1365,7 @@ static int load_and_check_logfile(struct ntfs_volume *vol,
 	int err = 0;
 
 	ntfs_debug("Entering.");
-	tmp_ino = ntfs_iget(vol->sb, FILE_LogFile);
+	tmp_ino = ntfs_system_iget(vol, FILE_LogFile);
 	if (IS_ERR(tmp_ino)) {
 		if (!IS_ERR(tmp_ino))
 			iput(tmp_ino);


  parent reply	other threads:[~2026-11-02  7:35 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:35 [PATCH v5 00/31] ntfs: report metadata errors and shutdown through FAN_FS_ERROR Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 01/31] ntfs: propagate mapping-pairs update errors from inode writeback Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 02/31] ntfs: preserve cluster-free counts in attribute cleanup Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 03/31] ntfs: add filesystem metadata error reporting helpers Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 04/31] ntfs: preserve attribute search context initialization errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 05/31] ntfs: report boot geometry and MFT bootstrap errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 06/31] ntfs: report required system file and volume metadata errors Xuewen Wang
2026-11-02  7:35 ` Xuewen Wang [this message]
2026-11-02  7:35 ` [PATCH v5 08/31] ntfs: report runlist and cluster allocation " Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 09/31] ntfs: report iomap corruption and preserve buffered read errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 10/31] ntfs: report LZNT1 and WOF compressed stream errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 11/31] ntfs: handle source record removal failure during attribute moves Xuewen Wang
2026-11-09  2:31   ` Hyunchul Lee
2026-11-10  3:13     ` Xuewen Wang
2026-11-10  4:11       ` Namjae Jeon
2026-11-10  6:16         ` Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 12/31] ntfs: report attribute lookup and validation errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 13/31] ntfs: report attribute record update and cleanup failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 14/31] ntfs: report attribute list update and recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 15/31] ntfs: report attribute conversion and mapping update failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 16/31] ntfs: report attribute resize and relocation recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 17/31] ntfs: report incomplete attribute range updates Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 18/31] ntfs: report inode metadata and eviction cleanup errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 19/31] ntfs: report index validation and block I/O errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 20/31] ntfs: preserve index traversal errors and directory retries Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 21/31] ntfs: report directory lookup and metadata corruption Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 22/31] ntfs: report index update and recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 23/31] ntfs: report namespace and file recovery errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 24/31] ntfs: serialize and report export parent reconstruction errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 25/31] ntfs: report MFT record validation and lifecycle errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 26/31] ntfs: report MFT bitmap and data growth recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 27/31] ntfs: report MFT writeback errors to fsnotify Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 28/31] ntfs: report EA metadata and restoration errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 29/31] ntfs: report named stream metadata and recovery errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 30/31] ntfs: report reparse and object ID metadata errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 31/31] ntfs: report each shutdown transition once Xuewen Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261102073532.98873-8-wangxuewen_ky@163.com \
    --to=wangxuewen_ky@163.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs@lists.linux.dev \
    --cc=wudandan@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®