1/* Part of the ht://Dig package   <http://www.htdig.org/> */
2/* Copyright (c) 2003 The ht://Dig Group */
3/* For copyright details, see the file COPYING in your distribution */
4/* or the GNU Library General Public License (LGPL) version 2 or later or later */
5/* <http://www.gnu.org/copyleft/lgpl.html> */
6
7/* BDB db.h header file for the Native WIN32 MSVC Platform */
8
9/*-
10 * See the file LICENSE for redistribution information.
11 *
12 * Copyright (c) 1996, 1997, 1998, 1999
13 *	Sleepycat Software.  All rights reserved.
14 *
15 *	@(#)db.src	11.20 (Sleepycat) 10/28/99
16 */
17
18/* WIN32 - MSVC++ Version */
19
20#ifndef _DB_H_
21#define	_DB_H_
22
23#ifndef __NO_SYSTEM_INCLUDES
24#include <sys/types.h>
25#include <sys/stat.h>
26
27#ifdef _MSC_VER /* _WIN32 */
28
29#include <windows.h>
30
31#define snprintf _snprintf
32#define vsnprintf _vsnprintf
33typedef unsigned char u_int8_t;
34typedef short int16_t;
35typedef unsigned short u_int16_t;
36typedef int int32_t;
37typedef unsigned int u_int32_t;
38typedef long int64_t;
39typedef unsigned long u_int64_t;
40typedef int32_t register_t;
41typedef unsigned long ssize_t;
42
43#endif
44
45#include <stdio.h>
46#endif
47
48/*
49 * XXX
50 * MacOS: ensure that Metrowerks C makes enumeration types int sized.
51 */
52#ifdef __MWERKS__
53#pragma enumsalwaysint on
54#endif
55
56/*
57 * XXX
58 * Handle function prototypes and the keyword "const".  This steps on name
59 * space that DB doesn't control, but all of the other solutions are worse.
60 *
61 * XXX
62 * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
63 * defined by default, you specify a command line flag or #pragma to turn
64 * it on.  Don't do that, however, because some of Microsoft's own header
65 * files won't compile.
66 */
67#undef	__P
68#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
69#define	__P(protos)	protos		/* ANSI C prototypes */
70#else
71#define	const
72#define	__P(protos)	()		/* K&R C preprocessor */
73#endif
74
75/*
76 * !!!
77 * DB needs basic information about specifically sized types.  If they're
78 * not provided by the system, typedef them here.
79 *
80 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
81 * as does BIND and Kerberos, since we don't know for sure what #include
82 * files the user is using.
83 *
84 * !!!
85 * We also provide the standard u_int, u_long etc., if they're not provided
86 * by the system.
87 */
88
89#ifndef _MSC_VER /* WIN32 */
90#ifndef	__BIT_TYPES_DEFINED__
91#define	__BIT_TYPES_DEFINED__
92@u_int8_decl@
93@int16_decl@
94@u_int16_decl@
95@int32_decl@
96@u_int32_decl@
97#endif
98
99@u_char_decl@
100@u_short_decl@
101@u_int_decl@
102@u_long_decl@
103@ssize_t_decl@
104
105#endif /* _MSC_VER - WIN32 */
106
107#define	DB_VERSION_MAJOR	3
108#define	DB_VERSION_MINOR	0
109#define	DB_VERSION_PATCH	55
110#define	DB_VERSION_STRING	"Sleepycat Software: Berkeley DB 3.0.55: (February 28, 2000)"
111
112typedef	u_int32_t	db_pgno_t;	/* Page number type. */
113typedef	u_int16_t	db_indx_t;	/* Page offset type. */
114#define	DB_MAX_PAGES	0xffffffff	/* >= # of pages in a file */
115
116typedef	u_int32_t	db_recno_t;	/* Record number type. */
117#define	DB_MAX_RECORDS	0xffffffff	/* >= # of records in a tree */
118
119/* Forward structure declarations, so applications get type checking. */
120struct __db;		typedef struct __db DB;
121#ifdef DB_DBM_HSEARCH
122			typedef struct __db DBM;
123#endif
124struct __db_bt_stat;	typedef struct __db_bt_stat DB_BTREE_STAT;
125struct __db_dbt;	typedef struct __db_dbt DBT;
126struct __db_env;	typedef struct __db_env DB_ENV;
127struct __db_h_stat;	typedef struct __db_h_stat DB_HASH_STAT;
128struct __db_ilock;	typedef struct __db_ilock DB_LOCK_ILOCK;
129struct __db_lock_stat;	typedef struct __db_lock_stat DB_LOCK_STAT;
130struct __db_lock_u;	typedef struct __db_lock_u DB_LOCK;
131struct __db_lockreq;	typedef struct __db_lockreq DB_LOCKREQ;
132struct __db_log_stat;	typedef struct __db_log_stat DB_LOG_STAT;
133struct __db_lsn;	typedef struct __db_lsn DB_LSN;
134struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
135struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
136struct __db_mpool_stat;	typedef struct __db_mpool_stat DB_MPOOL_STAT;
137struct __db_mpoolfile;	typedef struct __db_mpoolfile DB_MPOOLFILE;
138struct __db_qam_stat;	typedef struct __db_qam_stat DB_QUEUE_STAT;
139struct __db_txn;	typedef struct __db_txn DB_TXN;
140struct __db_txn_active;	typedef struct __db_txn_active DB_TXN_ACTIVE;
141struct __db_txn_stat;	typedef struct __db_txn_stat DB_TXN_STAT;
142struct __dbc;		typedef struct __dbc DBC;
143struct __fh_t;		typedef struct __fh_t DB_FH;
144struct __db_cmpr_info;	typedef struct __db_cmpr_info DB_CMPR_INFO;
145
146/* Key/data structure -- a Data-Base Thang. */
147struct __db_dbt {
148	void	 *data;			/* key/data */
149	u_int32_t size;			/* key/data length */
150	u_int32_t ulen;			/* RO: length of user buffer. */
151	u_int32_t dlen;			/* RO: get/put record length. */
152	u_int32_t doff;			/* RO: get/put record offset. */
153
154#define	DB_DBT_INTERNAL	0x001		/* Ignore user's malloc (internal). */
155#define	DB_DBT_MALLOC	0x002		/* Return in malloc'd memory. */
156#define	DB_DBT_PARTIAL	0x004		/* Partial put/get. */
157#define	DB_DBT_REALLOC	0x008		/* Return in realloc'd memory. */
158#define	DB_DBT_USERMEM	0x010		/* Return in user's memory. */
159	u_int32_t flags;
160};
161
162/*
163 * Information from user specified page compression
164 */
165struct __db_cmpr_info {
166    int (*compress)                     /* Compression function */
167	__P((const u_int8_t*, int, u_int8_t**, int*,void *));
168    int (*uncompress)                   /* Uncompression function */
169	__P((const u_int8_t*, int, u_int8_t*, int,void *));
170    u_int8_t coefficient;	        /* Compression factor is 1<<coefficient  */
171    u_int8_t max_npages;                /* Max number of pages  worst case */
172    u_int8_t zlib_flags;                /* Zlib Compresson Level */
173    void         *user_data;            /* Persistent information for compression functions */
174};
175
176/*
177 * Flags understood by both CDB_db_create and CDB_db_env_create.
178 */
179#define	DB_CXX_NO_EXCEPTIONS  0x000001	/* C++: return error values. */
180
181/*
182 * Flags understood by only CDB_db_create.
183 */
184#define	DB_XA_CREATE	      0x000002	/* Open in an XA environment. */
185
186/*
187 * Flags understood by both DBENV->open and DB->open.
188 */
189#define	DB_CREATE	      0x000001	/* Create file as necessary. */
190#define	DB_NOMMAP	      0x000002	/* Don't mmap underlying file. */
191#define	DB_THREAD	      0x000004	/* Applications are threaded. */
192
193/*
194 * Flags understood by both DBENV->open and DBENV->remove.
195 */
196#define	DB_FORCE	      0x000008	/* Force (anything). */
197#define	DB_INIT_CDB	      0x000010	/* Concurrent Access Methods. */
198#define	DB_INIT_LOCK	      0x000020	/* Initialize locking. */
199#define	DB_INIT_LOG	      0x000040	/* Initialize logging. */
200#define	DB_INIT_MPOOL	      0x000080	/* Initialize mpool. */
201#define	DB_INIT_TXN	      0x000100	/* Initialize transactions. */
202#define	DB_RECOVER	      0x000200	/* Run normal recovery. */
203#define	DB_RECOVER_FATAL      0x000400	/* Run catastrophic recovery. */
204#define	DB_SYSTEM_MEM	      0x000800	/* Use system-backed memory. */
205#define	DB_TXN_NOSYNC	      0x001000	/* Do not sync log on commit. */
206#define	DB_USE_ENVIRON	      0x002000	/* Use the environment. */
207#define	DB_USE_ENVIRON_ROOT   0x004000	/* Use the environment if root. */
208
209/*
210 * Flags understood by only DBENV->open.
211 */
212#define	DB_LOCKDOWN	      0x008000	/* Lock memory into physical core. */
213#define	DB_PRIVATE	      0x010000	/* DB_ENV is process local. */
214
215/*
216 * Flags understood by DBENV->CDB_txn_begin.
217 */
218/*	DB_TXN_NOSYNC	      0x001000	   Do not sync log on commit. */
219#define	DB_TXN_SYNC	      0x000001	/* Always sync log on commit. */
220#define	DB_TXN_NOWAIT	      0x000002	/* Do not wait for locks in this TXN. */
221
222/*
223 * Flags understood by only DB->open.
224 */
225#define	DB_EXCL		      0x000008	/* Exclusive open (O_EXCL). */
226#define	DB_RDONLY	      0x000010	/* Read-only (O_RDONLY). */
227#define	DB_TRUNCATE	      0x000020	/* Discard existing DB (O_TRUNC). */
228#define	DB_FCNTL_LOCKING      0x000040	/* Undocumented: fcntl(2) locking. */
229#define DB_COMPRESS	      0x000080  /* Transparent I/O compression */
230
231/*
232 * Flags understood by only DB->set_feedback's callback.
233 */
234/*	DB_RECOVER	      0x000200	   Running recovery. */
235#define	DB_UPGRADE	      0x000001	/* Upgrading. */
236
237/*
238 * Deadlock detector modes; used in the DBENV structure to configure the
239 * locking subsystem.
240 */
241#define	DB_LOCK_NORUN		0
242#define	DB_LOCK_DEFAULT		1	/* Default policy. */
243#define	DB_LOCK_OLDEST		2	/* Abort oldest transaction. */
244#define	DB_LOCK_RANDOM		3	/* Abort random transaction. */
245#define	DB_LOCK_YOUNGEST	4	/* Abort youngest transaction. */
246
247/*
248 * Flags understood by only DB->set_flags.
249 */
250#define	DB_DUP			0x0001	/* Btree, Hash: duplicate keys. */
251#define	DB_DUPSORT		0x0002	/* Btree, Hash: duplicate keys. */
252#define	DB_RECNUM		0x0004	/* Btree: record numbers. */
253#define	DB_RENUMBER		0x0008	/* Recno: renumber on insert/delete. */
254#define	DB_REVSPLITOFF		0x0010	/* Btree: turn off reverse splits. */
255#define	DB_SNAPSHOT		0x0020	/* Recno: snapshot the input. */
256
257struct __db_env {
258	/*******************************************************
259	 * Public: owned by the application.
260	 *******************************************************/
261	FILE		*db_errfile;	/* Error message file stream. */
262	const char	*db_errpfx;	/* Error message prefix. */
263					/* Callbacks. */
264	void (*db_errcall) __P((const char *, char *));
265	void (*db_feedback) __P((DB_ENV *, int, int));
266	void (*db_paniccall) __P((DB_ENV *, int));
267	int  (*db_recovery_init) __P((DB_ENV *));
268
269	/*
270	 * Currently, the verbose list is a bit field with room for 32
271	 * entries.  There's no reason that it needs to be limited, if
272	 * there are ever more than 32 entries, convert to a bit array.
273	 */
274#define	DB_VERB_CHKPOINT	0x0001	/* List checkpoints. */
275#define	DB_VERB_DEADLOCK	0x0002	/* Deadlock detection information. */
276#define	DB_VERB_RECOVERY	0x0004	/* Recovery information. */
277#define	DB_VERB_WAITSFOR	0x0008	/* Dump waits-for table. */
278	u_int32_t	 verbose;	/* Verbose output. */
279
280	/* Locking. */
281	u_int8_t	*lk_conflicts;	/* Two dimensional conflict matrix. */
282	u_int32_t	 lk_modes;	/* Number of lock modes in table. */
283	u_int32_t	 lk_max;	/* Maximum number of locks. */
284	u_int32_t	 lk_detect;	/* Deadlock detect on all conflicts. */
285
286	/* Logging. */
287	u_int32_t	 lg_bsize;	/* Buffer size. */
288	u_int32_t	 lg_max;	/* Maximum file size. */
289
290	/* Memory pool. */
291	u_int32_t	 mp_gbytes;	/* Cachesize: GB. */
292	u_int32_t	 mp_bytes;	/* Cachesize: Bytes. */
293	size_t		 mp_size;	/* DEPRECATED: Cachesize: bytes. */
294	int		 mp_ncache;	/* Number of cache regions. */
295	size_t		 mp_mmapsize;	/* Maximum file size for mmap. */
296	DB_CMPR_INFO   * mp_cmpr_info;  /* Compression info. */
297
298	/* Transactions. */
299	u_int32_t	 tx_max;	/* Maximum number of transactions. */
300	int (*tx_recover)		/* Dispatch function for recovery. */
301	    __P((DB_ENV *, DBT *, DB_LSN *, int, void *));
302
303	/*******************************************************
304	 * Private: owned by DB.
305	 *******************************************************/
306	int		 db_panic;	/* Panic causing errno. */
307
308	/* User files, paths. */
309	char		*db_home;	/* Database home. */
310	char		*db_log_dir;	/* Database log file directory. */
311	char		*db_tmp_dir;	/* Database tmp file directory. */
312
313	char	       **db_data_dir;	/* Database data file directories. */
314	int		 data_cnt;	/* Database data file slots. */
315	int		 data_next;	/* Next Database data file slot. */
316
317	int		 db_mode;	/* Default open permissions. */
318
319	void		*reginfo;	/* REGINFO structure reference. */
320	DB_FH		*lockfhp;	/* Fcntl(2) locking file handle. */
321
322	void		*lg_handle;	/* Log handle. */
323
324	void		*lk_handle;	/* Lock handle. */
325
326	void		*mp_handle;	/* Mpool handle. */
327
328	void		*tx_handle;	/* Txn handle. */
329
330	int	      (**dtab)		/* Dispatch table */
331			    __P((DB_ENV *, DBT *, DB_LSN *, int, void *));
332	size_t		 dtab_size;	/* Slots in the dispatch table. */
333
334	/*
335	 * XA support.
336	 *
337	 * !!!
338	 * Explicit representations of structures in queue.h.
339	 *
340	 * TAILQ_ENTRY(__db_env);
341	 */
342	struct {
343		struct __db_env *tqe_next;
344		struct __db_env **tqe_prev;
345	} links;
346	int		 xa_rmid;	/* XA Resource Manager ID. */
347	DB_TXN		*xa_txn;	/* XA Current transaction. */
348
349	void	*cj_internal;		/* C++/Java private. */
350
351					/* Methods. */
352	int  (*close) __P((DB_ENV *, u_int32_t));
353	void (*err) __P((const DB_ENV *, int, const char *, ...));
354	void (*errx) __P((const DB_ENV *, const char *, ...));
355	int  (*open) __P((DB_ENV *,
356		const char *, char * const *, u_int32_t, int));
357	int  (*remove) __P((DB_ENV *, const char *, char * const *, u_int32_t));
358	void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *)));
359	void (*set_errfile) __P((DB_ENV *, FILE *));
360	void (*set_errpfx) __P((DB_ENV *, const char *));
361	void (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
362	int  (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *)));
363	int  (*set_mutexlocks) __P((DB_ENV *, int));
364	int  (*set_pageyield) __P((DB_ENV *, int));
365	int  (*set_panic) __P((DB_ENV *, int));
366	void (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
367	int  (*set_region_init) __P((DB_ENV *, int));
368	int  (*set_tas_spins) __P((DB_ENV *, u_int32_t));
369	int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
370
371	int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
372	int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
373
374	int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
375	int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
376	int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
377
378	int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
379	int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
380
381	int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
382	int  (*set_tx_recover) __P((DB_ENV *,
383		int (*)(DB_ENV *, DBT *, DB_LSN *, int, void *)));
384
385	int  (*set_func_close) __P((DB_ENV *, int (*)(int)));
386	int  (*set_func_dirfree) __P((DB_ENV *, void (*)(char **, int)));
387	int  (*set_func_dirlist) __P((DB_ENV *,
388		int (*)(const char *, char ***, int *)));
389	int  (*set_func_exists) __P((DB_ENV *, int (*)(const char *, int *)));
390	int  (*set_func_free) __P((DB_ENV *, void (*)(void *)));
391	int  (*set_func_fsync) __P((DB_ENV *, int (*)(int)));
392	int  (*set_func_ioinfo) __P((DB_ENV *, int (*)(const char *,
393		int, u_int32_t *, u_int32_t *, u_int32_t *)));
394	int  (*set_func_malloc) __P((DB_ENV *, void *(*)(size_t)));
395	int  (*set_func_map) __P((DB_ENV *,
396		int (*)(char *, size_t, int, int, void **)));
397	int  (*set_func_open) __P((DB_ENV *, int (*)(const char *, int, ...)));
398	int  (*set_func_read) __P((DB_ENV *, ssize_t (*)(int, void *, size_t)));
399	int  (*set_func_realloc) __P((DB_ENV *, void *(*)(void *, size_t)));
400	int  (*set_func_rename) __P((DB_ENV *,
401		int (*)(const char *, const char *)));
402	int  (*set_func_seek) __P((DB_ENV *,
403		int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
404	int  (*set_func_sleep) __P((DB_ENV *, int (*)(u_long, u_long)));
405	int  (*set_func_unlink) __P((DB_ENV *, int (*)(const char *)));
406	int  (*set_func_unmap) __P((DB_ENV *, int (*)(void *, size_t)));
407	int  (*set_func_write) __P((DB_ENV *,
408		ssize_t (*)(int, const void *, size_t)));
409	int  (*set_func_yield) __P((DB_ENV *, int (*)(void)));
410
411#ifdef CONFIG_TEST
412#define	DB_TEST_PREOPEN		 1	/* before CDB___os_open */
413#define	DB_TEST_POSTOPEN	 2	/* after CDB___os_open */
414#define	DB_TEST_POSTLOGMETA	 3	/* after logging meta in btree */
415#define	DB_TEST_POSTLOG		 4	/* after logging all pages */
416#define	DB_TEST_POSTSYNC	 5	/* after syncing the log */
417#define	DB_TEST_PRERENAME	 6	/* before CDB___os_rename */
418#define	DB_TEST_POSTRENAME	 7	/* after CDB___os_rename */
419	int		 test_abort;	/* Abort value for testing. */
420	int		 test_copy;	/* Copy value for testing. */
421#endif
422
423#define	DB_ENV_CDB		0x00001	/* DB_INIT_CDB. */
424#define	DB_ENV_CREATE		0x00002	/* DB_CREATE set. */
425#define	DB_ENV_DBLOCAL		0x00004	/* DB_ENV allocated for private DB. */
426#define	DB_ENV_LOCKDOWN		0x00008	/* DB_LOCKDOWN set. */
427#define	DB_ENV_LOCKING		0x00010	/* Locking initialized. */
428#define	DB_ENV_LOGGING		0x00020	/* Logging initialized. */
429#define	DB_ENV_NOMMAP		0x00040	/* DB_NOMMAP set. */
430#define	DB_ENV_OPEN_CALLED	0x00080	/* DBENV->open called (paths valid). */
431#define	DB_ENV_PRIVATE		0x00100	/* DB_PRIVATE set. */
432#define	DB_ENV_STANDALONE	0x00200	/* Test: freestanding environment. */
433#define	DB_ENV_SYSTEM_MEM	0x00400	/* DB_SYSTEM_MEM set. */
434#define	DB_ENV_THREAD		0x00800	/* DB_THREAD set. */
435#define	DB_ENV_TXN		0x01000	/* DB_TXN_NOSYNC set. */
436#define	DB_ENV_TXN_NOSYNC	0x02000	/* DB_TXN_NOSYNC set. */
437#define	DB_ENV_USER_ALLOC	0x04000	/* User allocated the structure. */
438	u_int32_t	 flags;		/* Flags. */
439};
440
441/*******************************************************
442 * Access methods.
443 *******************************************************/
444/*
445 * !!!
446 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
447 */
448typedef enum {
449	DB_BTREE=1,
450	DB_HASH,
451	DB_RECNO,
452	DB_QUEUE,
453	DB_UNKNOWN			/* Figure it out on open. */
454} DBTYPE;
455
456#define	DB_BTREEVERSION	7		/* Current btree version. */
457#define	DB_BTREEOLDVER	6		/* Oldest btree version supported. */
458#define	DB_BTREEMAGIC	0x053162
459
460#define	DB_HASHVERSION	6		/* Current hash version. */
461#define	DB_HASHOLDVER	4		/* Oldest hash version supported. */
462#define	DB_HASHMAGIC	0x061561
463
464#define	DB_QAMVERSION	1		/* Current queue version. */
465#define	DB_QAMOLDVER	1		/* Oldest queue version supported. */
466#define	DB_QAMMAGIC	0x042253
467
468#define	DB_LOGVERSION	2		/* Current log version. */
469#define	DB_LOGOLDVER	2		/* Oldest log version supported. */
470#define	DB_LOGMAGIC	0x040988
471
472/*
473 * DB access method and cursor operation values.  Each value is an operation
474 * code to which additional bit flags are added.
475 */
476#define	DB_AFTER	 1		/* c_put() */
477#define	DB_APPEND	 2		/* put() */
478#define	DB_BEFORE	 3		/* c_put() */
479#define	DB_CHECKPOINT	 4		/* CDB_log_put(), CDB_log_get() */
480#define	DB_CONSUME	 5		/* c_get() */
481#define	DB_CURLSN	 6		/* CDB_log_put() */
482#define	DB_CURRENT	 7		/* c_get(), c_put(), CDB_log_get() */
483#define	DB_DUPCURSOR	 8		/* cursor() (internal) */
484#define	DB_FIRST	 9		/* c_get(), CDB_log_get() */
485#define	DB_FLUSH	10		/* CDB_log_put() */
486#define	DB_GET_BOTH	11		/* get(), c_get() */
487#define	DB_GET_RECNO	12		/* c_get() */
488#define	DB_JOIN_ITEM	13		/* c_get(); do not do primary lookup */
489#define	DB_KEYFIRST	14		/* c_put() */
490#define	DB_KEYLAST	15		/* c_put() */
491#define	DB_LAST		16		/* c_get(), CDB_log_get() */
492#define	DB_NEXT		17		/* c_get(), CDB_log_get() */
493#define	DB_NEXT_DUP	18		/* c_get() */
494#define	DB_NEXT_NODUP	19		/* c_get() */
495#define	DB_NOOVERWRITE	20		/* put() */
496#define	DB_NOSYNC	21		/* close() */
497#define	DB_POSITION	22		/* c_dup() */
498#define	DB_POSITIONI	23		/* c_dup() (internal) */
499#define	DB_PREV		24		/* c_get(), CDB_log_get() */
500#define	DB_RECORDCOUNT	25		/* stat() */
501#define	DB_SET		26		/* c_get(), CDB_log_get() */
502#define	DB_SET_RANGE	27		/* c_get() */
503#define	DB_SET_RECNO	28		/* get(), c_get() */
504#define	DB_WRITECURSOR	29		/* cursor() */
505#define	DB_WRITELOCK	30		/* cursor() (internal) */
506
507/* This has to change when the max opcode above hits 32. */
508#define	DB_OPFLAGS_MASK	0x000000ff	/* Mask for operations flags. */
509#define	DB_RMW		0x80000000	/* Acquire write flag immediately. */
510
511/*
512 * DB (user visible) error return codes.
513 *
514 * !!!
515 * Changes to any of the user visible error return codes must be reflected
516 * in java/src/com/sleepycat/db/Db.java.
517 *
518 * !!!
519 * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
520 * following:
521 *	#include <errno.h>
522 *	#define DB_LOCK_DEADLOCK EAGAIN
523 *
524 * !!!
525 * We don't want our error returns to conflict with other packages where
526 * possible, so pick a base error value that's hopefully not common.
527 */
528#define	DB_INCOMPLETE		(-30999)/* Sync didn't finish. */
529#define	DB_KEYEMPTY		(-30998)/* Key/data deleted or never created. */
530#define	DB_KEYEXIST		(-30997)/* The key/data pair already exists. */
531#define	DB_LOCK_DEADLOCK	(-30996)/* Deadlock. */
532#define	DB_LOCK_NOTGRANTED	(-30995)/* Lock unavailable. */
533#define	DB_NOTFOUND		(-30994)/* Key/data pair not found (EOF). */
534#define	DB_OLD_VERSION		(-30993)/* Out-of-date version. */
535#define	DB_RUNRECOVERY		(-30992)/* Panic return. */
536
537/* DB (private) error return codes. */
538#define	DB_DELETED		(-30991)/* Recovery file marked deleted. */
539#define	DB_NEEDSPLIT		(-30990)/* Page needs to be split. */
540#define	DB_SWAPBYTES		(-30989)/* Database needs byte swapping. */
541#define	DB_TXN_CKP		(-30988)/* Encountered ckp record in log. */
542
543#define	DB_FILE_ID_LEN		20	/* DB file ID length. */
544
545/* DB access method description structure. */
546struct __db {
547	/*******************************************************
548	 * Public: owned by the application.
549	 *******************************************************/
550	size_t	 pgsize;		/* Database logical page size. */
551
552					/* Callbacks. */
553	void (*db_feedback) __P((DB *, int, int));
554	void *(*db_malloc) __P((size_t));
555	void *(*db_realloc) __P((void *, size_t));
556	int (*dup_compare) __P((const DBT *, const DBT *));
557
558	/*******************************************************
559	 * Private: owned by DB.
560	 *******************************************************/
561	DB_ENV *dbenv;			/* Backing environment. */
562
563	DBTYPE	 type;			/* DB access method type. */
564
565	DB_MPOOLFILE *mpf;		/* Backing buffer pool. */
566
567	void	*mutexp;		/* Synchronization for free threading */
568
569	u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
570
571#define	DB_LOGFILEID_INVALID	-1
572	int32_t	 log_fileid;		/* File's unique ID for logging. */
573	DB_TXN	*open_txn;		/* Transaction to protect creates. */
574
575	/*
576	 * !!!
577	 * Some applications use DB but implement their own locking outside of
578	 * DB.  If they're using fcntl(2) locking on the underlying database
579	 * file, and we open and close a file descriptor for that file, we will
580	 * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
581	 * undocumented interface to support this usage which leaves any file
582	 * descriptors we open until DB->close.  This will only work with the
583	 * DB->open interface and simple caches, e.g., creating a transaction
584	 * thread may open/close file descriptors this flag doesn't protect.
585	 * Locking with fcntl(2) on a file that you don't own is a very, very
586	 * unsafe thing to do.  'Nuff said.
587	 */
588	DB_FH	*saved_open_fhp;	/* Saved file handle. */
589
590	/*
591	 * Cursor queues.
592	 *
593	 * !!!
594	 * Explicit representations of structures in queue.h.
595	 *
596	 * TAILQ_HEAD(free_queue, __dbc);
597	 * TAILQ_HEAD(active_queue, __dbc);
598	 */
599	struct {
600		struct __dbc *tqh_first;
601		struct __dbc **tqh_last;
602	} free_queue;
603	struct {
604		struct __dbc *tqh_first;
605		struct __dbc **tqh_last;
606	} active_queue;
607
608	void	*bt_internal;		/* Btree/Recno access method private. */
609	void	*cj_internal;		/* C++/Java private. */
610	void	*h_internal;		/* Hash access method private. */
611	void	*q_internal;		/* Queue access method private. */
612	void	*xa_internal;		/* XA private. */
613
614					/* Methods. */
615	int  (*close) __P((DB *, u_int32_t));
616	int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
617	int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
618	void (*err) __P((DB *, int, const char *, ...));
619	void (*errx) __P((DB *, const char *, ...));
620	int  (*fd) __P((DB *, int *));
621	int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
622	int  (*get_byteswapped) __P((DB *));
623	DBTYPE
624	     (*get_type) __P((DB *));
625	int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
626	int  (*open) __P((DB *,
627		const char *, const char *, DBTYPE, u_int32_t, int));
628	int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
629	int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
630	int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
631	int  (*set_dup_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
632	void (*set_errcall) __P((DB *, void (*)(const char *, char *)));
633	void (*set_errfile) __P((DB *, FILE *));
634	void (*set_errpfx) __P((DB *, const char *));
635	void (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
636	int  (*set_flags) __P((DB *, u_int32_t));
637	int  (*set_lorder) __P((DB *, int));
638	int  (*set_malloc) __P((DB *, void *(*)(size_t)));
639	int  (*set_pagesize) __P((DB *, u_int32_t));
640	void (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
641	int  (*set_realloc) __P((DB *, void *(*)(void *, size_t)));
642	int  (*stat) __P((DB *, void *, void *(*)(size_t), u_int32_t));
643	int  (*sync) __P((DB *, u_int32_t));
644	int  (*upgrade) __P((DB *, const char *, u_int32_t));
645
646	int  (*set_bt_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
647	int  (*set_bt_maxkey) __P((DB *, u_int32_t));
648	int  (*set_bt_minkey) __P((DB *, u_int32_t));
649	int  (*set_bt_prefix) __P((DB *, size_t (*)(const DBT *, const DBT *)));
650
651	int  (*set_h_ffactor) __P((DB *, u_int32_t));
652	int  (*set_h_hash) __P((DB *, u_int32_t (*)(const void *, u_int32_t)));
653	int  (*set_h_nelem) __P((DB *, u_int32_t));
654
655	int  (*set_re_delim) __P((DB *, int));
656	int  (*set_re_len) __P((DB *, u_int32_t));
657	int  (*set_re_pad) __P((DB *, int));
658	int  (*set_re_source) __P((DB *, const char *));
659
660#define	DB_OK_BTREE	0x01
661#define	DB_OK_HASH	0x02
662#define	DB_OK_QUEUE	0x04
663#define	DB_OK_RECNO	0x08
664	u_int32_t	am_ok;		/* Legal AM choices. */
665
666#define	DB_AM_DISCARD	0x00001		/* Discard any cached pages. */
667#define	DB_AM_DUP	0x00002		/* DB_DUP. */
668#define	DB_AM_INMEM	0x00004		/* In-memory; no sync on close. */
669#define	DB_AM_PGDEF	0x00008		/* Page size was defaulted. */
670#define	DB_AM_RDONLY	0x00010		/* Database is readonly. */
671#define	DB_AM_SUBDB	0x00020		/* Subdatabases supported. */
672#define	DB_AM_SWAP	0x00040		/* Pages need to be byte-swapped. */
673#define	DB_BT_RECNUM	0x00080		/* DB_RECNUM. */
674#define	DB_BT_REVSPLIT	0x00100		/* DB_REVSPLITOFF. */
675#define	DB_DBM_ERROR	0x00200		/* Error in DBM/NDBM database. */
676#define	DB_OPEN_CALLED	0x00400		/* DB->open called. */
677#define	DB_RE_DELIMITER	0x00800		/* Variablen length delimiter set. */
678#define	DB_RE_FIXEDLEN	0x01000		/* Fixed-length records. */
679#define	DB_RE_PAD	0x02000		/* Fixed-length record pad. */
680#define	DB_RE_RENUMBER	0x04000		/* DB_RENUMBER. */
681#define	DB_RE_SNAPSHOT	0x08000		/* DB_SNAPSHOT. */
682#define DB_AM_CMPR	0x10000         /* Transparent I/O compression */
683	u_int32_t flags;
684};
685
686/*
687 * DB_LOCK_ILOCK --
688 *	Internal DB access method lock.
689 */
690struct __db_ilock {
691	db_pgno_t pgno;			/* Page being locked. */
692	u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
693#define DB_RECORD_LOCK	1
694#define DB_PAGE_LOCK	2
695	u_int8_t type;			/* Record or Page lock */
696};
697
698/*
699 * DB_LOCK --
700 *	The structure is allocated by the caller and filled in during a
701 *	CDB_lock_get request (or a CDB_lock_vec/DB_LOCK_GET).
702 */
703struct __db_lock_u {
704	size_t		off;		/* Offset of the lock in the region */
705	u_int32_t	ndx;		/* Index of the object referenced by
706					 * this lock; used for locking. */
707	u_int32_t	gen;		/* Generation number of this lock. */
708};
709
710/* Cursor description structure. */
711struct __dbc {
712	DB *dbp;			/* Related DB access method. */
713	DB_TXN	 *txn;			/* Associated transaction. */
714
715	/*
716	 * !!!
717	 * Explicit representations of structures in queue.h.
718	 *
719	 * TAILQ_ENTRY(__dbc) links;	Active/free cursor queues.
720	 */
721	struct {
722		struct __dbc *tqe_next;
723		struct __dbc **tqe_prev;
724	} links;
725
726	u_int32_t lid;			/* Default process' locker id. */
727	u_int32_t locker;		/* Locker for this operation. */
728	DBT	  lock_dbt;		/* DBT referencing lock. */
729	DB_LOCK_ILOCK lock;		/* Object to be locked. */
730	DB_LOCK	mylock;			/* Lock held on this cursor. */
731
732	DBT rkey;			/* Returned key. */
733	DBT rdata;			/* Returned data. */
734
735	int (*c_close) __P((DBC *));	/* Methods: public. */
736	int (*c_del) __P((DBC *, u_int32_t));
737	int (*c_dup) __P((DBC *, DBC **, u_int32_t));
738	int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
739	int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
740
741	int (*c_am_close) __P((DBC *));	/* Methods: private. */
742	int (*c_am_destroy) __P((DBC *));
743
744	void	 *internal;		/* Access method private. */
745
746#define	DBC_CONTINUE	0x001		/* Continue dup search: next item. */
747#define	DBC_RECOVER	0x002		/* In recovery (do not log or lock). */
748#define	DBC_RMW		0x004		/* Acquire write flag in read op. */
749#define	DBC_WRITECURSOR	0x008		/* Cursor may be used to write (CDB). */
750#define	DBC_WRITER	0x010		/* Cursor immediately writing (CDB). */
751	u_int32_t flags;
752};
753
754/* Btree/Recno statistics structure. */
755struct __db_bt_stat {
756	u_int32_t bt_metaflags;		/* Metadata flags. */
757	u_int32_t bt_maxkey;		/* Maxkey value. */
758	u_int32_t bt_minkey;		/* Minkey value. */
759	u_int32_t bt_re_len;		/* Fixed-length record length. */
760	u_int32_t bt_re_pad;		/* Fixed-length record pad. */
761	u_int32_t bt_pagesize;		/* Page size. */
762	u_int32_t bt_levels;		/* Tree levels. */
763	u_int32_t bt_nrecs;		/* Number of records. */
764	u_int32_t bt_int_pg;		/* Internal pages. */
765	u_int32_t bt_leaf_pg;		/* Leaf pages. */
766	u_int32_t bt_dup_pg;		/* Duplicate pages. */
767	u_int32_t bt_over_pg;		/* Overflow pages. */
768	u_int32_t bt_free;		/* Pages on the free list. */
769	u_int32_t bt_int_pgfree;	/* Bytes free in internal pages. */
770	u_int32_t bt_leaf_pgfree;	/* Bytes free in leaf pages. */
771	u_int32_t bt_dup_pgfree;	/* Bytes free in duplicate pages. */
772	u_int32_t bt_over_pgfree;	/* Bytes free in overflow pages. */
773	u_int32_t bt_magic;		/* Magic number. */
774	u_int32_t bt_version;		/* Version number. */
775};
776
777/* Queue statistics structure. */
778struct __db_qam_stat {
779	u_int32_t qs_magic;		/* Magic number. */
780	u_int32_t qs_version;		/* Version number. */
781	u_int32_t qs_metaflags;		/* Metadata flags. */
782	u_int32_t qs_nrecs;		/* Number of records. */
783	u_int32_t qs_pages;		/* Data pages. */
784	u_int32_t qs_pagesize;		/* Page size. */
785	u_int32_t qs_pgfree;		/* Bytes free in data pages. */
786	u_int32_t qs_re_len;		/* Fixed-length record length. */
787	u_int32_t qs_re_pad;		/* Fixed-length record pad. */
788	u_int32_t qs_start;		/* Start offset. */
789	u_int32_t qs_first_recno;	/* First not deleted record. */
790	u_int32_t qs_cur_recno;		/* Last allocated record number. */
791};
792
793/* Hash statistics structure. */
794struct __db_h_stat {
795	u_int32_t hash_magic;		/* Magic number. */
796	u_int32_t hash_version;		/* Version number. */
797	u_int32_t hash_metaflags;	/* Metadata flags. */
798	u_int32_t hash_pagesize;	/* Page size. */
799	u_int32_t hash_nelem;		/* Original nelem specified. */
800	u_int32_t hash_ffactor;		/* Fill factor specified at create. */
801	u_int32_t hash_nrecs;		/* Number of records. */
802	u_int32_t hash_buckets;		/* Number of hash buckets. */
803	u_int32_t hash_free;		/* Pages on the free list. */
804	u_int32_t hash_bfree;		/* Bytes free on bucket pages. */
805	u_int32_t hash_bigpages;	/* Number of big key/data pages. */
806	u_int32_t hash_big_bfree;	/* Bytes free on big item pages. */
807	u_int32_t hash_overflows;	/* Number of overflow pages. */
808	u_int32_t hash_ovfl_free;	/* Bytes free on ovfl pages. */
809	u_int32_t hash_dup;		/* Number of dup pages. */
810	u_int32_t hash_dup_free;	/* Bytes free on duplicate pages. */
811};
812
813#if defined(__cplusplus)
814extern "C" {
815#endif
816int   CDB_db_create __P((DB **, DB_ENV *, u_int32_t));
817int   CDB_db_env_create __P((DB_ENV **, u_int32_t));
818char *CDB_db_strerror __P((int));
819char *CDB_db_version __P((int *, int *, int *));
820
821#if defined(__cplusplus)
822}
823#endif
824
825/*******************************************************
826 * Locking
827 *******************************************************/
828#define	DB_LOCKVERSION	1
829
830/* Flag values for CDB_lock_vec(), CDB_lock_get(). */
831#define	DB_LOCK_NOWAIT		0x01	/* Don't wait on unavailable lock. */
832#define	DB_LOCK_RECORD		0x02	/* Internal: record lock. */
833#define	DB_LOCK_UPGRADE		0x04	/* Internal: upgrade existing lock. */
834
835/* Flag values for CDB_lock_detect(). */
836#define	DB_LOCK_CONFLICT	0x01	/* Run on any conflict. */
837
838/*
839 * Request types.
840 *
841 * !!!
842 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
843 */
844typedef enum {
845	DB_LOCK_DUMP=0,			/* Display held locks. */
846	DB_LOCK_GET,			/* Get the lock. */
847	DB_LOCK_INHERIT,		/* Pass locks to parent. */
848	DB_LOCK_PUT,			/* Release the lock. */
849	DB_LOCK_PUT_ALL,		/* Release locker's locks. */
850	DB_LOCK_PUT_OBJ			/* Release locker's locks on obj. */
851} db_lockop_t;
852
853/*
854 * Simple R/W lock modes and for multi-granularity intention locking.
855 *
856 * !!!
857 * These values are NOT random, as they are used as an index into the lock
858 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
859 * must be == 4.
860 *
861 * !!!
862 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
863 */
864typedef enum {
865	DB_LOCK_NG=0,			/* Not granted. */
866	DB_LOCK_READ,			/* Shared/read. */
867	DB_LOCK_WRITE,			/* Exclusive/write. */
868	DB_LOCK_IWRITE,			/* Intent exclusive/write. */
869	DB_LOCK_IREAD,			/* Intent to share/read. */
870	DB_LOCK_IWR			/* Intent to read and write. */
871} db_lockmode_t;
872
873/*
874 * Status of a lock.
875 */
876typedef enum {
877	DB_LSTAT_ABORTED,		/* Lock belongs to an aborted txn. */
878	DB_LSTAT_ERR,			/* Lock is bad. */
879	DB_LSTAT_FREE,			/* Lock is unallocated. */
880	DB_LSTAT_HELD,			/* Lock is currently held. */
881	DB_LSTAT_NOGRANT,		/* Lock was not granted. */
882	DB_LSTAT_PENDING,		/* Lock was waiting and has been
883					 * promoted; waiting for the owner
884					 * to run and upgrade it to held. */
885	DB_LSTAT_WAITING		/* Lock is on the wait queue. */
886} db_status_t;
887
888/* Lock request structure. */
889struct __db_lockreq {
890	db_lockop_t	 op;		/* Operation. */
891	db_lockmode_t	 mode;		/* Requested mode. */
892	u_int32_t	 locker;	/* Locker identity. */
893	DBT		*obj;		/* Object being locked. */
894	DB_LOCK		 lock;		/* Lock returned. */
895};
896
897/*
898 * Commonly used conflict matrices.
899 *
900 * Standard Read/Write (or exclusive/shared) locks.
901 */
902#define	DB_LOCK_RW_N	3
903extern const u_int8_t CDB_db_rw_conflicts[];
904
905/* Multi-granularity locking. */
906#define	DB_LOCK_RIW_N	6
907extern const u_int8_t CDB_db_riw_conflicts[];
908
909struct __db_lock_stat {
910	u_int32_t st_lastid;		/* Last allocated locker ID. */
911	u_int32_t st_maxlocks;		/* Maximum number of locks in table. */
912	u_int32_t st_nmodes;		/* Number of lock modes. */
913	u_int32_t st_nlockers;		/* Number of lockers. */
914	u_int32_t st_maxnlockers;	/* Maximum number of lockers. */
915	u_int32_t st_nconflicts;	/* Number of lock conflicts. */
916	u_int32_t st_nrequests;		/* Number of lock gets. */
917	u_int32_t st_nreleases;		/* Number of lock puts. */
918	u_int32_t st_ndeadlocks;	/* Number of lock deadlocks. */
919	u_int32_t st_region_wait;	/* Region lock granted after wait. */
920	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
921	u_int32_t st_regsize;		/* Region size. */
922};
923
924#if defined(__cplusplus)
925extern "C" {
926#endif
927int	  CDB_lock_detect __P((DB_ENV *, u_int32_t, u_int32_t, int *));
928int	  CDB_lock_get __P((DB_ENV *,
929	    u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
930int	  CDB_lock_id __P((DB_ENV *, u_int32_t *));
931int	  CDB_lock_put __P((DB_ENV *, DB_LOCK *));
932int	  CDB_lock_stat __P((DB_ENV *, DB_LOCK_STAT **, void *(*)(size_t)));
933int	  CDB_lock_vec __P((DB_ENV *,
934	    u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
935#if defined(__cplusplus)
936}
937#endif
938
939/*******************************************************
940 * Logging.
941 *******************************************************/
942/* Flag values for CDB_log_archive(). */
943#define	DB_ARCH_ABS		0x001	/* Absolute pathnames. */
944#define	DB_ARCH_DATA		0x002	/* Data files. */
945#define	DB_ARCH_LOG		0x004	/* Log files. */
946
947/*
948 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
949 * offset within that file.  The fileid is an unsigned 4-byte quantity that
950 * uniquely identifies a file within the log directory -- currently a simple
951 * counter inside the log.  The offset is also an unsigned 4-byte value.  The
952 * log manager guarantees the offset is never more than 4 bytes by switching
953 * to a new log file before the maximum length imposed by an unsigned 4-byte
954 * offset is reached.
955 */
956struct __db_lsn {
957	u_int32_t	file;		/* File ID. */
958	u_int32_t	offset;		/* File offset. */
959};
960
961/* Log statistics structure. */
962struct __db_log_stat {
963	u_int32_t st_magic;		/* Log file magic number. */
964	u_int32_t st_version;		/* Log file version number. */
965	int st_mode;			/* Log file mode. */
966	u_int32_t st_lg_bsize;		/* Log buffer size. */
967	u_int32_t st_lg_max;		/* Maximum log file size. */
968	u_int32_t st_w_bytes;		/* Bytes to log. */
969	u_int32_t st_w_mbytes;		/* Megabytes to log. */
970	u_int32_t st_wc_bytes;		/* Bytes to log since checkpoint. */
971	u_int32_t st_wc_mbytes;		/* Megabytes to log since checkpoint. */
972	u_int32_t st_wcount;		/* Total writes to the log. */
973	u_int32_t st_wcount_fill;	/* Overflow writes to the log. */
974	u_int32_t st_scount;		/* Total syncs to the log. */
975	u_int32_t st_region_wait;	/* Region lock granted after wait. */
976	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
977	u_int32_t st_cur_file;		/* Current log file number. */
978	u_int32_t st_cur_offset;	/* Current log file offset. */
979	u_int32_t st_regsize;		/* Region size. */
980};
981
982#if defined(__cplusplus)
983extern "C" {
984#endif
985int	 CDB_log_archive __P((DB_ENV *, char **[], u_int32_t, void *(*)(size_t)));
986int	 CDB_log_compare __P((const DB_LSN *, const DB_LSN *));
987int	 CDB_log_file __P((DB_ENV *, const DB_LSN *, char *, size_t));
988int	 CDB_log_flush __P((DB_ENV *, const DB_LSN *));
989int	 CDB_log_get __P((DB_ENV *, DB_LSN *, DBT *, u_int32_t));
990int	 CDB_log_put __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
991int	 CDB_log_register __P((DB_ENV *, DB *, const char *, int32_t *));
992int	 CDB_log_stat __P((DB_ENV *, DB_LOG_STAT **, void *(*)(size_t)));
993int	 CDB_log_unregister __P((DB_ENV *, int32_t));
994#if defined(__cplusplus)
995}
996#endif
997
998/*******************************************************
999 * Mpool
1000 *******************************************************/
1001/* Flag values for CDB_memp_fget(). */
1002#define	DB_MPOOL_CREATE		0x001	/* Create a page. */
1003#define	DB_MPOOL_LAST		0x002	/* Return the last page. */
1004#define	DB_MPOOL_NEW		0x004	/* Create a new page. */
1005#define	DB_MPOOL_NEW_GROUP	0x008	/* Create a group of pages. */
1006
1007/* Flag values for CDB_memp_fput(), CDB_memp_fset(). */
1008#define	DB_MPOOL_CLEAN		0x001	/* Page is not modified. */
1009#define	DB_MPOOL_DIRTY		0x002	/* Page is modified. */
1010#define	DB_MPOOL_DISCARD	0x004	/* Don't cache the page. */
1011
1012/* Mpool statistics structure. */
1013struct __db_mpool_stat {
1014	u_int32_t st_cache_hit;		/* Pages found in the cache. */
1015	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
1016	u_int32_t st_map;		/* Pages from mapped files. */
1017	u_int32_t st_page_create;	/* Pages created in the cache. */
1018	u_int32_t st_page_in;		/* Pages read in. */
1019	u_int32_t st_page_out;		/* Pages written out. */
1020	u_int32_t st_ro_evict;		/* Clean pages forced from the cache. */
1021	u_int32_t st_rw_evict;		/* Dirty pages forced from the cache. */
1022	u_int32_t st_hash_buckets;	/* Number of hash buckets. */
1023	u_int32_t st_hash_searches;	/* Total hash chain searches. */
1024	u_int32_t st_hash_longest;	/* Longest hash chain searched. */
1025	u_int32_t st_hash_examined;	/* Total hash entries searched. */
1026	u_int32_t st_page_clean;	/* Clean pages. */
1027	u_int32_t st_page_dirty;	/* Dirty pages. */
1028	u_int32_t st_page_trickle;	/* Pages written by CDB_memp_trickle. */
1029	u_int32_t st_region_wait;	/* Region lock granted after wait. */
1030	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
1031	u_int32_t st_regsize;		/* Region size. */
1032	u_int32_t st_gbytes;		/* Cache size: GB. */
1033	u_int32_t st_bytes;		/* Cache size: B. */
1034};
1035
1036/* Mpool file open information structure. */
1037struct __db_mpool_finfo {
1038	int	   ftype;		/* File type. */
1039	DBT	  *pgcookie;		/* Byte-string passed to pgin/pgout. */
1040	u_int8_t  *fileid;		/* Unique file ID. */
1041	int32_t	   lsn_offset;		/* LSN offset in page. */
1042	u_int32_t  clear_len;		/* Cleared length on created pages. */
1043};
1044
1045/* Mpool file statistics structure. */
1046struct __db_mpool_fstat {
1047	char *file_name;		/* File name. */
1048	size_t st_pagesize;		/* Page size. */
1049	u_int32_t st_cache_hit;		/* Pages found in the cache. */
1050	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
1051	u_int32_t st_map;		/* Pages from mapped files. */
1052	u_int32_t st_page_create;	/* Pages created in the cache. */
1053	u_int32_t st_page_in;		/* Pages read in. */
1054	u_int32_t st_page_out;		/* Pages written out. */
1055};
1056
1057
1058#if defined(__cplusplus)
1059extern "C" {
1060#endif
1061
1062#if defined(__cplusplus)
1063}
1064#endif
1065
1066
1067#if defined(__cplusplus)
1068extern "C" {
1069#endif
1070int	CDB_memp_fclose __P((DB_MPOOLFILE *));
1071int	CDB_memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
1072int	CDB_memp_fopen __P((DB_ENV *, const char *,
1073	    u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
1074int	CDB_memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
1075int	CDB_memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
1076int	CDB_memp_fsync __P((DB_MPOOLFILE *));
1077int	CDB_memp_register __P((DB_ENV *, int,
1078	    int (*)(db_pgno_t, void *, DBT *),
1079	    int (*)(db_pgno_t, void *, DBT *)));
1080int	CDB_memp_stat __P((DB_ENV *,
1081	    DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
1082int	CDB_memp_sync __P((DB_ENV *, DB_LSN *));
1083int	CDB_memp_trickle __P((DB_ENV *, int, int *));
1084#if defined(__cplusplus)
1085}
1086#endif
1087
1088/*******************************************************
1089 * Transactions.
1090 *******************************************************/
1091#define	DB_TXNVERSION	1
1092
1093/* Operations values to the tx_recover() function. */
1094#define	DB_TXN_BACKWARD_ROLL	1	/* Read the log backwards. */
1095#define	DB_TXN_FORWARD_ROLL	2	/* Read the log forwards. */
1096#define	DB_TXN_OPENFILES	3	/* Read for open files. */
1097#define	DB_TXN_REDO		4	/* Redo the operation. */
1098#define	DB_TXN_UNDO		5	/* Undo the operation. */
1099
1100/* Internal transaction status values. */
1101
1102/* Transaction statistics structure. */
1103struct __db_txn_active {
1104	u_int32_t	txnid;		/* Transaction ID */
1105	u_int32_t	parentid;	/* Transaction ID of parent */
1106	DB_LSN		lsn;		/* Lsn of the begin record */
1107};
1108
1109struct __db_txn_stat {
1110	DB_LSN	  st_last_ckp;		/* lsn of the last checkpoint */
1111	DB_LSN	  st_pending_ckp;	/* last checkpoint did not finish */
1112	time_t	  st_time_ckp;		/* time of last checkpoint */
1113	u_int32_t st_last_txnid;	/* last transaction id given out */
1114	u_int32_t st_maxtxns;		/* maximum txns possible */
1115	u_int32_t st_naborts;		/* number of aborted transactions */
1116	u_int32_t st_nbegins;		/* number of begun transactions */
1117	u_int32_t st_ncommits;		/* number of committed transactions */
1118	u_int32_t st_nactive;		/* number of active transactions */
1119	u_int32_t st_maxnactive;	/* maximum active transactions */
1120	DB_TXN_ACTIVE
1121		 *st_txnarray;		/* array of active transactions */
1122	u_int32_t st_region_wait;	/* Region lock granted after wait. */
1123	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
1124	u_int32_t st_regsize;		/* Region size. */
1125};
1126
1127#if defined(__cplusplus)
1128extern "C" {
1129#endif
1130int	  CDB_txn_abort __P((DB_TXN *));
1131int	  CDB_txn_begin __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
1132int	  CDB_txn_checkpoint __P((DB_ENV *, u_int32_t, u_int32_t));
1133int	  CDB_txn_commit __P((DB_TXN *, u_int32_t));
1134u_int32_t CDB_txn_id __P((DB_TXN *));
1135int	  CDB_txn_prepare __P((DB_TXN *));
1136int	  CDB_txn_stat __P((DB_ENV *, DB_TXN_STAT **, void *(*)(size_t)));
1137#if defined(__cplusplus)
1138}
1139#endif
1140
1141#ifndef DB_DBM_HSEARCH
1142#define	DB_DBM_HSEARCH	0		/* No historic interfaces by default. */
1143#endif
1144#if DB_DBM_HSEARCH != 0
1145/*******************************************************
1146 * Dbm/Ndbm historic interfaces.
1147 *******************************************************/
1148#define	DBM_INSERT	0		/* Flags to dbm_store(). */
1149#define	DBM_REPLACE	1
1150
1151/*
1152 * The DB support for ndbm(3) always appends this suffix to the
1153 * file name to avoid overwriting the user's original database.
1154 */
1155#define	DBM_SUFFIX	".db"
1156
1157#if defined(_XPG4_2)
1158typedef struct {
1159	char *dptr;
1160	size_t dsize;
1161} datum;
1162#else
1163typedef struct {
1164	char *dptr;
1165	int dsize;
1166} datum;
1167#endif
1168
1169/*
1170 * Translate DBM calls into DB calls so that DB doesn't step on the
1171 * application's name space.
1172 *
1173 * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
1174 * replaced the dbm interface with ndbm, and are not supported here.
1175 */
1176#define	dbminit(a)	__db_dbm_init(a)
1177#define	dbmclose	__db_dbm_close
1178#if !defined(__cplusplus)
1179#define	delete(a)	__db_dbm_delete(a)
1180#endif
1181#define	fetch(a)	__db_dbm_fetch(a)
1182#define	firstkey	__db_dbm_firstkey
1183#define	nextkey(a)	__db_dbm_nextkey(a)
1184#define	store(a, b)	__db_dbm_store(a, b)
1185
1186/* Prototype the DB calls. */
1187#if defined(__cplusplus)
1188extern "C" {
1189#endif
1190int	 __db_dbm_close __P((void));
1191int	 __db_dbm_dbrdonly __P((void));
1192int	 __db_dbm_delete __P((datum));
1193int	 __db_dbm_dirf __P((void));
1194datum	 __db_dbm_fetch __P((datum));
1195datum	 __db_dbm_firstkey __P((void));
1196int	 __db_dbm_init __P((char *));
1197datum	 __db_dbm_nextkey __P((datum));
1198int	 __db_dbm_pagf __P((void));
1199int	 __db_dbm_store __P((datum, datum));
1200#if defined(__cplusplus)
1201}
1202#endif
1203
1204/*
1205 * Translate NDBM calls into DB calls so that DB doesn't step on the
1206 * application's name space.
1207 */
1208#define	dbm_clearerr(a)		__db_ndbm_clearerr(a)
1209#define	dbm_close(a)		__db_ndbm_close(a)
1210#define	dbm_delete(a, b)	__db_ndbm_delete(a, b)
1211#define	dbm_dirfno(a)		__db_ndbm_dirfno(a)
1212#define	dbm_error(a)		__db_ndbm_error(a)
1213#define	dbm_fetch(a, b)		__db_ndbm_fetch(a, b)
1214#define	dbm_firstkey(a)		__db_ndbm_firstkey(a)
1215#define	dbm_nextkey(a)		__db_ndbm_nextkey(a)
1216#define	dbm_open(a, b, c)	__db_ndbm_open(a, b, c)
1217#define	dbm_pagfno(a)		__db_ndbm_pagfno(a)
1218#define	dbm_rdonly(a)		__db_ndbm_rdonly(a)
1219#define	dbm_store(a, b, c, d)	__db_ndbm_store(a, b, c, d)
1220
1221/* Prototype the DB calls. */
1222#if defined(__cplusplus)
1223extern "C" {
1224#endif
1225int	 __db_ndbm_clearerr __P((DBM *));
1226void	 __db_ndbm_close __P((DBM *));
1227int	 __db_ndbm_delete __P((DBM *, datum));
1228int	 __db_ndbm_dirfno __P((DBM *));
1229int	 __db_ndbm_error __P((DBM *));
1230datum	 __db_ndbm_fetch __P((DBM *, datum));
1231datum	 __db_ndbm_firstkey __P((DBM *));
1232datum	 __db_ndbm_nextkey __P((DBM *));
1233DBM	*__db_ndbm_open __P((const char *, int, int));
1234int	 __db_ndbm_pagfno __P((DBM *));
1235int	 __db_ndbm_rdonly __P((DBM *));
1236int	 __db_ndbm_store __P((DBM *, datum, datum, int));
1237#if defined(__cplusplus)
1238}
1239#endif
1240
1241/*******************************************************
1242 * Hsearch historic interface.
1243 *******************************************************/
1244typedef enum {
1245	FIND, ENTER
1246} ACTION;
1247
1248typedef struct entry {
1249	char *key;
1250	char *data;
1251} ENTRY;
1252
1253/*
1254 * Translate HSEARCH calls into DB calls so that DB doesn't step on the
1255 * application's name space.
1256 */
1257#define	hcreate(a)	__db_hcreate(a)
1258#define	hdestroy	__db_hdestroy
1259#define	hsearch(a, b)	__db_hsearch(a, b)
1260
1261/* Prototype the DB calls. */
1262#if defined(__cplusplus)
1263extern "C" {
1264#endif
1265int	 __db_hcreate __P((size_t));
1266void	 __db_hdestroy __P((void));
1267ENTRY	*__db_hsearch __P((ENTRY, ACTION));
1268#if defined(__cplusplus)
1269}
1270#endif
1271#endif /* DB_DBM_HSEARCH */
1272
1273/*
1274 * XXX
1275 * MacOS: Reset Metrowerks C enum sizes.
1276 */
1277#ifdef __MWERKS__
1278#pragma enumsalwaysint reset
1279#endif
1280#endif /* !_DB_H_ */
1281