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:
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Ingo Weinhold, [email protected].
|
||||||
|
* 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
|
#define BLOCK_H
|
||||||
|
|
||||||
|
|
||||||
#include <fs_cache.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
#include "Transaction.h"
|
|
||||||
#include "Volume.h"
|
class Transaction;
|
||||||
|
class Volume;
|
||||||
|
|
||||||
|
|
||||||
class Block {
|
class Block {
|
||||||
public:
|
public:
|
||||||
Block()
|
inline Block();
|
||||||
:
|
inline ~Block();
|
||||||
fVolume(NULL),
|
|
||||||
fData(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~Block()
|
void TransferFrom(Block& other);
|
||||||
{
|
|
||||||
Put();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransferFrom(Block& other)
|
bool GetReadable(Volume* volume, uint64 blockIndex);
|
||||||
{
|
bool GetWritable(Volume* volume, uint64 blockIndex,
|
||||||
Put();
|
Transaction& transaction);
|
||||||
|
bool GetZero(Volume* volume, uint64 blockIndex,
|
||||||
|
Transaction& transaction);
|
||||||
|
|
||||||
fVolume = other.fVolume;
|
status_t MakeWritable(Transaction& transaction);
|
||||||
fData = other.fData;
|
|
||||||
fIndex = other.fIndex;
|
|
||||||
fWritable = other.fWritable;
|
|
||||||
|
|
||||||
other.fVolume = NULL;
|
void Put();
|
||||||
other.fData = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetReadable(Volume* volume, uint64 blockIndex)
|
void* Data() const { return fData; }
|
||||||
{
|
uint64 Index() const { return fIndex; }
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _Init(Volume* volume, uint64 blockIndex, const void* data,
|
bool _Init(Volume* volume, uint64 blockIndex,
|
||||||
bool writable)
|
const void* data, bool writable);
|
||||||
{
|
|
||||||
if (data == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
fVolume = volume;
|
|
||||||
fData = const_cast<void*>(data);
|
|
||||||
fIndex = blockIndex;
|
|
||||||
fWritable = writable;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Volume* fVolume;
|
Volume* fVolume;
|
||||||
void* fData;
|
void* fData;
|
||||||
uint64 fIndex;
|
uint64 fIndex;
|
||||||
bool fWritable;
|
bool fWritable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Block::Block()
|
||||||
|
:
|
||||||
|
fVolume(NULL),
|
||||||
|
fData(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Block::~Block()
|
||||||
|
{
|
||||||
|
Put();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // BLOCK_H
|
#endif // BLOCK_H
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "BlockAllocator.h"
|
#include "BlockAllocator.h"
|
||||||
#include "DebugSupport.h"
|
#include "DebugSupport.h"
|
||||||
|
#include "Transaction.h"
|
||||||
|
#include "Volume.h"
|
||||||
|
|
||||||
|
|
||||||
class DirEntryBlock {
|
class DirEntryBlock {
|
||||||
|
|||||||
@@ -11,11 +11,14 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
#include <fs_cache.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "BlockAllocator.h"
|
#include "BlockAllocator.h"
|
||||||
#include "DebugSupport.h"
|
#include "DebugSupport.h"
|
||||||
|
#include "Transaction.h"
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ SubDirC++Flags -Werror ;
|
|||||||
|
|
||||||
|
|
||||||
HAIKU_CHECKSUM_FS_SOURCES =
|
HAIKU_CHECKSUM_FS_SOURCES =
|
||||||
|
Block.cpp
|
||||||
BlockAllocator.cpp
|
BlockAllocator.cpp
|
||||||
checksumfs.cpp
|
checksumfs.cpp
|
||||||
Directory.cpp
|
Directory.cpp
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "DebugSupport.h"
|
#include "DebugSupport.h"
|
||||||
|
#include "Volume.h"
|
||||||
|
|
||||||
|
|
||||||
static inline uint64
|
static inline uint64
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "SuperBlock.h"
|
#include "SuperBlock.h"
|
||||||
#include "SymLink.h"
|
#include "SymLink.h"
|
||||||
|
#include "Transaction.h"
|
||||||
|
|
||||||
|
|
||||||
Volume::Volume(uint32 flags)
|
Volume::Volume(uint32 flags)
|
||||||
|
|||||||
Reference in New Issue
Block a user