db.h revision 1.2       1 /*-
      2  * Copyright (c) 1990 The Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  *	@(#)db.h	5.10 (Berkeley) 4/2/91
     34  *
     35  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
     36  * --------------------         -----   ----------------------
     37  * CURRENT PATCH LEVEL:         1       00093
     38  * --------------------         -----   ----------------------
     39  *
     40  * 27 Feb 93    Charles Hannum		Better byte-swapping macros for
     41  *					i386/i486.
     42  */
     43 
     44 #ifndef _DB_H_
     45 #define	_DB_H_
     46 
     47 #include <machine/endian.h>
     48 #include <sys/cdefs.h>
     49 
     50 /* flags for DB.put() call */
     51 #define	R_IBEFORE	1		/* RECNO */
     52 #define	R_IAFTER	2		/* RECNO */
     53 #define	R_NOOVERWRITE	3		/* BTREE, HASH, RECNO */
     54 #define	R_PUT		4		/* BTREE, HASH, RECNO */
     55 
     56 /* flags for DB.seq() call */
     57 #define	R_CURSOR	1		/* BTREE, RECNO */
     58 #define	R_FIRST		2		/* BTREE, HASH, RECNO */
     59 #define	R_LAST		3		/* BTREE, RECNO */
     60 #define	R_NEXT		4		/* BTREE, HASH, RECNO */
     61 #define	R_PREV		5		/* BTREE, RECNO */
     62 
     63 /* key/data structure -- a data-base thang */
     64 typedef struct {
     65 	void *data;
     66 	int size;
     67 } DBT;
     68 
     69 /* access method description structure */
     70 typedef struct __db {
     71 	void *internal;		/* access method private */
     72 #define	DB_BTREE	1
     73 #define	DB_HASH		2
     74 #define	DB_RECNO	3
     75 	int type;		/* type of underlying db */
     76 	int (*close) __P((const struct __db *));
     77 	int (*del) __P((const struct __db *, const DBT *, unsigned int));
     78 	int (*get) __P((const struct __db *, DBT *, DBT *, unsigned int));
     79 	int (*put) __P((const struct __db *, const DBT *, const DBT *,
     80 		unsigned int));
     81 	int (*seq) __P((const struct __db *, DBT *, DBT *, unsigned int));
     82 	int (*sync) __P((const struct __db *));
     83 } DB;
     84 
     85 #define	BTREEMAGIC	0x053162
     86 #define	BTREEVERSION	2
     87 
     88 /* structure used to pass parameters to the btree routines */
     89 typedef struct {
     90 #define	R_DUP		0x01	/* duplicate keys */
     91 	u_long flags;
     92 	int cachesize;		/* bytes to cache */
     93 	int psize;		/* page size */
     94 	int (*compare)();	/* compare function */
     95 	int lorder;		/* byte order */
     96 } BTREEINFO;
     97 
     98 #define	HASHMAGIC	0x061561
     99 #define	HASHVERSION	1
    100 
    101 /* structure used to pass parameters to the hashing routines */
    102 typedef struct {
    103 	int bsize;		/* bucket size */
    104 	int ffactor;		/* fill factor */
    105 	int nelem;		/* number of elements */
    106 	int cachesize;		/* bytes to cache */
    107 	int (*hash)();		/* hash function */
    108 	int lorder;		/* byte order */
    109 } HASHINFO;
    110 
    111 /* structure used to pass parameters to the record routines */
    112 typedef struct {
    113 #define	R_FIXEDLEN	0x01	/* fixed-length records */
    114 	u_long flags;
    115 	int cachesize;		/* bytes to cache */
    116 	size_t reclen;		/* record length (fixed-length records) */
    117 	u_char bval;		/* delimiting byte (variable-length records */
    118 } RECNOINFO;
    119 
    120 /* key structure for the record routines */
    121 typedef struct {
    122 	u_long number;
    123 	u_long offset;
    124 	u_long length;
    125 #define	R_LENGTH	0x01	/* length is valid */
    126 #define	R_NUMBER	0x02	/* record number is valid */
    127 #define	R_OFFSET	0x04	/* offset is valid */
    128 	u_char valid;
    129 } RECNOKEY;
    130 
    131 /* Little endian <--> big endian long swap macros. */
    132 #define BLSWAP(X) {(X) = __byte_swap_long(X);}
    133 #define BLSWAP_COPY(X,Y) {(Y) = __byte_swap_long(X);}
    134 
    135 /* Little endian <--> big endian short swap macros. */
    136 #define BSSWAP(X) {(X) = __byte_swap_word(X);}
    137 #define BSSWAP_COPY(X,Y) {(Y) = __byte_swap_word(X);}
    138 
    139 __BEGIN_DECLS
    140 DB	*btree_open
    141 	    __P((const char *, int, int, const BTREEINFO *));
    142 DB	*hash_open
    143 	    __P((const char *, int, int, const HASHINFO *));
    144 DB	*recno_open
    145 	    __P((const char *, int, int, const RECNOINFO *));
    146 __END_DECLS
    147 
    148 #endif /* !_DB_H_ */
    149