Skip to content

Commit

Permalink
fs/ntfs3: Fix alternative boot searching
Browse files Browse the repository at this point in the history
[ Upstream commit dcc852e ]

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
aalexandrovich authored and gregkh committed Nov 8, 2023
1 parent 1d7dd48 commit 31baaf8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fs/ntfs3/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,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;
Expand All @@ -847,6 +847,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);
Expand Down Expand Up @@ -1084,9 +1087,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)
Expand All @@ -1100,6 +1103,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);
Expand Down

0 comments on commit 31baaf8

Please sign in to comment.