From b5417d2089cd46d9ce92aeec2339d1831f715737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 27 Jun 2022 17:37:44 +0200 Subject: [PATCH] bfs: don't allocate more than the maximum in an AllocationGroup * The reserved blocks could exhaust the first allocation group, so iterate as much as needed. * fix #11753 Change-Id: Ib1d7f87946f7b96dfcade8f5778a14065d965f6b Reviewed-on: https://review.haiku-os.org/c/haiku/+/5417 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- .../kernel/file_systems/bfs/BlockAllocator.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index af0bdaa831..949e9a67ea 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -597,10 +597,16 @@ BlockAllocator::InitializeAndClearBitmap(Transaction& transaction) // reserve the boot block, the log area, and the block bitmap itself uint32 reservedBlocks = fVolume->Log().Start() + fVolume->Log().Length(); - - if (fGroups[0].Allocate(transaction, 0, reservedBlocks) < B_OK) { - FATAL(("could not allocate reserved space for block bitmap/log!\n")); - return B_ERROR; + uint32 blocksToReserve = reservedBlocks; + for (int32 i = 0; i < fNumGroups; i++) { + int32 reservedBlocksInGroup = min_c(blocksToReserve, numBits); + if (fGroups[i].Allocate(transaction, 0, reservedBlocksInGroup) < B_OK) { + FATAL(("could not allocate reserved space for block bitmap/log!\n")); + return B_ERROR; + } + blocksToReserve -= reservedBlocksInGroup; + if (blocksToReserve == 0) + break; } fVolume->SuperBlock().used_blocks = HOST_ENDIAN_TO_BFS_INT64(reservedBlocks);