From 0e7990cd615f9cec6cc13f77bc2ed8cd82145ceb Mon Sep 17 00:00:00 2001 From: Salvatore Benedetto Date: Mon, 18 Aug 2008 09:43:14 +0000 Subject: [PATCH] * Update CachedBlock.h git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27019 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/udf/CachedBlock.h | 150 ++++++++---------- 1 file changed, 68 insertions(+), 82 deletions(-) diff --git a/src/add-ons/kernel/file_systems/udf/CachedBlock.h b/src/add-ons/kernel/file_systems/udf/CachedBlock.h index b59369926a..e1dfd18008 100644 --- a/src/add-ons/kernel/file_systems/udf/CachedBlock.h +++ b/src/add-ons/kernel/file_systems/udf/CachedBlock.h @@ -1,11 +1,9 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -// -// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net -// Based on the CachedBlock class from OpenBFS, -// Copyright (c) 2002 Axel Dörfler, axeld@pinc-software.de -//--------------------------------------------------------------------- +/* + * Copyright 2008, Salvatore Benedetto, salvatore.benedetto@gmail.com + * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net + * Copyright 2002, Axel Dörfler, axeld@pinc-software.de + * Distributed under the terms of the MIT License. + */ #ifndef _UDF_CACHED_BLOCK_H #define _UDF_CACHED_BLOCK_H @@ -15,145 +13,133 @@ Axel Dörfler, axeld@pinc-software.de */ -#ifdef COMPILE_FOR_R5 -extern "C" { -#endif - #include "fsproto.h" -#ifdef COMPILE_FOR_R5 -} -#endif +#include +#include -extern "C" { - #ifndef _IMPEXP_KERNEL - # define _IMPEXP_KERNEL - #endif - - #include "lock.h" - #include "cache.h" -} - -#include "kernel_cpp.h" #include "UdfDebug.h" - #include "UdfStructures.h" #include "Volume.h" -namespace Udf { - class CachedBlock { - public: - CachedBlock(Volume *volume); - CachedBlock(Volume *volume, off_t block, bool empty = false); - CachedBlock(CachedBlock *cached); - ~CachedBlock(); +public: + CachedBlock(Volume *volume); + CachedBlock(Volume *volume, off_t block); + CachedBlock(CachedBlock *cached); + ~CachedBlock(); - inline void Keep(); - inline void Unset(); - inline uint8 *SetTo(off_t block, bool empty = false); - inline uint8 *SetTo(long_address address, bool empty = false); - template - inline uint8* SetTo(Accessor &accessor, Descriptor &descriptor, - bool empty = false); + uint8 *Block() const { return fBlock; } + off_t BlockNumber() const { return fBlockNumber; } + uint32 BlockSize() const { return fVolume->BlockSize(); } + uint32 BlockShift() const { return fVolume->BlockShift(); } - uint8 *Block() const { return fBlock; } - off_t BlockNumber() const { return fBlockNumber; } - uint32 BlockSize() const { return fVolume->BlockSize(); } - uint32 BlockShift() const { return fVolume->BlockShift(); } + inline void Keep(); + inline void Unset(); - private: - CachedBlock(const CachedBlock &); // unimplemented - CachedBlock &operator=(const CachedBlock &); // unimplemented + inline uint8 *SetTo(off_t block); + inline uint8 *SetTo(off_t block, off_t base, size_t length); + inline uint8 *SetTo(long_address address); + template + inline uint8* SetTo(Accessor &accessor, Descriptor &descriptor); - protected: - Volume *fVolume; - off_t fBlockNumber; - uint8 *fBlock; +protected: + uint8 *fBlock; + off_t fBlockNumber; + Volume *fVolume; }; + inline CachedBlock::CachedBlock(Volume *volume) : - fVolume(volume), - fBlock(NULL) + fBlock(NULL), + fBlockNumber(0), + fVolume(volume) { } + inline -CachedBlock::CachedBlock(Volume *volume, off_t block, bool empty = false) +CachedBlock::CachedBlock(Volume *volume, off_t block) : - fVolume(volume), - fBlock(NULL) + fBlock(NULL), + fBlockNumber(0), + fVolume(volume) { - SetTo(block, empty); + SetTo(block); } + inline CachedBlock::CachedBlock(CachedBlock *cached) - : fVolume(cached->fVolume) - , fBlockNumber(cached->BlockNumber()) - , fBlock(cached->fBlock) + : + fBlock(cached->fBlock), + fBlockNumber(cached->BlockNumber()), + fVolume(cached->fVolume) { cached->Keep(); } + inline CachedBlock::~CachedBlock() { Unset(); } + inline void CachedBlock::Keep() { fBlock = NULL; } + inline void CachedBlock::Unset() { - DEBUG_INIT("CachedBlock"); if (fBlock) { - PRINT(("releasing block #%Ld\n", BlockNumber())); - release_block(fVolume->Device(), fBlockNumber); - } else { - PRINT(("no block to release\n")); + block_cache_put(fVolume->BlockCache(), fBlockNumber); + fBlock = NULL; } } -inline uint8 * -CachedBlock::SetTo(off_t block, bool empty = false) + +inline uint8* +CachedBlock::SetTo(off_t block) { - DEBUG_INIT_ETC("CachedBlock", ("block: %Ld, empty: %s", - block, (empty ? "true" : "false"))); - Unset(); - fBlockNumber = block; - PRINT(("getting block #%Ld\n", block)); - return fBlock = empty ? (uint8 *)get_empty_block(fVolume->Device(), block, BlockSize()) - : (uint8 *)get_block(fVolume->Device(), block, BlockSize()); + return SetTo(block, block, 1); } + +inline uint8* +CachedBlock::SetTo(off_t block, off_t base, size_t length) +{ + Unset(); + fBlockNumber = block; + return fBlock = (uint8 *)block_cache_get_etc(fVolume->BlockCache(), + block, base, length); +} + + inline uint8 * -CachedBlock::SetTo(long_address address, bool empty = false) +CachedBlock::SetTo(long_address address) { off_t block; if (fVolume->MapBlock(address, &block) == B_OK) - return SetTo(block, empty); + return SetTo(block, block, 1); else return NULL; } template inline uint8* -CachedBlock::SetTo(Accessor &accessor, Descriptor &descriptor, bool empty = false) +CachedBlock::SetTo(Accessor &accessor, Descriptor &descriptor) { // Make a long_address out of the descriptor and call it a day long_address address; address.set_to(accessor.GetBlock(descriptor), - accessor.GetPartition(descriptor)); - return SetTo(address, empty); + accessor.GetPartition(descriptor)); + return SetTo(address); } -}; // namespace Udf - #endif // _UDF_CACHED_BLOCK_H -