db.h
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 50k
Category:

MySQL

Development Platform:

Visual C++

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