(afsrights2nnpfsrights): export
[arla.git] / arlad / blocks.h
blob81c39abff7267967d12558db30028af54c0b6c75
1 /*
2 * Copyright (c) 2005-2006, Stockholms Universitet
3 * (Stockholm University, Stockholm Sweden)
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
34 /* $Id$ */
36 #ifndef _BLOCKS_H_
37 #define _BLOCKS_H_
39 #include <nnpfs/nnpfs_blocks.h>
40 #include <fcache.h>
42 struct block {
43 uint64_t offset;
44 struct FCacheEntry *node;
46 Listitem *lru_le; /* block lru */
47 Listitem *block_le; /* node's block list, make it a tree? */
49 struct {
50 unsigned kernelp : 1;
51 unsigned busy : 1;
52 } flags;
55 typedef enum {
56 BLOCK_NONE = 0x0,
57 BLOCK_GOT = 0x01,
58 BLOCK_BUSY = 0x02
59 } BlockState;
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;
94 struct block *
95 block_get(FCacheEntry *node, uint64_t offset);
97 struct block *
98 block_add(FCacheEntry *node, uint64_t offset);
100 void
101 block_foreach(FCacheEntry *node,
102 block_callback_t fun,
103 void *data);
105 void
106 block_free(struct block *block);
108 BlockState
109 block_any(FCacheEntry *node);
111 Bool
112 block_emptyp(FCacheEntry *node);
114 #endif /* _BLOCKS_H_ */