Commit | Line | Data |
---|---|---|
1b1a0c94 KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | * | |
cdea9228 | 7 | * @(#)db.h 5.20 (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 | ||
8d43ae1a KB |
16 | #define RET_ERROR -1 /* Return values. */ |
17 | #define RET_SUCCESS 0 | |
18 | #define RET_SPECIAL 1 | |
19 | ||
20 | #define MAX_PAGE_NUMBER ULONG_MAX /* >= # of pages in a file */ | |
a3dd2fa9 | 21 | typedef u_long pgno_t; |
8d43ae1a | 22 | #define MAX_PAGE_OFFSET USHRT_MAX /* >= # of bytes in a page */ |
a3dd2fa9 | 23 | typedef u_short index_t; |
8d43ae1a | 24 | #define MAX_REC_NUMBER ULONG_MAX /* >= # of records in a tree */ |
a3dd2fa9 | 25 | typedef u_long recno_t; |
8d43ae1a KB |
26 | |
27 | /* Key/data structure -- a Data-Base Thang. */ | |
28 | typedef struct { | |
29 | void *data; /* data */ | |
30 | size_t size; /* data length */ | |
31 | } DBT; | |
32 | ||
ab7c24ac | 33 | /* Routine flags. */ |
a802d95b KB |
34 | #define R_CURSOR 1 /* del, put, seq */ |
35 | #define R_CURSORLOG 2 /* put (RECNO) */ | |
ab7c24ac KB |
36 | #define R_FIRST 3 /* seq */ |
37 | #define R_IAFTER 4 /* put (RECNO) */ | |
38 | #define R_IBEFORE 5 /* put (RECNO) */ | |
39 | #define R_LAST 6 /* seq (BTREE, RECNO) */ | |
40 | #define R_NEXT 7 /* seq */ | |
41 | #define R_NOOVERWRITE 8 /* put */ | |
42 | #define R_PREV 9 /* seq (BTREE, RECNO) */ | |
a802d95b | 43 | #define R_SETCURSOR 10 /* put (RECNO) */ |
1b1a0c94 | 44 | |
8d43ae1a | 45 | typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; |
1b1a0c94 | 46 | |
cdea9228 KB |
47 | #define __USE_OPEN_FLAGS \ |
48 | (O_CREAT|O_EXCL|O_EXLOCK|O_RDONLY|O_RDWR|O_SHLOCK|O_TRUNC) | |
49 | ||
8d43ae1a | 50 | /* Access method description structure. */ |
a528d733 | 51 | typedef struct __db { |
11b5f055 | 52 | DBTYPE type; /* underlying db type */ |
8d43ae1a | 53 | int (*close) __P((struct __db *)); |
a3dd2fa9 KB |
54 | int (*del) __P((const struct __db *, const DBT *, u_int)); |
55 | int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); | |
a802d95b | 56 | int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); |
a3dd2fa9 | 57 | int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); |
8d43ae1a | 58 | int (*sync) __P((const struct __db *)); |
11b5f055 | 59 | void *internal; /* access method private */ |
1b1a0c94 KB |
60 | } DB; |
61 | ||
62 | #define BTREEMAGIC 0x053162 | |
8d43ae1a | 63 | #define BTREEVERSION 3 |
1b1a0c94 | 64 | |
8d43ae1a | 65 | /* Structure used to pass parameters to the btree routines. */ |
1b1a0c94 KB |
66 | typedef struct { |
67 | #define R_DUP 0x01 /* duplicate keys */ | |
a3dd2fa9 | 68 | u_long flags; |
1b1a0c94 | 69 | int cachesize; /* bytes to cache */ |
8d43ae1a KB |
70 | int maxkeypage; /* maximum keys per page */ |
71 | int minkeypage; /* minimum keys per page */ | |
1b1a0c94 | 72 | int psize; /* page size */ |
8d43ae1a KB |
73 | /* comparison, prefix functions */ |
74 | int (*compare) __P((const DBT *, const DBT *)); | |
75 | int (*prefix) __P((const DBT *, const DBT *)); | |
dd8e004c | 76 | int lorder; /* byte order */ |
1b1a0c94 KB |
77 | } BTREEINFO; |
78 | ||
79 | #define HASHMAGIC 0x061561 | |
fa208463 | 80 | #define HASHVERSION 2 |
1b1a0c94 | 81 | |
8d43ae1a | 82 | /* Structure used to pass parameters to the hashing routines. */ |
1b1a0c94 KB |
83 | typedef struct { |
84 | int bsize; /* bucket size */ | |
85 | int ffactor; /* fill factor */ | |
86 | int nelem; /* number of elements */ | |
dab76def | 87 | int cachesize; /* bytes to cache */ |
1b1a0c94 | 88 | int (*hash)(); /* hash function */ |
dd8e004c | 89 | int lorder; /* byte order */ |
1b1a0c94 KB |
90 | } HASHINFO; |
91 | ||
8d43ae1a | 92 | /* Structure used to pass parameters to the record routines. */ |
1b1a0c94 KB |
93 | typedef struct { |
94 | #define R_FIXEDLEN 0x01 /* fixed-length records */ | |
8d43ae1a KB |
95 | #define R_NOKEY 0x02 /* key not required */ |
96 | #define R_SNAPSHOT 0x04 /* snapshot the input */ | |
a3dd2fa9 | 97 | u_long flags; |
1b1a0c94 | 98 | int cachesize; /* bytes to cache */ |
8d43ae1a | 99 | int lorder; /* byte order */ |
1b1a0c94 | 100 | size_t reclen; /* record length (fixed-length records) */ |
a3dd2fa9 | 101 | u_char bval; /* delimiting byte (variable-length records */ |
1b1a0c94 KB |
102 | } RECNOINFO; |
103 | ||
8d43ae1a | 104 | /* Key structure for the record routines. */ |
1b1a0c94 | 105 | typedef struct { |
a3dd2fa9 KB |
106 | u_long number; |
107 | u_long offset; | |
108 | u_long length; | |
1b1a0c94 KB |
109 | #define R_LENGTH 0x01 /* length is valid */ |
110 | #define R_NUMBER 0x02 /* record number is valid */ | |
111 | #define R_OFFSET 0x04 /* offset is valid */ | |
a3dd2fa9 | 112 | u_char valid; |
1b1a0c94 KB |
113 | } RECNOKEY; |
114 | ||
ab7c24ac KB |
115 | /* |
116 | * Little endian <==> big endian long swap macros. | |
117 | * BLSWAP swap a memory location | |
118 | * BLPSWAP swap a referenced memory location | |
119 | * BLSWAP_COPY swap from one location to another | |
120 | */ | |
dd8e004c | 121 | #define BLSWAP(a) { \ |
a3dd2fa9 | 122 | u_long _tmp = a; \ |
dd8e004c KB |
123 | ((char *)&a)[0] = ((char *)&_tmp)[3]; \ |
124 | ((char *)&a)[1] = ((char *)&_tmp)[2]; \ | |
125 | ((char *)&a)[2] = ((char *)&_tmp)[1]; \ | |
126 | ((char *)&a)[3] = ((char *)&_tmp)[0]; \ | |
127 | } | |
ab7c24ac | 128 | #define BLPSWAP(a) { \ |
a3dd2fa9 | 129 | u_long _tmp = *(u_long *)a; \ |
ab7c24ac KB |
130 | ((char *)a)[0] = ((char *)&_tmp)[3]; \ |
131 | ((char *)a)[1] = ((char *)&_tmp)[2]; \ | |
132 | ((char *)a)[2] = ((char *)&_tmp)[1]; \ | |
133 | ((char *)a)[3] = ((char *)&_tmp)[0]; \ | |
134 | } | |
135 | #define BLSWAP_COPY(a, b) { \ | |
dd8e004c KB |
136 | ((char *)&(b))[0] = ((char *)&(a))[3]; \ |
137 | ((char *)&(b))[1] = ((char *)&(a))[2]; \ | |
138 | ((char *)&(b))[2] = ((char *)&(a))[1]; \ | |
139 | ((char *)&(b))[3] = ((char *)&(a))[0]; \ | |
140 | } | |
141 | ||
ab7c24ac KB |
142 | /* |
143 | * Little endian <==> big endian short swap macros. | |
144 | * BSSWAP swap a memory location | |
145 | * BSPSWAP swap a referenced memory location | |
146 | * BSSWAP_COPY swap from one location to another | |
147 | */ | |
dd8e004c | 148 | #define BSSWAP(a) { \ |
a3dd2fa9 | 149 | u_short _tmp = a; \ |
dd8e004c KB |
150 | ((char *)&a)[0] = ((char *)&_tmp)[1]; \ |
151 | ((char *)&a)[1] = ((char *)&_tmp)[0]; \ | |
152 | } | |
ab7c24ac | 153 | #define BSPSWAP(a) { \ |
a3dd2fa9 | 154 | u_short _tmp = *(u_short *)a; \ |
ab7c24ac KB |
155 | ((char *)a)[0] = ((char *)&_tmp)[1]; \ |
156 | ((char *)a)[1] = ((char *)&_tmp)[0]; \ | |
157 | } | |
158 | #define BSSWAP_COPY(a, b) { \ | |
dd8e004c KB |
159 | ((char *)&(b))[0] = ((char *)&(a))[1]; \ |
160 | ((char *)&(b))[1] = ((char *)&(a))[0]; \ | |
161 | } | |
162 | ||
dd8e004c | 163 | __BEGIN_DECLS |
8d43ae1a KB |
164 | DB *dbopen __P((const char *, int, int, DBTYPE, const void *)); |
165 | ||
166 | #ifdef __DBINTERFACE_PRIVATE | |
167 | DB *__bt_open __P((const char *, int, int, const BTREEINFO *)); | |
168 | DB *__hash_open __P((const char *, int, int, const HASHINFO *)); | |
169 | DB *__rec_open __P((const char *, int, int, const RECNOINFO *)); | |
170 | void __dbpanic __P((DB *dbp)); | |
171 | #endif | |
dd8e004c | 172 | __END_DECLS |
dd8e004c | 173 | #endif /* !_DB_H_ */ |