Re: [PATCH v1 4/4] ntfs: account for direct MFT bitmap cluster allocation
From: liubaolin
Date: Wed Sep 23 2026 - 22:31:36 EST
在 2026/9/24 09:45, Xuewen Wang 写道:
The MFT bitmap extension fast path sets $Bitmap directly, bypassing
ntfs_cluster_alloc() and its free_clusters and lcn_empty_bits_per_page
updates. Successful extensions overreport free space, and rollback adds
back counts that were never deducted.
Update both counts under lcnbmp_lock and the bitmap folio lock. Require
a nonzero page count and space remaining after delayed-allocation
reservations; otherwise use the regular allocator. The page check also
prevents underflow when the initial scan recorded zero after a read error.
Fixes: 6251f0b0de7d ("ntfs: update super block operations")
Suggested-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
fs/ntfs/mft.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
index 489a5935202c..e01e367a588d 100644
--- a/fs/ntfs/mft.c
+++ b/fs/ntfs/mft.c
@@ -1404,10 +1404,18 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(struct ntfs_volume *vol)
folio_lock(folio);
b = (u8 *)kmap_local_folio(folio, 0) + (ll & ~PAGE_MASK);
tb = 1 << (lcn & 7ull);
- if (*b != 0xff && !(*b & tb)) {
+ /*
+ * A page skipped by the initial scan has no free bits recorded.
+ * Honor that and the space reserved for delayed allocation.
+ */
+ if (*b != 0xff && !(*b & tb) &&
+ vol->lcn_empty_bits_per_page[ll >> PAGE_SHIFT] &&
+ ntfs_available_clusters_count(vol, 1) > 0) {
/* Next cluster is free, allocate it. */
*b |= tb;
folio_mark_dirty(folio);
+ ntfs_dec_free_clusters(vol, 1);
+ ntfs_set_lcn_empty_bits(vol, ll >> PAGE_SHIFT, 1, 1);
folio_unlock(folio);
kunmap_local(b);
folio_put(folio);
Looks good to me.
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>