public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	<linux-fsdevel@vger.kernel.org>
Subject: [PATCH 03/10] fs/ntfs3: Mark ntfs dirty when on-disk struct is corrupted
Date: Mon, 8 May 2023 16:36:59 +0400	[thread overview]
Message-ID: <f4e07222-4f9e-e50d-a898-0583c5a168d0@paragon-software.com> (raw)
In-Reply-To: <b21a4bc9-166d-2631-d73b-cb4e802ff69e@paragon-software.com>

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
  fs/ntfs3/fsntfs.c  | 2 +-
  fs/ntfs3/index.c   | 6 ++++++
  fs/ntfs3/ntfs_fs.h | 2 ++
  fs/ntfs3/record.c  | 6 ++++++
  4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index 28cc421102e5..21567e58265c 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -178,7 +178,7 @@ int ntfs_fix_post_read(struct NTFS_RECORD_HEADER 
*rhdr, size_t bytes,
      /* Check errors. */
      if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- ||
          fn * SECTOR_SIZE > bytes) {
-        return -EINVAL; /* Native chkntfs returns ok! */
+        return -E_NTFS_CORRUPT;
      }

      /* Get fixup pointer. */
diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 0a48d2d67219..b40da258e684 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -1113,6 +1113,12 @@ int indx_read(struct ntfs_index *indx, struct 
ntfs_inode *ni, CLST vbn,
      *node = in;

  out:
+    if (err == -E_NTFS_CORRUPT) {
+        ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
+        ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
+        err = -EINVAL;
+    }
+
      if (ib != in->index)
          kfree(ib);

diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index eb01f7e76479..2e4be773728d 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -53,6 +53,8 @@ enum utf16_endian;
  #define E_NTFS_NONRESIDENT        556
  /* NTFS specific error code about punch hole. */
  #define E_NTFS_NOTALIGNED        557
+/* NTFS specific error code when on-disk struct is corrupted. */
+#define E_NTFS_CORRUPT            558


  /* sbi->flags */
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 7060f784c2d7..7974ca35a15c 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -180,6 +180,12 @@ int mi_read(struct mft_inode *mi, bool is_mft)
      return 0;

  out:
+    if (err == -E_NTFS_CORRUPT) {
+        ntfs_err(sbi->sb, "mft corrupted");
+        ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
+        err = -EINVAL;
+    }
+
      return err;
  }

-- 
2.34.1


  parent reply	other threads:[~2023-05-08 12:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 12:35 [PATCH 00/10] Refactoring and bugfix Konstantin Komarov
2023-05-08 12:36 ` [PATCH 01/10] fs/ntfs3: Correct checking while generating attr_list Konstantin Komarov
2023-05-08 12:36 ` [PATCH 02/10] fs/ntfs3: Fix ntfs_atomic_open Konstantin Komarov
2023-05-08 12:36 ` Konstantin Komarov [this message]
2023-05-08 12:37 ` [PATCH 04/10] fs/ntfs3: Alternative boot if primary boot is corrupted Konstantin Komarov
2023-05-08 12:38 ` [PATCH 05/10] fs/ntfs3: Do not update primary boot in ntfs_init_from_boot() Konstantin Komarov
2023-05-08 12:38 ` [PATCH 06/10] fs/ntfs3: Code formatting Konstantin Komarov
2023-05-08 12:38 ` [PATCH 07/10] fs/ntfs3: Code refactoring Konstantin Komarov
2023-05-08 12:39 ` [PATCH 08/10] fs/ntfs3: Add ability to format new mft records with bigger/smaller header Konstantin Komarov
2023-05-08 12:39 ` [PATCH 09/10] fs/ntfs3: Fix endian problem Konstantin Komarov
2023-05-08 12:40 ` [PATCH 10/10] fs/ntfs3: Add support /proc/fs/ntfs3/<dev>/volinfo and /proc/fs/ntfs3/<dev>/label Konstantin Komarov

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=f4e07222-4f9e-e50d-a898-0583c5a168d0@paragon-software.com \
    --to=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /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