have to protect acct_process from acctwatch closing the vnode
[unix-history] / usr / src / include / db.h
CommitLineData
1b1a0c94 1/*-
56559b70
KB
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
1b1a0c94
KB
4 *
5 * %sccs.include.redist.c%
6 *
ce3b58e2 7 * @(#)db.h 8.4 (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
19a5aa6a
KB
16#include <limits.h>
17
8d43ae1a
KB
18#define RET_ERROR -1 /* Return values. */
19#define RET_SUCCESS 0
20#define RET_SPECIAL 1
21
ce3b58e2
KB
22#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
23typedef u_int32_t pgno_t;
24#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
25typedef u_int16_t indx_t;
26#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
27typedef u_int32_t recno_t;
8d43ae1a
KB
28
29/* Key/data structure -- a Data-Base Thang. */
30typedef struct {
31 void *data; /* data */
32 size_t size; /* data length */
33} DBT;
34
ab7c24ac 35/* Routine flags. */
a802d95b 36#define R_CURSOR 1 /* del, put, seq */
8b10626b 37#define __R_UNUSED 2 /* UNUSED */
ab7c24ac
KB
38#define R_FIRST 3 /* seq */
39#define R_IAFTER 4 /* put (RECNO) */
40#define R_IBEFORE 5 /* put (RECNO) */
41#define R_LAST 6 /* seq (BTREE, RECNO) */
42#define R_NEXT 7 /* seq */
43#define R_NOOVERWRITE 8 /* put */
44#define R_PREV 9 /* seq (BTREE, RECNO) */
a802d95b 45#define R_SETCURSOR 10 /* put (RECNO) */
4c94d216 46#define R_RECNOSYNC 11 /* sync (RECNO) */
1b1a0c94 47
8d43ae1a 48typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
1b1a0c94 49
19a5aa6a
KB
50/*
51 * !!!
52 * The following flags are included in the dbopen(3) call as part of the
53 * open(2) flags. In order to avoid conflicts with the open flags, start
54 * at the top of the 16 or 32-bit number space and work our way down. If
55 * the open flags were significantly expanded in the future, it could be
56 * a problem. Wish I'd left another flags word in the dbopen call.
57 *
58 * !!!
59 * None of this stuff is implemented yet. The only reason that it's here
60 * is so that the access methods can skip copying the key/data pair when
61 * the DB_LOCK flag isn't set.
62 */
63#if UINT_MAX > 65535
64#define DB_LOCK 0x20000000 /* Do locking. */
65#define DB_SHMEM 0x40000000 /* Use shared memory. */
66#define DB_TXN 0x80000000 /* Do transactions. */
67#else
ce3b58e2
KB
68#define DB_LOCK 0x2000 /* Do locking. */
69#define DB_SHMEM 0x4000 /* Use shared memory. */
70#define DB_TXN 0x8000 /* Do transactions. */
19a5aa6a 71#endif
cdea9228 72
8d43ae1a 73/* Access method description structure. */
a528d733 74typedef struct __db {
19a5aa6a 75 DBTYPE type; /* Underlying db type. */
8d43ae1a 76 int (*close) __P((struct __db *));
a3dd2fa9
KB
77 int (*del) __P((const struct __db *, const DBT *, u_int));
78 int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
a802d95b 79 int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
a3dd2fa9 80 int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
4c94d216 81 int (*sync) __P((const struct __db *, u_int));
8ec0a6c3
KB
82 void *internal; /* Access method private. */
83 int (*fd) __P((const struct __db *));
1b1a0c94
KB
84} DB;
85
86#define BTREEMAGIC 0x053162
8d43ae1a 87#define BTREEVERSION 3
1b1a0c94 88
8d43ae1a 89/* Structure used to pass parameters to the btree routines. */
1b1a0c94
KB
90typedef struct {
91#define R_DUP 0x01 /* duplicate keys */
ce3b58e2
KB
92 u_long flags;
93 u_int cachesize; /* bytes to cache */
94 int maxkeypage; /* maximum keys per page */
95 int minkeypage; /* minimum keys per page */
96 u_int psize; /* page size */
97 int (*compare) /* comparison function */
98 __P((const DBT *, const DBT *));
99 size_t (*prefix) /* prefix function */
100 __P((const DBT *, const DBT *));
101 int lorder; /* byte order */
1b1a0c94
KB
102} BTREEINFO;
103
104#define HASHMAGIC 0x061561
fa208463 105#define HASHVERSION 2
1b1a0c94 106
8d43ae1a 107/* Structure used to pass parameters to the hashing routines. */
1b1a0c94 108typedef struct {
ce3b58e2
KB
109 u_int bsize; /* bucket size */
110 u_int ffactor; /* fill factor */
111 u_int nelem; /* number of elements */
112 u_int cachesize; /* bytes to cache */
113 u_int32_t /* hash function */
114 (*hash) __P((const void *, size_t));
115 int lorder; /* byte order */
1b1a0c94
KB
116} HASHINFO;
117
8d43ae1a 118/* Structure used to pass parameters to the record routines. */
1b1a0c94
KB
119typedef struct {
120#define R_FIXEDLEN 0x01 /* fixed-length records */
8d43ae1a
KB
121#define R_NOKEY 0x02 /* key not required */
122#define R_SNAPSHOT 0x04 /* snapshot the input */
ce3b58e2
KB
123 u_long flags;
124 u_int cachesize; /* bytes to cache */
125 u_int psize; /* page size */
126 int lorder; /* byte order */
127 size_t reclen; /* record length (fixed-length records) */
128 u_char bval; /* delimiting byte (variable-length records */
4c94d216 129 char *bfname; /* btree file name */
1b1a0c94
KB
130} RECNOINFO;
131
ce3b58e2 132#ifdef __DBINTERFACE_PRIVATE
ab7c24ac 133/*
ce3b58e2
KB
134 * Little endian <==> big endian 32-bit swap macros.
135 * M_32_SWAP swap a memory location
136 * P_32_SWAP swap a referenced memory location
137 * P_32_COPY swap from one location to another
ab7c24ac 138 */
ce3b58e2
KB
139#define M_32_SWAP(a) { \
140 u_int32_t _tmp = a; \
19a5aa6a
KB
141 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
142 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
143 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
144 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
dd8e004c 145}
ce3b58e2
KB
146#define P_32_SWAP(a) { \
147 u_int32_t _tmp = *(u_int32_t *)a; \
19a5aa6a
KB
148 ((char *)a)[0] = ((char *)&_tmp)[3]; \
149 ((char *)a)[1] = ((char *)&_tmp)[2]; \
150 ((char *)a)[2] = ((char *)&_tmp)[1]; \
151 ((char *)a)[3] = ((char *)&_tmp)[0]; \
ab7c24ac 152}
ce3b58e2 153#define P_32_COPY(a, b) { \
19a5aa6a
KB
154 ((char *)&(b))[0] = ((char *)&(a))[3]; \
155 ((char *)&(b))[1] = ((char *)&(a))[2]; \
156 ((char *)&(b))[2] = ((char *)&(a))[1]; \
157 ((char *)&(b))[3] = ((char *)&(a))[0]; \
dd8e004c
KB
158}
159
ab7c24ac 160/*
ce3b58e2
KB
161 * Little endian <==> big endian 16-bit swap macros.
162 * M_16_SWAP swap a memory location
163 * P_16_SWAP swap a referenced memory location
164 * P_16_COPY swap from one location to another
ab7c24ac 165 */
ce3b58e2
KB
166#define M_16_SWAP(a) { \
167 u_int16_t _tmp = a; \
19a5aa6a
KB
168 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
169 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
dd8e004c 170}
ce3b58e2
KB
171#define P_16_SWAP(a) { \
172 u_int16_t _tmp = *(u_int16_t *)a; \
19a5aa6a
KB
173 ((char *)a)[0] = ((char *)&_tmp)[1]; \
174 ((char *)a)[1] = ((char *)&_tmp)[0]; \
ab7c24ac 175}
ce3b58e2 176#define P_16_COPY(a, b) { \
19a5aa6a
KB
177 ((char *)&(b))[0] = ((char *)&(a))[1]; \
178 ((char *)&(b))[1] = ((char *)&(a))[0]; \
dd8e004c 179}
ce3b58e2 180#endif
dd8e004c 181
dd8e004c 182__BEGIN_DECLS
8d43ae1a
KB
183DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
184
185#ifdef __DBINTERFACE_PRIVATE
19a5aa6a
KB
186DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
187DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
188DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
8d43ae1a
KB
189void __dbpanic __P((DB *dbp));
190#endif
dd8e004c 191__END_DECLS
dd8e004c 192#endif /* !_DB_H_ */