xref: /original-bsd/include/db.h (revision 3a8172c6)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)db.h	5.10 (Berkeley) 04/02/91
8  */
9 
10 #ifndef _DB_H_
11 #define	_DB_H_
12 
13 #include <sys/cdefs.h>
14 
15 /* flags for DB.put() call */
16 #define	R_IBEFORE	1		/* RECNO */
17 #define	R_IAFTER	2		/* RECNO */
18 #define	R_NOOVERWRITE	3		/* BTREE, HASH, RECNO */
19 #define	R_PUT		4		/* BTREE, HASH, RECNO */
20 
21 /* flags for DB.seq() call */
22 #define	R_CURSOR	1		/* BTREE, RECNO */
23 #define	R_FIRST		2		/* BTREE, HASH, RECNO */
24 #define	R_LAST		3		/* BTREE, RECNO */
25 #define	R_NEXT		4		/* BTREE, HASH, RECNO */
26 #define	R_PREV		5		/* BTREE, RECNO */
27 
28 /* key/data structure -- a data-base thang */
29 typedef struct {
30 	void *data;
31 	int size;
32 } DBT;
33 
34 /* access method description structure */
35 typedef struct __db {
36 	void *internal;		/* access method private */
37 #define	DB_BTREE	1
38 #define	DB_HASH		2
39 #define	DB_RECNO	3
40 	int type;		/* type of underlying db */
41 	int (*close) __P((const struct __db *));
42 	int (*del) __P((const struct __db *, const DBT *, unsigned int));
43 	int (*get) __P((const struct __db *, DBT *, DBT *, unsigned int));
44 	int (*put) __P((const struct __db *, const DBT *, const DBT *,
45 		unsigned int));
46 	int (*seq) __P((const struct __db *, DBT *, DBT *, unsigned int));
47 	int (*sync) __P((const struct __db *));
48 } DB;
49 
50 #define	BTREEMAGIC	0x053162
51 #define	BTREEVERSION	2
52 
53 /* structure used to pass parameters to the btree routines */
54 typedef struct {
55 #define	R_DUP		0x01	/* duplicate keys */
56 	u_long flags;
57 	int cachesize;		/* bytes to cache */
58 	int psize;		/* page size */
59 	int (*compare)();	/* compare function */
60 	int lorder;		/* byte order */
61 } BTREEINFO;
62 
63 #define	HASHMAGIC	0x061561
64 #define	HASHVERSION	1
65 
66 /* structure used to pass parameters to the hashing routines */
67 typedef struct {
68 	int bsize;		/* bucket size */
69 	int ffactor;		/* fill factor */
70 	int nelem;		/* number of elements */
71 	int cachesize;		/* bytes to cache */
72 	int (*hash)();		/* hash function */
73 	int lorder;		/* byte order */
74 } HASHINFO;
75 
76 /* structure used to pass parameters to the record routines */
77 typedef struct {
78 #define	R_FIXEDLEN	0x01	/* fixed-length records */
79 	u_long flags;
80 	int cachesize;		/* bytes to cache */
81 	size_t reclen;		/* record length (fixed-length records) */
82 	u_char bval;		/* delimiting byte (variable-length records */
83 } RECNOINFO;
84 
85 /* key structure for the record routines */
86 typedef struct {
87 	u_long number;
88 	u_long offset;
89 	u_long length;
90 #define	R_LENGTH	0x01	/* length is valid */
91 #define	R_NUMBER	0x02	/* record number is valid */
92 #define	R_OFFSET	0x04	/* offset is valid */
93 	u_char valid;
94 } RECNOKEY;
95 
96 /* Little endian <--> big endian long swap macros. */
97 #define BLSWAP(a) { \
98 	u_long _tmp = a; \
99 	((char *)&a)[0] = ((char *)&_tmp)[3]; \
100 	((char *)&a)[1] = ((char *)&_tmp)[2]; \
101 	((char *)&a)[2] = ((char *)&_tmp)[1]; \
102 	((char *)&a)[3] = ((char *)&_tmp)[0]; \
103 }
104 #define	BLSWAP_COPY(a,b) { \
105 	((char *)&(b))[0] = ((char *)&(a))[3]; \
106 	((char *)&(b))[1] = ((char *)&(a))[2]; \
107 	((char *)&(b))[2] = ((char *)&(a))[1]; \
108 	((char *)&(b))[3] = ((char *)&(a))[0]; \
109 }
110 
111 
112 /* Little endian <--> big endian short swap macros. */
113 #define BSSWAP(a) { \
114 	u_short _tmp = a; \
115 	((char *)&a)[0] = ((char *)&_tmp)[1]; \
116 	((char *)&a)[1] = ((char *)&_tmp)[0]; \
117 }
118 #define BSSWAP_COPY(a,b) { \
119 	((char *)&(b))[0] = ((char *)&(a))[1]; \
120 	((char *)&(b))[1] = ((char *)&(a))[0]; \
121 }
122 
123 __BEGIN_DECLS
124 DB	*btree_open
125 	    __P((const char *, int, int, const BTREEINFO *));
126 DB	*hash_open
127 	    __P((const char *, int, int, const HASHINFO *));
128 DB	*recno_open
129 	    __P((const char *, int, int, const RECNOINFO *));
130 __END_DECLS
131 
132 #endif /* !_DB_H_ */
133