| 1 | /*	$OpenBSD: db.h,v 1.14 2026/03/10 04:30:34 deraadt Exp $	*/ |
| 2 | /*	$NetBSD: db.h,v 1.13 1994/10/26 00:55:48 cgd Exp $	*/ |
| 3 | |
| 4 | /*- |
| 5 | * Copyright (c) 1990, 1993, 1994 |
| 6 | *	The Regents of the University of California. All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the name of the University nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this software |
| 18 | * without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | * |
| 32 | *	@(#)db.h	8.7 (Berkeley) 6/16/94 |
| 33 | */ |
| 34 | |
| 35 | #ifndef _DB_H_ |
| 36 | #define	_DB_H_ |
| 37 | |
| 38 | #include <sys/types.h> |
| 39 | |
| 40 | #include <limits.h> |
| 41 | |
| 42 | #define	RET_ERROR	-1		/* Return values. */ |
| 43 | #define	RET_SUCCESS	 0 |
| 44 | #define	RET_SPECIAL	 1 |
| 45 | |
| 46 | #define	MAX_PAGE_NUMBER	0xffffffff	/* >= # of pages in a file */ |
| 47 | typedef u_int32_t	pgno_t; |
| 48 | #define	MAX_PAGE_OFFSET	65535		/* >= # of bytes in a page */ |
| 49 | typedef u_int16_t	indx_t; |
| 50 | #define	MAX_REC_NUMBER	0xffffffff	/* >= # of records in a tree */ |
| 51 | typedef u_int32_t	recno_t; |
| 52 | |
| 53 | /* Key/data structure -- a Data-Base Thang. */ |
| 54 | typedef struct { |
| 55 | 	void	*data;			/* data */ |
| 56 | 	size_t	 size;			/* data length */ |
| 57 | } DBT; |
| 58 | |
| 59 | /* Routine flags. */ |
| 60 | #define	R_CURSOR	1		/* del, put, seq */ |
| 61 | #define	__R_UNUSED	2		/* UNUSED */ |
| 62 | #define	R_FIRST		3		/* seq */ |
| 63 | #define	R_IAFTER	4		/* put (RECNO) */ |
| 64 | #define	R_IBEFORE	5		/* put (RECNO) */ |
| 65 | #define	R_LAST		6		/* seq (BTREE, RECNO) */ |
| 66 | #define	R_NEXT		7		/* seq */ |
| 67 | #define	R_NOOVERWRITE	8		/* put */ |
| 68 | #define	R_PREV		9		/* seq (BTREE, RECNO) */ |
| 69 | #define	R_SETCURSOR	10		/* put (RECNO) */ |
| 70 | #define	R_RECNOSYNC	11		/* sync (RECNO) */ |
| 71 | |
| 72 | typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; |
| 73 | |
| 74 | /* |
| 75 | * !!! |
| 76 | * The following flags are included in the dbopen(3) call as part of the |
| 77 | * open(2) flags. In order to avoid conflicts with the open flags, start |
| 78 | * at the top of the 16 or 32-bit number space and work our way down. If |
| 79 | * the open flags were significantly expanded in the future, it could be |
| 80 | * a problem. Wish I'd left another flags word in the dbopen call. |
| 81 | * |
| 82 | * !!! |
| 83 | * None of this stuff is implemented yet. The only reason that it's here |
| 84 | * is so that the access methods can skip copying the key/data pair when |
| 85 | * the DB_LOCK flag isn't set. |
| 86 | */ |
| 87 | #define	DB_LOCK		0x20000000	/* Do locking. */ |
| 88 | #define	DB_SHMEM	0x40000000	/* Use shared memory. */ |
| 89 | #define	DB_TXN		0x80000000	/* Do transactions. */ |
| 90 | |
| 91 | /* Access method description structure. */ |
| 92 | typedef struct __db { |
| 93 | 	DBTYPE type;			/* Underlying db type. */ |
| 94 | 	int (*close)(struct __db *); |
| 95 | 	int (*del)(const struct __db *, const DBT *, unsigned int); |
| 96 | 	int (*get)(const struct __db *, const DBT *, DBT *, unsigned int); |
| 97 | 	int (*put)(const struct __db *, DBT *, const DBT *, unsigned int); |
| 98 | 	int (*seq)(const struct __db *, DBT *, DBT *, unsigned int); |
| 99 | 	int (*sync)(const struct __db *, unsigned int); |
| 100 | 	void *internal;			/* Access method private. */ |
| 101 | 	int (*fd)(const struct __db *); |
| 102 | } DB; |
| 103 | |
| 104 | #define	BTREEMAGIC	0x053162 |
| 105 | #define	BTREEVERSION	3 |
| 106 | |
| 107 | /* Structure used to pass parameters to the btree routines. */ |
| 108 | typedef struct { |
| 109 | #define	R_DUP		0x01	/* duplicate keys */ |
| 110 | 	unsigned long	flags; |
| 111 | 	unsigned int	cachesize;	/* bytes to cache */ |
| 112 | 	int		maxkeypage;	/* maximum keys per page */ |
| 113 | 	int		minkeypage;	/* minimum keys per page */ |
| 114 | 	unsigned int	psize;		/* page size */ |
| 115 | 	int		(*compare)	/* comparison function */ |
| 116 | 			 (const DBT *, const DBT *); |
| 117 | 	size_t		(*prefix)	/* prefix function */ |
| 118 | 			 (const DBT *, const DBT *); |
| 119 | 	int		lorder;		/* byte order */ |
| 120 | } BTREEINFO; |
| 121 | |
| 122 | #define	HASHMAGIC	0x061561 |
| 123 | #define	HASHVERSION	2 |
| 124 | |
| 125 | /* Structure used to pass parameters to the hashing routines. */ |
| 126 | typedef struct { |
| 127 | 	unsigned int	bsize;		/* bucket size */ |
| 128 | 	unsigned int	ffactor;	/* fill factor */ |
| 129 | 	unsigned int	nelem;		/* number of elements */ |
| 130 | 	unsigned int	cachesize;	/* bytes to cache */ |
| 131 | 	u_int32_t			/* hash function */ |
| 132 | 			(*hash)(const void *, size_t); |
| 133 | 	int		lorder;		/* byte order */ |
| 134 | } HASHINFO; |
| 135 | |
| 136 | /* Structure used to pass parameters to the record routines. */ |
| 137 | typedef struct { |
| 138 | #define	R_FIXEDLEN		0x01	/* fixed-length records */ |
| 139 | #define	R_NOKEY			0x02	/* key not required */ |
| 140 | #define	R_SNAPSHOT		0x04	/* snapshot the input */ |
| 141 | 	unsigned long	flags; |
| 142 | 	unsigned int	cachesize;	/* bytes to cache */ |
| 143 | 	unsigned int	psize;		/* page size */ |
| 144 | 	int		lorder;		/* byte order */ |
| 145 | 	size_t		reclen;		/* record length |
| 146 | 					 (fixed-length records) */ |
| 147 | 	unsigned char	bval;		/* delimiting byte |
| 148 | 					 (variable-length records) */ |
| 149 | 	char	*bfname;		/* btree file name */ |
| 150 | } RECNOINFO; |
| 151 | |
| 152 | __BEGIN_DECLS |
| 153 | DB *dbopen(const char *, int, int, DBTYPE, const void *); |
| 154 | __END_DECLS |
| 155 | #endif /* !_DB_H_ */ |