1 /* init.c - initialize mdb backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2011 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
24 int mdb_next_id( BackendDB *be, ID *out )
26 struct mdb_info *mdb = (struct mdb_info *) be->be_private;
28 ldap_pvt_thread_mutex_lock( &mdb->bi_lastid_mutex );
29 *out = ++mdb->bi_lastid;
30 ldap_pvt_thread_mutex_unlock( &mdb->bi_lastid_mutex );
35 int mdb_last_id( BackendDB *be, DB_TXN *tid )
37 struct mdb_info *mdb = (struct mdb_info *) be->be_private;
40 unsigned char idbuf[sizeof(ID)];
45 key.flags = DB_DBT_USERMEM;
46 key.data = (char *) idbuf;
47 key.ulen = sizeof( idbuf );
50 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
52 /* Get a read cursor */
53 rc = mdb->bi_id2entry->bdi_db->cursor( mdb->bi_id2entry->bdi_db,
57 rc = cursor->c_get(cursor, &key, &data, DB_LAST);
58 cursor->c_close(cursor);
66 MDB_DISK2ID( idbuf, &id );
70 Debug( LDAP_DEBUG_ANY,
71 "=> mdb_last_id: get failed: %s (%d)\n",
72 db_strerror(rc), rc, 0 );