@@ -711,9 +711,16 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
711
711
712
712
/*
713
713
* ntfs_init_from_boot - Init internal info from on-disk boot sector.
714
+ *
715
+ * NTFS mount begins from boot - special formatted 512 bytes.
716
+ * There are two boots: the first and the last 512 bytes of volume.
717
+ * The content of boot is not changed during ntfs life.
718
+ *
719
+ * NOTE: ntfs.sys checks only first (primary) boot.
720
+ * chkdsk checks both boots.
714
721
*/
715
722
static int ntfs_init_from_boot (struct super_block * sb , u32 sector_size ,
716
- u64 dev_size )
723
+ u64 dev_size , struct NTFS_BOOT * * boot2 )
717
724
{
718
725
struct ntfs_sb_info * sbi = sb -> s_fs_info ;
719
726
int err ;
@@ -937,23 +944,11 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
937
944
938
945
if (bh -> b_blocknr && !sb_rdonly (sb )) {
939
946
/*
940
- * Alternative boot is ok but primary is not ok.
941
- * Update primary boot.
942
- */
943
- struct buffer_head * bh0 = sb_getblk (sb , 0 );
944
- if (bh0 ) {
945
- if (buffer_locked (bh0 ))
946
- __wait_on_buffer (bh0 );
947
-
948
- lock_buffer (bh0 );
949
- memcpy (bh0 -> b_data , boot , sizeof (* boot ));
950
- set_buffer_uptodate (bh0 );
951
- mark_buffer_dirty (bh0 );
952
- unlock_buffer (bh0 );
953
- if (!sync_dirty_buffer (bh0 ))
954
- ntfs_warn (sb , "primary boot is updated" );
955
- put_bh (bh0 );
956
- }
947
+ * Alternative boot is ok but primary is not ok.
948
+ * Do not update primary boot here 'cause it may be faked boot.
949
+ * Let ntfs to be mounted and update boot later.
950
+ */
951
+ * boot2 = kmemdup (boot , sizeof (* boot ), GFP_NOFS | __GFP_NOWARN );
957
952
}
958
953
959
954
out :
@@ -1000,6 +995,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
1000
995
u16 * shared ;
1001
996
struct MFT_REF ref ;
1002
997
bool ro = sb_rdonly (sb );
998
+ struct NTFS_BOOT * boot2 = NULL ;
1003
999
1004
1000
ref .high = 0 ;
1005
1001
@@ -1030,7 +1026,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
1030
1026
1031
1027
/* Parse boot. */
1032
1028
err = ntfs_init_from_boot (sb , bdev_logical_block_size (bdev ),
1033
- bdev_nr_bytes (bdev ));
1029
+ bdev_nr_bytes (bdev ), & boot2 );
1034
1030
if (err )
1035
1031
goto out ;
1036
1032
@@ -1412,6 +1408,29 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
1412
1408
goto put_inode_out ;
1413
1409
}
1414
1410
1411
+ if (boot2 ) {
1412
+ /*
1413
+ * Alternative boot is ok but primary is not ok.
1414
+ * Volume is recognized as NTFS. Update primary boot.
1415
+ */
1416
+ struct buffer_head * bh0 = sb_getblk (sb , 0 );
1417
+ if (bh0 ) {
1418
+ if (buffer_locked (bh0 ))
1419
+ __wait_on_buffer (bh0 );
1420
+
1421
+ lock_buffer (bh0 );
1422
+ memcpy (bh0 -> b_data , boot2 , sizeof (* boot2 ));
1423
+ set_buffer_uptodate (bh0 );
1424
+ mark_buffer_dirty (bh0 );
1425
+ unlock_buffer (bh0 );
1426
+ if (!sync_dirty_buffer (bh0 ))
1427
+ ntfs_warn (sb , "primary boot is updated" );
1428
+ put_bh (bh0 );
1429
+ }
1430
+
1431
+ kfree (boot2 );
1432
+ }
1433
+
1415
1434
return 0 ;
1416
1435
1417
1436
put_inode_out :
@@ -1424,6 +1443,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
1424
1443
put_mount_options (sbi -> options );
1425
1444
put_ntfs (sbi );
1426
1445
sb -> s_fs_info = NULL ;
1446
+ kfree (boot2 );
1427
1447
1428
1448
return err ;
1429
1449
}
0 commit comments