Skip to content

Commit dcc852e

Browse files
fs/ntfs3: Fix alternative boot searching
Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 4ad5c92 commit dcc852e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/ntfs3/super.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
846846
struct ntfs_sb_info *sbi = sb->s_fs_info;
847847
int err;
848848
u32 mb, gb, boot_sector_size, sct_per_clst, record_size;
849-
u64 sectors, clusters, mlcn, mlcn2;
849+
u64 sectors, clusters, mlcn, mlcn2, dev_size0;
850850
struct NTFS_BOOT *boot;
851851
struct buffer_head *bh;
852852
struct MFT_REC *rec;
@@ -855,6 +855,9 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
855855
u32 boot_off = 0;
856856
const char *hint = "Primary boot";
857857

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

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

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

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

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

0 commit comments

Comments
 (0)