source: trunk/src/emx/include/db.h@ 1010

Last change on this file since 1010 was 981, checked in by bird, 22 years ago

New db.h from FreeBSD 5.1 (with new port).

  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.6 KB
Line 
1/*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. 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 8.7 (Berkeley) 6/16/94
34 * $FreeBSD: src/include/db.h,v 1.5 2002/03/26 01:35:05 bde Exp $
35 */
36
37/** @file
38 * FreeBSD 5.1
39 */
40
41#ifndef _DB_H_
42#define _DB_H_
43
44#include <sys/types.h>
45#include <sys/cdefs.h>
46
47#include <limits.h>
48
49#define RET_ERROR -1 /* Return values. */
50#define RET_SUCCESS 0
51#define RET_SPECIAL 1
52
53#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
54typedef u_int32_t pgno_t;
55#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
56typedef u_int16_t indx_t;
57#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
58typedef u_int32_t recno_t;
59
60/* Key/data structure -- a Data-Base Thang. */
61typedef struct {
62 void *data; /* data */
63 size_t size; /* data length */
64} DBT;
65
66/* Routine flags. */
67#define R_CURSOR 1 /* del, put, seq */
68#define __R_UNUSED 2 /* UNUSED */
69#define R_FIRST 3 /* seq */
70#define R_IAFTER 4 /* put (RECNO) */
71#define R_IBEFORE 5 /* put (RECNO) */
72#define R_LAST 6 /* seq (BTREE, RECNO) */
73#define R_NEXT 7 /* seq */
74#define R_NOOVERWRITE 8 /* put */
75#define R_PREV 9 /* seq (BTREE, RECNO) */
76#define R_SETCURSOR 10 /* put (RECNO) */
77#define R_RECNOSYNC 11 /* sync (RECNO) */
78
79typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
80
81/*
82 * !!!
83 * The following flags are included in the dbopen(3) call as part of the
84 * open(2) flags. In order to avoid conflicts with the open flags, start
85 * at the top of the 16 or 32-bit number space and work our way down. If
86 * the open flags were significantly expanded in the future, it could be
87 * a problem. Wish I'd left another flags word in the dbopen call.
88 *
89 * !!!
90 * None of this stuff is implemented yet. The only reason that it's here
91 * is so that the access methods can skip copying the key/data pair when
92 * the DB_LOCK flag isn't set.
93 */
94#if UINT_MAX > 65535
95#define DB_LOCK 0x20000000 /* Do locking. */
96#define DB_SHMEM 0x40000000 /* Use shared memory. */
97#define DB_TXN 0x80000000 /* Do transactions. */
98#else
99#define DB_LOCK 0x2000 /* Do locking. */
100#define DB_SHMEM 0x4000 /* Use shared memory. */
101#define DB_TXN 0x8000 /* Do transactions. */
102#endif
103
104/* Access method description structure. */
105typedef struct __db {
106 DBTYPE type; /* Underlying db type. */
107 int (*close)(struct __db *);
108 int (*del)(const struct __db *, const DBT *, u_int);
109 int (*get)(const struct __db *, const DBT *, DBT *, u_int);
110 int (*put)(const struct __db *, DBT *, const DBT *, u_int);
111 int (*seq)(const struct __db *, DBT *, DBT *, u_int);
112 int (*sync)(const struct __db *, u_int);
113 void *internal; /* Access method private. */
114 int (*fd)(const struct __db *);
115} DB;
116
117#define BTREEMAGIC 0x053162
118#define BTREEVERSION 3
119
120/* Structure used to pass parameters to the btree routines. */
121typedef struct {
122#define R_DUP 0x01 /* duplicate keys */
123 u_long flags;
124 u_int cachesize; /* bytes to cache */
125 int maxkeypage; /* maximum keys per page */
126 int minkeypage; /* minimum keys per page */
127 u_int psize; /* page size */
128 int (*compare) /* comparison function */
129 (const DBT *, const DBT *);
130 size_t (*prefix) /* prefix function */
131 (const DBT *, const DBT *);
132 int lorder; /* byte order */
133} BTREEINFO;
134
135#define HASHMAGIC 0x061561
136#define HASHVERSION 2
137
138/* Structure used to pass parameters to the hashing routines. */
139typedef struct {
140 u_int bsize; /* bucket size */
141 u_int ffactor; /* fill factor */
142 u_int nelem; /* number of elements */
143 u_int cachesize; /* bytes to cache */
144 u_int32_t /* hash function */
145 (*hash)(const void *, size_t);
146 int lorder; /* byte order */
147} HASHINFO;
148
149/* Structure used to pass parameters to the record routines. */
150typedef struct {
151#define R_FIXEDLEN 0x01 /* fixed-length records */
152#define R_NOKEY 0x02 /* key not required */
153#define R_SNAPSHOT 0x04 /* snapshot the input */
154 u_long flags;
155 u_int cachesize; /* bytes to cache */
156 u_int psize; /* page size */
157 int lorder; /* byte order */
158 size_t reclen; /* record length (fixed-length records) */
159 u_char bval; /* delimiting byte (variable-length records */
160 char *bfname; /* btree file name */
161} RECNOINFO;
162
163#ifdef __DBINTERFACE_PRIVATE
164/*
165 * Little endian <==> big endian 32-bit swap macros.
166 * M_32_SWAP swap a memory location
167 * P_32_SWAP swap a referenced memory location
168 * P_32_COPY swap from one location to another
169 */
170#define M_32_SWAP(a) { \
171 u_int32_t _tmp = a; \
172 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
173 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
174 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
175 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
176}
177#define P_32_SWAP(a) { \
178 u_int32_t _tmp = *(u_int32_t *)a; \
179 ((char *)a)[0] = ((char *)&_tmp)[3]; \
180 ((char *)a)[1] = ((char *)&_tmp)[2]; \
181 ((char *)a)[2] = ((char *)&_tmp)[1]; \
182 ((char *)a)[3] = ((char *)&_tmp)[0]; \
183}
184#define P_32_COPY(a, b) { \
185 ((char *)&(b))[0] = ((char *)&(a))[3]; \
186 ((char *)&(b))[1] = ((char *)&(a))[2]; \
187 ((char *)&(b))[2] = ((char *)&(a))[1]; \
188 ((char *)&(b))[3] = ((char *)&(a))[0]; \
189}
190
191/*
192 * Little endian <==> big endian 16-bit swap macros.
193 * M_16_SWAP swap a memory location
194 * P_16_SWAP swap a referenced memory location
195 * P_16_COPY swap from one location to another
196 */
197#define M_16_SWAP(a) { \
198 u_int16_t _tmp = a; \
199 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
200 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
201}
202#define P_16_SWAP(a) { \
203 u_int16_t _tmp = *(u_int16_t *)a; \
204 ((char *)a)[0] = ((char *)&_tmp)[1]; \
205 ((char *)a)[1] = ((char *)&_tmp)[0]; \
206}
207#define P_16_COPY(a, b) { \
208 ((char *)&(b))[0] = ((char *)&(a))[1]; \
209 ((char *)&(b))[1] = ((char *)&(a))[0]; \
210}
211#endif
212
213__BEGIN_DECLS
214DB *dbopen(const char *, int, int, DBTYPE, const void *);
215
216#ifdef __DBINTERFACE_PRIVATE
217DB *__bt_open(const char *, int, int, const BTREEINFO *, int);
218DB *__hash_open(const char *, int, int, const HASHINFO *, int);
219DB *__rec_open(const char *, int, int, const RECNOINFO *, int);
220void __dbpanic(DB *dbp);
221#endif
222__END_DECLS
223#endif /* !_DB_H_ */
Note: See TracBrowser for help on using the repository browser.