11 #if defined(HAVE_FTOK) && defined(HAVE_SYS_IPC_H)
21 #define _RPMTAG_INTERNAL
24 #define _RPMEVR_INTERNAL
27 #define _RPMDB_INTERNAL
33 extern int logio_dispatch(
DB_ENV * dbenv,
DBT * dbt, DB_LSN * lsn, db_recops op)
37 #define DBIDEBUG(_dbi, _list) if ((_dbi)->dbi_debug) fprintf _list
59 if (_endian.
uc[0] == 0x44) {
60 uint8_t _b, *_c = _a.
uc; \
61 _b = _c[7]; _c[7] = _c[0]; _c[0] = _b; \
62 _b = _c[6]; _c[6] = _c[1]; _c[1] = _b; \
63 _b = _c[5]; _c[5] = _c[2]; _c[2] = _b; \
64 _b = _c[4]; _c[4] = _c[3]; _c[3] = _b; \
79 if (_endian.
uc[0] == 0x44) {
80 uint8_t _b, *_c = _a.
uc; \
81 _b = _c[3]; _c[3] = _c[0]; _c[0] = _b; \
82 _b = _c[2]; _c[2] = _c[1]; _c[1] = _b; \
97 if (_endian.
uc[0] == 0x44) {
98 uint8_t _b, *_c = _a.
uc; \
99 _b = _c[1]; _c[1] = _c[0]; _c[0] = _b; \
110 static const char * bfstring(
unsigned int x,
const char * xbf)
112 const char * s = xbf;
113 static char digits[] =
"0123456789abcdefghijklmnopqrstuvwxyz";
114 static char buf[BUFSIZ];
119 radix = (s != NULL ? *s++ : 16);
121 if (radix <= 1 || radix >= 32)
126 case 8: *t++ =
'0';
break;
127 case 16: *t++ =
'0'; *t++ =
'x';
break;
132 do { i++; k /= radix; }
while (k);
137 do { --i; t[i] = digits[k % radix]; k /= radix; }
while (k);
142 while ((c = *s++) !=
'\0') {
143 if (c >
' ')
continue;
146 if (!(x & k))
continue;
148 if (t == te) *t++ =
'=';
155 if (t > te) *t++ =
'>';
161 static const char * dbtFlags =
162 "\20\1APPMALLOC\2ISSET\3MALLOC\4PARTIAL\5REALLOC\6USERMEM\7DUPOK";
164 static const char * dbenvOpenFlags =
165 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CDB\20LOCK\21LOG\22MPOOL\23REP\24TXN\25LOCKDOWN\26PRIVATE\27RECOVER_FATAL\30REGISTER\31SYSTEM_MEM";
167 static const char * dbOpenFlags =
168 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17EXCL\20FCNTL_LOCKING\21NO_AUTO_COMMIT\22RDWRMASTER\23WRITEOPEN";
170 static const char * dbenvSetFlags =
171 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CDB_ALLDB\20DIRECT_DB\21DIRECT_LOG\22DSYNC_DB\23DSYNC_LOG\24LOG_AUTOREMOVE\25LOG_INMEMORY\26NOLOCKING\27NOPANIC\30OVERWRITE\31PANIC_ENV\36REGION_INIT\37TIME_NOTGRANTED\40YIELDCPU";
173 static const char * dbSetFlags =
174 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CHKSUM\20DUP\21DUPSORT\22ENCRYPT\23INORDER\24RECNUM\25RENUMBER\26REVSPLITOFF\27SNAPSHOT";
176 static const char * dbiModeFlags =
177 "\20\1WRONLY\2RDWR\7CREAT\10EXCL\11NOCTTY\12TRUNC\13APPEND\14NONBLOCK\15SYNC\16ASYNC\17DIRECT\20LARGEFILE\21DIRECTORY\22NOFOLLOW";
189 static const char *
tblName(uint32_t v,
KEY * tbl,
size_t ntbl)
192 const char * n = NULL;
196 for (i = 0; i < ntbl; i++) {
203 (void)
snprintf(buf,
sizeof(buf),
"0x%x", (unsigned)v);
209 static const char *
fmtBits(uint32_t flags,
KEY tbl[],
size_t ntbl,
char *t)
216 sprintf(t,
"0x%x", (
unsigned)flags);
219 for (i = 0; i < 32; i++) {
220 uint32_t mask = (1 << i);
226 name =
tblName(mask, tbl, ntbl);
231 if (pre ==
',') *te++ =
'>';
236 #define _ENTRY(_v) { DB_##_v, #_v, }
253 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR == 5)
267 static char buf[BUFSIZ];
269 te =
stpcpy(te,
"\n\tflags: ");
270 (void)
fmtBits(flags, DBeflags, nDBeflags, te);
273 #define _EFLAGS(_eflags) fmtDBeflags(_eflags)
293 static char buf[BUFSIZ];
295 te =
stpcpy(te,
"\n\tflags: ");
296 (void)
fmtBits(flags, DBoflags, nDBoflags, te);
299 #define _OFLAGS(_oflags) fmtDBoflags(_oflags)
312 static char buf[BUFSIZ];
314 te =
stpcpy(te,
"\n\tflags: ");
315 (void)
fmtBits(flags, DBaflags, nDBaflags, te);
318 #define _AFLAGS(_aflags) fmtDBaflags(_aflags)
332 static char buf[BUFSIZ];
334 te =
stpcpy(te,
"\n\tflags: ");
335 (void)
fmtBits(flags, DBafflags, nDBafflags, te);
338 #define _AFFLAGS(_afflags) fmtDBafflags(_afflags)
343 #if defined(DB_CURSOR_BULK)
357 static char buf[BUFSIZ];
359 (void)
fmtBits(flags, DBCoflags, nDBCoflags, te);
362 #define _DBCOFLAGS(_coflags) fmtDBCoflags(_coflags)
387 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR == 5)
398 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR == 5)
418 static char buf[BUFSIZ];
420 uint32_t op = (flags & DB_OPFLAGS_MASK);
421 flags &= ~DB_OPFLAGS_MASK;
423 te =
stpcpy(te,
"\n\tflags: ");
430 (void)
fmtBits(flags, DBCflags, nDBCflags, te);
433 #define _DBCFLAGS(_flags) fmtDBCflags(_flags)
435 #define _DBT_ENTRY(_v) { DB_DBT_##_v, #_v, }
444 #if defined(DB_DBT_READONLY)
456 static size_t keymax = 35;
460 sprintf(te,
"%p[%u]\t", K->
data, (
unsigned)K->
size);
479 for (i = 0; i < _nu; i++)
484 size_t nb = (_nu < keymax ? _nu : keymax);
485 char * ellipsis = (_nu < keymax ?
"" :
"...");
486 sprintf(te,
"\t\"%.*s%s\"", (
int)nb, (
char *)_u, ellipsis);
490 case 4: sprintf(te,
"\t0x%08x", (
unsigned)*(uint32_t *)_u);
break;
503 static char buf[BUFSIZ];
507 te =
stpcpy(te,
"\n\t key: ");
511 te =
stpcpy(te,
"\n\t pkey: ");
515 te =
stpcpy(te,
"\n\t data: ");
519 te =
stpcpy(te,
"\n\t res: ");
526 #define _KEYDATA(_K, _P, _D, _R) fmtKDR(_K, _P, _D, _R)
530 int error,
int printit,
531 const char * func,
const char * fn,
unsigned ln)
540 func, fn, ln, msg, rc, db_strerror(error));
547 #define cvtdberr(_dbi, _msg, _error, _printit) \
548 Xcvtdberr(_dbi, _msg, _error, _printit, __FUNCTION__, __FILE__, __LINE__)
564 while (dbix < rpmdb->db_ndbi) {
565 if (dbi->dbi_rpmtag == dbiTags->tag)
571 return tagName(dbi->dbi_rpmtag);
576 const char * dbsubfile)
581 DB_ENV * dbenv = rpmdb->db_dbenv;
584 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%s,%s,%s)\n", __FUNCTION__, dbi, dbhome, dbfile, dbsubfile));
589 rc = dbenv->close(dbenv, 0);
591 rpmdb->db_dbenv = NULL;
597 if (rpmdb->db_remove_env) {
601 xx = db_env_create(&dbenv, 0);
603 if (!xx && dbenv != NULL) {
605 xx = dbenv->remove(dbenv, dbhome, DB_FORCE);
623 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR == 5)
632 static int db3is_alive(
DB_ENV *dbenv, pid_t pid,
640 case DB_MUTEX_PROCESS_ONLY:
643 is_alive = (!(kill(pid, 0) < 0 &&
errno == ESRCH));
653 #if defined(HAVE_PHYSMEM_SYSCTL) || defined(HAVE_NCPU_SYSCTL)
654 #include <sys/sysctl.h>
660 static uint64_t _physmem = 0;
661 static int oneshot = 0;
664 #if defined(HAVE_PHYSMEM_SYSCONF)
665 const long _pagesize = sysconf(_SC_PAGESIZE);
666 const long _pages = sysconf(_SC_PHYS_PAGES);
667 if (_pagesize != -1 || _pages != -1)
668 _physmem = (uint64_t)(_pagesize) * (uint64_t)(_pages);
669 #elif defined(HAVE_PHYSMEM_SYSCTL)
670 int name[2] = { CTL_HW, HW_PHYSMEM };
672 size_t mem_ptr_size =
sizeof(mem);
673 if (!sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0)) {
674 if (mem_ptr_size !=
sizeof(mem)) {
675 if (mem_ptr_size ==
sizeof(
unsigned int))
676 _physmem = *(
unsigned int *)(&mem);
690 static size_t _ncores = 1;
691 static int oneshot = 0;
694 #if defined(HAVE_NCPU_SYSCONF)
695 const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
696 #elif defined(HAVE_NCPU_SYSCTL)
697 int name[2] = { CTL_HW, HW_NCPU };
699 size_t cpus_size =
sizeof(cpus);
700 if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0)
701 || cpus_size !=
sizeof(cpus))
704 if (cpus > (
int)_ncores)
705 _ncores = (
size_t)(cpus);
712 #define _TABLE(_v) { #_v, DB_EVENT_##_v }
717 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
722 _TABLE(REP_CONNECT_BROKEN),
724 _TABLE(REP_CONNECT_TRY_FAILED),
727 _TABLE(REP_ELECTION_FAILED),
730 _TABLE(REP_LOCAL_SITE_REMOVED),
732 _TABLE(REP_MASTER_FAILURE),
738 _TABLE(REP_WOULD_ROLLBACK),
750 #elif (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR < 2)
758 _TABLE(REP_ELECTION_FAILED),
761 _TABLE(REP_MASTER_FAILURE),
787 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8)
830 fprintf(stderr,
"==> %s(%p, %s(%u), %p) app_private %p\n", __FUNCTION__, dbenv,
_events[event & 0x1f].n, event, event_info, o);
841 fprintf(stderr,
"\rrecovery %d%% complete", percent);
842 (void)fflush(stderr);
852 const char * dbsubfile,
858 static int oneshot = 0;
860 size_t _ncores =
ncores();
869 (
unsigned)_ncores, (
unsigned)(_physmem/(1024 * 1024)));
870 xx = db_env_set_func_open((
int (*)(
const char *,
int, ...))
Open);
880 if (rpmdb->db_errfile == NULL)
881 rpmdb->db_errfile = stderr;
884 eflags = (dbi->dbi_oeflags | dbi->dbi_eflags);
887 if (eflags & DB_JOINENV) eflags &= DB_JOINENV;
889 if (!(eflags &
DB_INIT_TXN)) eflags &= ~DB_RECOVER;
893 dbhome, dbfile, prDbiOpenFlags(eflags, 1));
896 #if defined(DB_RPCCLIENT)
897 if (dbi->dbi_host == NULL)
898 dbi->dbi_ecflags &= ~DB_RPCCLIENT;
902 rc = db_env_create(&dbenv, dbi->dbi_ecflags);
904 if (dbenv == NULL || rc)
909 dbenv->set_errcall(dbenv, (
void *)rpmdb->db_errcall);
911 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
912 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
935 #if defined(DB_RPCCLIENT)
936 if ((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) {
940 if ((home = strrchr(dbhome,
'/')) != NULL)
943 while (retry++ < 5) {
945 xx = dbenv->set_rpc_server(dbenv, NULL, dbi->dbi_host,
946 dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0);
956 {
size_t _lo = 16 * 1024 * 1024;
957 size_t _hi = 512 * 1024 * 1024;
958 size_t _mp_mmapsize = _physmem;
959 if (_mp_mmapsize < _lo) _mp_mmapsize = _lo;
960 if (_mp_mmapsize > _hi) _mp_mmapsize = _hi;
961 xx = dbenv->set_mp_mmapsize(dbenv, _mp_mmapsize);
965 if (dbi->dbi_tmpdir) {
969 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
970 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
973 tmpdir =
rpmGenPath(root, dbi->dbi_tmpdir, NULL);
975 xx = dbenv->set_tmp_dir(dbenv, tmpdir);
977 tmpdir =
_free(tmpdir);
982 #define _RPMDB_NLOCKS 16384
988 xx = dbenv->set_lk_max_lockers(dbenv, _lk_max_lockers);
990 xx = dbenv->set_lk_max_locks(dbenv, _lk_max_locks);
992 xx = dbenv->set_lk_max_objects(dbenv, _lk_max_objects);
996 xx = dbenv->mutex_set_max(dbenv, _max);
1005 logdir =
rpmGetPath(dbhome,
"/",
"log", NULL);
1011 xx = dbenv->set_lg_dir(dbenv, logdir);
1018 uint32_t _lo = 16 * 1024 * 1024;
1019 uint32_t _hi = 512 * 1024 * 1024;
1021 uint32_t _bytes = _physmem;
1023 if (_bytes < _lo) _bytes = _lo;
1024 if (_bytes > _hi) _bytes = _hi;
1025 xx = dbenv->set_cache_max(dbenv, _gb, _hi);
1029 xx = dbenv->set_cachesize(dbenv, _gb, _bytes, _ncache);
1038 if (eflags & DB_INIT_TXN) {
1039 xx = dbenv->set_app_dispatch(dbenv, logio_dispatch);
1045 if (dbi->dbi_no_fsync) {
1051 if ((eflags & DB_SYSTEM_MEM) && dbi->dbi_shmkey == 0) {
1052 #if defined(HAVE_FTOK)
1053 dbi->dbi_shmkey = ftok(dbhome, 0);
1055 dbi->dbi_shmkey = 0x44631380;
1058 if (dbi->dbi_shmkey) {
1059 xx = dbenv->set_shm_key(dbenv, dbi->dbi_shmkey);
1063 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR == 5)
1066 dbenv->set_msgfile(dbenv, rpmdb->db_errfile);
1068 if (dbi->dbi_thread_count >= 8) {
1069 xx = dbenv->set_thread_count(dbenv, dbi->dbi_thread_count);
1075 if (eflags & DB_RECOVER) {
1077 xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
1081 rc = (dbenv->open)(dbenv, dbhome, eflags, dbi->dbi_perms);
1083 #if defined(DB_VERSION_MISMATCH)
1084 if (rc == DB_VERSION_MISMATCH) xx = 0;
1086 if (rc == EINVAL) xx = 0;
1087 rc =
cvtdberr(dbi,
"dbenv->open", rc, xx);
1091 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR == 5)
1092 if (dbi->dbi_thread_count >= 8) {
1094 xx = dbenv->set_isalive(dbenv, db3is_alive);
1097 xx = dbenv->failchk(dbenv, 0);
1099 if (xx == DB_RUNRECOVERY) {
1108 DBIDEBUG(dbi, (stderr,
"<-- %s(%p(%s),%s,%s,%s,%p) dbenv %p %s\n", __FUNCTION__, dbi,
tagName(dbi->dbi_rpmtag), dbhome, dbfile, dbsubfile, dbenvp, dbenv,
_EFLAGS(eflags)));
1114 xx = dbenv->close(dbenv, 0);
1123 static int db3remove(
dbiIndex dbi,
const char * dbfile,
1124 const char * dbsubfile,
1129 DB * db = (
DB *) dbi->dbi_db;
1133 rc = db->remove(db, dbfile, dbsubfile, flags);
1136 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, dbsubfile, flags, rc));
1143 static int db3rename(
dbiIndex dbi,
const char * dbfile,
1144 const char * dbsubfile,
1145 const char * newname,
1150 DB * db = (
DB *) dbi->dbi_db;
1154 rc = db->rename(db, dbfile, dbsubfile, newname, flags);
1157 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,%s,0x%x) rc %d %s\n", __FUNCTION__, dbi, dbfile, dbsubfile, newname, flags, rc,
_DBCFLAGS(flags)));
1164 static int db3truncate(
dbiIndex dbi,
unsigned int * countp,
unsigned int flags)
1168 DB * db = (
DB *) dbi->dbi_db;
1169 DB_TXN * _txnid = dbiTxnid(dbi);
1173 rc = db->truncate(db, _txnid, countp, flags);
1176 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, countp, flags, rc));
1183 static int db3upgrade(
dbiIndex dbi,
const char * dbfile,
1188 DB * db = (
DB *) dbi->dbi_db;
1192 rc = db->upgrade(db, dbfile, flags);
1195 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, flags, rc));
1206 DB * db = (
DB *) dbi->dbi_db;
1211 rc = db->sync(db, flags);
1213 rc =
cvtdberr(dbi,
"db->sync", rc, _printit);
1215 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1225 DB * db = (
DB *) dbi->dbi_db;
1226 DB_TXN * _txnid = dbiTxnid(dbi);
1231 rc = db->exists(db, _txnid, key, flags);
1234 rc =
cvtdberr(dbi,
"db->exists", rc, _printit);
1236 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d %s\n", __FUNCTION__, dbi, key, flags, rc,
_KEYDATA(key, NULL, NULL, NULL)));
1247 DB * db = (
DB *) dbi->dbi_db;
1248 DB_TXN * _txnid = dbiTxnid(dbi);
1255 assert(seq != NULL);
1257 if (seqnop && *seqnop)
1260 rc = seq->get(seq, _txnid, _delta, &seqno, 0);
1268 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) seqno %lld rc %d\n", __FUNCTION__, dbi, seqnop, flags, (
long long)seqno, rc));
1281 if (dbcp) *dbcp = NULL;
1282 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1283 rc = dbcursor->dup(dbcursor, dbcp, flags);
1286 rc = dbcursor->c_dup(dbcursor, dbcp, flags);
1290 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, dbcp, flags, rc));
1304 if (dbcursor != NULL) {
1305 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1306 rc = dbcursor->close(dbcursor);
1309 rc = dbcursor->c_close(dbcursor);
1314 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, flags, rc));
1321 DBC ** dbcp,
unsigned int dbiflags)
1325 DB * db = (
DB *) dbi->dbi_db;
1326 DBC * dbcursor = NULL;
1333 (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
1339 rc = db->cursor(db, txnid, &dbcursor, flags);
1347 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) dbc %p %s rc %d\n", __FUNCTION__, dbi, txnid, dbcp, dbiflags, dbcursor,
_DBCOFLAGS(flags), rc));
1356 DB * db = (
DB *) dbi->dbi_db;
1357 DB_TXN * _txnid = dbiTxnid(dbi);
1361 if (dbcursor == NULL) {
1363 rc = db->put(db, _txnid, key, data, flags);
1367 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1368 rc = dbcursor->put(dbcursor, key, data, flags);
1371 rc = dbcursor->c_put(dbcursor, key, data, flags);
1376 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,%p,0x%x) rc %d %s%s\n", __FUNCTION__, dbi, dbcursor, key, data, flags, rc,
_DBCFLAGS(flags),
_KEYDATA(key, NULL, data, NULL)));
1386 DB * db = (
DB *) dbi->dbi_db;
1387 DB_TXN * _txnid = dbiTxnid(dbi);
1392 if (dbcursor == NULL) {
1394 rc = db->get(db, _txnid, key, data, flags);
1397 rc =
cvtdberr(dbi,
"db->get", rc, _printit);
1399 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1401 rc = dbcursor->get(dbcursor, key, data, flags);
1406 rc =
cvtdberr(dbi,
"dbcursor->get", rc, _printit);
1409 rc = dbcursor->c_get(dbcursor, key, data, flags);
1412 rc =
cvtdberr(dbi,
"dbcursor->c_get", rc, _printit);
1416 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,%p,0x%x) rc %d %s%s\n", __FUNCTION__, dbi, dbcursor, key, data, flags, rc,
_DBCFLAGS(flags),
_KEYDATA(key, NULL, data, NULL)));
1423 DBT * data,
unsigned int flags)
1427 DB * db = (
DB *) dbi->dbi_db;
1428 DB_TXN * _txnid = dbiTxnid(dbi);
1433 if (dbcursor == NULL) {
1435 rc = db->pget(db, _txnid, key, pkey, data, flags);
1438 rc =
cvtdberr(dbi,
"db->pget", rc, _printit);
1440 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1442 rc = dbcursor->pget(dbcursor, key, pkey, data, flags);
1445 rc =
cvtdberr(dbi,
"dbcursor->pget", rc, _printit);
1448 rc = dbcursor->c_pget(dbcursor, key, pkey, data, flags);
1451 rc =
cvtdberr(dbi,
"dbcursor->c_pget", rc, _printit);
1455 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,%p,%p,0x%x) rc %d %s%s\n", __FUNCTION__, dbi, dbcursor, key, pkey, data, flags, rc,
_DBCFLAGS(flags),
_KEYDATA(key, pkey, data, NULL)));
1466 DB * db = (
DB *) dbi->dbi_db;
1467 DB_TXN * _txnid = dbiTxnid(dbi);
1471 if (dbcursor == NULL) {
1472 rc = db->del(db, _txnid, key, flags);
1480 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1481 rc = dbcursor->del(dbcursor, flags);
1484 rc = dbcursor->c_del(dbcursor, flags);
1490 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,%p,0x%x) rc %d %s%s\n", __FUNCTION__, dbi, dbcursor, key, data, flags, rc,
_DBCFLAGS(flags),
_KEYDATA(key, NULL, data, NULL)));
1496 unsigned int * countp,
1501 db_recno_t count = 0;
1505 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR == 5)
1506 rc = dbcursor->count(dbcursor, &count, flags);
1509 rc = dbcursor->c_count(dbcursor, &count, flags);
1512 if (countp) *countp = (!rc ? count : 0);
1514 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) count %d\n", __FUNCTION__, dbi, dbcursor, countp, flags, count));
1521 DB * db = (
DB *) dbi->dbi_db;
1526 rc = db->get_byteswapped(db, &isswapped);
1538 DB * db = (
DB *) dbi->dbi_db;
1540 DB_TXN * _txnid = dbiTxnid(dbi);
1545 #if defined(DB_FAST_STAT)
1547 flags = DB_FAST_STAT;
1551 dbi->dbi_stats =
_free(dbi->dbi_stats);
1553 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3) || (DB_VERSION_MAJOR == 5)
1554 rc = db->stat(db, _txnid, &dbi->dbi_stats, flags);
1556 rc = db->stat(db, &dbi->dbi_stats, flags);
1560 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1567 int (*callback)(
DB *,
const DBT *,
const DBT *,
DBT *),
1572 DB * db = (
DB *) dbi->dbi_db;
1573 DB * secondary = (
DB *) dbisecondary->dbi_db;
1574 DB_TXN * _txnid = dbiTxnid(dbi);
1580 rc = db->associate(db, _txnid, secondary, callback, flags);
1584 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1586 fprintf(stderr,
"<-- %s(%p(%s),%p(%s),%p,0x%x) rc %d %s\n", __FUNCTION__, dbi,
tagName(dbi->dbi_rpmtag), dbisecondary, tag2, (
void *)callback, flags, rc,
_AFLAGS(flags));
1596 int (*callback)(
DB *,
const DBT *,
DBT *,
const DBT *,
int *),
1603 #if !defined(__LCLINT__)
1605 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR == 5)
1606 DB * db = (
DB *) dbi->dbi_db;
1607 DB * secondary = (
DB *) dbisecondary->dbi_db;
1609 rc = db->associate_foreign(db, secondary, callback, flags);
1615 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1617 fprintf(stderr,
"<-- %s(%p(%s),%p(%s),%p,0x%x) rc %d %s\n", __FUNCTION__, dbi,
tagName(dbi->dbi_rpmtag), dbisecondary, tag2, callback, flags, rc,
_AFFLAGS(flags));
1631 DB * db = (
DB *) dbi->dbi_db;
1634 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%p,%p,0x%x)\n", __FUNCTION__, dbi, curslist, dbcp, flags));
1637 rc = db->join(db, curslist, dbcp, flags);
1651 const char * urlfn = NULL;
1654 const char * dbhome;
1655 const char * dbfile;
1656 const char * dbsubfile;
1657 DB * db = (
DB *) dbi->dbi_db;
1668 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1669 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1671 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
1680 (void)
urlPath(urlfn, &dbhome);
1681 if (dbi->dbi_temporary) {
1686 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
1687 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
1689 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
1695 rc = seq->close(seq, 0);
1697 seq = dbi->dbi_seq = NULL;
1700 dbhome, (dbfile ? dbfile : dbiBN));
1704 rc = db->close(db, 0);
1706 _printit = (rc == ENOENT ? 0 :
_debug);
1707 rc =
cvtdberr(dbi,
"db->close", rc, _printit);
1708 db = dbi->dbi_db = NULL;
1711 dbhome, (dbfile ? dbfile : dbiBN));
1716 if (rpmdb->db_dbenv != NULL && dbi->dbi_use_dbenv && !dbi->dbi_temporary) {
1717 if (rpmdb->db_opens == 1) {
1719 xx =
db_fini(dbi, (dbhome ? dbhome :
""), dbfile, dbsubfile);
1721 rpmdb->db_dbenv = NULL;
1726 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1730 urlfn =
_free(urlfn);
1746 if (c >=
'0' && c <=
'9')
1747 return (
unsigned char)(c -
'0');
1748 if (c >=
'A' && c <=
'F')
1749 return (
unsigned char)((int)(c -
'A') + 10);
1750 if (c >=
'a' && c <=
'f')
1751 return (
unsigned char)((int)(c -
'a') + 10);
1758 const char * s = _s;
1765 if (ns == 0) ns = strlen(s);
1769 if (ns > 0 && !(ns & 1)) {
1772 for (i = 0; i < ns; i++, t++, s += 2) {
1773 if (!(isxdigit(s[0]) && isxdigit(s[1])))
1793 data = (
void *) memcpy(
xmalloc(ns), _s, ns);
1798 return (_r->
size = size);
1804 const uint32_t * a = _a;
1805 const uint32_t * b = _b;
1806 return ((*a < *b) ? -1 :
1807 ((*a > *b) ? 1 : 0));
1813 const uint64_t * a = _a;
1814 const uint64_t * b = _b;
1815 return ((*a < *b) ? -1 :
1816 ((*a > *b) ? 1 : 0));
1827 HE_t FMhe = (
HE_t) memset(
alloca(
sizeof(*FMhe)), 0,
sizeof(*FMhe));
1834 const char * s = NULL;
1836 int rc = DB_DONOTINDEX;
1840 assert(key->
size ==
sizeof(hdrNum));
1841 memcpy(&hdrNum, key->
data, key->
size);
1849 rpmdb = dbi->dbi_rpmdb;
1853 if (hdrNum > rpmdb->db_maxkey)
1854 rpmdb->db_maxkey = hdrNum;
1862 _(
"db3: header #%u cannot be loaded -- skipping.\n"),
1868 memset(_r, 0,
sizeof(*_r));
1870 he->
tag = dbi->dbi_rpmtag;
1875 assert(he->
p.
ptr != NULL && he->
c > 0);
1902 { uint8_t * _u = (uint8_t *) he->
p.
ui8p;
1904 for (i = 0; i < he->
c; i++)
1910 { uint16_t * _u = (uint16_t *) he->
p.
ui16p;
1912 for (i = 0; i < he->
c; i++)
1919 { uint32_t * _u = (uint32_t *) he->
p.
ui32p;
1920 size_t _ulen =
sizeof(*_u);
1943 for (i = 0; i < he->
c; i++, _u++) {
1945 if (i > 0 && _u[-1] == _u[0])
1955 { uint64_t * _u = (uint64_t *) he->
p.
ui64p;
1956 size_t _ulen =
sizeof(*_u);
1970 for (i = 0; i < he->
c; i++, _u++) {
1972 if (i > 0 && _u[-1] == _u[0])
1982 s = (
char *) he->
p.
ptr; ns = he->
c;
1989 s = he->
p.
str; ns = strlen(s);
1996 s = he->
p.
argv[0]; ns = strlen(s);
2000 static double e = 1.0e-5;
2001 static size_t nmin = 16;
2002 size_t n = 2 * (he->
c > nmin ? he->
c : nmin);
2006 rpmbfParams(n, e, &m, &k);
2007 bf = rpmbfNew(m, k, 0);
2012 for (i = 0; i < he->
c; i++) {
2013 s = he->
p.
argv[i]; ns = strlen(s);
2016 if (s[0] ==
'-' && s[1] ==
' ') {
2022 if (FMhe->
p.
ui16p && !S_ISREG((mode_t)FMhe->
p.
ui16p[i])) {
2035 if (rpmbfChk(bf, s, ns) > 0)
2037 xx = rpmbfAdd(bf, s, ns);
2053 memset(_r, 0,
sizeof(*_r));
2057 if (!dbi->dbi_no_dbsync && rc != DB_DONOTINDEX)
2058 xx = dbiSync(dbi, 0);
2066 DBIDEBUG(dbi, (stderr,
"<-- %s(%p, %p, %p, %p) rc %d\n\tdbi %p(%s) rpmdb %p h %p %s\n", __FUNCTION__, db, key, data, _r, rc, dbi,
tagName(dbi->dbi_rpmtag), rpmdb, h,
_KEYDATA(key, NULL, data, _r)));
2075 DB * db = (
DB *) dbi->dbi_db;
2077 DB_TXN * _txnid = dbiTxnid(dbi);
2079 db_seq_t _rangemin = -922337203685477600LL;
2080 db_seq_t _rangemax = 922337203685477600LL;
2082 int32_t _cachesize = 0;
2083 uint32_t _flags = DB_SEQ_INC;
2088 if (seqp) *seqp = NULL;
2091 rc = db_sequence_create(&seq, db, 0);
2095 assert(seq != NULL);
2097 if (dbi->dbi_seq_cachesize) {
2098 _cachesize = dbi->dbi_seq_cachesize;
2099 rc = seq->set_cachesize(seq, _cachesize);
2104 if (dbi->dbi_seq_initial)
2105 _value = dbi->dbi_seq_initial;
2106 if (_value <= 0) _value = 1;
2107 rc = seq->initial_value(seq, _value);
2111 if (dbi->dbi_seq_min)
2112 _rangemin = dbi->dbi_seq_min;
2113 if (dbi->dbi_seq_max)
2114 _rangemax = dbi->dbi_seq_max;
2115 rc = seq->set_range(seq, _rangemin, _rangemax);
2119 if (dbi->dbi_seq_flags)
2120 _flags = dbi->dbi_seq_flags;
2121 rc = seq->set_flags(seq, _flags);
2125 k.data = (
void *)keyp;
2126 k.size = (u_int32_t) (keylen > 0 ? keylen : strlen(keyp));
2127 rc = seq->open(seq, _txnid, &k, _oflags);
2132 if (rc == 0 && seqp != NULL)
2135 int xx = seq->close(seq, 0);
2139 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p[%u],%p) seq %p rc %d %s\n", __FUNCTION__, dbi, keyp, (
unsigned)keylen, seqp, (seqp ? *seqp : NULL), rc,
_KEYDATA(&k, NULL, NULL, NULL)));
2157 extern struct _dbiVec db3vec;
2159 const char * urlfn = NULL;
2162 const char * dbhome;
2163 const char * dbfile;
2164 const char * dbsubfile;
2184 if ((dbi = db3New(rpmdb, rpmtag)) == NULL)
2191 dbi->dbi_txnid = NULL;
2197 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
2198 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
2200 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
2209 (void)
urlPath(urlfn, &dbhome);
2210 if (dbi->dbi_temporary) {
2215 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
2216 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
2218 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
2223 oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
2225 if (dbi->dbi_primary) oflags &= ~DB_TRUNCATE;
2228 if ( dbi->dbi_mode & O_EXCL) oflags |=
DB_EXCL;
2234 if (dbi->dbi_temporary) {
2237 oflags &= ~DB_RDONLY;
2238 dbi->dbi_oflags &= ~DB_RDONLY;
2240 if (!(dbi->dbi_mode & (O_RDWR|O_WRONLY))) oflags |= DB_RDONLY;
2241 if (dbi->dbi_mode & O_CREAT) {
2246 if (dbi->dbi_primary && (dbi->dbi_mode & O_TRUNC))
2247 oflags |= DB_TRUNCATE;
2253 (void)
rpmioMkpath(dbhome, 0755, getuid(), getgid());
2258 if (dbi->dbi_use_dbenv) {
2260 if (access(dbhome,
W_OK) == -1) {
2268 dbi->dbi_eflags &= ~DB_JOINENV;
2270 dbi->dbi_eflags |= DB_JOINENV;
2276 dbi->dbi_use_dbenv = 0;
2280 if (dbi->dbi_temporary) {
2283 oflags &= ~DB_RDONLY;
2284 dbi->dbi_oflags &= ~DB_RDONLY;
2286 oflags |= DB_RDONLY;
2288 dbi->dbi_oflags |= DB_RDONLY;
2293 const char * dbf =
rpmGetPath(dbhome,
"/__db.001", NULL);
2296 #if defined(RPM_VENDOR_OPENPKG)
2301 if (stat(dbf, &sb) == 0)
2302 size = (long)sb.st_size;
2303 if (access(dbf,
F_OK) == -1 || size == 0)
2305 if (access(dbf,
F_OK) == -1)
2310 dbi->dbi_eflags &= ~DB_JOINENV;
2314 dbi->dbi_eflags &= ~DB_JOINENV;
2316 dbi->dbi_eflags |= DB_JOINENV;
2334 if ((oflags &
DB_CREATE) && (oflags & DB_RDONLY)) {
2336 const char * dbfn = (dbfile ? dbfile : dbiBN);
2338 const char * dbf =
rpmGetPath(dbhome,
"/", dbfn, NULL);
2341 if (access(dbf,
F_OK) == -1) {
2343 oflags &= ~DB_RDONLY;
2346 oflags &= ~DB_CREATE;
2350 if (!(oflags & DB_RDONLY) && access(dbf,
W_OK) == 0) {
2351 dbi->dbi_oflags &= ~DB_RDONLY;
2353 dbi->dbi_oflags |= DB_RDONLY;
2361 if (oflags & (DB_CREATE|DB_TRUNCATE))
2362 dbi_type = (
DBTYPE) dbi->dbi_type;
2364 if (dbi->dbi_use_dbenv) {
2366 if (rpmdb->db_dbenv == NULL) {
2367 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2371 case DB_RUNRECOVERY:
2376 dbi->dbi_eflags |= DB_RECOVER;
2377 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2378 dbi->dbi_eflags &= ~DB_RECOVER;
2385 rpmdb->db_dbenv = dbenv;
2386 rpmdb->db_opens = 1;
2389 #if defined(DB_VERSION_MISMATCH)
2390 case DB_VERSION_MISMATCH:
2395 {
char * filename = (
char *)
alloca(BUFSIZ);
2399 for (i = 0; i < 16; i++) {
2400 sprintf(filename,
"%s/__db.%03d", dbhome, i);
2402 if (
Stat(filename, &st)
2409 dbi->dbi_eflags &= ~DB_JOINENV;
2410 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2418 rpmdb->db_dbenv = dbenv;
2419 rpmdb->db_opens = 1;
2423 assert(rpmdb && rpmdb->db_dbenv);
2424 dbenv = (
DB_ENV *) rpmdb->db_dbenv;
2431 dbhome, (dbfile ? dbfile : dbiBN),
2432 prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
2435 static int _lockdbfd = 0;
2438 rc = db_create(&db, dbenv, dbi->dbi_cflags);
2441 if (rc == 0 && db != NULL) {
2445 rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free)
2447 rc = db->set_alloc(db,
2448 rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free);
2457 if (rc == 0 && dbi->dbi_lorder) {
2458 rc = db->set_lorder(db, dbi->dbi_lorder);
2461 if (rc == 0 && dbi->dbi_pagesize) {
2462 rc = db->set_pagesize(db, dbi->dbi_pagesize);
2466 if (rc == 0 && oflags & DB_CREATE) {
2467 switch(dbi->dbi_type) {
2470 if (dbi->dbi_h_ffactor) {
2471 rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor);
2475 if (dbi->dbi_h_nelem) {
2476 rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
2480 if (dbi->dbi_h_flags) {
2481 rc = db->set_flags(db, dbi->dbi_h_flags);
2485 if (dbi->dbi_h_hash_fcn) {
2486 rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
2490 if (dbi->dbi_h_dup_compare_fcn) {
2491 rc = db->set_dup_compare(db, dbi->dbi_h_dup_compare_fcn);
2498 if (dbi->dbi_bt_flags) {
2499 rc = db->set_flags(db, dbi->dbi_bt_flags);
2503 if (dbi->dbi_bt_minkey) {
2504 rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
2508 if (dbi->dbi_bt_compare_fcn) {
2509 rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
2513 if (dbi->dbi_bt_dup_compare_fcn) {
2514 rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
2518 if (dbi->dbi_bt_prefix_fcn) {
2519 rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
2526 if (dbi->dbi_re_delim) {
2527 rc = db->set_re_delim(db, dbi->dbi_re_delim);
2531 if (dbi->dbi_re_len) {
2532 rc = db->set_re_len(db, dbi->dbi_re_len);
2536 if (dbi->dbi_re_pad) {
2537 rc = db->set_re_pad(db, dbi->dbi_re_pad);
2541 if (dbi->dbi_re_source) {
2542 rc = db->set_re_source(db, dbi->dbi_re_source);
2548 if (dbi->dbi_q_extentsize) {
2549 rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize);
2554 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
2556 if (dbi->dbi_heapsize) {
2557 static uint32_t _gbytes = 0;
2558 uint32_t _bytes = dbi->dbi_heapsize;
2559 static uint32_t _flags = 0;
2560 assert(dbi->dbi_heapsize >= (3 * dbi->dbi_pagesize));
2561 rc = db->set_heapsize(db, _gbytes, _bytes, _flags);
2565 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 3)
2566 if (dbi->dbi_heap_regionsize) {
2567 uint32_t _npages = dbi->dbi_heap_regionsize;
2569 rc = db->set_heap_regionsize(db, _npages);
2580 const char * dbfullpath;
2581 const char * dbpath;
2585 nb = strlen(dbhome);
2586 if (dbfile) nb += 1 + strlen(dbfile);
2587 dbfullpath = t = (
char *)
alloca(nb + 1);
2593 dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary)
2594 ? dbfullpath : dbfile;
2598 dbpath = (!dbi->dbi_use_dbenv)
2599 ? dbfullpath : dbfile;
2601 dbpath = (!dbi->dbi_temporary)
2602 ? dbfullpath : dbfile;
2606 rc = (db->open)(db, _txnid, dbpath, dbsubfile,
2607 dbi_type, oflags, dbi->dbi_perms);
2610 xx = db->get_type(db, &dbi_type);
2612 dbi->dbi_type = dbi_type;
2617 _printit = (rc > 0 ? 0 :
_debug);
2618 xx =
cvtdberr(dbi,
"db->open", rc, _printit);
2638 if (rc == 0 && dbi->dbi_lockdbfd &&
2639 #
if defined(DB_RPCCLIENT)
2640 !((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) &&
2642 (!dbi->dbi_use_dbenv || _lockdbfd++ == 0))
2646 if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
2650 memset(&l, 0,
sizeof(l));
2654 l.l_type = (dbi->dbi_mode & (O_RDWR|O_WRONLY))
2655 ? F_WRLCK : F_RDLCK;
2658 rc = fcntl(fdno, F_SETLK, (
void *) &l);
2661 rc = ((dbi->dbi_use_dbenv &&
2662 (dbi->dbi_eflags & DB_INIT_CDB) &&
2666 _(
"cannot get %s lock on %s/%s\n"),
2667 ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
2668 ?
_(
"exclusive") :
_(
"shared")),
2669 dbhome, (dbfile ? dbfile :
""));
2670 }
else if (dbfile) {
2672 D_(
"locked db index %s/%s\n"),
2680 dbi->dbi_db = (
void *) db;
2684 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%p) dbi %p rc %d %s\n", __FUNCTION__, rpmdb,
tagName(rpmtag), dbip, dbi, rc,
_OFLAGS(dbi->dbi_oflags)));
2686 if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) {
2689 if (dbi->dbi_primary) {
2692 int (*_callback)(
DB *,
const DBT *,
const DBT *, DBT *)
2695 int _flags = DB_IMMUTABLE_KEY;
2700 Pdbi =
dbiOpen(rpmdb, Ptag, 0);
2701 assert(Pdbi != NULL);
2702 if (oflags & (DB_CREATE|DB_TRUNCATE)) _flags |=
DB_CREATE;
2705 if (dbi->dbi_seq_id && !(oflags & DB_RDONLY)) {
2707 uint32_t u = (uint32_t) strtoll(dbi->dbi_seq_id, &end, 0);
2710 if (oflags & (DB_CREATE|DB_TRUNCATE))
2711 dbi->dbi_seq_initial = rpmdb->db_maxkey + 1;
2720 if (dbip) *dbip = dbi;
2726 if (dbip) *dbip = dbi;
2729 urlfn =
_free(urlfn);