Moved Block implementation to its own source file.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37633 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
decde2b030
commit
0f9dda9f00
src/tests/system/kernel/file_corruption/fs
105
src/tests/system/kernel/file_corruption/fs/Block.cpp
Normal file
105
src/tests/system/kernel/file_corruption/fs/Block.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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;
|
||||
}
|
@ -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();
|
||||
|
||||
return _Init(volume, blockIndex,
|
||||
block_cache_get(volume->BlockCache(), blockIndex), false);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
fVolume = volume;
|
||||
fData = const_cast<void*>(data);
|
||||
fIndex = blockIndex;
|
||||
fWritable = writable;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _Init(Volume* volume, uint64 blockIndex,
|
||||
const void* data, bool writable);
|
||||
|
||||
private:
|
||||
Volume* fVolume;
|
||||
void* fData;
|
||||
uint64 fIndex;
|
||||
bool fWritable;
|
||||
Volume* fVolume;
|
||||
void* fData;
|
||||
uint64 fIndex;
|
||||
bool fWritable;
|
||||
};
|
||||
|
||||
|
||||
Block::Block()
|
||||
:
|
||||
fVolume(NULL),
|
||||
fData(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Block::~Block()
|
||||
{
|
||||
Put();
|
||||
}
|
||||
|
||||
|
||||
#endif // BLOCK_H
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include "Block.h"
|
||||
#include "BlockAllocator.h"
|
||||
#include "DebugSupport.h"
|
||||
#include "Transaction.h"
|
||||
#include "Volume.h"
|
||||
|
||||
|
||||
class DirEntryBlock {
|
||||
|
@ -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"
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ SubDirC++Flags -Werror ;
|
||||
|
||||
|
||||
HAIKU_CHECKSUM_FS_SOURCES =
|
||||
Block.cpp
|
||||
BlockAllocator.cpp
|
||||
checksumfs.cpp
|
||||
Directory.cpp
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "Block.h"
|
||||
#include "DebugSupport.h"
|
||||
#include "Volume.h"
|
||||
|
||||
|
||||
static inline uint64
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "File.h"
|
||||
#include "SuperBlock.h"
|
||||
#include "SymLink.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
|
||||
Volume::Volume(uint32 flags)
|
||||
|
Loading…
x
Reference in New Issue
Block a user