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