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