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