/** The version number for a database's file format. */
#define MDB_VERSION 1
- /** The maximum size of a key in the database.
+ /** @brief The maximum size of a key in the database.
+ *
* While data items have essentially unbounded size, we require that
* keys all fit onto a regular page. This limit could be raised a bit
* further if needed; to something just under #MDB_PAGESIZE / #MDB_MINKEYS.
+ *
+ * Note that data items in an #MDB_DUPSORT database are actually keys
+ * of a subDB, so they're also limited to this size.
*/
-#define MAXKEYSIZE 511
+#ifndef MDB_MAXKEYSIZE
+#define MDB_MAXKEYSIZE 511
+#endif
#if MDB_DEBUG
/** A key buffer.
* @ingroup debug
* This is used for printing a hex dump of a key's contents.
*/
-#define DKBUF char kbuf[(MAXKEYSIZE*2+1)]
+#define DKBUF char kbuf[(MDB_MAXKEYSIZE*2+1)]
/** Display a key in hex.
* @ingroup debug
* Invoke a function to display a key in hex.
char *ptr = buf;
unsigned char *c = key->mv_data;
unsigned int i;
- if (key->mv_size > MAXKEYSIZE)
- return "MAXKEYSIZE";
+ if (key->mv_size > MDB_MAXKEYSIZE)
+ return "MDB_MAXKEYSIZE";
/* may want to make this a dynamic check: if the key is mostly
* printable characters, print it as-is instead of converting to hex.
*/
MDB_val key, data;
/* make sure last page of freeDB is touched and on freelist */
- key.mv_size = MAXKEYSIZE+1;
+ key.mv_size = MDB_MAXKEYSIZE+1;
key.mv_data = NULL;
rc = mdb_page_search(&mc, &key, MDB_PS_MODIFY);
if (rc && rc != MDB_NOTFOUND)
if (key == NULL) /* Initialize cursor to first page. */
i = 0;
- else if (key->mv_size > MAXKEYSIZE && key->mv_data == NULL) {
+ else if (key->mv_size > MDB_MAXKEYSIZE && key->mv_data == NULL) {
/* cursor to last page */
i = NUMKEYS(mp)-1;
} else {
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
- if (key->mv_size == 0 || key->mv_size > MAXKEYSIZE) {
+ if (key->mv_size == 0 || key->mv_size > MDB_MAXKEYSIZE) {
return EINVAL;
}
if (!(mc->mc_flags & C_INITIALIZED) || mc->mc_top) {
MDB_val lkey;
- lkey.mv_size = MAXKEYSIZE+1;
+ lkey.mv_size = MDB_MAXKEYSIZE+1;
lkey.mv_data = NULL;
rc = mdb_page_search(mc, &lkey, 0);
if (rc != MDB_SUCCESS)
case MDB_SET:
case MDB_SET_KEY:
case MDB_SET_RANGE:
- if (key == NULL || key->mv_size == 0 || key->mv_size > MAXKEYSIZE) {
+ if (key == NULL || key->mv_size == 0 || key->mv_size > MDB_MAXKEYSIZE) {
rc = EINVAL;
} else if (op == MDB_SET_RANGE)
rc = mdb_cursor_set(mc, key, data, op, NULL);
size_t nsize;
int rc, rc2;
MDB_pagebuf pbuf;
- char dbuf[MAXKEYSIZE+1];
+ char dbuf[MDB_MAXKEYSIZE+1];
unsigned int nflags;
DKBUF;
if (F_ISSET(mc->mc_txn->mt_flags, MDB_TXN_RDONLY))
return EACCES;
+ if (key->mv_size == 0 || key->mv_size > MDB_MAXKEYSIZE)
+ return EINVAL;
+
DPRINTF("==> put db %u key [%s], size %zu, data size %zu",
mc->mc_dbi, DKEY(key), key ? key->mv_size:0, data->mv_size);
#if MDB_DEBUG
{
MDB_val k2;
- char kbuf2[(MAXKEYSIZE*2+1)];
+ char kbuf2[(MDB_MAXKEYSIZE*2+1)];
k2.mv_data = NODEKEY(node);
k2.mv_size = node->mn_ksize;
DPRINTF("update key %u (ofs %u) [%s] to [%s] on page %zu",
return EACCES;
}
- if (key->mv_size == 0 || key->mv_size > MAXKEYSIZE) {
+ if (key->mv_size == 0 || key->mv_size > MDB_MAXKEYSIZE) {
return EINVAL;
}
return EACCES;
}
- if (key->mv_size == 0 || key->mv_size > MAXKEYSIZE) {
+ if (key->mv_size == 0 || key->mv_size > MDB_MAXKEYSIZE) {
return EINVAL;
}