1:
2:
3:
4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34:
35: #ifndef _DB_H_
36: #define _DB_H_
37:
38: #include <sys/types.h>
39: #include <sys/cdefs.h>
40:
41: #include <limits.h>
42:
43: #define RET_ERROR -1
44: #define RET_SUCCESS 0
45: #define RET_SPECIAL 1
46:
47: #define MAX_PAGE_NUMBER 0xffffffff
48: typedef u_int32_t pgno_t;
49: #define MAX_PAGE_OFFSET 65535
50: typedef u_int16_t indx_t;
51: #define MAX_REC_NUMBER 0xffffffff
52: typedef u_int32_t recno_t;
53:
54:
55: typedef struct {
56: void *data;
57: size_t size;
58: } DBT;
59:
60:
61: #define R_CURSOR 1
62: #define __R_UNUSED 2
63: #define R_FIRST 3
64: #define R_IAFTER 4
65: #define R_IBEFORE 5
66: #define R_LAST 6
67: #define R_NEXT 7
68: #define R_NOOVERWRITE 8
69: #define R_PREV 9
70: #define R_SETCURSOR 10
71: #define R_RECNOSYNC 11
72:
73: typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
74:
75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87:
88: #if UINT_MAX > 65535
89: #define DB_LOCK 0x20000000
90: #define DB_SHMEM 0x40000000
91: #define DB_TXN 0x80000000
92: #else
93: #define DB_LOCK 0x2000
94: #define DB_SHMEM 0x4000
95: #define DB_TXN 0x8000
96: #endif
97:
98:
99: typedef struct __db {
100: DBTYPE type;
101: int (*close)(struct __db *);
102: int (*del)(const struct __db *, const DBT *, unsigned int);
103: int (*get)(const struct __db *, const DBT *, DBT *, unsigned int);
104: int (*put)(const struct __db *, DBT *, const DBT *, unsigned int);
105: int (*seq)(const struct __db *, DBT *, DBT *, unsigned int);
106: int (*sync)(const struct __db *, unsigned int);
107: void *internal;
108: int (*fd)(const struct __db *);
109: } DB;
110:
111: #define BTREEMAGIC 0x053162
112: #define BTREEVERSION 3
113:
114:
115: typedef struct {
116: #define R_DUP 0x01
117: unsigned long flags;
118: unsigned int cachesize;
119: int maxkeypage;
120: int minkeypage;
121: unsigned int psize;
122: int (*compare)
123: (const DBT *, const DBT *);
124: size_t (*prefix)
125: (const DBT *, const DBT *);
126: int lorder;
127: } BTREEINFO;
128:
129: #define HASHMAGIC 0x061561
130: #define HASHVERSION 2
131:
132:
133: typedef struct {
134: unsigned int bsize;
135: unsigned int ffactor;
136: unsigned int nelem;
137: unsigned int cachesize;
138: u_int32_t
139: (*hash)(const void *, size_t);
140: int lorder;
141: } HASHINFO;
142:
143:
144: typedef struct {
145: #define R_FIXEDLEN 0x01
146: #define R_NOKEY 0x02
147: #define R_SNAPSHOT 0x04
148: unsigned long flags;
149: unsigned int cachesize;
150: unsigned int psize;
151: int lorder;
152: size_t reclen; 153:
154: unsigned char bval; 155:
156: char *bfname;
157: } RECNOINFO;
158:
159: #ifdef __DBINTERFACE_PRIVATE
160: 161: 162: 163: 164: 165:
166: #define M_32_SWAP(a) { \
167: u_int32_t _tmp = a; \
168: ((char *)&a)[0] = ((char *)&_tmp)[3]; \
169: ((char *)&a)[1] = ((char *)&_tmp)[2]; \
170: ((char *)&a)[2] = ((char *)&_tmp)[1]; \
171: ((char *)&a)[3] = ((char *)&_tmp)[0]; \
172: }
173: #define P_32_SWAP(a) { \
174: u_int32_t _tmp = *(u_int32_t *)a; \
175: ((char *)a)[0] = ((char *)&_tmp)[3]; \
176: ((char *)a)[1] = ((char *)&_tmp)[2]; \
177: ((char *)a)[2] = ((char *)&_tmp)[1]; \
178: ((char *)a)[3] = ((char *)&_tmp)[0]; \
179: }
180: #define P_32_COPY(a, b) { \
181: ((char *)&(b))[0] = ((char *)&(a))[3]; \
182: ((char *)&(b))[1] = ((char *)&(a))[2]; \
183: ((char *)&(b))[2] = ((char *)&(a))[1]; \
184: ((char *)&(b))[3] = ((char *)&(a))[0]; \
185: }
186:
187: 188: 189: 190: 191: 192:
193: #define M_16_SWAP(a) { \
194: u_int16_t _tmp = a; \
195: ((char *)&a)[0] = ((char *)&_tmp)[1]; \
196: ((char *)&a)[1] = ((char *)&_tmp)[0]; \
197: }
198: #define P_16_SWAP(a) { \
199: u_int16_t _tmp = *(u_int16_t *)a; \
200: ((char *)a)[0] = ((char *)&_tmp)[1]; \
201: ((char *)a)[1] = ((char *)&_tmp)[0]; \
202: }
203: #define P_16_COPY(a, b) { \
204: ((char *)&(b))[0] = ((char *)&(a))[1]; \
205: ((char *)&(b))[1] = ((char *)&(a))[0]; \
206: }
207: #endif
208:
209: __BEGIN_DECLS
210: DB *dbopen(const char *, int, int, DBTYPE, const void *);
211:
212: #ifdef __DBINTERFACE_PRIVATE
213: DB *__bt_open(const char *, int, int, const BTREEINFO *, int);
214: DB *__hash_open(const char *, int, int, const HASHINFO *, int);
215: DB *__rec_open(const char *, int, int, const RECNOINFO *, int);
216: void __dbpanic(DB *dbp);
217: #endif
218: __END_DECLS
219: #endif