xref: /original-bsd/include/db.h (revision 95a66346)
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.8 (Berkeley) 03/18/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 	unsigned char *data;
31 	int size;
32 } DBT;
33 
34 /* access method description structure */
35 typedef struct __db {
36 	void *internal;		/* access method private; really void * */
37 	int (*close) __P((const struct __db *));
38 	int (*del) __P((const struct __db *, const DBT *, unsigned int));
39 	int (*get) __P((const struct __db *, DBT *, DBT *, unsigned int));
40 	int (*put) __P((const struct __db *, const DBT *, const DBT *,
41 		unsigned int));
42 	int (*seq) __P((const struct __db *, DBT *, DBT *, unsigned int));
43 	int (*sync) __P((const struct __db *));
44 } DB;
45 
46 #define	BTREEMAGIC	0x053162
47 #define	BTREEVERSION	2
48 
49 /* structure used to pass parameters to the btree routines */
50 typedef struct {
51 #define	R_DUP		0x01	/* duplicate keys */
52 	u_long flags;
53 	int cachesize;		/* bytes to cache */
54 	int psize;		/* page size */
55 	int (*compare)();	/* compare function */
56 	int lorder;		/* byte order */
57 } BTREEINFO;
58 
59 #define	HASHMAGIC	0x061561
60 #define	HASHVERSION	1
61 
62 /* structure used to pass parameters to the hashing routines */
63 typedef struct {
64 	int bsize;		/* bucket size */
65 	int ffactor;		/* fill factor */
66 	int nelem;		/* number of elements */
67 	int cachesize;		/* bytes to cache */
68 	int (*hash)();		/* hash function */
69 	int lorder;		/* byte order */
70 } HASHINFO;
71 
72 /* structure used to pass parameters to the record routines */
73 typedef struct {
74 #define	R_FIXEDLEN	0x01	/* fixed-length records */
75 	u_long flags;
76 	int cachesize;		/* bytes to cache */
77 	size_t reclen;		/* record length (fixed-length records) */
78 	u_char bval;		/* delimiting byte (variable-length records */
79 } RECNOINFO;
80 
81 /* key structure for the record routines */
82 typedef struct {
83 	u_long number;
84 	u_long offset;
85 	u_long length;
86 #define	R_LENGTH	0x01	/* length is valid */
87 #define	R_NUMBER	0x02	/* record number is valid */
88 #define	R_OFFSET	0x04	/* offset is valid */
89 	u_char valid;
90 } RECNOKEY;
91 
92 /* Little endian <--> big endian long swap macros. */
93 #define BLSWAP(a) { \
94 	u_long _tmp = a; \
95 	((char *)&a)[0] = ((char *)&_tmp)[3]; \
96 	((char *)&a)[1] = ((char *)&_tmp)[2]; \
97 	((char *)&a)[2] = ((char *)&_tmp)[1]; \
98 	((char *)&a)[3] = ((char *)&_tmp)[0]; \
99 }
100 #define	BLSWAP_COPY(a,b) { \
101 	((char *)&(b))[0] = ((char *)&(a))[3]; \
102 	((char *)&(b))[1] = ((char *)&(a))[2]; \
103 	((char *)&(b))[2] = ((char *)&(a))[1]; \
104 	((char *)&(b))[3] = ((char *)&(a))[0]; \
105 }
106 
107 
108 /* Little endian <--> big endian short swap macros. */
109 #define BSSWAP(a) { \
110 	u_short _tmp = a; \
111 	((char *)&a)[0] = ((char *)&_tmp)[1]; \
112 	((char *)&a)[1] = ((char *)&_tmp)[0]; \
113 }
114 #define BSSWAP_COPY(a,b) { \
115 	((char *)&(b))[0] = ((char *)&(a))[1]; \
116 	((char *)&(b))[1] = ((char *)&(a))[0]; \
117 }
118 
119 __BEGIN_DECLS
120 DB	*btree_open
121 	    __P((const char *, int, int, const BTREEINFO *));
122 DB	*hash_open
123 	    __P((const char *, int, int, const HASHINFO *));
124 DB	*recno_open
125 	    __P((const char *, int, int, const RECNOINFO *));
126 __END_DECLS
127 
128 #endif /* !_DB_H_ */
129