]> git.sur5r.net Git - openldap/blob - libraries/liblmdb/lmdb.h
Merge remote-tracking branch 'origin/mdb.master'
[openldap] / libraries / liblmdb / lmdb.h
1 /** @file lmdb.h
2  *      @brief Lightning memory-mapped database library
3  *
4  *      @mainpage       MDB Lightning Memory-Mapped Database Manager
5  *
6  *      @section intro_sec Introduction
7  *      MDB is a Btree-based database management library modeled loosely on the
8  *      BerkeleyDB API, but much simplified. The entire database is exposed
9  *      in a memory map, and all data fetches return data directly
10  *      from the mapped memory, so no malloc's or memcpy's occur during
11  *      data fetches. As such, the library is extremely simple because it
12  *      requires no page caching layer of its own, and it is extremely high
13  *      performance and memory-efficient. It is also fully transactional with
14  *      full ACID semantics, and when the memory map is read-only, the
15  *      database integrity cannot be corrupted by stray pointer writes from
16  *      application code.
17  *
18  *      The library is fully thread-aware and supports concurrent read/write
19  *      access from multiple processes and threads. Data pages use a copy-on-
20  *      write strategy so no active data pages are ever overwritten, which
21  *      also provides resistance to corruption and eliminates the need of any
22  *      special recovery procedures after a system crash. Writes are fully
23  *      serialized; only one write transaction may be active at a time, which
24  *      guarantees that writers can never deadlock. The database structure is
25  *      multi-versioned so readers run with no locks; writers cannot block
26  *      readers, and readers don't block writers.
27  *
28  *      Unlike other well-known database mechanisms which use either write-ahead
29  *      transaction logs or append-only data writes, MDB requires no maintenance
30  *      during operation. Both write-ahead loggers and append-only databases
31  *      require periodic checkpointing and/or compaction of their log or database
32  *      files otherwise they grow without bound. MDB tracks free pages within
33  *      the database and re-uses them for new write operations, so the database
34  *      size does not grow without bound in normal use.
35  *
36  *      The memory map can be used as a read-only or read-write map. It is
37  *      read-only by default as this provides total immunity to corruption.
38  *      Using read-write mode offers much higher write performance, but adds
39  *      the possibility for stray application writes thru pointers to silently
40  *      corrupt the database. Of course if your application code is known to
41  *      be bug-free (...) then this is not an issue.
42  *
43  *      @section caveats_sec Caveats
44  *      Troubleshooting the lock file, plus semaphores on BSD systems:
45  *
46  *      - A broken lockfile can cause sync issues.
47  *        Stale reader transactions left behind by an aborted program
48  *        cause further writes to grow the database quickly, and
49  *        stale locks can block further operation.
50  *
51  *        Fix: Terminate all programs using the database, or make
52  *        them close it.  Next database user will reset the lockfile.
53  *
54  *      - On BSD systems or others configured with MDB_USE_POSIX_SEM,
55  *        startup can fail due to semaphores owned by another userid.
56  *
57  *        Fix: Open and close the database as the user which owns the
58  *        semaphores (likely last user) or as root, while no other
59  *        process is using the database.
60  *
61  *      Restrictions/caveats (in addition to those listed for some functions):
62  *
63  *      - Only the database owner should normally use the database on
64  *        BSD systems or when otherwise configured with MDB_USE_POSIX_SEM.
65  *        Multiple users can cause startup to fail later, as noted above.
66  *
67  *      - A thread can only use one transaction at a time, plus any child
68  *        transactions.  Each transaction belongs to one thread.  See below.
69  *
70  *      - Use an MDB_env* in the process which opened it, without fork()ing.
71  *
72  *      - Do not have open an MDB database twice in the same process at
73  *        the same time.  Not even from a plain open() call - close()ing it
74  *        breaks flock() advisory locking.
75  *
76  *      - Avoid long-lived transactions.  Read transactions prevent
77  *        reuse of pages freed by newer write transactions, thus the
78  *        database can grow quickly.  Write transactions prevent
79  *        other write transactions, since writes are serialized.
80  *
81  *      ...when several processes can use a database concurrently:
82  *
83  *      - Avoid suspending a process with active transactions.  These
84  *        would then be "long-lived" as above.
85  *
86  *      - Avoid aborting a process with an active transaction.
87  *        The transaction becomes "long-lived" as above until the lockfile
88  *        is reset, since the process may not remove it from the lockfile.
89  *
90  *      - If you do that anyway, close the environment once in a while,
91  *        so the lockfile can get reset.
92  *
93  *      - Do not use MDB databases on remote filesystems, even between
94  *        processes on the same host.  This breaks flock() on some OSes,
95  *        possibly memory map sync, and certainly sync between programs
96  *        on different hosts.
97  *
98  *      - Opening a database can fail if another process is opening or
99  *        closing it at exactly the same time.
100  *
101  *      @author Howard Chu, Symas Corporation.
102  *
103  *      @copyright Copyright 2011-2012 Howard Chu, Symas Corp. All rights reserved.
104  *
105  * Redistribution and use in source and binary forms, with or without
106  * modification, are permitted only as authorized by the OpenLDAP
107  * Public License.
108  *
109  * A copy of this license is available in the file LICENSE in the
110  * top-level directory of the distribution or, alternatively, at
111  * <http://www.OpenLDAP.org/license.html>.
112  *
113  *      @par Derived From:
114  * This code is derived from btree.c written by Martin Hedenfalk.
115  *
116  * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
117  *
118  * Permission to use, copy, modify, and distribute this software for any
119  * purpose with or without fee is hereby granted, provided that the above
120  * copyright notice and this permission notice appear in all copies.
121  *
122  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
123  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
124  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
125  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
126  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
127  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
128  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
129  */
130 #ifndef _LMDB_H_
131 #define _LMDB_H_
132
133 #include <sys/types.h>
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138
139 /** @defgroup mdb MDB API
140  *      @{
141  *      @brief OpenLDAP Lightning Memory-Mapped Database Manager
142  */
143 /** @defgroup Version Version Macros
144  *      @{
145  */
146 /** Library major version */
147 #define MDB_VERSION_MAJOR       0
148 /** Library minor version */
149 #define MDB_VERSION_MINOR       9
150 /** Library patch version */
151 #define MDB_VERSION_PATCH       5
152
153 /** Combine args a,b,c into a single integer for easy version comparisons */
154 #define MDB_VERINT(a,b,c)       (((a) << 24) | ((b) << 16) | (c))
155
156 /** The full library version as a single integer */
157 #define MDB_VERSION_FULL        \
158         MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
159
160 /** The release date of this library version */
161 #define MDB_VERSION_DATE        "November 30, 2012"
162
163 /** A stringifier for the version info */
164 #define MDB_VERSTR(a,b,c,d)     "MDB " #a "." #b "." #c ": (" d ")"
165
166 /** A helper for the stringifier macro */
167 #define MDB_VERFOO(a,b,c,d)     MDB_VERSTR(a,b,c,d)
168
169 /** The full library version as a C string */
170 #define MDB_VERSION_STRING      \
171         MDB_VERFOO(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH,MDB_VERSION_DATE)
172 /**     @} */
173
174 /** @brief Opaque structure for a database environment.
175  *
176  * A DB environment supports multiple databases, all residing in the same
177  * shared-memory map.
178  */
179 typedef struct MDB_env MDB_env;
180
181 /** @brief Opaque structure for a transaction handle.
182  *
183  * All database operations require a transaction handle. Transactions may be
184  * read-only or read-write.
185  */
186 typedef struct MDB_txn MDB_txn;
187
188 /** @brief A handle for an individual database in the DB environment. */
189 typedef unsigned int    MDB_dbi;
190
191 /** @brief Opaque structure for navigating through a database */
192 typedef struct MDB_cursor MDB_cursor;
193
194 /** @brief Generic structure used for passing keys and data in and out of the database. */
195 typedef struct MDB_val {
196         size_t           mv_size;       /**< size of the data item */
197         void            *mv_data;       /**< address of the data item */
198 } MDB_val;
199
200 /** @brief A callback function used to compare two keys in a database */
201 typedef int  (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
202
203 /** @brief A callback function used to relocate a position-dependent data item
204  * in a fixed-address database.
205  *
206  * The \b newptr gives the item's desired address in
207  * the memory map, and \b oldptr gives its previous address. The item's actual
208  * data resides at the address in \b item.  This callback is expected to walk
209  * through the fields of the record in \b item and modify any
210  * values based at the \b oldptr address to be relative to the \b newptr address.
211  * @param[in,out] item The item that is to be relocated.
212  * @param[in] oldptr The previous address.
213  * @param[in] newptr The new address to relocate to.
214  * @param[in] relctx An application-provided context, set by #mdb_set_relctx().
215  * @todo This feature is currently unimplemented.
216  */
217 typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx);
218
219 /** @defgroup   mdb_env Environment Flags
220  *
221  *      Values do not overlap Database Flags.
222  *      @{
223  */
224         /** mmap at a fixed address */
225 #define MDB_FIXEDMAP    0x01
226         /** no environment directory */
227 #define MDB_NOSUBDIR    0x4000
228         /** don't fsync after commit */
229 #define MDB_NOSYNC              0x10000
230         /** read only */
231 #define MDB_RDONLY              0x20000
232         /** don't fsync metapage after commit */
233 #define MDB_NOMETASYNC          0x40000
234         /** use writable mmap */
235 #define MDB_WRITEMAP            0x80000
236         /** use asynchronous msync */
237 #define MDB_MAPASYNC            0x100000
238 /** @} */
239
240 /**     @defgroup       mdb_open        Database Flags
241  *
242  *      Values do not overlap Environment Flags.
243  *      @{
244  */
245         /** use reverse string keys */
246 #define MDB_REVERSEKEY  0x02
247         /** use sorted duplicates */
248 #define MDB_DUPSORT             0x04
249         /** numeric keys in native byte order.
250          *  The keys must all be of the same size. */
251 #define MDB_INTEGERKEY  0x08
252         /** with #MDB_DUPSORT, sorted dup items have fixed size */
253 #define MDB_DUPFIXED    0x10
254         /** with #MDB_DUPSORT, dups are numeric in native byte order */
255 #define MDB_INTEGERDUP  0x20
256         /** with #MDB_DUPSORT, use reverse string dups */
257 #define MDB_REVERSEDUP  0x40
258         /** create DB if not already existing */
259 #define MDB_CREATE              0x40000
260 /** @} */
261
262 /**     @defgroup mdb_put       Write Flags
263  *      @{
264  */
265 /** For put: Don't write if the key already exists. */
266 #define MDB_NOOVERWRITE 0x10
267 /** Only for #MDB_DUPSORT<br>
268  * For put: don't write if the key and data pair already exist.<br>
269  * For mdb_cursor_del: remove all duplicate data items.
270  */
271 #define MDB_NODUPDATA   0x20
272 /** For mdb_cursor_put: overwrite the current key/data pair */
273 #define MDB_CURRENT     0x40
274 /** For put: Just reserve space for data, don't copy it. Return a
275  * pointer to the reserved space.
276  */
277 #define MDB_RESERVE     0x10000
278 /** Data is being appended, don't split full pages. */
279 #define MDB_APPEND      0x20000
280 /** Duplicate data is being appended, don't split full pages. */
281 #define MDB_APPENDDUP   0x40000
282 /** Store multiple data items in one call. */
283 #define MDB_MULTIPLE    0x80000
284 /*      @} */
285
286 /** @brief Cursor Get operations.
287  *
288  *      This is the set of all operations for retrieving data
289  *      using a cursor.
290  */
291 typedef enum MDB_cursor_op {
292         MDB_FIRST,                              /**< Position at first key/data item */
293         MDB_FIRST_DUP,                  /**< Position at first data item of current key.
294                                                                 Only for #MDB_DUPSORT */
295         MDB_GET_BOTH,                   /**< Position at key/data pair. Only for #MDB_DUPSORT */
296         MDB_GET_BOTH_RANGE,             /**< position at key, nearest data. Only for #MDB_DUPSORT */
297         MDB_GET_CURRENT,                /**< Return key/data at current cursor position */
298         MDB_GET_MULTIPLE,               /**< Return all the duplicate data items at the current
299                                                                  cursor position. Only for #MDB_DUPFIXED */
300         MDB_LAST,                               /**< Position at last key/data item */
301         MDB_LAST_DUP,                   /**< Position at last data item of current key.
302                                                                 Only for #MDB_DUPSORT */
303         MDB_NEXT,                               /**< Position at next data item */
304         MDB_NEXT_DUP,                   /**< Position at next data item of current key.
305                                                                 Only for #MDB_DUPSORT */
306         MDB_NEXT_MULTIPLE,              /**< Return all duplicate data items at the next
307                                                                 cursor position. Only for #MDB_DUPFIXED */
308         MDB_NEXT_NODUP,                 /**< Position at first data item of next key.
309                                                                 Only for #MDB_DUPSORT */
310         MDB_PREV,                               /**< Position at previous data item */
311         MDB_PREV_DUP,                   /**< Position at previous data item of current key.
312                                                                 Only for #MDB_DUPSORT */
313         MDB_PREV_NODUP,                 /**< Position at last data item of previous key.
314                                                                 Only for #MDB_DUPSORT */
315         MDB_SET,                                /**< Position at specified key */
316         MDB_SET_KEY,                    /**< Position at specified key, return key + data */
317         MDB_SET_RANGE                   /**< Position at first key greater than or equal to specified key. */
318 } MDB_cursor_op;
319
320 /** @defgroup  errors   Return Codes
321  *
322  *      BerkeleyDB uses -30800 to -30999, we'll go under them
323  *      @{
324  */
325         /**     Successful result */
326 #define MDB_SUCCESS      0
327         /** key/data pair already exists */
328 #define MDB_KEYEXIST    (-30799)
329         /** key/data pair not found (EOF) */
330 #define MDB_NOTFOUND    (-30798)
331         /** Requested page not found - this usually indicates corruption */
332 #define MDB_PAGE_NOTFOUND       (-30797)
333         /** Located page was wrong type */
334 #define MDB_CORRUPTED   (-30796)
335         /** Update of meta page failed, probably I/O error */
336 #define MDB_PANIC               (-30795)
337         /** Environment version mismatch */
338 #define MDB_VERSION_MISMATCH    (-30794)
339         /** File is not a valid MDB file */
340 #define MDB_INVALID     (-30793)
341         /** Environment mapsize reached */
342 #define MDB_MAP_FULL    (-30792)
343         /** Environment maxdbs reached */
344 #define MDB_DBS_FULL    (-30791)
345         /** Environment maxreaders reached */
346 #define MDB_READERS_FULL        (-30790)
347         /** Too many TLS keys in use - Windows only */
348 #define MDB_TLS_FULL    (-30789)
349         /** Nested txn has too many dirty pages */
350 #define MDB_TXN_FULL    (-30788)
351         /** Cursor stack too deep - internal error */
352 #define MDB_CURSOR_FULL (-30787)
353         /** Page has not enough space - internal error */
354 #define MDB_PAGE_FULL   (-30786)
355 #define MDB_LAST_ERRCODE        MDB_PAGE_FULL
356 /** @} */
357
358 /** @brief Statistics for a database in the environment */
359 typedef struct MDB_stat {
360         unsigned int    ms_psize;                       /**< Size of a database page.
361                                                                                         This is currently the same for all databases. */
362         unsigned int    ms_depth;                       /**< Depth (height) of the B-tree */
363         size_t          ms_branch_pages;        /**< Number of internal (non-leaf) pages */
364         size_t          ms_leaf_pages;          /**< Number of leaf pages */
365         size_t          ms_overflow_pages;      /**< Number of overflow pages */
366         size_t          ms_entries;                     /**< Number of data items */
367 } MDB_stat;
368
369 /** @brief Information about the environment */
370 typedef struct MDB_envinfo {
371         void    *me_mapaddr;                    /**< Address of map, if fixed */
372         size_t  me_mapsize;                             /**< Size of the data memory map */
373         size_t  me_last_pgno;                   /**< ID of the last used page */
374         size_t  me_last_txnid;                  /**< ID of the last committed transaction */
375         unsigned int me_maxreaders;             /**< maximum number of threads for the environment */
376         unsigned int me_numreaders;             /**< maximum number of threads used in the environment */
377 } MDB_envinfo;
378
379         /** @brief Return the mdb library version information.
380          *
381          * @param[out] major if non-NULL, the library major version number is copied here
382          * @param[out] minor if non-NULL, the library minor version number is copied here
383          * @param[out] patch if non-NULL, the library patch version number is copied here
384          * @retval "version string" The library version as a string
385          */
386 char *mdb_version(int *major, int *minor, int *patch);
387
388         /** @brief Return a string describing a given error code.
389          *
390          * This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror(3)
391          * function. If the error code is greater than or equal to 0, then the string
392          * returned by the system function strerror(3) is returned. If the error code
393          * is less than 0, an error string corresponding to the MDB library error is
394          * returned. See @ref errors for a list of MDB-specific error codes.
395          * @param[in] err The error code
396          * @retval "error message" The description of the error
397          */
398 char *mdb_strerror(int err);
399
400         /** @brief Create an MDB environment handle.
401          *
402          * This function allocates memory for a #MDB_env structure. To release
403          * the allocated memory and discard the handle, call #mdb_env_close().
404          * Before the handle may be used, it must be opened using #mdb_env_open().
405          * Various other options may also need to be set before opening the handle,
406          * e.g. #mdb_env_set_mapsize(), #mdb_env_set_maxreaders(), #mdb_env_set_maxdbs(),
407          * depending on usage requirements.
408          * @param[out] env The address where the new handle will be stored
409          * @return A non-zero error value on failure and 0 on success.
410          */
411 int  mdb_env_create(MDB_env **env);
412
413         /** @brief Open an environment handle.
414          *
415          * If this function fails, #mdb_env_close() must be called to discard the #MDB_env handle.
416          * @param[in] env An environment handle returned by #mdb_env_create()
417          * @param[in] path The directory in which the database files reside. This
418          * directory must already exist and be writable.
419          * @param[in] flags Special options for this environment. This parameter
420          * must be set to 0 or by bitwise OR'ing together one or more of the
421          * values described here.
422          * Flags set by mdb_env_set_flags() are also used.
423          * <ul>
424          *      <li>#MDB_FIXEDMAP
425          *      use a fixed address for the mmap region. This flag must be specified
426          *      when creating the environment, and is stored persistently in the environment.
427          *              If successful, the memory map will always reside at the same virtual address
428          *              and pointers used to reference data items in the database will be constant
429          *              across multiple invocations. This option may not always work, depending on
430          *              how the operating system has allocated memory to shared libraries and other uses.
431          *              The feature is highly experimental.
432          *      <li>#MDB_NOSUBDIR
433          *              By default, MDB creates its environment in a directory whose
434          *              pathname is given in \b path, and creates its data and lock files
435          *              under that directory. With this option, \b path is used as-is for
436          *              the database main data file. The database lock file is the \b path
437          *              with "-lock" appended.
438          *      <li>#MDB_NOSYNC
439          *              Don't perform a synchronous flush after committing a transaction. This means
440          *              transactions will exhibit the ACI (atomicity, consistency, and isolation)
441          *              properties, but not D (durability); that is database integrity will be
442          *              maintained but it is possible some number of the most recently committed
443          *              transactions may be undone after a system crash. The number of transactions
444          *              at risk is governed by how often the system flushes dirty buffers to disk
445          *              and how often #mdb_env_sync() is called. This flag may be changed
446          *              at any time using #mdb_env_set_flags().
447          *      <li>#MDB_NOMETASYNC
448          *              Don't perform a synchronous flush of the meta page after committing
449          *              a transaction. This is similar to the #MDB_NOSYNC case, but safer
450          *              because the transaction data is still flushed. The meta page for any
451          *              transaction N will be flushed by the data flush of transaction N+1.
452          *              In case of a system crash, the last committed transaction may be
453          *              lost. This flag may be changed at any time using #mdb_env_set_flags().
454          *      <li>#MDB_RDONLY
455          *              Open the environment in read-only mode. No write operations will be allowed.
456          * </ul>
457          * @param[in] mode The UNIX permissions to set on created files. This parameter
458          * is ignored on Windows.
459          * @return A non-zero error value on failure and 0 on success. Some possible
460          * errors are:
461          * <ul>
462          *      <li>#MDB_VERSION_MISMATCH - the version of the MDB library doesn't match the
463          *      version that created the database environment.
464          *      <li>EINVAL - the environment file headers are corrupted.
465          *      <li>ENOENT - the directory specified by the path parameter doesn't exist.
466          *      <li>EACCES - the user didn't have permission to access the environment files.
467          *      <li>EAGAIN - the environment was locked by another process.
468          * </ul>
469          */
470 int  mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode);
471
472         /** @brief Copy an MDB environment to the specified path.
473          *
474          * This function may be used to make a backup of an existing environment.
475          * @param[in] env An environment handle returned by #mdb_env_create(). It
476          * must have already been opened successfully.
477          * @param[in] path The directory in which the copy will reside. This
478          * directory must already exist and be writable but must otherwise be
479          * empty.
480          * @return A non-zero error value on failure and 0 on success.
481          */
482 int  mdb_env_copy(MDB_env *env, const char *path);
483
484         /** @brief Return statistics about the MDB environment.
485          *
486          * @param[in] env An environment handle returned by #mdb_env_create()
487          * @param[out] stat The address of an #MDB_stat structure
488          *      where the statistics will be copied
489          */
490 int  mdb_env_stat(MDB_env *env, MDB_stat *stat);
491
492         /** @brief Return information about the MDB environment.
493          *
494          * @param[in] env An environment handle returned by #mdb_env_create()
495          * @param[out] stat The address of an #MDB_envinfo structure
496          *      where the information will be copied
497          */
498 int  mdb_env_info(MDB_env *env, MDB_envinfo *stat);
499
500         /** @brief Flush the data buffers to disk.
501          *
502          * Data is always written to disk when #mdb_txn_commit() is called,
503          * but the operating system may keep it buffered. MDB always flushes
504          * the OS buffers upon commit as well, unless the environment was
505          * opened with #MDB_NOSYNC.
506          * @param[in] env An environment handle returned by #mdb_env_create()
507          * @param[in] force If non-zero, force a synchronous flush.  Otherwise
508          *  if the environment has the #MDB_NOSYNC flag set the flushes
509          *      will be omitted, and with #MDB_MAPASYNC they will be asynchronous.
510          * @return A non-zero error value on failure and 0 on success. Some possible
511          * errors are:
512          * <ul>
513          *      <li>EINVAL - an invalid parameter was specified.
514          *      <li>EIO - an error occurred during synchronization.
515          * </ul>
516          */
517 int  mdb_env_sync(MDB_env *env, int force);
518
519         /** @brief Close the environment and release the memory map.
520          *
521          * Only a single thread may call this function. All transactions, databases,
522          * and cursors must already be closed before calling this function. Attempts to
523          * use any such handles after calling this function will cause a SIGSEGV.
524          * The environment handle will be freed and must not be used again after this call.
525          * @param[in] env An environment handle returned by #mdb_env_create()
526          */
527 void mdb_env_close(MDB_env *env);
528
529         /** @brief Set environment flags.
530          *
531          * This may be used to set some flags in addition to those from
532          * #mdb_env_open(), or to unset these flags.
533          * @param[in] env An environment handle returned by #mdb_env_create()
534          * @param[in] flags The flags to change, bitwise OR'ed together
535          * @param[in] onoff A non-zero value sets the flags, zero clears them.
536          * @return A non-zero error value on failure and 0 on success. Some possible
537          * errors are:
538          * <ul>
539          *      <li>EINVAL - an invalid parameter was specified.
540          * </ul>
541          */
542 int  mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
543
544         /** @brief Get environment flags.
545          *
546          * @param[in] env An environment handle returned by #mdb_env_create()
547          * @param[out] flags The address of an integer to store the flags
548          * @return A non-zero error value on failure and 0 on success. Some possible
549          * errors are:
550          * <ul>
551          *      <li>EINVAL - an invalid parameter was specified.
552          * </ul>
553          */
554 int  mdb_env_get_flags(MDB_env *env, unsigned int *flags);
555
556         /** @brief Return the path that was used in #mdb_env_open().
557          *
558          * @param[in] env An environment handle returned by #mdb_env_create()
559          * @param[out] path Address of a string pointer to contain the path. This
560          * is the actual string in the environment, not a copy. It should not be
561          * altered in any way.
562          * @return A non-zero error value on failure and 0 on success. Some possible
563          * errors are:
564          * <ul>
565          *      <li>EINVAL - an invalid parameter was specified.
566          * </ul>
567          */
568 int  mdb_env_get_path(MDB_env *env, const char **path);
569
570         /** @brief Set the size of the memory map to use for this environment.
571          *
572          * The size should be a multiple of the OS page size. The default is
573          * 10485760 bytes. The size of the memory map is also the maximum size
574          * of the database. The value should be chosen as large as possible,
575          * to accommodate future growth of the database.
576          * This function may only be called after #mdb_env_create() and before #mdb_env_open().
577          * @param[in] env An environment handle returned by #mdb_env_create()
578          * @param[in] size The size in bytes
579          * @return A non-zero error value on failure and 0 on success. Some possible
580          * errors are:
581          * <ul>
582          *      <li>EINVAL - an invalid parameter was specified, or the environment is already open.
583          * </ul>
584          */
585 int  mdb_env_set_mapsize(MDB_env *env, size_t size);
586
587         /** @brief Set the maximum number of threads for the environment.
588          *
589          * This defines the number of slots in the lock table that is used to track readers in the
590          * the environment. The default is 126.
591          * This function may only be called after #mdb_env_create() and before #mdb_env_open().
592          * @param[in] env An environment handle returned by #mdb_env_create()
593          * @param[in] readers The maximum number of threads
594          * @return A non-zero error value on failure and 0 on success. Some possible
595          * errors are:
596          * <ul>
597          *      <li>EINVAL - an invalid parameter was specified, or the environment is already open.
598          * </ul>
599          */
600 int  mdb_env_set_maxreaders(MDB_env *env, unsigned int readers);
601
602         /** @brief Get the maximum number of threads for the environment.
603          *
604          * @param[in] env An environment handle returned by #mdb_env_create()
605          * @param[out] readers Address of an integer to store the number of readers
606          * @return A non-zero error value on failure and 0 on success. Some possible
607          * errors are:
608          * <ul>
609          *      <li>EINVAL - an invalid parameter was specified.
610          * </ul>
611          */
612 int  mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
613
614         /** @brief Set the maximum number of named databases for the environment.
615          *
616          * This function is only needed if multiple databases will be used in the
617          * environment. Simpler applications that use the environment as a single
618          * unnamed database can ignore this option.
619          * This function may only be called after #mdb_env_create() and before #mdb_env_open().
620          * @param[in] env An environment handle returned by #mdb_env_create()
621          * @param[in] dbs The maximum number of databases
622          * @return A non-zero error value on failure and 0 on success. Some possible
623          * errors are:
624          * <ul>
625          *      <li>EINVAL - an invalid parameter was specified, or the environment is already open.
626          * </ul>
627          */
628 int  mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
629
630         /** @brief Create a transaction for use with the environment.
631          *
632          * The transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit().
633          * @note Transactions may not span threads; a transaction must only be used by a
634          * single thread. Also, a thread may only have a single transaction.
635          * @note Cursors may not span transactions; each cursor must be opened and closed
636          * within a single transaction.
637          * @param[in] env An environment handle returned by #mdb_env_create()
638          * @param[in] parent If this parameter is non-NULL, the new transaction
639          * will be a nested transaction, with the transaction indicated by \b parent
640          * as its parent. Transactions may be nested to any level. A parent
641          * transaction may not issue any other operations besides mdb_txn_begin,
642          * mdb_txn_abort, or mdb_txn_commit while it has active child transactions.
643          * @param[in] flags Special options for this transaction. This parameter
644          * must be set to 0 or by bitwise OR'ing together one or more of the
645          * values described here.
646          * <ul>
647          *      <li>#MDB_RDONLY
648          *              This transaction will not perform any write operations.
649          * </ul>
650          * @param[out] txn Address where the new #MDB_txn handle will be stored
651          * @return A non-zero error value on failure and 0 on success. Some possible
652          * errors are:
653          * <ul>
654          *      <li>#MDB_PANIC - a fatal error occurred earlier and the environment
655          *              must be shut down.
656          *      <li>ENOMEM - out of memory, or a read-only transaction was requested and
657          *              the reader lock table is full. See #mdb_env_set_maxreaders().
658          * </ul>
659          */
660 int  mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
661
662         /** @brief Commit all the operations of a transaction into the database.
663          *
664          * All cursors opened within the transaction will be closed by this call. The cursors
665          * and transaction handle will be freed and must not be used again after this call.
666          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
667          * @return A non-zero error value on failure and 0 on success. Some possible
668          * errors are:
669          * <ul>
670          *      <li>EINVAL - an invalid parameter was specified.
671          *      <li>ENOSPC - no more disk space.
672          *      <li>EIO - a low-level I/O error occurred while writing.
673          *      <li>ENOMEM - the transaction is nested and could not be merged into its parent.
674          * </ul>
675          */
676 int  mdb_txn_commit(MDB_txn *txn);
677
678         /** @brief Abandon all the operations of the transaction instead of saving them.
679          *
680          * All cursors opened within the transaction will be closed by this call. The cursors
681          * and transaction handle will be freed and must not be used again after this call.
682          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
683          */
684 void mdb_txn_abort(MDB_txn *txn);
685
686         /** @brief Reset a read-only transaction.
687          *
688          * This releases the current reader lock but doesn't free the
689          * transaction handle, allowing it to be used again later by #mdb_txn_renew().
690          * It otherwise has the same effect as #mdb_txn_abort() but saves some memory
691          * allocation/deallocation overhead if a thread is going to start a new
692          * read-only transaction again soon.
693          * All cursors opened within the transaction must be closed before the transaction
694          * is reset.
695          * Reader locks generally don't interfere with writers, but they keep old
696          * versions of database pages allocated. Thus they prevent the old pages
697          * from being reused when writers commit new data, and so under heavy load
698          * the database size may grow much more rapidly than otherwise.
699          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
700          */
701 void mdb_txn_reset(MDB_txn *txn);
702
703         /** @brief Renew a read-only transaction.
704          *
705          * This acquires a new reader lock for a transaction handle that had been
706          * released by #mdb_txn_reset(). It must be called before a reset transaction
707          * may be used again.
708          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
709          * @return A non-zero error value on failure and 0 on success. Some possible
710          * errors are:
711          * <ul>
712          *      <li>#MDB_PANIC - a fatal error occurred earlier and the environment
713          *              must be shut down.
714          *      <li>EINVAL - an invalid parameter was specified.
715          * </ul>
716          */
717 int  mdb_txn_renew(MDB_txn *txn);
718
719         /** @brief Open a database in the environment.
720          *
721          * The database handle may be discarded by calling #mdb_close().  The
722          * database handle resides in the shared environment, it is not owned
723          * by the given transaction. Only one thread should call this function;
724          * it is not mutex-protected in a read-only transaction.
725          * To use named databases (with name != NULL), #mdb_env_set_maxdbs()
726          * must be called before opening the enviorment.
727          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
728          * @param[in] name The name of the database to open. If only a single
729          *      database is needed in the environment, this value may be NULL.
730          * @param[in] flags Special options for this database. This parameter
731          * must be set to 0 or by bitwise OR'ing together one or more of the
732          * values described here.
733          * <ul>
734          *      <li>#MDB_REVERSEKEY
735          *              Keys are strings to be compared in reverse order, from the end
736          *              of the strings to the beginning. By default, Keys are treated as strings and
737          *              compared from beginning to end.
738          *      <li>#MDB_DUPSORT
739          *              Duplicate keys may be used in the database. (Or, from another perspective,
740          *              keys may have multiple data items, stored in sorted order.) By default
741          *              keys must be unique and may have only a single data item.
742          *      <li>#MDB_INTEGERKEY
743          *              Keys are binary integers in native byte order. Setting this option
744          *              requires all keys to be the same size, typically sizeof(int)
745          *              or sizeof(size_t).
746          *      <li>#MDB_DUPFIXED
747          *              This flag may only be used in combination with #MDB_DUPSORT. This option
748          *              tells the library that the data items for this database are all the same
749          *              size, which allows further optimizations in storage and retrieval. When
750          *              all data items are the same size, the #MDB_GET_MULTIPLE and #MDB_NEXT_MULTIPLE
751          *              cursor operations may be used to retrieve multiple items at once.
752          *      <li>#MDB_INTEGERDUP
753          *              This option specifies that duplicate data items are also integers, and
754          *              should be sorted as such.
755          *      <li>#MDB_REVERSEDUP
756          *              This option specifies that duplicate data items should be compared as
757          *              strings in reverse order.
758          *      <li>#MDB_CREATE
759          *              Create the named database if it doesn't exist. This option is not
760          *              allowed in a read-only transaction or a read-only environment.
761          * </ul>
762          * @param[out] dbi Address where the new #MDB_dbi handle will be stored
763          * @return A non-zero error value on failure and 0 on success. Some possible
764          * errors are:
765          * <ul>
766          *      <li>#MDB_NOTFOUND - the specified database doesn't exist in the environment
767          *              and #MDB_CREATE was not specified.
768          *      <li>ENFILE - too many databases have been opened. See #mdb_env_set_maxdbs().
769          * </ul>
770          */
771 int  mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi);
772
773         /** @brief Retrieve statistics for a database.
774          *
775          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
776          * @param[in] dbi A database handle returned by #mdb_open()
777          * @param[out] stat The address of an #MDB_stat structure
778          *      where the statistics will be copied
779          * @return A non-zero error value on failure and 0 on success. Some possible
780          * errors are:
781          * <ul>
782          *      <li>EINVAL - an invalid parameter was specified.
783          * </ul>
784          */
785 int  mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat);
786
787         /** @brief Close a database handle.
788          *
789          * This call is not mutex protected. Handles should only be closed by
790          * a single thread, and only if no other threads are going to reference
791          * the database handle any further.
792          * @param[in] env An environment handle returned by #mdb_env_create()
793          * @param[in] dbi A database handle returned by #mdb_open()
794          */
795 void mdb_close(MDB_env *env, MDB_dbi dbi);
796
797         /** @brief Delete a database and/or free all its pages.
798          *
799          * If the \b del parameter is 1, the DB handle will be closed
800          * and the DB will be deleted.
801          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
802          * @param[in] dbi A database handle returned by #mdb_open()
803          * @param[in] del 1 to delete the DB from the environment,
804          * 0 to just free its pages.
805          * @return A non-zero error value on failure and 0 on success.
806          */
807 int  mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
808
809         /** @brief Set a custom key comparison function for a database.
810          *
811          * The comparison function is called whenever it is necessary to compare a
812          * key specified by the application with a key currently stored in the database.
813          * If no comparison function is specified, and no special key flags were specified
814          * with #mdb_open(), the keys are compared lexically, with shorter keys collating
815          * before longer keys.
816          * @warning This function must be called before any data access functions are used,
817          * otherwise data corruption may occur. The same comparison function must be used by every
818          * program accessing the database, every time the database is used.
819          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
820          * @param[in] dbi A database handle returned by #mdb_open()
821          * @param[in] cmp A #MDB_cmp_func function
822          * @return A non-zero error value on failure and 0 on success. Some possible
823          * errors are:
824          * <ul>
825          *      <li>EINVAL - an invalid parameter was specified.
826          * </ul>
827          */
828 int  mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
829
830         /** @brief Set a custom data comparison function for a #MDB_DUPSORT database.
831          *
832          * This comparison function is called whenever it is necessary to compare a data
833          * item specified by the application with a data item currently stored in the database.
834          * This function only takes effect if the database was opened with the #MDB_DUPSORT
835          * flag.
836          * If no comparison function is specified, and no special key flags were specified
837          * with #mdb_open(), the data items are compared lexically, with shorter items collating
838          * before longer items.
839          * @warning This function must be called before any data access functions are used,
840          * otherwise data corruption may occur. The same comparison function must be used by every
841          * program accessing the database, every time the database is used.
842          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
843          * @param[in] dbi A database handle returned by #mdb_open()
844          * @param[in] cmp A #MDB_cmp_func function
845          * @return A non-zero error value on failure and 0 on success. Some possible
846          * errors are:
847          * <ul>
848          *      <li>EINVAL - an invalid parameter was specified.
849          * </ul>
850          */
851 int  mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
852
853         /** @brief Set a relocation function for a #MDB_FIXEDMAP database.
854          *
855          * @todo The relocation function is called whenever it is necessary to move the data
856          * of an item to a different position in the database (e.g. through tree
857          * balancing operations, shifts as a result of adds or deletes, etc.). It is
858          * intended to allow address/position-dependent data items to be stored in
859          * a database in an environment opened with the #MDB_FIXEDMAP option.
860          * Currently the relocation feature is unimplemented and setting
861          * this function has no effect.
862          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
863          * @param[in] dbi A database handle returned by #mdb_open()
864          * @param[in] rel A #MDB_rel_func function
865          * @return A non-zero error value on failure and 0 on success. Some possible
866          * errors are:
867          * <ul>
868          *      <li>EINVAL - an invalid parameter was specified.
869          * </ul>
870          */
871 int  mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel);
872
873         /** @brief Set a context pointer for a #MDB_FIXEDMAP database's relocation function.
874          *
875          * See #mdb_set_relfunc and #MDB_rel_func for more details.
876          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
877          * @param[in] dbi A database handle returned by #mdb_open()
878          * @param[in] ctx An arbitrary pointer for whatever the application needs.
879          * It will be passed to the callback function set by #mdb_set_relfunc
880          * as its \b relctx parameter whenever the callback is invoked.
881          * @return A non-zero error value on failure and 0 on success. Some possible
882          * errors are:
883          * <ul>
884          *      <li>EINVAL - an invalid parameter was specified.
885          * </ul>
886          */
887 int  mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
888
889         /** @brief Get items from a database.
890          *
891          * This function retrieves key/data pairs from the database. The address
892          * and length of the data associated with the specified \b key are returned
893          * in the structure to which \b data refers.
894          * If the database supports duplicate keys (#MDB_DUPSORT) then the
895          * first data item for the key will be returned. Retrieval of other
896          * items requires the use of #mdb_cursor_get().
897          *
898          * @note The memory pointed to by the returned values is owned by the
899          * database. The caller need not dispose of the memory, and may not
900          * modify it in any way. For values returned in a read-only transaction
901          * any modification attempts will cause a SIGSEGV.
902          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
903          * @param[in] dbi A database handle returned by #mdb_open()
904          * @param[in] key The key to search for in the database
905          * @param[out] data The data corresponding to the key
906          * @return A non-zero error value on failure and 0 on success. Some possible
907          * errors are:
908          * <ul>
909          *      <li>#MDB_NOTFOUND - the key was not in the database.
910          *      <li>EINVAL - an invalid parameter was specified.
911          * </ul>
912          */
913 int  mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
914
915         /** @brief Store items into a database.
916          *
917          * This function stores key/data pairs in the database. The default behavior
918          * is to enter the new key/data pair, replacing any previously existing key
919          * if duplicates are disallowed, or adding a duplicate data item if
920          * duplicates are allowed (#MDB_DUPSORT).
921          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
922          * @param[in] dbi A database handle returned by #mdb_open()
923          * @param[in] key The key to store in the database
924          * @param[in,out] data The data to store
925          * @param[in] flags Special options for this operation. This parameter
926          * must be set to 0 or by bitwise OR'ing together one or more of the
927          * values described here.
928          * <ul>
929          *      <li>#MDB_NODUPDATA - enter the new key/data pair only if it does not
930          *              already appear in the database. This flag may only be specified
931          *              if the database was opened with #MDB_DUPSORT. The function will
932          *              return #MDB_KEYEXIST if the key/data pair already appears in the
933          *              database.
934          *      <li>#MDB_NOOVERWRITE - enter the new key/data pair only if the key
935          *              does not already appear in the database. The function will return
936          *              #MDB_KEYEXIST if the key already appears in the database, even if
937          *              the database supports duplicates (#MDB_DUPSORT). The \b data
938          *              parameter will be set to point to the existing item.
939          *      <li>#MDB_RESERVE - reserve space for data of the given size, but
940          *              don't copy the given data. Instead, return a pointer to the
941          *              reserved space, which the caller can fill in later. This saves
942          *              an extra memcpy if the data is being generated later.
943          *      <li>#MDB_APPEND - append the given key/data pair to the end of the
944          *              database. No key comparisons are performed. This option allows
945          *              fast bulk loading when keys are already known to be in the
946          *              correct order. Loading unsorted keys with this flag will cause
947          *              data corruption.
948          *      <li>#MDB_APPENDDUP - as above, but for sorted dup data.
949          * </ul>
950          * @return A non-zero error value on failure and 0 on success. Some possible
951          * errors are:
952          * <ul>
953          *      <li>EACCES - an attempt was made to write in a read-only transaction.
954          *      <li>EINVAL - an invalid parameter was specified.
955          *      <li>ENOMEM - the database is full, see #mdb_env_set_mapsize().
956          * </ul>
957          */
958 int  mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data,
959                             unsigned int flags);
960
961         /** @brief Delete items from a database.
962          *
963          * This function removes key/data pairs from the database.
964          * If the database does not support sorted duplicate data items
965          * (#MDB_DUPSORT) the data parameter is ignored.
966          * If the database supports sorted duplicates and the data parameter
967          * is NULL, all of the duplicate data items for the key will be
968          * deleted. Otherwise, if the data parameter is non-NULL
969          * only the matching data item will be deleted.
970          * This function will return #MDB_NOTFOUND if the specified key/data
971          * pair is not in the database.
972          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
973          * @param[in] dbi A database handle returned by #mdb_open()
974          * @param[in] key The key to delete from the database
975          * @param[in] data The data to delete
976          * @return A non-zero error value on failure and 0 on success. Some possible
977          * errors are:
978          * <ul>
979          *      <li>EACCES - an attempt was made to write in a read-only transaction.
980          *      <li>EINVAL - an invalid parameter was specified.
981          * </ul>
982          */
983 int  mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
984
985         /** @brief Create a cursor handle.
986          *
987          * Cursors are associated with a specific transaction and database and
988          * may not span threads.
989          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
990          * @param[in] dbi A database handle returned by #mdb_open()
991          * @param[out] cursor Address where the new #MDB_cursor handle will be stored
992          * @return A non-zero error value on failure and 0 on success. Some possible
993          * errors are:
994          * <ul>
995          *      <li>EINVAL - an invalid parameter was specified.
996          * </ul>
997          */
998 int  mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor);
999
1000         /** @brief Close a cursor handle.
1001          *
1002          * The cursor handle will be freed and must not be used again after this call.
1003          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1004          */
1005 void mdb_cursor_close(MDB_cursor *cursor);
1006
1007         /** @brief Renew a cursor handle.
1008          *
1009          * Cursors are associated with a specific transaction and database and
1010          * may not span threads. Cursors that are only used in read-only
1011          * transactions may be re-used, to avoid unnecessary malloc/free overhead.
1012          * The cursor may be associated with a new read-only transaction, and
1013          * referencing the same database handle as it was created with.
1014          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1015          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1016          * @return A non-zero error value on failure and 0 on success. Some possible
1017          * errors are:
1018          * <ul>
1019          *      <li>EINVAL - an invalid parameter was specified.
1020          * </ul>
1021          */
1022 int  mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor);
1023
1024         /** @brief Return the cursor's transaction handle.
1025          *
1026          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1027          */
1028 MDB_txn *mdb_cursor_txn(MDB_cursor *cursor);
1029
1030         /** @brief Return the cursor's database handle.
1031          *
1032          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1033          */
1034 MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
1035
1036         /** @brief Retrieve by cursor.
1037          *
1038          * This function retrieves key/data pairs from the database. The address and length
1039          * of the key are returned in the object to which \b key refers (except for the
1040          * case of the #MDB_SET option, in which the \b key object is unchanged), and
1041          * the address and length of the data are returned in the object to which \b data
1042          * refers.
1043          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1044          * @param[in,out] key The key for a retrieved item
1045          * @param[in,out] data The data of a retrieved item
1046          * @param[in] op A cursor operation #MDB_cursor_op
1047          * @return A non-zero error value on failure and 0 on success. Some possible
1048          * errors are:
1049          * <ul>
1050          *      <li>#MDB_NOTFOUND - no matching key found.
1051          *      <li>EINVAL - an invalid parameter was specified.
1052          * </ul>
1053          */
1054 int  mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1055                             MDB_cursor_op op);
1056
1057         /** @brief Store by cursor.
1058          *
1059          * This function stores key/data pairs into the database.
1060          * If the function fails for any reason, the state of the cursor will be
1061          * unchanged. If the function succeeds and an item is inserted into the
1062          * database, the cursor is always positioned to refer to the newly inserted item.
1063          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1064          * @param[in] key The key operated on.
1065          * @param[in] data The data operated on.
1066          * @param[in] flags Options for this operation. This parameter
1067          * must be set to 0 or one of the values described here.
1068          * <ul>
1069          *      <li>#MDB_CURRENT - overwrite the data of the key/data pair to which
1070          *              the cursor refers with the specified data item. The \b key
1071          *              parameter is ignored.
1072          *      <li>#MDB_NODUPDATA - enter the new key/data pair only if it does not
1073          *              already appear in the database. This flag may only be specified
1074          *              if the database was opened with #MDB_DUPSORT. The function will
1075          *              return #MDB_KEYEXIST if the key/data pair already appears in the
1076          *              database.
1077          *      <li>#MDB_NOOVERWRITE - enter the new key/data pair only if the key
1078          *              does not already appear in the database. The function will return
1079          *              #MDB_KEYEXIST if the key already appears in the database, even if
1080          *              the database supports duplicates (#MDB_DUPSORT).
1081          *      <li>#MDB_RESERVE - reserve space for data of the given size, but
1082          *              don't copy the given data. Instead, return a pointer to the
1083          *              reserved space, which the caller can fill in later. This saves
1084          *              an extra memcpy if the data is being generated later.
1085          *      <li>#MDB_APPEND - append the given key/data pair to the end of the
1086          *              database. No key comparisons are performed. This option allows
1087          *              fast bulk loading when keys are already known to be in the
1088          *              correct order. Loading unsorted keys with this flag will cause
1089          *              data corruption.
1090          *      <li>#MDB_APPENDDUP - as above, but for sorted dup data.
1091          * </ul>
1092          * @return A non-zero error value on failure and 0 on success. Some possible
1093          * errors are:
1094          * <ul>
1095          *      <li>EACCES - an attempt was made to modify a read-only database.
1096          *      <li>EINVAL - an invalid parameter was specified.
1097          * </ul>
1098          */
1099 int  mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1100                                 unsigned int flags);
1101
1102         /** @brief Delete current key/data pair
1103          *
1104          * This function deletes the key/data pair to which the cursor refers.
1105          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1106          * @param[in] flags Options for this operation. This parameter
1107          * must be set to 0 or one of the values described here.
1108          * <ul>
1109          *      <li>#MDB_NODUPDATA - delete all of the data items for the current key.
1110          *              This flag may only be specified if the database was opened with #MDB_DUPSORT.
1111          * </ul>
1112          * @return A non-zero error value on failure and 0 on success. Some possible
1113          * errors are:
1114          * <ul>
1115          *      <li>EACCES - an attempt was made to modify a read-only database.
1116          *      <li>EINVAL - an invalid parameter was specified.
1117          * </ul>
1118          */
1119 int  mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1120
1121         /** @brief Return count of duplicates for current key.
1122          *
1123          * This call is only valid on databases that support sorted duplicate
1124          * data items #MDB_DUPSORT.
1125          * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1126          * @param[out] countp Address where the count will be stored
1127          * @return A non-zero error value on failure and 0 on success. Some possible
1128          * errors are:
1129          * <ul>
1130          *      <li>EINVAL - cursor is not initialized, or an invalid parameter was specified.
1131          * </ul>
1132          */
1133 int  mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
1134
1135         /** @brief Compare two data items according to a particular database.
1136          *
1137          * This returns a comparison as if the two data items were keys in the
1138          * specified database.
1139          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1140          * @param[in] dbi A database handle returned by #mdb_open()
1141          * @param[in] a The first item to compare
1142          * @param[in] b The second item to compare
1143          * @return < 0 if a < b, 0 if a == b, > 0 if a > b
1144          */
1145 int  mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1146
1147         /** @brief Compare two data items according to a particular database.
1148          *
1149          * This returns a comparison as if the two items were data items of
1150          * a sorted duplicates #MDB_DUPSORT database.
1151          * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1152          * @param[in] dbi A database handle returned by #mdb_open()
1153          * @param[in] a The first item to compare
1154          * @param[in] b The second item to compare
1155          * @return < 0 if a < b, 0 if a == b, > 0 if a > b
1156          */
1157 int  mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1158 /**     @} */
1159
1160 #ifdef __cplusplus
1161 }
1162 #endif
1163 #endif /* _LMDB_H_ */