2 * Copyright (c) 2005-2006, Stockholms Universitet
3 * (Stockholm University, Stockholm Sweden)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the university nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
39 #include <nnpfs/nnpfs_blocks.h>
44 struct FCacheEntry
*node
;
46 Listitem
*lru_le
; /* block lru */
47 Listitem
*block_le
; /* node's block list, make it a tree? */
61 typedef void (*block_callback_t
)(struct block
*block
, void *data
);
64 * get block offset of data offset 'off'
67 static inline uint64_t
68 block_offset(uint64_t off
) {
69 return off
- (off
& (fcache_getblocksize() - 1));
73 * get next block offset after data offset 'off'
75 * This actually gives the same block if it is aligned on a block
76 * boundary. Current users depend on that.
79 static inline uint64_t
80 block_next_offset(uint64_t off
) {
81 return block_offset(off
+ fcache_getblocksize() - 1);
85 * get last block offset for file length 'len'
86 * Result may not be what is expected for zero.
89 static inline uint64_t
90 block_end_offset(uint64_t len
) {
91 return len
? block_offset(len
- 1) : len
;
95 block_get(FCacheEntry
*node
, uint64_t offset
);
98 block_add(FCacheEntry
*node
, uint64_t offset
);
101 block_foreach(FCacheEntry
*node
,
102 block_callback_t fun
,
106 block_free(struct block
*block
);
109 block_any(FCacheEntry
*node
);
112 block_emptyp(FCacheEntry
*node
);
114 #endif /* _BLOCKS_H_ */