Commit | Line | Data |
---|---|---|
1b1a0c94 | 1 | /*- |
56559b70 KB |
2 | * Copyright (c) 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
1b1a0c94 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
6 | * | |
8ec0a6c3 | 7 | * @(#)db.h 8.3 (Berkeley) %G% |
1b1a0c94 KB |
8 | */ |
9 | ||
dd8e004c KB |
10 | #ifndef _DB_H_ |
11 | #define _DB_H_ | |
12 | ||
6f4e6f9c | 13 | #include <sys/types.h> |
a528d733 KB |
14 | #include <sys/cdefs.h> |
15 | ||
19a5aa6a KB |
16 | #include <limits.h> |
17 | ||
8d43ae1a KB |
18 | #define RET_ERROR -1 /* Return values. */ |
19 | #define RET_SUCCESS 0 | |
20 | #define RET_SPECIAL 1 | |
21 | ||
22 | #define MAX_PAGE_NUMBER ULONG_MAX /* >= # of pages in a file */ | |
a3dd2fa9 | 23 | typedef u_long pgno_t; |
8d43ae1a | 24 | #define MAX_PAGE_OFFSET USHRT_MAX /* >= # of bytes in a page */ |
93a5373b | 25 | typedef u_short indx_t; |
8d43ae1a | 26 | #define MAX_REC_NUMBER ULONG_MAX /* >= # of records in a tree */ |
a3dd2fa9 | 27 | typedef u_long recno_t; |
8d43ae1a KB |
28 | |
29 | /* Key/data structure -- a Data-Base Thang. */ | |
30 | typedef struct { | |
31 | void *data; /* data */ | |
32 | size_t size; /* data length */ | |
33 | } DBT; | |
34 | ||
ab7c24ac | 35 | /* Routine flags. */ |
a802d95b | 36 | #define R_CURSOR 1 /* del, put, seq */ |
8b10626b | 37 | #define __R_UNUSED 2 /* UNUSED */ |
ab7c24ac KB |
38 | #define R_FIRST 3 /* seq */ |
39 | #define R_IAFTER 4 /* put (RECNO) */ | |
40 | #define R_IBEFORE 5 /* put (RECNO) */ | |
41 | #define R_LAST 6 /* seq (BTREE, RECNO) */ | |
42 | #define R_NEXT 7 /* seq */ | |
43 | #define R_NOOVERWRITE 8 /* put */ | |
44 | #define R_PREV 9 /* seq (BTREE, RECNO) */ | |
a802d95b | 45 | #define R_SETCURSOR 10 /* put (RECNO) */ |
4c94d216 | 46 | #define R_RECNOSYNC 11 /* sync (RECNO) */ |
1b1a0c94 | 47 | |
8d43ae1a | 48 | typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; |
1b1a0c94 | 49 | |
19a5aa6a KB |
50 | /* |
51 | * !!! | |
52 | * The following flags are included in the dbopen(3) call as part of the | |
53 | * open(2) flags. In order to avoid conflicts with the open flags, start | |
54 | * at the top of the 16 or 32-bit number space and work our way down. If | |
55 | * the open flags were significantly expanded in the future, it could be | |
56 | * a problem. Wish I'd left another flags word in the dbopen call. | |
57 | * | |
58 | * !!! | |
59 | * None of this stuff is implemented yet. The only reason that it's here | |
60 | * is so that the access methods can skip copying the key/data pair when | |
61 | * the DB_LOCK flag isn't set. | |
62 | */ | |
63 | #if UINT_MAX > 65535 | |
64 | #define DB_LOCK 0x20000000 /* Do locking. */ | |
65 | #define DB_SHMEM 0x40000000 /* Use shared memory. */ | |
66 | #define DB_TXN 0x80000000 /* Do transactions. */ | |
67 | #else | |
68 | #define DB_LOCK 0x00002000 /* Do locking. */ | |
69 | #define DB_SHMEM 0x00004000 /* Use shared memory. */ | |
70 | #define DB_TXN 0x00008000 /* Do transactions. */ | |
71 | #endif | |
cdea9228 | 72 | |
8d43ae1a | 73 | /* Access method description structure. */ |
a528d733 | 74 | typedef struct __db { |
19a5aa6a | 75 | DBTYPE type; /* Underlying db type. */ |
8d43ae1a | 76 | int (*close) __P((struct __db *)); |
a3dd2fa9 KB |
77 | int (*del) __P((const struct __db *, const DBT *, u_int)); |
78 | int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); | |
a802d95b | 79 | int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); |
a3dd2fa9 | 80 | int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); |
4c94d216 | 81 | int (*sync) __P((const struct __db *, u_int)); |
8ec0a6c3 KB |
82 | void *internal; /* Access method private. */ |
83 | int (*fd) __P((const struct __db *)); | |
1b1a0c94 KB |
84 | } DB; |
85 | ||
86 | #define BTREEMAGIC 0x053162 | |
8d43ae1a | 87 | #define BTREEVERSION 3 |
1b1a0c94 | 88 | |
8d43ae1a | 89 | /* Structure used to pass parameters to the btree routines. */ |
1b1a0c94 KB |
90 | typedef struct { |
91 | #define R_DUP 0x01 /* duplicate keys */ | |
4c94d216 KB |
92 | u_long flags; |
93 | int cachesize; /* bytes to cache */ | |
94 | int maxkeypage; /* maximum keys per page */ | |
95 | int minkeypage; /* minimum keys per page */ | |
96 | int psize; /* page size */ | |
8d43ae1a | 97 | /* comparison, prefix functions */ |
4c94d216 KB |
98 | int (*compare) __P((const DBT *, const DBT *)); |
99 | int (*prefix) __P((const DBT *, const DBT *)); | |
100 | int lorder; /* byte order */ | |
1b1a0c94 KB |
101 | } BTREEINFO; |
102 | ||
103 | #define HASHMAGIC 0x061561 | |
fa208463 | 104 | #define HASHVERSION 2 |
1b1a0c94 | 105 | |
8d43ae1a | 106 | /* Structure used to pass parameters to the hashing routines. */ |
1b1a0c94 | 107 | typedef struct { |
4c94d216 KB |
108 | int bsize; /* bucket size */ |
109 | int ffactor; /* fill factor */ | |
110 | int nelem; /* number of elements */ | |
111 | int cachesize; /* bytes to cache */ | |
112 | /* hash function */ | |
113 | int (*hash) __P((const void *, size_t)); | |
114 | int lorder; /* byte order */ | |
1b1a0c94 KB |
115 | } HASHINFO; |
116 | ||
8d43ae1a | 117 | /* Structure used to pass parameters to the record routines. */ |
1b1a0c94 KB |
118 | typedef struct { |
119 | #define R_FIXEDLEN 0x01 /* fixed-length records */ | |
8d43ae1a KB |
120 | #define R_NOKEY 0x02 /* key not required */ |
121 | #define R_SNAPSHOT 0x04 /* snapshot the input */ | |
4c94d216 KB |
122 | u_long flags; |
123 | int cachesize; /* bytes to cache */ | |
2436b2e2 | 124 | int psize; /* page size */ |
4c94d216 KB |
125 | int lorder; /* byte order */ |
126 | size_t reclen; /* record length (fixed-length records) */ | |
127 | u_char bval; /* delimiting byte (variable-length records */ | |
128 | char *bfname; /* btree file name */ | |
1b1a0c94 KB |
129 | } RECNOINFO; |
130 | ||
ab7c24ac KB |
131 | /* |
132 | * Little endian <==> big endian long swap macros. | |
133 | * BLSWAP swap a memory location | |
134 | * BLPSWAP swap a referenced memory location | |
135 | * BLSWAP_COPY swap from one location to another | |
136 | */ | |
19a5aa6a KB |
137 | #define BLSWAP(a) { \ |
138 | u_long _tmp = a; \ | |
139 | ((char *)&a)[0] = ((char *)&_tmp)[3]; \ | |
140 | ((char *)&a)[1] = ((char *)&_tmp)[2]; \ | |
141 | ((char *)&a)[2] = ((char *)&_tmp)[1]; \ | |
142 | ((char *)&a)[3] = ((char *)&_tmp)[0]; \ | |
dd8e004c | 143 | } |
19a5aa6a KB |
144 | #define BLPSWAP(a) { \ |
145 | u_long _tmp = *(u_long *)a; \ | |
146 | ((char *)a)[0] = ((char *)&_tmp)[3]; \ | |
147 | ((char *)a)[1] = ((char *)&_tmp)[2]; \ | |
148 | ((char *)a)[2] = ((char *)&_tmp)[1]; \ | |
149 | ((char *)a)[3] = ((char *)&_tmp)[0]; \ | |
ab7c24ac | 150 | } |
19a5aa6a KB |
151 | #define BLSWAP_COPY(a, b) { \ |
152 | ((char *)&(b))[0] = ((char *)&(a))[3]; \ | |
153 | ((char *)&(b))[1] = ((char *)&(a))[2]; \ | |
154 | ((char *)&(b))[2] = ((char *)&(a))[1]; \ | |
155 | ((char *)&(b))[3] = ((char *)&(a))[0]; \ | |
dd8e004c KB |
156 | } |
157 | ||
ab7c24ac KB |
158 | /* |
159 | * Little endian <==> big endian short swap macros. | |
160 | * BSSWAP swap a memory location | |
161 | * BSPSWAP swap a referenced memory location | |
162 | * BSSWAP_COPY swap from one location to another | |
163 | */ | |
19a5aa6a KB |
164 | #define BSSWAP(a) { \ |
165 | u_short _tmp = a; \ | |
166 | ((char *)&a)[0] = ((char *)&_tmp)[1]; \ | |
167 | ((char *)&a)[1] = ((char *)&_tmp)[0]; \ | |
dd8e004c | 168 | } |
19a5aa6a KB |
169 | #define BSPSWAP(a) { \ |
170 | u_short _tmp = *(u_short *)a; \ | |
171 | ((char *)a)[0] = ((char *)&_tmp)[1]; \ | |
172 | ((char *)a)[1] = ((char *)&_tmp)[0]; \ | |
ab7c24ac | 173 | } |
19a5aa6a KB |
174 | #define BSSWAP_COPY(a, b) { \ |
175 | ((char *)&(b))[0] = ((char *)&(a))[1]; \ | |
176 | ((char *)&(b))[1] = ((char *)&(a))[0]; \ | |
dd8e004c KB |
177 | } |
178 | ||
dd8e004c | 179 | __BEGIN_DECLS |
8d43ae1a KB |
180 | DB *dbopen __P((const char *, int, int, DBTYPE, const void *)); |
181 | ||
182 | #ifdef __DBINTERFACE_PRIVATE | |
19a5aa6a KB |
183 | DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int)); |
184 | DB *__hash_open __P((const char *, int, int, const HASHINFO *, int)); | |
185 | DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int)); | |
8d43ae1a KB |
186 | void __dbpanic __P((DB *dbp)); |
187 | #endif | |
dd8e004c | 188 | __END_DECLS |
dd8e004c | 189 | #endif /* !_DB_H_ */ |