btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / exfat / CachedBlock.h
blob09fec08abb835dbc11258b0edcbf3ea31603b6bf
1 /*
2 * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
3 * This file may be used under the terms of the MIT License.
4 */
5 #ifndef CACHED_BLOCK_H
6 #define CACHED_BLOCK_H
8 //! interface for the block cache
10 #include <fs_cache.h>
12 #include "Volume.h"
15 class CachedBlock {
16 public:
17 CachedBlock(Volume* volume);
18 CachedBlock(Volume* volume, off_t block);
19 ~CachedBlock();
21 void Keep();
22 void Unset();
24 const uint8* SetTo(off_t block);
26 const uint8* Block() const { return fBlock; }
27 off_t BlockNumber() const { return fBlockNumber; }
29 private:
30 CachedBlock(const CachedBlock &);
31 CachedBlock &operator=(const CachedBlock &);
32 // no implementation
34 protected:
35 Volume* fVolume;
36 off_t fBlockNumber;
37 uint8* fBlock;
41 // inlines
44 inline
45 CachedBlock::CachedBlock(Volume* volume)
47 fVolume(volume),
48 fBlockNumber(0),
49 fBlock(NULL)
54 inline
55 CachedBlock::CachedBlock(Volume* volume, off_t block)
57 fVolume(volume),
58 fBlockNumber(0),
59 fBlock(NULL)
61 SetTo(block);
65 inline
66 CachedBlock::~CachedBlock()
68 Unset();
72 inline void
73 CachedBlock::Keep()
75 fBlock = NULL;
79 inline void
80 CachedBlock::Unset()
82 if (fBlock != NULL) {
83 block_cache_put(fVolume->BlockCache(), fBlockNumber);
84 fBlock = NULL;
89 inline const uint8 *
90 CachedBlock::SetTo(off_t block)
92 Unset();
93 fBlockNumber = block;
94 return fBlock = (uint8 *)block_cache_get(fVolume->BlockCache(), block);
97 #endif // CACHED_BLOCK_H