1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-bdb/nextid.c,v 1.26.2.4 2008/02/12 00:34:58 quanah Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 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 bdb_next_id( BackendDB
*be
, ID
*out
)
26 struct bdb_info
*bdb
= (struct bdb_info
*) be
->be_private
;
28 ldap_pvt_thread_mutex_lock( &bdb
->bi_lastid_mutex
);
29 *out
= ++bdb
->bi_lastid
;
30 ldap_pvt_thread_mutex_unlock( &bdb
->bi_lastid_mutex
);
35 int bdb_last_id( BackendDB
*be
, DB_TXN
*tid
)
37 struct bdb_info
*bdb
= (struct bdb_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
= bdb
->bi_id2entry
->bdi_db
->cursor( bdb
->bi_id2entry
->bdi_db
,
57 rc
= cursor
->c_get(cursor
, &key
, &data
, DB_LAST
);
58 cursor
->c_close(cursor
);
66 BDB_DISK2ID( idbuf
, &id
);
70 Debug( LDAP_DEBUG_ANY
,
71 "=> bdb_last_id: get failed: %s (%d)\n",
72 db_strerror(rc
), rc
, 0 );