| 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 |
|
| 36 |
#ifndef _DB_H |
| 37 |
#define _DB_H 1 |
| 38 |
|
| 39 |
#include <sys/types.h> |
| 40 |
|
| 41 |
#include <limits.h> |
| 42 |
|
| 43 |
#ifdef __DBINTERFACE_PRIVATE |
| 44 |
#include <compat.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifdef SOLARIS |
| 48 |
#include "solaris-compat/compat.h" |
| 49 |
#endif |
| 50 |
|
| 51 |
#define RET_ERROR -1 |
| 52 |
#define RET_SUCCESS 0 |
| 53 |
#define RET_SPECIAL 1 |
| 54 |
|
| 55 |
#ifndef __BIT_TYPES_DEFINED__ |
| 56 |
#define __BIT_TYPES_DEFINED__ |
| 57 |
#if (!defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__)) |
| 58 |
typedef __signed char int8_t; |
| 59 |
typedef short int16_t; |
| 60 |
typedef int int32_t; |
| 61 |
typedef unsigned char u_int8_t; |
| 62 |
typedef unsigned short u_int16_t; |
| 63 |
typedef unsigned int u_int32_t; |
| 64 |
#ifdef WE_DONT_NEED_QUADS |
| 65 |
typedef long long int64_t; |
| 66 |
typedef unsigned long long u_int64_t; |
| 67 |
#endif |
| 68 |
#endif |
| 69 |
#endif |
| 70 |
|
| 71 |
#ifdef SOLARIS |
| 72 |
#define __P(p) p |
| 73 |
#define __BEGIN_DECLS |
| 74 |
#define __END_DECLS |
| 75 |
#endif |
| 76 |
|
| 77 |
#define MAX_PAGE_NUMBER 0xffffffff |
| 78 |
typedef u_int32_t pgno_t; |
| 79 |
#define MAX_PAGE_OFFSET 65535 |
| 80 |
typedef u_int16_t indx_t; |
| 81 |
#define MAX_REC_NUMBER 0xffffffff |
| 82 |
typedef u_int32_t recno_t; |
| 83 |
|
| 84 |
|
| 85 |
typedef struct { |
| 86 |
void *data; |
| 87 |
size_t size; |
| 88 |
} DBT; |
| 89 |
|
| 90 |
|
| 91 |
#define R_CURSOR 1 |
| 92 |
#define __R_UNUSED 2 |
| 93 |
#define R_FIRST 3 |
| 94 |
#define R_IAFTER 4 |
| 95 |
#define R_IBEFORE 5 |
| 96 |
#define R_LAST 6 |
| 97 |
#define R_NEXT 7 |
| 98 |
#define R_NOOVERWRITE 8 |
| 99 |
#define R_PREV 9 |
| 100 |
#define R_SETCURSOR 10 |
| 101 |
#define R_RECNOSYNC 11 |
| 102 |
|
| 103 |
typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
#if UINT_MAX > 65535 |
| 119 |
#define DB_LOCK 0x20000000 |
| 120 |
#define DB_SHMEM 0x40000000 |
| 121 |
#define DB_TXN 0x80000000 |
| 122 |
#else |
| 123 |
#define DB_LOCK 0x2000 |
| 124 |
#define DB_SHMEM 0x4000 |
| 125 |
#define DB_TXN 0x8000 |
| 126 |
#endif |
| 127 |
|
| 128 |
|
| 129 |
typedef struct __db { |
| 130 |
DBTYPE type; |
| 131 |
int (*close) __P((struct __db *)); |
| 132 |
int (*del) __P((const struct __db *, const DBT *, u_int)); |
| 133 |
int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); |
| 134 |
int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); |
| 135 |
int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); |
| 136 |
int (*sync) __P((const struct __db *, u_int)); |
| 137 |
void *internal; |
| 138 |
int (*fd) __P((const struct __db *)); |
| 139 |
} DB; |
| 140 |
|
| 141 |
#define BTREEMAGIC 0x053162 |
| 142 |
#define BTREEVERSION 3 |
| 143 |
|
| 144 |
|
| 145 |
typedef struct { |
| 146 |
#define R_DUP 0x01 |
| 147 |
u_long flags; |
| 148 |
u_int cachesize; |
| 149 |
int maxkeypage; |
| 150 |
int minkeypage; |
| 151 |
u_int psize; |
| 152 |
int (*compare) |
| 153 |
__P((const DBT *, const DBT *)); |
| 154 |
size_t (*prefix) |
| 155 |
__P((const DBT *, const DBT *)); |
| 156 |
int lorder; |
| 157 |
} BTREEINFO; |
| 158 |
|
| 159 |
#define HASHMAGIC 0x061561 |
| 160 |
#define HASHVERSION 2 |
| 161 |
|
| 162 |
|
| 163 |
typedef struct { |
| 164 |
u_int bsize; |
| 165 |
u_int ffactor; |
| 166 |
u_int nelem; |
| 167 |
u_int cachesize; |
| 168 |
u_int32_t |
| 169 |
(*hash) __P((const void *, size_t)); |
| 170 |
int lorder; |
| 171 |
} HASHINFO; |
| 172 |
|
| 173 |
|
| 174 |
typedef struct { |
| 175 |
#define R_FIXEDLEN 0x01 |
| 176 |
#define R_NOKEY 0x02 |
| 177 |
#define R_SNAPSHOT 0x04 |
| 178 |
u_long flags; |
| 179 |
u_int cachesize; |
| 180 |
u_int psize; |
| 181 |
int lorder; |
| 182 |
size_t reclen; |
| 183 |
u_char bval; |
| 184 |
char *bfname; |
| 185 |
} RECNOINFO; |
| 186 |
|
| 187 |
#ifdef __DBINTERFACE_PRIVATE |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
#define M_32_SWAP(a) { \ |
| 195 |
u_int32_t _tmp = a; \ |
| 196 |
((char *)&a)[0] = ((char *)&_tmp)[3]; \ |
| 197 |
((char *)&a)[1] = ((char *)&_tmp)[2]; \ |
| 198 |
((char *)&a)[2] = ((char *)&_tmp)[1]; \ |
| 199 |
((char *)&a)[3] = ((char *)&_tmp)[0]; \ |
| 200 |
} |
| 201 |
#define P_32_SWAP(a) { \ |
| 202 |
u_int32_t _tmp = *(u_int32_t *)a; \ |
| 203 |
((char *)a)[0] = ((char *)&_tmp)[3]; \ |
| 204 |
((char *)a)[1] = ((char *)&_tmp)[2]; \ |
| 205 |
((char *)a)[2] = ((char *)&_tmp)[1]; \ |
| 206 |
((char *)a)[3] = ((char *)&_tmp)[0]; \ |
| 207 |
} |
| 208 |
#define P_32_COPY(a, b) { \ |
| 209 |
((char *)&(b))[0] = ((char *)&(a))[3]; \ |
| 210 |
((char *)&(b))[1] = ((char *)&(a))[2]; \ |
| 211 |
((char *)&(b))[2] = ((char *)&(a))[1]; \ |
| 212 |
((char *)&(b))[3] = ((char *)&(a))[0]; \ |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
#define M_16_SWAP(a) { \ |
| 222 |
u_int16_t _tmp = a; \ |
| 223 |
((char *)&a)[0] = ((char *)&_tmp)[1]; \ |
| 224 |
((char *)&a)[1] = ((char *)&_tmp)[0]; \ |
| 225 |
} |
| 226 |
#define P_16_SWAP(a) { \ |
| 227 |
u_int16_t _tmp = *(u_int16_t *)a; \ |
| 228 |
((char *)a)[0] = ((char *)&_tmp)[1]; \ |
| 229 |
((char *)a)[1] = ((char *)&_tmp)[0]; \ |
| 230 |
} |
| 231 |
#define P_16_COPY(a, b) { \ |
| 232 |
((char *)&(b))[0] = ((char *)&(a))[1]; \ |
| 233 |
((char *)&(b))[1] = ((char *)&(a))[0]; \ |
| 234 |
} |
| 235 |
#endif |
| 236 |
|
| 237 |
__BEGIN_DECLS |
| 238 |
DB *__dbopen __P((const char *, int, int, DBTYPE, const void *)); |
| 239 |
DB *dbopen __P((const char *, int, int, DBTYPE, const void *)); |
| 240 |
|
| 241 |
#ifdef __DBINTERFACE_PRIVATE |
| 242 |
DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int)); |
| 243 |
DB *__hash_open __P((const char *, int, int, const HASHINFO *, int)); |
| 244 |
DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int)); |
| 245 |
void __dbpanic __P((DB *dbp)); |
| 246 |
#endif |
| 247 |
__END_DECLS |
| 248 |
|
| 249 |
#endif |