2 * Copyright 2008, Salvatore Benedetto, salvatore.benedetto@gmail.com
3 * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net
4 * Copyright 2002, Axel Dörfler, axeld@pinc-software.de
5 * Distributed under the terms of the MIT License.
7 #ifndef _UDF_CACHED_BLOCK_H
8 #define _UDF_CACHED_BLOCK_H
10 /*! \file CachedBlock.h
12 Based on the CachedBlock class from OpenBFS, written by
13 Axel Dörfler, axeld@pinc-software.de
17 #include <util/kernel_cpp.h>
20 #include "UdfStructures.h"
25 CachedBlock(Volume
*volume
);
26 CachedBlock(Volume
*volume
, off_t block
);
27 CachedBlock(CachedBlock
*cached
);
30 uint8
*Block() const { return fBlock
; }
31 off_t
BlockNumber() const { return fBlockNumber
; }
32 uint32
BlockSize() const { return fVolume
->BlockSize(); }
33 uint32
BlockShift() const { return fVolume
->BlockShift(); }
38 inline uint8
*SetTo(off_t block
);
39 inline uint8
*SetTo(off_t block
, off_t base
, size_t length
);
40 inline uint8
*SetTo(long_address address
);
41 template <class Accessor
, class Descriptor
>
42 inline uint8
* SetTo(Accessor
&accessor
, Descriptor
&descriptor
);
52 CachedBlock::CachedBlock(Volume
*volume
)
62 CachedBlock::CachedBlock(Volume
*volume
, off_t block
)
73 CachedBlock::CachedBlock(CachedBlock
*cached
)
75 fBlock(cached
->fBlock
),
76 fBlockNumber(cached
->BlockNumber()),
77 fVolume(cached
->fVolume
)
84 CachedBlock::~CachedBlock()
101 block_cache_put(fVolume
->BlockCache(), fBlockNumber
);
108 CachedBlock::SetTo(off_t block
)
110 return SetTo(block
, block
, 1);
115 CachedBlock::SetTo(off_t block
, off_t base
, size_t length
)
118 fBlockNumber
= block
;
119 return fBlock
= (uint8
*)block_cache_get_etc(fVolume
->BlockCache(),
120 block
, base
, length
);
125 CachedBlock::SetTo(long_address address
)
128 if (fVolume
->MapBlock(address
, &block
) == B_OK
)
129 return SetTo(block
, block
, 1);
135 template <class Accessor
, class Descriptor
>
137 CachedBlock::SetTo(Accessor
&accessor
, Descriptor
&descriptor
)
139 // Make a long_address out of the descriptor and call it a day
140 long_address address
;
141 address
.set_to(accessor
.GetBlock(descriptor
),
142 accessor
.GetPartition(descriptor
));
143 return SetTo(address
);
146 #endif // _UDF_CACHED_BLOCK_H