1// BlockCache.h 2// 3// Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de) 4// 5// This program is free software; you can redistribute it and/or modify 6// it under the terms of the GNU General Public License as published by 7// the Free Software Foundation; either version 2 of the License, or 8// (at your option) any later version. 9// 10// This program is distributed in the hope that it will be useful, 11// but WITHOUT ANY WARRANTY; without even the implied warranty of 12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13// GNU General Public License for more details. 14// 15// You should have received a copy of the GNU General Public License 16// along with this program; if not, write to the Free Software 17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18// 19// You can alternatively use *this file* under the terms of the the MIT 20// license included in this package. 21 22#ifndef BLOCK_CACHE_H 23#define BLOCK_CACHE_H 24 25#include <SupportDefs.h> 26 27#include "List.h" 28#include "Locker.h" 29 30class Block; 31class Node; 32 33class BlockCache { 34public: 35 BlockCache(); 36 ~BlockCache(); 37 38 status_t Init(int device, uint64 blockCount, uint32 blockSize); 39 40 int GetDevice() const { return fDevice; } 41 uint32 GetBlockSize() const { return fBlockSize; } 42 off_t GetBlockCount() const { return fBlockCount; } 43 44 status_t GetBlock(Block *block); 45 status_t GetBlock(uint64 number, Block **block); 46 void PutBlock(Block *block); 47 48private: 49 Block *_FindBlock(uint64 number); 50 status_t _ReadBlock(uint64 number, Block **block); 51 52 53 friend class Block; 54 void *_GetBlock(off_t number) const; 55 void _ReleaseBlock(off_t number, void *data) const; 56 57private: 58 int fDevice; 59 uint32 fBlockSize; 60 uint64 fBlockCount; 61 Locker fLock; 62 List<Block*> fBlocks; 63 void* fCacheHandle; 64 // statistics 65 int64 fReads; 66 mutable int64 fBlockGets; 67 mutable int64 fBlockReleases; 68}; 69 70#endif // BLOCK_CACHE_H 71