Author: axeld Date: 2009-10-20 02:23:53 +0200 (Tue, 20 Oct 2009) New Revision: 33674 Changeset: http://dev.haiku-os.org/changeset/33674/haiku Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Added a very simple way to fragment your disk. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2009-10-20 00:18:32 UTC (rev 33673) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2009-10-20 00:23:53 UTC (rev 33674) @@ -1062,6 +1062,37 @@ } +#ifdef DEBUG_FRAGMENTER +void +BlockAllocator::Fragment() +{ + AllocationBlock cached(fVolume); + MutexLocker lock(fLock); + + // only leave 4 block holes + static const uint32 kMask = 0x0f0f0f0f; + uint32 valuesPerBlock = fVolume->BlockSize() / 4; + + for (int32 i = 0; i < fNumGroups; i++) { + AllocationGroup& group = fGroups[i]; + + for (uint32 block = 0; block < group.NumBlocks(); block++) { + Transaction transaction(fVolume, 0); + + if (cached.SetToWritable(transaction, group, block) != B_OK) + return; + + for (int32 index = 0; index < valuesPerBlock; index++) { + cached.Block(index) |= HOST_ENDIAN_TO_BFS_INT32(kMask); + } + + transaction.Done(); + } + } +} +#endif // DEBUG_FRAGMENTER + + #ifdef DEBUG_ALLOCATION_GROUPS void BlockAllocator::_CheckGroup(int32 groupIndex) const Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h 2009-10-20 00:18:32 UTC (rev 33673) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h 2009-10-20 00:23:53 UTC (rev 33674) @@ -21,6 +21,7 @@ //#define DEBUG_ALLOCATION_GROUPS +//#define DEBUG_FRAGMENTER class BlockAllocator { @@ -63,6 +64,9 @@ #ifdef BFS_DEBUGGER_COMMANDS void Dump(int32 index); #endif +#ifdef DEBUG_FRAGMENTER + void Fragment(); +#endif private: status_t _RemoveInvalidNode(Inode* parent, BPlusTree* tree, Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2009-10-20 00:18:32 UTC (rev 33673) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2009-10-20 00:23:53 UTC (rev 33674) @@ -682,6 +682,16 @@ return volume->WriteSuperBlock(); } + +#ifdef DEBUG_FRAGMENTER + case 56741: + { + BlockAllocator& allocator = volume->Allocator(); + allocator.Fragment(); + return B_OK; + } +#endif + #ifdef DEBUG case 56742: {