db.h revision 1.2 1 1.1 cgd /*-
2 1.1 cgd * Copyright (c) 1990 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.1 cgd * @(#)db.h 5.10 (Berkeley) 4/2/91
34 1.2 cgd *
35 1.2 cgd * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
36 1.2 cgd * -------------------- ----- ----------------------
37 1.2 cgd * CURRENT PATCH LEVEL: 1 00093
38 1.2 cgd * -------------------- ----- ----------------------
39 1.2 cgd *
40 1.2 cgd * 27 Feb 93 Charles Hannum Better byte-swapping macros for
41 1.2 cgd * i386/i486.
42 1.1 cgd */
43 1.1 cgd
44 1.1 cgd #ifndef _DB_H_
45 1.1 cgd #define _DB_H_
46 1.1 cgd
47 1.2 cgd #include <machine/endian.h>
48 1.1 cgd #include <sys/cdefs.h>
49 1.1 cgd
50 1.1 cgd /* flags for DB.put() call */
51 1.1 cgd #define R_IBEFORE 1 /* RECNO */
52 1.1 cgd #define R_IAFTER 2 /* RECNO */
53 1.1 cgd #define R_NOOVERWRITE 3 /* BTREE, HASH, RECNO */
54 1.1 cgd #define R_PUT 4 /* BTREE, HASH, RECNO */
55 1.1 cgd
56 1.1 cgd /* flags for DB.seq() call */
57 1.1 cgd #define R_CURSOR 1 /* BTREE, RECNO */
58 1.1 cgd #define R_FIRST 2 /* BTREE, HASH, RECNO */
59 1.1 cgd #define R_LAST 3 /* BTREE, RECNO */
60 1.1 cgd #define R_NEXT 4 /* BTREE, HASH, RECNO */
61 1.1 cgd #define R_PREV 5 /* BTREE, RECNO */
62 1.1 cgd
63 1.1 cgd /* key/data structure -- a data-base thang */
64 1.1 cgd typedef struct {
65 1.1 cgd void *data;
66 1.1 cgd int size;
67 1.1 cgd } DBT;
68 1.1 cgd
69 1.1 cgd /* access method description structure */
70 1.1 cgd typedef struct __db {
71 1.1 cgd void *internal; /* access method private */
72 1.1 cgd #define DB_BTREE 1
73 1.1 cgd #define DB_HASH 2
74 1.1 cgd #define DB_RECNO 3
75 1.1 cgd int type; /* type of underlying db */
76 1.1 cgd int (*close) __P((const struct __db *));
77 1.1 cgd int (*del) __P((const struct __db *, const DBT *, unsigned int));
78 1.1 cgd int (*get) __P((const struct __db *, DBT *, DBT *, unsigned int));
79 1.1 cgd int (*put) __P((const struct __db *, const DBT *, const DBT *,
80 1.1 cgd unsigned int));
81 1.1 cgd int (*seq) __P((const struct __db *, DBT *, DBT *, unsigned int));
82 1.1 cgd int (*sync) __P((const struct __db *));
83 1.1 cgd } DB;
84 1.1 cgd
85 1.1 cgd #define BTREEMAGIC 0x053162
86 1.1 cgd #define BTREEVERSION 2
87 1.1 cgd
88 1.1 cgd /* structure used to pass parameters to the btree routines */
89 1.1 cgd typedef struct {
90 1.1 cgd #define R_DUP 0x01 /* duplicate keys */
91 1.1 cgd u_long flags;
92 1.1 cgd int cachesize; /* bytes to cache */
93 1.1 cgd int psize; /* page size */
94 1.1 cgd int (*compare)(); /* compare function */
95 1.1 cgd int lorder; /* byte order */
96 1.1 cgd } BTREEINFO;
97 1.1 cgd
98 1.1 cgd #define HASHMAGIC 0x061561
99 1.1 cgd #define HASHVERSION 1
100 1.1 cgd
101 1.1 cgd /* structure used to pass parameters to the hashing routines */
102 1.1 cgd typedef struct {
103 1.1 cgd int bsize; /* bucket size */
104 1.1 cgd int ffactor; /* fill factor */
105 1.1 cgd int nelem; /* number of elements */
106 1.1 cgd int cachesize; /* bytes to cache */
107 1.1 cgd int (*hash)(); /* hash function */
108 1.1 cgd int lorder; /* byte order */
109 1.1 cgd } HASHINFO;
110 1.1 cgd
111 1.1 cgd /* structure used to pass parameters to the record routines */
112 1.1 cgd typedef struct {
113 1.1 cgd #define R_FIXEDLEN 0x01 /* fixed-length records */
114 1.1 cgd u_long flags;
115 1.1 cgd int cachesize; /* bytes to cache */
116 1.1 cgd size_t reclen; /* record length (fixed-length records) */
117 1.1 cgd u_char bval; /* delimiting byte (variable-length records */
118 1.1 cgd } RECNOINFO;
119 1.1 cgd
120 1.1 cgd /* key structure for the record routines */
121 1.1 cgd typedef struct {
122 1.1 cgd u_long number;
123 1.1 cgd u_long offset;
124 1.1 cgd u_long length;
125 1.1 cgd #define R_LENGTH 0x01 /* length is valid */
126 1.1 cgd #define R_NUMBER 0x02 /* record number is valid */
127 1.1 cgd #define R_OFFSET 0x04 /* offset is valid */
128 1.1 cgd u_char valid;
129 1.1 cgd } RECNOKEY;
130 1.1 cgd
131 1.1 cgd /* Little endian <--> big endian long swap macros. */
132 1.2 cgd #define BLSWAP(X) {(X) = __byte_swap_long(X);}
133 1.2 cgd #define BLSWAP_COPY(X,Y) {(Y) = __byte_swap_long(X);}
134 1.1 cgd
135 1.1 cgd /* Little endian <--> big endian short swap macros. */
136 1.2 cgd #define BSSWAP(X) {(X) = __byte_swap_word(X);}
137 1.2 cgd #define BSSWAP_COPY(X,Y) {(Y) = __byte_swap_word(X);}
138 1.1 cgd
139 1.1 cgd __BEGIN_DECLS
140 1.1 cgd DB *btree_open
141 1.1 cgd __P((const char *, int, int, const BTREEINFO *));
142 1.1 cgd DB *hash_open
143 1.1 cgd __P((const char *, int, int, const HASHINFO *));
144 1.1 cgd DB *recno_open
145 1.1 cgd __P((const char *, int, int, const RECNOINFO *));
146 1.1 cgd __END_DECLS
147 1.1 cgd
148 1.1 cgd #endif /* !_DB_H_ */
149