db.h revision 1.5 1 1.1 cgd /*-
2 1.1 cgd * Copyright (c) 1990 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.3 proven * @(#)db.h 5.21 (Berkeley) 2/14/93
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd #ifndef _DB_H_
37 1.1 cgd #define _DB_H_
38 1.1 cgd
39 1.3 proven #include <sys/types.h>
40 1.1 cgd #include <sys/cdefs.h>
41 1.5 proven #include <machine/endian.h>
42 1.1 cgd
43 1.3 proven #define RET_ERROR -1 /* Return values. */
44 1.3 proven #define RET_SUCCESS 0
45 1.3 proven #define RET_SPECIAL 1
46 1.3 proven
47 1.3 proven #define MAX_PAGE_NUMBER ULONG_MAX /* >= # of pages in a file */
48 1.3 proven typedef u_long pgno_t;
49 1.3 proven #define MAX_PAGE_OFFSET USHRT_MAX /* >= # of bytes in a page */
50 1.3 proven typedef u_short indx_t;
51 1.3 proven #define MAX_REC_NUMBER ULONG_MAX /* >= # of records in a tree */
52 1.3 proven typedef u_long recno_t;
53 1.3 proven
54 1.3 proven /* Key/data structure -- a Data-Base Thang. */
55 1.1 cgd typedef struct {
56 1.3 proven void *data; /* data */
57 1.3 proven size_t size; /* data length */
58 1.1 cgd } DBT;
59 1.1 cgd
60 1.3 proven /* Routine flags. */
61 1.3 proven #define R_CURSOR 1 /* del, put, seq */
62 1.3 proven #define R_CURSORLOG 2 /* put (RECNO) */
63 1.3 proven #define R_FIRST 3 /* seq */
64 1.3 proven #define R_IAFTER 4 /* put (RECNO) */
65 1.3 proven #define R_IBEFORE 5 /* put (RECNO) */
66 1.3 proven #define R_LAST 6 /* seq (BTREE, RECNO) */
67 1.3 proven #define R_NEXT 7 /* seq */
68 1.3 proven #define R_NOOVERWRITE 8 /* put */
69 1.3 proven #define R_PREV 9 /* seq (BTREE, RECNO) */
70 1.3 proven #define R_SETCURSOR 10 /* put (RECNO) */
71 1.3 proven
72 1.3 proven typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
73 1.3 proven
74 1.3 proven #define __USE_OPEN_FLAGS \
75 1.3 proven (O_CREAT|O_EXCL|O_EXLOCK|O_RDONLY|O_RDWR|O_SHLOCK|O_TRUNC)
76 1.3 proven
77 1.3 proven /* Access method description structure. */
78 1.1 cgd typedef struct __db {
79 1.3 proven DBTYPE type; /* underlying db type */
80 1.3 proven int (*close) __P((struct __db *));
81 1.3 proven int (*del) __P((const struct __db *, const DBT *, u_int));
82 1.3 proven int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
83 1.3 proven int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
84 1.3 proven int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
85 1.3 proven int (*sync) __P((const struct __db *));
86 1.3 proven void *internal; /* access method private */
87 1.1 cgd } DB;
88 1.1 cgd
89 1.1 cgd #define BTREEMAGIC 0x053162
90 1.3 proven #define BTREEVERSION 3
91 1.1 cgd
92 1.3 proven /* Structure used to pass parameters to the btree routines. */
93 1.1 cgd typedef struct {
94 1.1 cgd #define R_DUP 0x01 /* duplicate keys */
95 1.1 cgd u_long flags;
96 1.1 cgd int cachesize; /* bytes to cache */
97 1.3 proven int maxkeypage; /* maximum keys per page */
98 1.3 proven int minkeypage; /* minimum keys per page */
99 1.1 cgd int psize; /* page size */
100 1.3 proven /* comparison, prefix functions */
101 1.3 proven int (*compare) __P((const DBT *, const DBT *));
102 1.3 proven int (*prefix) __P((const DBT *, const DBT *));
103 1.1 cgd int lorder; /* byte order */
104 1.1 cgd } BTREEINFO;
105 1.1 cgd
106 1.1 cgd #define HASHMAGIC 0x061561
107 1.3 proven #define HASHVERSION 2
108 1.1 cgd
109 1.3 proven /* Structure used to pass parameters to the hashing routines. */
110 1.1 cgd typedef struct {
111 1.1 cgd int bsize; /* bucket size */
112 1.1 cgd int ffactor; /* fill factor */
113 1.1 cgd int nelem; /* number of elements */
114 1.1 cgd int cachesize; /* bytes to cache */
115 1.1 cgd int (*hash)(); /* hash function */
116 1.1 cgd int lorder; /* byte order */
117 1.1 cgd } HASHINFO;
118 1.1 cgd
119 1.3 proven /* Structure used to pass parameters to the record routines. */
120 1.1 cgd typedef struct {
121 1.1 cgd #define R_FIXEDLEN 0x01 /* fixed-length records */
122 1.3 proven #define R_NOKEY 0x02 /* key not required */
123 1.3 proven #define R_SNAPSHOT 0x04 /* snapshot the input */
124 1.1 cgd u_long flags;
125 1.1 cgd int cachesize; /* bytes to cache */
126 1.3 proven int lorder; /* byte order */
127 1.1 cgd size_t reclen; /* record length (fixed-length records) */
128 1.1 cgd u_char bval; /* delimiting byte (variable-length records */
129 1.1 cgd } RECNOINFO;
130 1.1 cgd
131 1.3 proven /* Key structure for the record routines. */
132 1.1 cgd typedef struct {
133 1.1 cgd u_long number;
134 1.1 cgd u_long offset;
135 1.1 cgd u_long length;
136 1.1 cgd #define R_LENGTH 0x01 /* length is valid */
137 1.1 cgd #define R_NUMBER 0x02 /* record number is valid */
138 1.1 cgd #define R_OFFSET 0x04 /* offset is valid */
139 1.1 cgd u_char valid;
140 1.1 cgd } RECNOKEY;
141 1.1 cgd
142 1.3 proven /*
143 1.3 proven * Little endian <==> big endian long swap macros.
144 1.3 proven * BLSWAP swap a memory location
145 1.3 proven * BLPSWAP swap a referenced memory location
146 1.3 proven * BLSWAP_COPY swap from one location to another
147 1.3 proven */
148 1.5 proven #define BLSWAP(a) { a = __byte_swap_long(a); }
149 1.5 proven #define BLPSWAP(a) BLSWAP((*a))
150 1.5 proven #define BLSWAP_COPY(a, b) { b = __byte_swap_long(a); }
151 1.3 proven
152 1.3 proven /*
153 1.3 proven * Little endian <==> big endian short swap macros.
154 1.3 proven * BSSWAP swap a memory location
155 1.3 proven * BSPSWAP swap a referenced memory location
156 1.3 proven * BSSWAP_COPY swap from one location to another
157 1.3 proven */
158 1.5 proven #define BSSWAP(a) { a = __byte_swap_word(a); }
159 1.5 proven #define BSPSWAP(a) BSSWAP((*a))
160 1.5 proven #define BSSWAP_COPY(a, b) { b = __byte_swap_word(a); }
161 1.1 cgd
162 1.1 cgd __BEGIN_DECLS
163 1.3 proven DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
164 1.3 proven
165 1.3 proven #ifdef __DBINTERFACE_PRIVATE
166 1.3 proven DB *__bt_open __P((const char *, int, int, const BTREEINFO *));
167 1.3 proven DB *__hash_open __P((const char *, int, int, const HASHINFO *));
168 1.3 proven DB *__rec_open __P((const char *, int, int, const RECNOINFO *));
169 1.3 proven void __dbpanic __P((DB *dbp));
170 1.3 proven #endif
171 1.1 cgd __END_DECLS
172 1.1 cgd #endif /* !_DB_H_ */
173