Author: bonefish Date: 2010-07-20 23:19:11 +0200 (Tue, 20 Jul 2010) New Revision: 37633 Changeset: http://dev.haiku-os.org/changeset/37633 Added: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.cpp Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.h haiku/trunk/src/tests/system/kernel/file_corruption/fs/Directory.cpp haiku/trunk/src/tests/system/kernel/file_corruption/fs/File.cpp haiku/trunk/src/tests/system/kernel/file_corruption/fs/Jamfile haiku/trunk/src/tests/system/kernel/file_corruption/fs/Node.cpp haiku/trunk/src/tests/system/kernel/file_corruption/fs/Volume.cpp Log: Moved Block implementation to its own source file. Added: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.cpp (rev 0) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.cpp 2010-07-20 21:19:11 UTC (rev 37633) @@ -0,0 +1,105 @@ +/* + * Copyright 2010, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ + + +#include "Block.h" + +#include <fs_cache.h> + +#include "Transaction.h" +#include "Volume.h" + + +void +Block::TransferFrom(Block& other) +{ + Put(); + + fVolume = other.fVolume; + fData = other.fData; + fIndex = other.fIndex; + fWritable = other.fWritable; + + other.fVolume = NULL; + other.fData = NULL; +} + + +bool +Block::GetReadable(Volume* volume, uint64 blockIndex) +{ + Put(); + + return _Init(volume, blockIndex, + block_cache_get(volume->BlockCache(), blockIndex), false); +} + + +bool +Block::GetWritable(Volume* volume, uint64 blockIndex, Transaction& transaction) +{ + Put(); + + return _Init(volume, blockIndex, + block_cache_get_writable(volume->BlockCache(), blockIndex, + transaction.ID()), + true); +} + + +bool +Block::GetZero(Volume* volume, uint64 blockIndex, Transaction& transaction) +{ + Put(); + + return _Init(volume, blockIndex, + block_cache_get_empty(volume->BlockCache(), blockIndex, + transaction.ID()), + true); +} + + +status_t +Block::MakeWritable(Transaction& transaction) +{ + if (fVolume == NULL) + return B_BAD_VALUE; + if (fWritable) + return B_OK; + + status_t error = block_cache_make_writable(fVolume->BlockCache(), + fIndex, transaction.ID()); + if (error != B_OK) + return error; + + fWritable = true; + return B_OK; +} + + +void +Block::Put() +{ + if (fVolume != NULL) { + block_cache_put(fVolume->BlockCache(), fIndex); + fVolume = NULL; + fData = NULL; + } +} + + +bool +Block::_Init(Volume* volume, uint64 blockIndex, const void* data, bool writable) +{ + if (data == NULL) + return false; + + fVolume = volume; + fData = const_cast<void*>(data); + fIndex = blockIndex; + fWritable = writable; + + return true; +} Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.h =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.h 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Block.h 2010-07-20 21:19:11 UTC (rev 37633) @@ -6,134 +6,57 @@ #define BLOCK_H -#include <fs_cache.h> +#include <SupportDefs.h> -#include "Transaction.h" -#include "Volume.h" +class Transaction; +class Volume; + class Block { public: - Block() - : - fVolume(NULL), - fData(NULL) - { - } + inline Block(); + inline ~Block(); - ~Block() - { - Put(); - } + void TransferFrom(Block& other); - void TransferFrom(Block& other) - { - Put(); + bool GetReadable(Volume* volume, uint64 blockIndex); + bool GetWritable(Volume* volume, uint64 blockIndex, + Transaction& transaction); + bool GetZero(Volume* volume, uint64 blockIndex, + Transaction& transaction); - fVolume = other.fVolume; - fData = other.fData; - fIndex = other.fIndex; - fWritable = other.fWritable; + status_t MakeWritable(Transaction& transaction); - other.fVolume = NULL; - other.fData = NULL; - } + void Put(); - bool GetReadable(Volume* volume, uint64 blockIndex) - { - Put(); + void* Data() const { return fData; } + uint64 Index() const { return fIndex; } - return _Init(volume, blockIndex, - block_cache_get(volume->BlockCache(), blockIndex), false); - } +private: + bool _Init(Volume* volume, uint64 blockIndex, + const void* data, bool writable); - bool GetWritable(Volume* volume, uint64 blockIndex, - Transaction& transaction) - { - Put(); - - return _Init(volume, blockIndex, - block_cache_get_writable(volume->BlockCache(), blockIndex, - transaction.ID()), - true); - } - - bool GetZero(Volume* volume, uint64 blockIndex, Transaction& transaction) - { - Put(); - - return _Init(volume, blockIndex, - block_cache_get_empty(volume->BlockCache(), blockIndex, - transaction.ID()), - true); - } - - status_t MakeWritable(Transaction& transaction) - { - if (fVolume == NULL) - return B_BAD_VALUE; - if (fWritable) - return B_OK; - - status_t error = block_cache_make_writable(fVolume->BlockCache(), - fIndex, transaction.ID()); - if (error != B_OK) - return error; - - fWritable = true; - return B_OK; - } - - void Put() - { - if (fVolume != NULL) { - block_cache_put(fVolume->BlockCache(), fIndex); - fVolume = NULL; - fData = NULL; - } - } - - void Discard() - { - if (fVolume != NULL) { - block_cache_discard(fVolume->BlockCache(), fIndex, 1); - fVolume = NULL; - fData = NULL; - } - } - - void* Data() const - { - return fData; - } - - uint64 Index() const - { - return fIndex; - } - private: - bool _Init(Volume* volume, uint64 blockIndex, const void* data, - bool writable) - { - if (data == NULL) - return false; + Volume* fVolume; + void* fData; + uint64 fIndex; + bool fWritable; +}; - fVolume = volume; - fData = const_cast<void*>(data); - fIndex = blockIndex; - fWritable = writable; - return true; - } +Block::Block() + : + fVolume(NULL), + fData(NULL) +{ +} -private: - Volume* fVolume; - void* fData; - uint64 fIndex; - bool fWritable; -}; +Block::~Block() +{ + Put(); +} #endif // BLOCK_H Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Directory.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Directory.cpp 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Directory.cpp 2010-07-20 21:19:11 UTC (rev 37633) @@ -14,6 +14,8 @@ #include "Block.h" #include "BlockAllocator.h" #include "DebugSupport.h" +#include "Transaction.h" +#include "Volume.h" class DirEntryBlock { Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/File.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/File.cpp 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/File.cpp 2010-07-20 21:19:11 UTC (rev 37633) @@ -11,11 +11,14 @@ #include <algorithm> #include <new> +#include <fs_cache.h> + #include <AutoDeleter.h> #include "Block.h" #include "BlockAllocator.h" #include "DebugSupport.h" +#include "Transaction.h" #include "Volume.h" Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Jamfile 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Jamfile 2010-07-20 21:19:11 UTC (rev 37633) @@ -17,6 +17,7 @@ HAIKU_CHECKSUM_FS_SOURCES = + Block.cpp BlockAllocator.cpp checksumfs.cpp Directory.cpp Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Node.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Node.cpp 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Node.cpp 2010-07-20 21:19:11 UTC (rev 37633) @@ -12,6 +12,7 @@ #include "Block.h" #include "DebugSupport.h" +#include "Volume.h" static inline uint64 Modified: haiku/trunk/src/tests/system/kernel/file_corruption/fs/Volume.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/file_corruption/fs/Volume.cpp 2010-07-20 21:11:56 UTC (rev 37632) +++ haiku/trunk/src/tests/system/kernel/file_corruption/fs/Volume.cpp 2010-07-20 21:19:11 UTC (rev 37633) @@ -29,6 +29,7 @@ #include "File.h" #include "SuperBlock.h" #include "SymLink.h" +#include "Transaction.h" Volume::Volume(uint32 flags)