From 109c9b0f67f97a34b19491fa82242a2130114903 Mon Sep 17 00:00:00 2001 From: Xuewen Wang Date: Thu, 24 Sep 2026 09:45:14 +0800 Subject: [PATCH] ntfs: account for direct MFT bitmap cluster allocation 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 Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang Reviewed-by: Baolin Liu Signed-off-by: Namjae Jeon --- 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);