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