Deleted Added
full compact
btree.h (1573) btree.h (14272)
1/*-
1/*-
2 * Copyright (c) 1991, 1993
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Olson.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 17 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Olson.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 17 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)btree.h 8.5 (Berkeley) 2/21/94
36 * @(#)btree.h 8.11 (Berkeley) 8/17/94
37 */
38
37 */
38
39/* Macros to set/clear/test flags. */
40#define F_SET(p, f) (p)->flags |= (f)
41#define F_CLR(p, f) (p)->flags &= ~(f)
42#define F_ISSET(p, f) ((p)->flags & (f))
43
39#include <mpool.h>
40
41#define DEFMINKEYPAGE (2) /* Minimum keys per page */
42#define MINCACHE (5) /* Minimum cached pages */
43#define MINPSIZE (512) /* Minimum page size */
44
45/*
46 * Page 0 of a btree file contains a copy of the meta-data. This page is also

--- 27 unchanged lines hidden (view full) ---

74 u_int32_t flags;
75
76 indx_t lower; /* lower bound of free space on page */
77 indx_t upper; /* upper bound of free space on page */
78 indx_t linp[1]; /* indx_t-aligned VAR. LENGTH DATA */
79} PAGE;
80
81/* First and next index. */
44#include <mpool.h>
45
46#define DEFMINKEYPAGE (2) /* Minimum keys per page */
47#define MINCACHE (5) /* Minimum cached pages */
48#define MINPSIZE (512) /* Minimum page size */
49
50/*
51 * Page 0 of a btree file contains a copy of the meta-data. This page is also

--- 27 unchanged lines hidden (view full) ---

79 u_int32_t flags;
80
81 indx_t lower; /* lower bound of free space on page */
82 indx_t upper; /* upper bound of free space on page */
83 indx_t linp[1]; /* indx_t-aligned VAR. LENGTH DATA */
84} PAGE;
85
86/* First and next index. */
82#define BTDATAOFF (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \
83 sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))
87#define BTDATAOFF \
88 (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \
89 sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))
84#define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t))
85
86/*
87 * For pages other than overflow pages, there is an array of offsets into the
88 * rest of the page immediately following the page header. Each offset is to
89 * an item which is unique to the type of page. The h_lower offset is just
90 * past the last filled-in index. The h_upper offset is the first item on the
91 * page. Offsets are from the beginning of the page.
92 *
93 * If an item is too big to store on a single page, a flag is set and the item
94 * is a { page, size } pair such that the page is the first page of an overflow
95 * chain with size bytes of item. Overflow pages are simply bytes without any
96 * external structure.
97 *
98 * The page number and size fields in the items are pgno_t-aligned so they can
99 * be manipulated without copying. (This presumes that 32 bit items can be
100 * manipulated on this system.)
101 */
90#define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t))
91
92/*
93 * For pages other than overflow pages, there is an array of offsets into the
94 * rest of the page immediately following the page header. Each offset is to
95 * an item which is unique to the type of page. The h_lower offset is just
96 * past the last filled-in index. The h_upper offset is the first item on the
97 * page. Offsets are from the beginning of the page.
98 *
99 * If an item is too big to store on a single page, a flag is set and the item
100 * is a { page, size } pair such that the page is the first page of an overflow
101 * chain with size bytes of item. Overflow pages are simply bytes without any
102 * external structure.
103 *
104 * The page number and size fields in the items are pgno_t-aligned so they can
105 * be manipulated without copying. (This presumes that 32 bit items can be
106 * manipulated on this system.)
107 */
102#define LALIGN(n) \
103 (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1))
104#define NOVFLSIZE (sizeof(pgno_t) + sizeof(size_t))
108#define LALIGN(n) (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1))
109#define NOVFLSIZE (sizeof(pgno_t) + sizeof(u_int32_t))
105
106/*
107 * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno}
108 * pairs, such that the key compares less than or equal to all of the records
109 * on that page. For a tree without duplicate keys, an internal page with two
110 * consecutive keys, a and b, will have all records greater than or equal to a
111 * and less than b stored on the page associated with a. Duplicate keys are
112 * somewhat special and can cause duplicate internal and leaf page records and
113 * some minor modifications of the above rule.
114 */
115typedef struct _binternal {
110
111/*
112 * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno}
113 * pairs, such that the key compares less than or equal to all of the records
114 * on that page. For a tree without duplicate keys, an internal page with two
115 * consecutive keys, a and b, will have all records greater than or equal to a
116 * and less than b stored on the page associated with a. Duplicate keys are
117 * somewhat special and can cause duplicate internal and leaf page records and
118 * some minor modifications of the above rule.
119 */
120typedef struct _binternal {
116 size_t ksize; /* key size */
121 u_int32_t ksize; /* key size */
117 pgno_t pgno; /* page number stored on */
118#define P_BIGDATA 0x01 /* overflow data */
119#define P_BIGKEY 0x02 /* overflow key */
120 u_char flags;
121 char bytes[1]; /* data */
122} BINTERNAL;
123
124/* Get the page's BINTERNAL structure at index indx. */
122 pgno_t pgno; /* page number stored on */
123#define P_BIGDATA 0x01 /* overflow data */
124#define P_BIGKEY 0x02 /* overflow key */
125 u_char flags;
126 char bytes[1]; /* data */
127} BINTERNAL;
128
129/* Get the page's BINTERNAL structure at index indx. */
125#define GETBINTERNAL(pg, indx) \
130#define GETBINTERNAL(pg, indx) \
126 ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
127
128/* Get the number of bytes in the entry. */
131 ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
132
133/* Get the number of bytes in the entry. */
129#define NBINTERNAL(len) \
130 LALIGN(sizeof(size_t) + sizeof(pgno_t) + sizeof(u_char) + (len))
134#define NBINTERNAL(len) \
135 LALIGN(sizeof(u_int32_t) + sizeof(pgno_t) + sizeof(u_char) + (len))
131
132/* Copy a BINTERNAL entry to the page. */
136
137/* Copy a BINTERNAL entry to the page. */
133#define WR_BINTERNAL(p, size, pgno, flags) { \
134 *(size_t *)p = size; \
135 p += sizeof(size_t); \
136 *(pgno_t *)p = pgno; \
137 p += sizeof(pgno_t); \
138 *(u_char *)p = flags; \
139 p += sizeof(u_char); \
138#define WR_BINTERNAL(p, size, pgno, flags) { \
139 *(u_int32_t *)p = size; \
140 p += sizeof(u_int32_t); \
141 *(pgno_t *)p = pgno; \
142 p += sizeof(pgno_t); \
143 *(u_char *)p = flags; \
144 p += sizeof(u_char); \
140}
141
142/*
143 * For the recno internal pages, the item is a page number with the number of
144 * keys found on that page and below.
145 */
146typedef struct _rinternal {
147 recno_t nrecs; /* number of records */
148 pgno_t pgno; /* page number stored below */
149} RINTERNAL;
150
151/* Get the page's RINTERNAL structure at index indx. */
145}
146
147/*
148 * For the recno internal pages, the item is a page number with the number of
149 * keys found on that page and below.
150 */
151typedef struct _rinternal {
152 recno_t nrecs; /* number of records */
153 pgno_t pgno; /* page number stored below */
154} RINTERNAL;
155
156/* Get the page's RINTERNAL structure at index indx. */
152#define GETRINTERNAL(pg, indx) \
157#define GETRINTERNAL(pg, indx) \
153 ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
154
155/* Get the number of bytes in the entry. */
158 ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
159
160/* Get the number of bytes in the entry. */
156#define NRINTERNAL \
161#define NRINTERNAL \
157 LALIGN(sizeof(recno_t) + sizeof(pgno_t))
158
159/* Copy a RINTERAL entry to the page. */
162 LALIGN(sizeof(recno_t) + sizeof(pgno_t))
163
164/* Copy a RINTERAL entry to the page. */
160#define WR_RINTERNAL(p, nrecs, pgno) { \
161 *(recno_t *)p = nrecs; \
162 p += sizeof(recno_t); \
163 *(pgno_t *)p = pgno; \
165#define WR_RINTERNAL(p, nrecs, pgno) { \
166 *(recno_t *)p = nrecs; \
167 p += sizeof(recno_t); \
168 *(pgno_t *)p = pgno; \
164}
165
166/* For the btree leaf pages, the item is a key and data pair. */
167typedef struct _bleaf {
169}
170
171/* For the btree leaf pages, the item is a key and data pair. */
172typedef struct _bleaf {
168 size_t ksize; /* size of key */
169 size_t dsize; /* size of data */
173 u_int32_t ksize; /* size of key */
174 u_int32_t dsize; /* size of data */
170 u_char flags; /* P_BIGDATA, P_BIGKEY */
171 char bytes[1]; /* data */
172} BLEAF;
173
174/* Get the page's BLEAF structure at index indx. */
175 u_char flags; /* P_BIGDATA, P_BIGKEY */
176 char bytes[1]; /* data */
177} BLEAF;
178
179/* Get the page's BLEAF structure at index indx. */
175#define GETBLEAF(pg, indx) \
180#define GETBLEAF(pg, indx) \
176 ((BLEAF *)((char *)(pg) + (pg)->linp[indx]))
177
178/* Get the number of bytes in the entry. */
179#define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize)
180
181/* Get the number of bytes in the user's key/data pair. */
181 ((BLEAF *)((char *)(pg) + (pg)->linp[indx]))
182
183/* Get the number of bytes in the entry. */
184#define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize)
185
186/* Get the number of bytes in the user's key/data pair. */
182#define NBLEAFDBT(ksize, dsize) \
183 LALIGN(sizeof(size_t) + sizeof(size_t) + sizeof(u_char) + \
187#define NBLEAFDBT(ksize, dsize) \
188 LALIGN(sizeof(u_int32_t) + sizeof(u_int32_t) + sizeof(u_char) + \
184 (ksize) + (dsize))
185
186/* Copy a BLEAF entry to the page. */
189 (ksize) + (dsize))
190
191/* Copy a BLEAF entry to the page. */
187#define WR_BLEAF(p, key, data, flags) { \
188 *(size_t *)p = key->size; \
189 p += sizeof(size_t); \
190 *(size_t *)p = data->size; \
191 p += sizeof(size_t); \
192 *(u_char *)p = flags; \
193 p += sizeof(u_char); \
194 memmove(p, key->data, key->size); \
195 p += key->size; \
196 memmove(p, data->data, data->size); \
192#define WR_BLEAF(p, key, data, flags) { \
193 *(u_int32_t *)p = key->size; \
194 p += sizeof(u_int32_t); \
195 *(u_int32_t *)p = data->size; \
196 p += sizeof(u_int32_t); \
197 *(u_char *)p = flags; \
198 p += sizeof(u_char); \
199 memmove(p, key->data, key->size); \
200 p += key->size; \
201 memmove(p, data->data, data->size); \
197}
198
199/* For the recno leaf pages, the item is a data entry. */
200typedef struct _rleaf {
202}
203
204/* For the recno leaf pages, the item is a data entry. */
205typedef struct _rleaf {
201 size_t dsize; /* size of data */
206 u_int32_t dsize; /* size of data */
202 u_char flags; /* P_BIGDATA */
203 char bytes[1];
204} RLEAF;
205
206/* Get the page's RLEAF structure at index indx. */
207 u_char flags; /* P_BIGDATA */
208 char bytes[1];
209} RLEAF;
210
211/* Get the page's RLEAF structure at index indx. */
207#define GETRLEAF(pg, indx) \
212#define GETRLEAF(pg, indx) \
208 ((RLEAF *)((char *)(pg) + (pg)->linp[indx]))
209
210/* Get the number of bytes in the entry. */
211#define NRLEAF(p) NRLEAFDBT((p)->dsize)
212
213/* Get the number of bytes from the user's data. */
213 ((RLEAF *)((char *)(pg) + (pg)->linp[indx]))
214
215/* Get the number of bytes in the entry. */
216#define NRLEAF(p) NRLEAFDBT((p)->dsize)
217
218/* Get the number of bytes from the user's data. */
214#define NRLEAFDBT(dsize) \
215 LALIGN(sizeof(size_t) + sizeof(u_char) + (dsize))
219#define NRLEAFDBT(dsize) \
220 LALIGN(sizeof(u_int32_t) + sizeof(u_char) + (dsize))
216
217/* Copy a RLEAF entry to the page. */
221
222/* Copy a RLEAF entry to the page. */
218#define WR_RLEAF(p, data, flags) { \
219 *(size_t *)p = data->size; \
220 p += sizeof(size_t); \
221 *(u_char *)p = flags; \
222 p += sizeof(u_char); \
223 memmove(p, data->data, data->size); \
223#define WR_RLEAF(p, data, flags) { \
224 *(u_int32_t *)p = data->size; \
225 p += sizeof(u_int32_t); \
226 *(u_char *)p = flags; \
227 p += sizeof(u_char); \
228 memmove(p, data->data, data->size); \
224}
225
226/*
227 * A record in the tree is either a pointer to a page and an index in the page
228 * or a page number and an index. These structures are used as a cursor, stack
229 * entry and search returns as well as to pass records to other routines.
230 *
231 * One comment about searches. Internal page searches must find the largest
232 * record less than key in the tree so that descents work. Leaf page searches
233 * must find the smallest record greater than key so that the returned index
234 * is the record's correct position for insertion.
229}
230
231/*
232 * A record in the tree is either a pointer to a page and an index in the page
233 * or a page number and an index. These structures are used as a cursor, stack
234 * entry and search returns as well as to pass records to other routines.
235 *
236 * One comment about searches. Internal page searches must find the largest
237 * record less than key in the tree so that descents work. Leaf page searches
238 * must find the smallest record greater than key so that the returned index
239 * is the record's correct position for insertion.
235 *
236 * One comment about cursors. The cursor key is never removed from the tree,
237 * even if deleted. This is because it is quite difficult to decide where the
238 * cursor should be when other keys have been inserted/deleted in the tree;
239 * duplicate keys make it impossible. This scheme does require extra work
240 * though, to make sure that we don't perform an operation on a deleted key.
241 */
242typedef struct _epgno {
243 pgno_t pgno; /* the page number */
244 indx_t index; /* the index on the page */
245} EPGNO;
246
247typedef struct _epg {
248 PAGE *page; /* the (pinned) page */
249 indx_t index; /* the index on the page */
250} EPG;
251
252/*
240 */
241typedef struct _epgno {
242 pgno_t pgno; /* the page number */
243 indx_t index; /* the index on the page */
244} EPGNO;
245
246typedef struct _epg {
247 PAGE *page; /* the (pinned) page */
248 indx_t index; /* the index on the page */
249} EPG;
250
251/*
253 * The metadata of the tree. The m_nrecs field is used only by the RECNO code.
252 * About cursors. The cursor (and the page that contained the key/data pair
253 * that it referenced) can be deleted, which makes things a bit tricky. If
254 * there are no duplicates of the cursor key in the tree (i.e. B_NODUPS is set
255 * or there simply aren't any duplicates of the key) we copy the key that it
256 * referenced when it's deleted, and reacquire a new cursor key if the cursor
257 * is used again. If there are duplicates keys, we move to the next/previous
258 * key, and set a flag so that we know what happened. NOTE: if duplicate (to
259 * the cursor) keys are added to the tree during this process, it is undefined
260 * if they will be returned or not in a cursor scan.
261 *
262 * The flags determine the possible states of the cursor:
263 *
264 * CURS_INIT The cursor references *something*.
265 * CURS_ACQUIRE The cursor was deleted, and a key has been saved so that
266 * we can reacquire the right position in the tree.
267 * CURS_AFTER, CURS_BEFORE
268 * The cursor was deleted, and now references a key/data pair
269 * that has not yet been returned, either before or after the
270 * deleted key/data pair.
271 * XXX
272 * This structure is broken out so that we can eventually offer multiple
273 * cursors as part of the DB interface.
274 */
275typedef struct _cursor {
276 EPGNO pg; /* B: Saved tree reference. */
277 DBT key; /* B: Saved key, or key.data == NULL. */
278 recno_t rcursor; /* R: recno cursor (1-based) */
279
280#define CURS_ACQUIRE 0x01 /* B: Cursor needs to be reacquired. */
281#define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */
282#define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */
283#define CURS_INIT 0x08 /* RB: Cursor initialized. */
284 u_int8_t flags;
285} CURSOR;
286
287/*
288 * The metadata of the tree. The nrecs field is used only by the RECNO code.
254 * This is because the btree doesn't really need it and it requires that every
255 * put or delete call modify the metadata.
256 */
257typedef struct _btmeta {
289 * This is because the btree doesn't really need it and it requires that every
290 * put or delete call modify the metadata.
291 */
292typedef struct _btmeta {
258 u_int32_t m_magic; /* magic number */
259 u_int32_t m_version; /* version */
260 u_int32_t m_psize; /* page size */
261 u_int32_t m_free; /* page number of first free page */
262 u_int32_t m_nrecs; /* R: number of records */
293 u_int32_t magic; /* magic number */
294 u_int32_t version; /* version */
295 u_int32_t psize; /* page size */
296 u_int32_t free; /* page number of first free page */
297 u_int32_t nrecs; /* R: number of records */
298
263#define SAVEMETA (B_NODUPS | R_RECNO)
299#define SAVEMETA (B_NODUPS | R_RECNO)
264 u_int32_t m_flags; /* bt_flags & SAVEMETA */
265 u_int32_t m_unused; /* unused */
300 u_int32_t flags; /* bt_flags & SAVEMETA */
266} BTMETA;
267
268/* The in-memory btree/recno data structure. */
269typedef struct _btree {
301} BTMETA;
302
303/* The in-memory btree/recno data structure. */
304typedef struct _btree {
270 MPOOL *bt_mp; /* memory pool cookie */
305 MPOOL *bt_mp; /* memory pool cookie */
271
306
272 DB *bt_dbp; /* pointer to enclosing DB */
307 DB *bt_dbp; /* pointer to enclosing DB */
273
308
274 EPG bt_cur; /* current (pinned) page */
275 PAGE *bt_pinned; /* page pinned across calls */
309 EPG bt_cur; /* current (pinned) page */
310 PAGE *bt_pinned; /* page pinned across calls */
276
311
277 EPGNO bt_bcursor; /* B: btree cursor */
278 recno_t bt_rcursor; /* R: recno cursor (1-based) */
312 CURSOR bt_cursor; /* cursor */
279
313
280#define BT_POP(t) (t->bt_sp ? t->bt_stack + --t->bt_sp : NULL)
281#define BT_CLR(t) (t->bt_sp = 0)
282 EPGNO *bt_stack; /* stack of parent pages */
283 u_int bt_sp; /* current stack pointer */
284 u_int bt_maxstack; /* largest stack */
314#define BT_PUSH(t, p, i) { \
315 t->bt_sp->pgno = p; \
316 t->bt_sp->index = i; \
317 ++t->bt_sp; \
318}
319#define BT_POP(t) (t->bt_sp == t->bt_stack ? NULL : --t->bt_sp)
320#define BT_CLR(t) (t->bt_sp = t->bt_stack)
321 EPGNO bt_stack[50]; /* stack of parent pages */
322 EPGNO *bt_sp; /* current stack pointer */
285
323
286 char *bt_kbuf; /* key buffer */
287 size_t bt_kbufsz; /* key buffer size */
288 char *bt_dbuf; /* data buffer */
289 size_t bt_dbufsz; /* data buffer size */
324 DBT bt_rkey; /* returned key */
325 DBT bt_rdata; /* returned data */
290
326
291 int bt_fd; /* tree file descriptor */
327 int bt_fd; /* tree file descriptor */
292
328
293 pgno_t bt_free; /* next free page */
329 pgno_t bt_free; /* next free page */
294 u_int32_t bt_psize; /* page size */
330 u_int32_t bt_psize; /* page size */
295 indx_t bt_ovflsize; /* cut-off for key/data overflow */
296 int bt_lorder; /* byte order */
331 indx_t bt_ovflsize; /* cut-off for key/data overflow */
332 int bt_lorder; /* byte order */
297 /* sorted order */
298 enum { NOT, BACK, FORWARD } bt_order;
333 /* sorted order */
334 enum { NOT, BACK, FORWARD } bt_order;
299 EPGNO bt_last; /* last insert */
335 EPGNO bt_last; /* last insert */
300
301 /* B: key comparison function */
302 int (*bt_cmp) __P((const DBT *, const DBT *));
303 /* B: prefix comparison function */
304 size_t (*bt_pfx) __P((const DBT *, const DBT *));
305 /* R: recno input function */
306 int (*bt_irec) __P((struct _btree *, recno_t));
307
336
337 /* B: key comparison function */
338 int (*bt_cmp) __P((const DBT *, const DBT *));
339 /* B: prefix comparison function */
340 size_t (*bt_pfx) __P((const DBT *, const DBT *));
341 /* R: recno input function */
342 int (*bt_irec) __P((struct _btree *, recno_t));
343
308 FILE *bt_rfp; /* R: record FILE pointer */
309 int bt_rfd; /* R: record file descriptor */
344 FILE *bt_rfp; /* R: record FILE pointer */
345 int bt_rfd; /* R: record file descriptor */
310
346
311 caddr_t bt_cmap; /* R: current point in mapped space */
312 caddr_t bt_smap; /* R: start of mapped space */
313 caddr_t bt_emap; /* R: end of mapped space */
314 size_t bt_msize; /* R: size of mapped region. */
347 caddr_t bt_cmap; /* R: current point in mapped space */
348 caddr_t bt_smap; /* R: start of mapped space */
349 caddr_t bt_emap; /* R: end of mapped space */
350 size_t bt_msize; /* R: size of mapped region. */
315
351
316 recno_t bt_nrecs; /* R: number of records */
317 size_t bt_reclen; /* R: fixed record length */
318 u_char bt_bval; /* R: delimiting byte/pad character */
352 recno_t bt_nrecs; /* R: number of records */
353 size_t bt_reclen; /* R: fixed record length */
354 u_char bt_bval; /* R: delimiting byte/pad character */
319
320/*
321 * NB:
322 * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
323 */
355
356/*
357 * NB:
358 * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
359 */
324#define B_DELCRSR 0x00001 /* cursor has been deleted */
325#define B_INMEM 0x00002 /* in-memory tree */
326#define B_METADIRTY 0x00004 /* need to write metadata */
327#define B_MODIFIED 0x00008 /* tree modified */
328#define B_NEEDSWAP 0x00010 /* if byte order requires swapping */
360#define B_INMEM 0x00001 /* in-memory tree */
361#define B_METADIRTY 0x00002 /* need to write metadata */
362#define B_MODIFIED 0x00004 /* tree modified */
363#define B_NEEDSWAP 0x00008 /* if byte order requires swapping */
364#define B_RDONLY 0x00010 /* read-only tree */
365
329#define B_NODUPS 0x00020 /* no duplicate keys permitted */
366#define B_NODUPS 0x00020 /* no duplicate keys permitted */
330#define B_RDONLY 0x00040 /* read-only tree */
331#define R_RECNO 0x00080 /* record oriented tree */
367#define R_RECNO 0x00080 /* record oriented tree */
332#define B_SEQINIT 0x00100 /* sequential scan initialized */
333
368
334#define R_CLOSEFP 0x00200 /* opened a file pointer */
335#define R_EOF 0x00400 /* end of input file reached. */
336#define R_FIXLEN 0x00800 /* fixed length records */
337#define R_MEMMAPPED 0x01000 /* memory mapped file. */
338#define R_INMEM 0x02000 /* in-memory file */
339#define R_MODIFIED 0x04000 /* modified file */
340#define R_RDONLY 0x08000 /* read-only file */
369#define R_CLOSEFP 0x00040 /* opened a file pointer */
370#define R_EOF 0x00100 /* end of input file reached. */
371#define R_FIXLEN 0x00200 /* fixed length records */
372#define R_MEMMAPPED 0x00400 /* memory mapped file. */
373#define R_INMEM 0x00800 /* in-memory file */
374#define R_MODIFIED 0x01000 /* modified file */
375#define R_RDONLY 0x02000 /* read-only file */
341
376
342#define B_DB_LOCK 0x10000 /* DB_LOCK specified. */
343#define B_DB_SHMEM 0x20000 /* DB_SHMEM specified. */
344#define B_DB_TXN 0x40000 /* DB_TXN specified. */
345
346 u_int32_t bt_flags; /* btree state */
377#define B_DB_LOCK 0x04000 /* DB_LOCK specified. */
378#define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */
379#define B_DB_TXN 0x10000 /* DB_TXN specified. */
380 u_int32_t flags;
347} BTREE;
348
381} BTREE;
382
349#define SET(t, f) ((t)->bt_flags |= (f))
350#define CLR(t, f) ((t)->bt_flags &= ~(f))
351#define ISSET(t, f) ((t)->bt_flags & (f))
352
353#include "extern.h"
383#include "extern.h"