devname and getbsize move in from ps and df
[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 *
e4802a01 7 * @(#)db.h 5.26 (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 55 int (*del) __P((const struct __db *, const DBT *, u_int));
bd01cf94 56 int (*fd) __P((const struct __db *));
a3dd2fa9 57 int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
a802d95b 58 int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
a3dd2fa9 59 int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
4c94d216 60 int (*sync) __P((const struct __db *, u_int));
11b5f055 61 void *internal; /* access method private */
1b1a0c94
KB
62} DB;
63
64#define BTREEMAGIC 0x053162
8d43ae1a 65#define BTREEVERSION 3
1b1a0c94 66
8d43ae1a 67/* Structure used to pass parameters to the btree routines. */
1b1a0c94
KB
68typedef struct {
69#define R_DUP 0x01 /* duplicate keys */
4c94d216
KB
70 u_long flags;
71 int cachesize; /* bytes to cache */
72 int maxkeypage; /* maximum keys per page */
73 int minkeypage; /* minimum keys per page */
74 int psize; /* page size */
8d43ae1a 75 /* comparison, prefix functions */
4c94d216
KB
76 int (*compare) __P((const DBT *, const DBT *));
77 int (*prefix) __P((const DBT *, const DBT *));
78 int lorder; /* byte order */
1b1a0c94
KB
79} BTREEINFO;
80
81#define HASHMAGIC 0x061561
fa208463 82#define HASHVERSION 2
1b1a0c94 83
8d43ae1a 84/* Structure used to pass parameters to the hashing routines. */
1b1a0c94 85typedef struct {
4c94d216
KB
86 int bsize; /* bucket size */
87 int ffactor; /* fill factor */
88 int nelem; /* number of elements */
89 int cachesize; /* bytes to cache */
90 /* hash function */
91 int (*hash) __P((const void *, size_t));
92 int lorder; /* byte order */
1b1a0c94
KB
93} HASHINFO;
94
8d43ae1a 95/* Structure used to pass parameters to the record routines. */
1b1a0c94
KB
96typedef struct {
97#define R_FIXEDLEN 0x01 /* fixed-length records */
8d43ae1a
KB
98#define R_NOKEY 0x02 /* key not required */
99#define R_SNAPSHOT 0x04 /* snapshot the input */
4c94d216
KB
100 u_long flags;
101 int cachesize; /* bytes to cache */
2436b2e2 102 int psize; /* page size */
4c94d216
KB
103 int lorder; /* byte order */
104 size_t reclen; /* record length (fixed-length records) */
105 u_char bval; /* delimiting byte (variable-length records */
106 char *bfname; /* btree file name */
1b1a0c94
KB
107} RECNOINFO;
108
ab7c24ac
KB
109/*
110 * Little endian <==> big endian long swap macros.
111 * BLSWAP swap a memory location
112 * BLPSWAP swap a referenced memory location
113 * BLSWAP_COPY swap from one location to another
114 */
dd8e004c 115#define BLSWAP(a) { \
a3dd2fa9 116 u_long _tmp = a; \
dd8e004c
KB
117 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
118 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
119 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
120 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
121}
ab7c24ac 122#define BLPSWAP(a) { \
a3dd2fa9 123 u_long _tmp = *(u_long *)a; \
ab7c24ac
KB
124 ((char *)a)[0] = ((char *)&_tmp)[3]; \
125 ((char *)a)[1] = ((char *)&_tmp)[2]; \
126 ((char *)a)[2] = ((char *)&_tmp)[1]; \
127 ((char *)a)[3] = ((char *)&_tmp)[0]; \
128}
129#define BLSWAP_COPY(a, b) { \
dd8e004c
KB
130 ((char *)&(b))[0] = ((char *)&(a))[3]; \
131 ((char *)&(b))[1] = ((char *)&(a))[2]; \
132 ((char *)&(b))[2] = ((char *)&(a))[1]; \
133 ((char *)&(b))[3] = ((char *)&(a))[0]; \
134}
135
ab7c24ac
KB
136/*
137 * Little endian <==> big endian short swap macros.
138 * BSSWAP swap a memory location
139 * BSPSWAP swap a referenced memory location
140 * BSSWAP_COPY swap from one location to another
141 */
dd8e004c 142#define BSSWAP(a) { \
a3dd2fa9 143 u_short _tmp = a; \
dd8e004c
KB
144 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
145 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
146}
ab7c24ac 147#define BSPSWAP(a) { \
a3dd2fa9 148 u_short _tmp = *(u_short *)a; \
ab7c24ac
KB
149 ((char *)a)[0] = ((char *)&_tmp)[1]; \
150 ((char *)a)[1] = ((char *)&_tmp)[0]; \
151}
152#define BSSWAP_COPY(a, b) { \
dd8e004c
KB
153 ((char *)&(b))[0] = ((char *)&(a))[1]; \
154 ((char *)&(b))[1] = ((char *)&(a))[0]; \
155}
156
dd8e004c 157__BEGIN_DECLS
8d43ae1a
KB
158DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
159
160#ifdef __DBINTERFACE_PRIVATE
161DB *__bt_open __P((const char *, int, int, const BTREEINFO *));
162DB *__hash_open __P((const char *, int, int, const HASHINFO *));
163DB *__rec_open __P((const char *, int, int, const RECNOINFO *));
164void __dbpanic __P((DB *dbp));
165#endif
dd8e004c 166__END_DECLS
dd8e004c 167#endif /* !_DB_H_ */