fs/ntfs3: Fix alternative boot searching

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
This commit is contained in:
Konstantin Komarov 2023-09-22 13:12:11 +03:00
parent 4ad5c924df
commit dcc852e509
No known key found for this signature in database
GPG Key ID: A9B0331F832407B6

View File

@ -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; struct ntfs_sb_info *sbi = sb->s_fs_info;
int err; int err;
u32 mb, gb, boot_sector_size, sct_per_clst, record_size; 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 NTFS_BOOT *boot;
struct buffer_head *bh; struct buffer_head *bh;
struct MFT_REC *rec; 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; u32 boot_off = 0;
const char *hint = "Primary boot"; const char *hint = "Primary boot";
/* Save original dev_size. Used with alternative boot. */
dev_size0 = dev_size;
sbi->volume.blocks = dev_size >> PAGE_SHIFT; sbi->volume.blocks = dev_size >> PAGE_SHIFT;
bh = ntfs_bread(sb, 0); bh = ntfs_bread(sb, 0);
@ -1087,9 +1090,9 @@ check_boot:
} }
out: 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); 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) * Try alternative boot (last sector)
@ -1103,6 +1106,7 @@ out:
boot_off = lbo & (block_size - 1); boot_off = lbo & (block_size - 1);
hint = "Alternative boot"; hint = "Alternative boot";
dev_size = dev_size0; /* restore original size. */
goto check_boot; goto check_boot;
} }
brelse(bh); brelse(bh);