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