Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ntfs3: fix mount failure on volumes with fragmented MFT bitmap

When the $MFT's $BITMAP attribute is fragmented across multiple MFT
records (base record + extent records), ntfs_fill_super() fails with
-ENOENT during wnd_init() because the MFT bitmap's run list only
contains runs from the base MFT record.

The issue is that wnd_init() (which calls wnd_rescan()) is invoked
before ni_load_all_mi(), so the extent MFT records containing
additional $BITMAP runs have not been loaded yet. When wnd_rescan()
tries to look up a VCN beyond the base record's runs, run_lookup_entry()
fails and returns -ENOENT.

This affects NTFS volumes with a large or heavily fragmented MFT, which
is common on long-used Windows systems where the MFT bitmap's run list
doesn't fit in the base MFT record and spills into extent records.

Fix this by:
1. Moving ni_load_all_mi() before wnd_init() so all extent records
are available.
2. After ni_load_all_mi(), iterating through the attribute list to
find any $BITMAP extent attributes and unpacking their runs into
sbi->mft.bitmap.run before wnd_init() is called.

Tested on a 664GB NTFS volume with 86 MFT bitmap runs spanning
records 0 (VCN 0-105) and 17 (VCN 106-165). Before the fix, mount
fails with -ENOENT. After the fix, mount succeeds and all read/write
operations work correctly. Stress-tested with 8 test categories
(large file integrity, 10K small files, copy, move, delete/recreate
cycles, concurrent writes, deep directories, overwrite persistence).

Signed-off-by: Ruslan Elishev <relishev@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

+35 -4
+35 -4
fs/ntfs3/super.c
··· 1426 1426 tt = inode->i_size >> sbi->record_bits; 1427 1427 sbi->mft.next_free = MFT_REC_USER; 1428 1428 1429 - err = wnd_init(&sbi->mft.bitmap, sb, tt); 1430 - if (err) 1431 - goto put_inode_out; 1432 - 1433 1429 err = ni_load_all_mi(ni); 1434 1430 if (err) { 1435 1431 ntfs_err(sb, "Failed to load $MFT's subrecords (%d).", err); 1436 1432 goto put_inode_out; 1437 1433 } 1434 + 1435 + /* Merge MFT bitmap runs from extent records loaded by ni_load_all_mi. */ 1436 + { 1437 + struct ATTRIB *a = NULL; 1438 + struct ATTR_LIST_ENTRY *le = NULL; 1439 + 1440 + while ((a = ni_enum_attr_ex(ni, a, &le, NULL))) { 1441 + CLST svcn, evcn; 1442 + u16 roff; 1443 + 1444 + if (a->type != ATTR_BITMAP || !a->non_res) 1445 + continue; 1446 + 1447 + svcn = le64_to_cpu(a->nres.svcn); 1448 + if (!svcn) 1449 + continue; /* Base record runs already loaded. */ 1450 + 1451 + evcn = le64_to_cpu(a->nres.evcn); 1452 + roff = le16_to_cpu(a->nres.run_off); 1453 + 1454 + err = run_unpack_ex(&sbi->mft.bitmap.run, sbi, 1455 + MFT_REC_MFT, svcn, evcn, svcn, 1456 + Add2Ptr(a, roff), 1457 + le32_to_cpu(a->size) - roff); 1458 + if (err < 0) { 1459 + ntfs_err(sb, "Failed to unpack $MFT bitmap extent (%d).", err); 1460 + goto put_inode_out; 1461 + } 1462 + err = 0; 1463 + } 1464 + } 1465 + 1466 + err = wnd_init(&sbi->mft.bitmap, sb, tt); 1467 + if (err) 1468 + goto put_inode_out; 1438 1469 1439 1470 sbi->mft.ni = ni; 1440 1471