diff --git a/src/tests/system/kernel/file_corruption/fs/BlockAllocator.cpp b/src/tests/system/kernel/file_corruption/fs/BlockAllocator.cpp index 94507014f9..dedc757b9a 100644 --- a/src/tests/system/kernel/file_corruption/fs/BlockAllocator.cpp +++ b/src/tests/system/kernel/file_corruption/fs/BlockAllocator.cpp @@ -15,6 +15,7 @@ #include "Block.h" #include "checksumfs.h" #include "DebugSupport.h" +#include "SuperBlock.h" #include "Volume.h" @@ -177,12 +178,18 @@ dprintf("BlockAllocator::Allocate(%llu, %llu)\n", baseHint, count); // search from base hint to end status_t error = _Allocate(baseHint, fTotalBlocks, count, transaction, &_allocatedBase, _allocatedCount); - if (error == B_OK || baseHint == 0) + if (error == B_OK) + return _UpdateSuperBlock(transaction); + if (baseHint == 0) return error; // search from 0 to hint - return _Allocate(0, baseHint, count, transaction, &_allocatedBase, + error = _Allocate(0, baseHint, count, transaction, &_allocatedBase, _allocatedCount); + if (error != B_OK) + return error; + + return _UpdateSuperBlock(transaction); } @@ -204,7 +211,7 @@ dprintf("BlockAllocator::AllocateExactly(%llu, %llu)\n", base, count); return B_BUSY; } - return B_OK; + return _UpdateSuperBlock(transaction); } @@ -213,7 +220,11 @@ BlockAllocator::Free(uint64 base, uint64 count, Transaction& transaction) { MutexLocker locker(fLock); - return _Free(base, count, transaction); + status_t error = _Free(base, count, transaction); + if (error != B_OK) + return error; + + return _UpdateSuperBlock(transaction); } @@ -695,3 +706,22 @@ dprintf("BlockAllocator::_FreeInBitmapBlock(%llu, %lu)\n", base, count); return B_OK; } + + +status_t +BlockAllocator::_UpdateSuperBlock(Transaction& transaction) +{ + // write the super block + Block block; + if (!block.GetWritable(fVolume, kCheckSumFSSuperBlockOffset / B_PAGE_SIZE, + transaction)) { + return B_ERROR; + } + + SuperBlock* superBlock = (SuperBlock*)block.Data(); + superBlock->SetFreeBlocks(fFreeBlocks); + + block.Put(); + + return B_OK; +} diff --git a/src/tests/system/kernel/file_corruption/fs/BlockAllocator.h b/src/tests/system/kernel/file_corruption/fs/BlockAllocator.h index 3b797352f6..fb34375406 100644 --- a/src/tests/system/kernel/file_corruption/fs/BlockAllocator.h +++ b/src/tests/system/kernel/file_corruption/fs/BlockAllocator.h @@ -58,6 +58,8 @@ private: status_t _FreeInBitmapBlock(uint64 base, uint32 count, Transaction& transaction); + status_t _UpdateSuperBlock(Transaction& transaction); + private: mutex fLock; Volume* fVolume; diff --git a/src/tests/system/kernel/file_corruption/fs/SuperBlock.cpp b/src/tests/system/kernel/file_corruption/fs/SuperBlock.cpp index 02ad536bee..901af4cbd4 100644 --- a/src/tests/system/kernel/file_corruption/fs/SuperBlock.cpp +++ b/src/tests/system/kernel/file_corruption/fs/SuperBlock.cpp @@ -45,3 +45,10 @@ SuperBlock::Initialize(Volume* volume) rootDir = volume->RootDirectory()->BlockIndex(); strlcpy(name, volume->Name(), kCheckSumFSNameLength); } + + +void +SuperBlock::SetFreeBlocks(uint64 count) +{ + freeBlocks = count; +} diff --git a/src/tests/system/kernel/file_corruption/fs/SuperBlock.h b/src/tests/system/kernel/file_corruption/fs/SuperBlock.h index be4d1cdc28..4ffc1781b5 100644 --- a/src/tests/system/kernel/file_corruption/fs/SuperBlock.h +++ b/src/tests/system/kernel/file_corruption/fs/SuperBlock.h @@ -23,6 +23,8 @@ public: bool Check(uint64 totalBlocks) const; void Initialize(Volume* volume); + + void SetFreeBlocks(uint64 count); };