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