2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
9 * Copyright (c) 2007, The Storage Networking Industry Association.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * - Neither the name of The Storage Networking Industry Association (SNIA)
23 * nor the names of its contributors may be used to endorse or promote
24 * products derived from this software without specific prior written
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
46 #include <sys/errno.h>
49 * This interface is designed to provide an abatract data type
50 * for manipulating in-core and on-disk bitmaps.
52 * When a bitmap is allocated, a descriptor to the bitmap is
53 * returned to the caller. The descriptor is an integer. All
54 * functions of the API use this descriptor to locate the
57 * Each bitmap is divided into chunks (internally). Each chunk
58 * is BMAP_CHUNK_WORDS words (4K now). Chunks are kept in an
59 * LRU list for caching.
61 * There is also a hashing on the chunks for accessing them.
62 * Each hash is an MRU list.
65 * bm_alloc: To allocate a new bitmap.
66 * bm_free: To release the bitmap.
67 * bm_getlen: To get the length of the bitmap.
68 * bm_getiov: To get the bits specified by the vectors.
69 * bm_setiov: To set the bits specified by the vectors.
70 * bm_apply_ifset: Calls a callback function on each set
72 * bm_apply_ifunset: Calls a callback function on each
73 * clear bit in the bitmap.
75 * There are some other interface for simpilicty of programs:
76 * bm_get To get a range of bits.
77 * bm_set: To set a range of bits.
78 * bm_getone: To get one bit only.
79 * bm_setone: To set one bit only.
80 * bm_unsetone: To unset one bit only.
82 * The on-disk bitmap functions are the same except they start
86 typedef u_longlong_t u_quad_t
;
89 * A vector for setting bits in the bitmap.
90 * - bmv_base: The starting bit number.
91 * - bmv_len: Lenght of the vector.
92 * - bmv_val: Pointer to the new value of bits.
94 typedef struct bm_iovec
{
102 * An array of vectors on which the set/get operations
104 * - bmio_iovcnt: Number of entries in the array.
105 * - bmio_iov: Array of vectors.
107 typedef struct bm_io
{
109 bm_iovec_t
*bmio_iov
;
112 extern void bm_print(int);
115 * External Interface.
117 extern int bm_alloc(u_quad_t
, int);
118 extern int dbm_alloc(char *, u_quad_t
, int);
120 extern int bm_free(int);
121 extern int dbm_free(int);
123 extern int bm_realloc(int, u_quad_t
);
124 extern int dbm_realloc(int, u_quad_t
);
126 extern int bm_setiov(int, bm_io_t
*);
127 extern int dbm_setiov(int, bm_io_t
*);
128 extern int bm_getiov(int, bm_io_t
*);
129 extern int dbm_getiov(int, bm_io_t
*);
131 extern int bm_apply_ifset(int, int (*)(), void *);
132 extern int dbm_apply_ifset(int, int (*)(), void *);
133 extern int bm_apply_ifunset(int, int (*)(), void *);
134 extern int dbm_apply_ifunset(int, int (*)(), void *);
136 extern char *dbm_getfname(int);
137 extern u_quad_t
bm_getlen(int);
138 extern u_quad_t
dbm_getlen(int);
140 extern void dbm_print(int);
144 * Statistical and debugging interface.
146 extern void dbitmap_stats_clear(void);
150 * Macros for setting and unsetting only one bit.
152 #define bm_setone(bmd, bn) bm_set((bmd), (bn), 1, 1)
153 #define dbm_setone(bmd, bn) dbm_set((bmd), (bn), 1, 1)
154 #define bm_unsetone(bmd, bn) bm_set((bmd), (bn), 1, 0)
155 #define dbm_unsetone(bmd, bn) dbm_set((bmd), (bn), 1, 0)
157 extern int bm_set(int, u_quad_t
, u_quad_t
, uint_t
);
158 extern int dbm_set(int, u_quad_t
, u_quad_t
, uint_t
);
159 extern int bm_get(int, u_quad_t
, u_quad_t
, uint_t
*);
160 extern int dbm_get(int, u_quad_t
, u_quad_t
, uint_t
*);
161 extern int bm_getone(int, u_quad_t
);
162 extern int dbm_getone(int, u_quad_t
);
167 #endif /* _BITMAP_H_ */