All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konstantin Komarovc <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 3/8] fs/ntfs3: Fix alternative boot searching
Date: Tue, 26 Sep 2023 12:55:53 +0300	[thread overview]
Message-ID: <1f95ab55-ce05-4c11-8c14-8df260514208@paragon-software.com> (raw)
In-Reply-To: <7c217d7d-6ee4-4603-b5f1-ebe7b68cf430@paragon-software.com>


Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
  fs/ntfs3/super.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 71c80c578feb..d2951b23f52a 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -846,7 +846,7 @@ static int ntfs_init_from_boot(struct super_block 
*sb, u32 sector_size,
      struct ntfs_sb_info *sbi = sb->s_fs_info;
      int err;
      u32 mb, gb, boot_sector_size, sct_per_clst, record_size;
-    u64 sectors, clusters, mlcn, mlcn2;
+    u64 sectors, clusters, mlcn, mlcn2, dev_size0;
      struct NTFS_BOOT *boot;
      struct buffer_head *bh;
      struct MFT_REC *rec;
@@ -855,6 +855,9 @@ static int ntfs_init_from_boot(struct super_block 
*sb, u32 sector_size,
      u32 boot_off = 0;
      const char *hint = "Primary boot";

+    /* Save original dev_size. Used with alternative boot. */
+    dev_size0 = dev_size;
+
      sbi->volume.blocks = dev_size >> PAGE_SHIFT;

      bh = ntfs_bread(sb, 0);
@@ -1087,9 +1090,9 @@ static int ntfs_init_from_boot(struct super_block 
*sb, u32 sector_size,
      }

  out:
-    if (err == -EINVAL && !bh->b_blocknr && dev_size > PAGE_SHIFT) {
+    if (err == -EINVAL && !bh->b_blocknr && dev_size0 > PAGE_SHIFT) {
          u32 block_size = min_t(u32, sector_size, PAGE_SIZE);
-        u64 lbo = dev_size - sizeof(*boot);
+        u64 lbo = dev_size0 - sizeof(*boot);

          /*
            * Try alternative boot (last sector)
@@ -1103,6 +1106,7 @@ static int ntfs_init_from_boot(struct super_block 
*sb, u32 sector_size,

          boot_off = lbo & (block_size - 1);
          hint = "Alternative boot";
+        dev_size = dev_size0; /* restore original size. */
          goto check_boot;
      }
      brelse(bh);
-- 
2.34.1


  parent reply	other threads:[~2023-09-26  9:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26  9:54 [PATCH 0/8] fs/ntfs3: Bugfix and refactoring Konstantin Komarovc
2023-09-26  9:55 ` [PATCH 1/8] fs/ntfs3: Use inode_set_ctime_to_ts instead of inode_set_ctime Konstantin Komarovc
2023-09-26  9:55 ` [PATCH 2/8] fs/ntfs3: Allow repeated call to ntfs3_put_sbi Konstantin Komarovc
2023-09-26  9:55 ` Konstantin Komarovc [this message]
2023-09-26  9:56 ` [PATCH 4/8] fs/ntfs3: Refactoring and comments Konstantin Komarovc
2023-09-26  9:56 ` [PATCH 5/8] fs/ntfs3: Add more info into /proc/fs/ntfs3/<dev>/volinfo Konstantin Komarovc
2023-09-26  9:56 ` [PATCH 6/8] fs/ntfs3: Do not allow to change label if volume is read-only Konstantin Komarovc
2023-09-26  9:57 ` [PATCH 7/8] fs/ntfs3: Fix possible NULL-ptr-deref in ni_readpage_cmpr() Konstantin Komarovc
2023-09-26  9:57 ` [PATCH 8/8] fs/ntfs3: Fix NULL pointer dereference on error in attr_allocate_frame() Konstantin Komarovc

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=1f95ab55-ce05-4c11-8c14-8df260514208@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.