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++) {
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: ");
273 #define _EFLAGS(_eflags) fmtDBeflags(_eflags)
293 static char buf[BUFSIZ];
295 te =
stpcpy(te,
"\n\tflags: ");
299 #define _OFLAGS(_oflags) fmtDBoflags(_oflags)
312 static char buf[BUFSIZ];
314 te =
stpcpy(te,
"\n\tflags: ");
318 #define _AFLAGS(_aflags) fmtDBaflags(_aflags)
332 static char buf[BUFSIZ];
334 te =
stpcpy(te,
"\n\tflags: ");
338 #define _AFFLAGS(_afflags) fmtDBafflags(_afflags)
343 #if defined(DB_CURSOR_BULK)
357 static char buf[BUFSIZ];
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: ");
433 #define _DBCFLAGS(_flags) fmtDBCflags(_flags)
435 #define _DBT_ENTRY(_v) { DB_DBT_##_v, #_v, }
444 #if defined(DB_DBT_READONLY)
447 #if defined(DB_DBT_ISSET)
450 #if defined(DB_DBT_USERCOPY)
453 #if defined(DB_DBT_USERMEM)
456 #if defined(DB_DBT_BLOB)
459 #if defined(DB_DBT_BLOB_REC)
462 #if defined(DB_DBT_STREAMING)
465 #if defined(DB_DBT_BULK)
468 #if defined(DB_DBT_DUPOK)
480 static size_t keymax = 35;
503 for (i = 0; i < _nu; i++)
508 size_t nb = (_nu < keymax ? _nu : keymax);
509 char *
ellipsis = (_nu < keymax ?
"" :
"...");
510 sprintf(te,
"\t\"%.*s%s\"", (
int)nb, (
char *)_u, ellipsis);
514 case 4:
sprintf(te,
"\t0x%08x", (
unsigned)*(uint32_t *)_u);
break;
527 static char buf[BUFSIZ];
531 te =
stpcpy(te,
"\n\t key: ");
535 te =
stpcpy(te,
"\n\t pkey: ");
539 te =
stpcpy(te,
"\n\t data: ");
543 te =
stpcpy(te,
"\n\t res: ");
550 #define _KEYDATA(_K, _P, _D, _R) fmtKDR(_K, _P, _D, _R)
554 int error,
int printit,
555 const char * func,
const char *
fn,
unsigned ln)
564 func, fn, ln, msg, rc, db_strerror(error));
571 #define cvtdberr(_dbi, _msg, _error, _printit) \
572 Xcvtdberr(_dbi, _msg, _error, _printit, __FUNCTION__, __FILE__, __LINE__)
588 while (dbix < rpmdb->db_ndbi) {
589 if (dbi->dbi_rpmtag == dbiTags->tag)
595 return tagName(dbi->dbi_rpmtag);
600 const char * dbsubfile)
608 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%s,%s,%s)\n", __FUNCTION__, dbi, dbhome, dbfile, dbsubfile));
613 rc = dbenv->close(dbenv, 0);
615 rpmdb->db_dbenv =
NULL;
621 if (rpmdb->db_remove_env) {
625 xx = db_env_create(&dbenv, 0);
627 if (!xx && dbenv !=
NULL) {
629 xx = dbenv->remove(dbenv, dbhome, DB_FORCE);
647 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
664 case DB_MUTEX_PROCESS_ONLY:
667 is_alive = (!(kill(pid, 0) < 0 &&
errno == ESRCH));
677 #if defined(HAVE_PHYSMEM_SYSCTL) || defined(HAVE_NCPU_SYSCTL)
678 #include <sys/sysctl.h>
684 static uint64_t _physmem = 0;
685 static int oneshot = 0;
688 #if defined(HAVE_PHYSMEM_SYSCONF)
689 const long _pagesize = sysconf(_SC_PAGESIZE);
690 const long _pages = sysconf(_SC_PHYS_PAGES);
691 if (_pagesize != -1 || _pages != -1)
692 _physmem = (uint64_t)(_pagesize) * (uint64_t)(_pages);
693 #elif defined(HAVE_PHYSMEM_SYSCTL)
694 int name[2] = { CTL_HW, HW_PHYSMEM };
696 size_t mem_ptr_size =
sizeof(mem);
697 if (!sysctl(name, 2, &mem, &mem_ptr_size,
NULL, 0)) {
698 if (mem_ptr_size !=
sizeof(mem)) {
699 if (mem_ptr_size ==
sizeof(
unsigned int))
700 _physmem = *(
unsigned int *)(&mem);
714 static size_t _ncores = 1;
715 static int oneshot = 0;
718 #if defined(HAVE_NCPU_SYSCONF)
719 const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
720 #elif defined(HAVE_NCPU_SYSCTL)
721 int name[2] = { CTL_HW, HW_NCPU };
723 size_t cpus_size =
sizeof(cpus);
724 if (sysctl(name, 2, &cpus, &cpus_size,
NULL, 0)
725 || cpus_size !=
sizeof(cpus))
728 if (cpus > (
int)_ncores)
729 _ncores = (
size_t)(cpus);
736 #define _TABLE(_v) { #_v, DB_EVENT_##_v }
741 #if (DB_VERSION_MAJOR == 6 && DB_VERSION_MINOR >= 0)
745 _TABLE(REP_AUTOTAKEOVER_FAILED),
747 _TABLE(REP_CONNECT_BROKEN),
749 _TABLE(REP_CONNECT_TRY_FAILED),
752 _TABLE(REP_ELECTION_FAILED),
755 _TABLE(REP_LOCAL_SITE_REMOVED),
757 _TABLE(REP_MASTER_FAILURE),
763 _TABLE(REP_WOULD_ROLLBACK),
774 #elif (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
779 _TABLE(REP_CONNECT_BROKEN),
781 _TABLE(REP_CONNECT_TRY_FAILED),
784 _TABLE(REP_ELECTION_FAILED),
787 _TABLE(REP_LOCAL_SITE_REMOVED),
789 _TABLE(REP_MASTER_FAILURE),
795 _TABLE(REP_WOULD_ROLLBACK),
807 #elif (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR < 2) || (DB_VERSION_MAJOR >= 6)
815 _TABLE(REP_ELECTION_FAILED),
818 _TABLE(REP_MASTER_FAILURE),
844 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8)
887 fprintf(stderr,
"==> %s(%p, %s(%u), %p) app_private %p\n", __FUNCTION__, dbenv,
_events[event & 0x1f].
n, event, event_info, o);
891 rpmdbe_feedback(
DB_ENV * dbenv,
int opcode,
int percent)
898 fprintf(stderr,
"\rrecovery %d%% complete", percent);
899 (
void)fflush(stderr);
909 const char * dbsubfile,
915 static int oneshot = 0;
917 size_t _ncores =
ncores();
926 (
unsigned)_ncores, (
unsigned)(_physmem/(1024 * 1024)));
927 xx = db_env_set_func_open((
int (*)(
const char *,
int, ...))
Open);
937 if (rpmdb->db_errfile ==
NULL)
938 rpmdb->db_errfile = stderr;
941 eflags = (dbi->dbi_oeflags | dbi->dbi_eflags);
944 if (eflags & DB_JOINENV) eflags &= DB_JOINENV;
946 if (!(eflags &
DB_INIT_TXN)) eflags &= ~DB_RECOVER;
950 dbhome, dbfile, prDbiOpenFlags(eflags, 1));
953 #if defined(DB_RPCCLIENT)
954 if (dbi->dbi_host ==
NULL)
955 dbi->dbi_ecflags &= ~DB_RPCCLIENT;
959 rc = db_env_create(&dbenv, dbi->dbi_ecflags);
961 if (dbenv ==
NULL || rc)
966 dbenv->set_errcall(dbenv, (
void *)rpmdb->db_errcall);
968 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
969 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
983 xx = dbenv->set_feedback(dbenv, rpmdbe_feedback);
992 #if defined(DB_RPCCLIENT)
993 if ((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) {
997 if ((home = strrchr(dbhome,
'/')) !=
NULL)
1000 while (retry++ < 5) {
1002 xx = dbenv->set_rpc_server(dbenv,
NULL, dbi->dbi_host,
1003 dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0);
1013 {
size_t _lo = 16 * 1024 * 1024;
1014 size_t _hi = 512 * 1024 * 1024;
1015 size_t _mp_mmapsize = _physmem;
1016 if (_mp_mmapsize < _lo) _mp_mmapsize = _lo;
1017 if (_mp_mmapsize > _hi) _mp_mmapsize = _hi;
1018 xx = dbenv->set_mp_mmapsize(dbenv, _mp_mmapsize);
1022 if (dbi->dbi_tmpdir) {
1024 const char * tmpdir;
1026 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1027 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1032 xx = dbenv->set_tmp_dir(dbenv, tmpdir);
1034 tmpdir =
_free(tmpdir);
1039 #define _RPMDB_NLOCKS 16384
1045 xx = dbenv->set_lk_max_lockers(dbenv, _lk_max_lockers);
1047 xx = dbenv->set_lk_max_locks(dbenv, _lk_max_locks);
1049 xx = dbenv->set_lk_max_objects(dbenv, _lk_max_objects);
1053 xx = dbenv->mutex_set_max(dbenv, _max);
1068 xx = dbenv->set_lg_dir(dbenv, logdir);
1075 uint32_t _lo = 16 * 1024 * 1024;
1076 uint32_t _hi = 512 * 1024 * 1024;
1078 uint32_t _bytes = _physmem;
1080 if (_bytes < _lo) _bytes = _lo;
1081 if (_bytes > _hi) _bytes = _hi;
1082 xx = dbenv->set_cache_max(dbenv, _gb, _hi);
1086 xx = dbenv->set_cachesize(dbenv, _gb, _bytes, _ncache);
1095 if (eflags & DB_INIT_TXN) {
1096 xx = dbenv->set_app_dispatch(dbenv, logio_dispatch);
1102 if (dbi->dbi_no_fsync) {
1108 if ((eflags & DB_SYSTEM_MEM) && dbi->dbi_shmkey == 0) {
1109 #if defined(HAVE_FTOK)
1110 dbi->dbi_shmkey = ftok(dbhome, 0);
1112 dbi->dbi_shmkey = 0x44631380;
1115 if (dbi->dbi_shmkey) {
1116 xx = dbenv->set_shm_key(dbenv, dbi->dbi_shmkey);
1120 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
1123 dbenv->set_msgfile(dbenv, rpmdb->db_errfile);
1125 if (dbi->dbi_thread_count >= 8) {
1126 xx = dbenv->set_thread_count(dbenv, dbi->dbi_thread_count);
1132 if (eflags & DB_RECOVER) {
1134 xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
1138 rc = (dbenv->open)(dbenv, dbhome, eflags, dbi->dbi_perms);
1140 #if defined(DB_VERSION_MISMATCH)
1141 if (rc == DB_VERSION_MISMATCH) xx = 0;
1143 if (rc == EINVAL) xx = 0;
1144 rc =
cvtdberr(dbi,
"dbenv->open", rc, xx);
1148 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
1149 if (dbi->dbi_thread_count >= 8) {
1151 xx = dbenv->set_isalive(dbenv, db3is_alive);
1154 xx = dbenv->failchk(dbenv, 0);
1156 if (xx == DB_RUNRECOVERY) {
1165 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)));
1171 xx = dbenv->close(dbenv, 0);
1180 static int db3remove(
dbiIndex dbi,
const char * dbfile,
1181 const char * dbsubfile,
1186 DB * db = (
DB *) dbi->dbi_db;
1190 rc = db->remove(db, dbfile, dbsubfile, flags);
1193 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, dbsubfile, flags,
rc));
1200 static int db3rename(
dbiIndex dbi,
const char * dbfile,
1201 const char * dbsubfile,
1202 const char * newname,
1207 DB * db = (
DB *) dbi->dbi_db;
1211 rc = db->rename(db, dbfile, dbsubfile, newname, flags);
1214 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,%s,0x%x) rc %d %s\n", __FUNCTION__, dbi, dbfile, dbsubfile, newname, flags,
rc,
_DBCFLAGS(flags)));
1221 static int db3truncate(
dbiIndex dbi,
unsigned int * countp,
unsigned int flags)
1225 DB * db = (
DB *) dbi->dbi_db;
1226 DB_TXN * _txnid = dbiTxnid(dbi);
1230 rc = db->truncate(db, _txnid, countp, flags);
1233 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, countp, flags, rc));
1240 static int db3upgrade(
dbiIndex dbi,
const char * dbfile,
1245 DB * db = (
DB *) dbi->dbi_db;
1249 rc = db->upgrade(db, dbfile, flags);
1252 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, flags, rc));
1263 DB * db = (
DB *) dbi->dbi_db;
1268 rc = db->sync(db, flags);
1270 rc =
cvtdberr(dbi,
"db->sync", rc, _printit);
1272 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1282 DB * db = (
DB *) dbi->dbi_db;
1283 DB_TXN * _txnid = dbiTxnid(dbi);
1288 rc = db->exists(db, _txnid, key, flags);
1291 rc =
cvtdberr(dbi,
"db->exists", rc, _printit);
1293 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d %s\n", __FUNCTION__, dbi, key, flags, rc,
_KEYDATA(key,
NULL,
NULL,
NULL)));
1304 DB * db = (
DB *) dbi->dbi_db;
1305 DB_TXN * _txnid = dbiTxnid(dbi);
1314 if (seqnop && *seqnop)
1317 rc = seq->get(seq, _txnid, _delta, &seqno, 0);
1325 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) seqno %lld rc %d\n", __FUNCTION__, dbi, seqnop, flags, (
long long)seqno, rc));
1338 if (dbcp) *dbcp =
NULL;
1339 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1340 rc = dbcursor->dup(dbcursor, dbcp, flags);
1343 rc = dbcursor->c_dup(dbcursor, dbcp, flags);
1347 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, dbcp, flags, rc));
1361 if (dbcursor !=
NULL) {
1362 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1363 rc = dbcursor->close(dbcursor);
1366 rc = dbcursor->c_close(dbcursor);
1371 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, flags, rc));
1378 DBC ** dbcp,
unsigned int dbiflags)
1382 DB * db = (
DB *) dbi->dbi_db;
1390 (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
1396 rc = db->cursor(db, txnid, &dbcursor, flags);
1404 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) dbc %p %s rc %d\n", __FUNCTION__, dbi, txnid, dbcp, dbiflags, dbcursor,
_DBCOFLAGS(flags), rc));
1413 DB * db = (
DB *) dbi->dbi_db;
1414 DB_TXN * _txnid = dbiTxnid(dbi);
1418 if (dbcursor ==
NULL) {
1420 rc = db->put(db, _txnid, key, data, flags);
1424 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1425 rc = dbcursor->put(dbcursor, key, data, flags);
1428 rc = dbcursor->c_put(dbcursor, key, data, flags);
1433 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)));
1443 DB * db = (
DB *) dbi->dbi_db;
1444 DB_TXN * _txnid = dbiTxnid(dbi);
1449 if (dbcursor ==
NULL) {
1451 rc = db->get(db, _txnid, key, data, flags);
1454 rc =
cvtdberr(dbi,
"db->get", rc, _printit);
1456 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1458 rc = dbcursor->get(dbcursor, key, data, flags);
1463 rc =
cvtdberr(dbi,
"dbcursor->get", rc, _printit);
1466 rc = dbcursor->c_get(dbcursor, key, data, flags);
1469 rc =
cvtdberr(dbi,
"dbcursor->c_get", rc, _printit);
1473 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)));
1480 DBT * data,
unsigned int flags)
1484 DB * db = (
DB *) dbi->dbi_db;
1485 DB_TXN * _txnid = dbiTxnid(dbi);
1490 if (dbcursor ==
NULL) {
1492 rc = db->pget(db, _txnid, key, pkey, data, flags);
1495 rc =
cvtdberr(dbi,
"db->pget", rc, _printit);
1497 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1499 rc = dbcursor->pget(dbcursor, key, pkey, data, flags);
1502 rc =
cvtdberr(dbi,
"dbcursor->pget", rc, _printit);
1505 rc = dbcursor->c_pget(dbcursor, key, pkey, data, flags);
1508 rc =
cvtdberr(dbi,
"dbcursor->c_pget", rc, _printit);
1512 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)));
1523 DB * db = (
DB *) dbi->dbi_db;
1524 DB_TXN * _txnid = dbiTxnid(dbi);
1528 if (dbcursor ==
NULL) {
1529 rc = db->del(db, _txnid, key, flags);
1537 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1538 rc = dbcursor->del(dbcursor, flags);
1541 rc = dbcursor->c_del(dbcursor, flags);
1547 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)));
1553 unsigned int * countp,
1558 db_recno_t
count = 0;
1562 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1563 rc = dbcursor->count(dbcursor, &count, flags);
1566 rc = dbcursor->c_count(dbcursor, &count, flags);
1569 if (countp) *countp = (!rc ? count : 0);
1571 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) count %d\n", __FUNCTION__, dbi, dbcursor, countp, flags, count));
1578 DB * db = (
DB *) dbi->dbi_db;
1583 rc = db->get_byteswapped(db, &isswapped);
1595 DB * db = (
DB *) dbi->dbi_db;
1597 DB_TXN * _txnid = dbiTxnid(dbi);
1602 #if defined(DB_FAST_STAT)
1604 flags = DB_FAST_STAT;
1608 dbi->dbi_stats =
_free(dbi->dbi_stats);
1610 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3) || (DB_VERSION_MAJOR >= 5)
1611 rc = db->stat(db, _txnid, &dbi->dbi_stats, flags);
1613 rc = db->stat(db, &dbi->dbi_stats, flags);
1617 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1624 int (*callback)(
DB *,
const DBT *,
const DBT *,
DBT *),
1629 DB * db = (
DB *) dbi->dbi_db;
1630 DB * secondary = (
DB *) dbisecondary->dbi_db;
1631 DB_TXN * _txnid = dbiTxnid(dbi);
1637 rc = db->associate(db, _txnid, secondary, callback, flags);
1641 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1643 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));
1653 int (*callback)(
DB *,
const DBT *,
DBT *,
const DBT *,
int *),
1660 #if !defined(__LCLINT__)
1662 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR >= 5)
1663 DB * db = (
DB *) dbi->dbi_db;
1664 DB * secondary = (
DB *) dbisecondary->dbi_db;
1666 rc = db->associate_foreign(db, secondary, callback, flags);
1672 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1674 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));
1688 DB * db = (
DB *) dbi->dbi_db;
1691 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%p,%p,0x%x)\n", __FUNCTION__, dbi, curslist, dbcp, flags));
1694 rc = db->join(db, curslist, dbcp, flags);
1708 const char * urlfn =
NULL;
1711 const char * dbhome;
1712 const char * dbfile;
1713 const char * dbsubfile;
1714 DB * db = (
DB *) dbi->dbi_db;
1725 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1726 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1728 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
1738 if (dbi->dbi_temporary) {
1743 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
1744 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
1746 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
1752 rc = seq->close(seq, 0);
1754 seq = dbi->dbi_seq =
NULL;
1757 dbhome, (dbfile ? dbfile : dbiBN));
1761 rc = db->close(db, 0);
1763 _printit = (rc == ENOENT ? 0 :
_debug);
1764 rc =
cvtdberr(dbi,
"db->close", rc, _printit);
1765 db = dbi->dbi_db =
NULL;
1768 dbhome, (dbfile ? dbfile : dbiBN));
1773 if (rpmdb->db_dbenv !=
NULL && dbi->dbi_use_dbenv && !dbi->dbi_temporary) {
1774 if (rpmdb->db_opens == 1) {
1776 xx =
db_fini(dbi, (dbhome ? dbhome :
""), dbfile, dbsubfile);
1778 rpmdb->db_dbenv =
NULL;
1783 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1787 urlfn =
_free(urlfn);
1803 if (c >=
'0' && c <=
'9')
1804 return (
unsigned char)(c -
'0');
1805 if (c >=
'A' && c <=
'F')
1806 return (
unsigned char)((
int)(c -
'A') + 10);
1807 if (c >=
'a' && c <=
'f')
1808 return (
unsigned char)((
int)(c -
'a') + 10);
1815 const char * s = _s;
1822 if (ns == 0) ns = strlen(s);
1826 if (ns > 0 && !(ns & 1)) {
1829 for (i = 0; i <
ns; i++, t++, s += 2) {
1830 if (!(isxdigit(s[0]) && isxdigit(s[1])))
1850 data = (
void *) memcpy(
xmalloc(ns), _s,
ns);
1861 const uint32_t * a = _a;
1862 const uint32_t *
b = _b;
1863 return ((*a < *b) ? -1 :
1864 ((*a > *b) ? 1 : 0));
1870 const uint64_t * a = _a;
1871 const uint64_t *
b = _b;
1872 return ((*a < *b) ? -1 :
1873 ((*a > *b) ? 1 : 0));
1877 db3Acallback(
DB * db,
const DBT *
key,
const DBT * data,
DBT * _r)
1893 int rc = DB_DONOTINDEX;
1898 memcpy(&hdrNum, key->
data, key->
size);
1906 rpmdb = dbi->dbi_rpmdb;
1910 if (hdrNum > rpmdb->db_maxkey)
1919 _(
"db3: header #%u cannot be loaded -- skipping.\n"),
1925 memset(_r, 0,
sizeof(*_r));
1959 { uint8_t * _u = (uint8_t *) he->
p.
ui8p;
1961 for (i = 0; i < he->
c; i++)
1967 { uint16_t * _u = (uint16_t *) he->
p.
ui16p;
1969 for (i = 0; i < he->
c; i++)
1976 { uint32_t * _u = (uint32_t *) he->
p.
ui32p;
1977 size_t _ulen =
sizeof(*_u);
2000 for (i = 0; i < he->
c; i++, _u++) {
2002 if (i > 0 && _u[-1] == _u[0])
2012 { uint64_t * _u = (uint64_t *) he->
p.
ui64p;
2013 size_t _ulen =
sizeof(*_u);
2027 for (i = 0; i < he->
c; i++, _u++) {
2029 if (i > 0 && _u[-1] == _u[0])
2039 s = (
char *) he->
p.
ptr; ns = he->
c;
2046 s = he->
p.
str; ns = strlen(s);
2053 s = he->
p.
argv[0]; ns = strlen(s);
2057 static double e = 1.0e-5;
2058 static size_t nmin = 16;
2059 size_t n = 2 * (he->
c > nmin ? he->
c : nmin);
2063 rpmbfParams(n, e, &m, &k);
2064 bf = rpmbfNew(m, k, 0);
2069 for (i = 0; i < he->
c; i++) {
2070 s = he->
p.
argv[
i]; ns = strlen(s);
2073 if (s[0] ==
'-' && s[1] ==
' ') {
2079 if (FMhe->
p.
ui16p && !S_ISREG((mode_t)FMhe->
p.
ui16p[i])) {
2092 if (rpmbfChk(bf, s, ns) > 0)
2094 xx = rpmbfAdd(bf, s, ns);
2110 memset(_r, 0,
sizeof(*_r));
2114 if (!dbi->dbi_no_dbsync && rc != DB_DONOTINDEX)
2115 xx = dbiSync(dbi, 0);
2123 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)));
2132 DB * db = (
DB *) dbi->dbi_db;
2134 DB_TXN * _txnid = dbiTxnid(dbi);
2136 db_seq_t _rangemin = -922337203685477600LL;
2137 db_seq_t _rangemax = 922337203685477600LL;
2139 int32_t _cachesize = 0;
2140 uint32_t _flags = DB_SEQ_INC;
2145 if (seqp) *seqp =
NULL;
2148 rc = db_sequence_create(&seq, db, 0);
2154 if (dbi->dbi_seq_cachesize) {
2155 _cachesize = dbi->dbi_seq_cachesize;
2156 rc = seq->set_cachesize(seq, _cachesize);
2161 if (dbi->dbi_seq_initial)
2162 _value = dbi->dbi_seq_initial;
2163 if (_value <= 0) _value = 1;
2164 rc = seq->initial_value(seq, _value);
2168 if (dbi->dbi_seq_min)
2169 _rangemin = dbi->dbi_seq_min;
2170 if (dbi->dbi_seq_max)
2171 _rangemax = dbi->dbi_seq_max;
2172 rc = seq->set_range(seq, _rangemin, _rangemax);
2176 if (dbi->dbi_seq_flags)
2177 _flags = dbi->dbi_seq_flags;
2178 rc = seq->set_flags(seq, _flags);
2182 k.data = (
void *)keyp;
2183 k.size = (u_int32_t) (keylen > 0 ? keylen : strlen(keyp));
2184 rc = seq->open(seq, _txnid, &k, _oflags);
2189 if (rc == 0 && seqp !=
NULL)
2192 int xx = seq->close(seq, 0);
2196 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)));
2214 extern struct _dbiVec db3vec;
2216 const char * urlfn =
NULL;
2219 const char * dbhome;
2220 const char * dbfile;
2221 const char * dbsubfile;
2241 if ((dbi = db3New(rpmdb, rpmtag)) ==
NULL)
2248 dbi->dbi_txnid =
NULL;
2254 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
2255 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
2257 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
2267 if (dbi->dbi_temporary) {
2272 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
2273 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
2275 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
2280 oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
2282 if (dbi->dbi_primary) oflags &= ~DB_TRUNCATE;
2285 if ( dbi->dbi_mode & O_EXCL) oflags |=
DB_EXCL;
2291 if (dbi->dbi_temporary) {
2294 oflags &= ~DB_RDONLY;
2295 dbi->dbi_oflags &= ~DB_RDONLY;
2297 if (!(dbi->dbi_mode & (O_RDWR|O_WRONLY))) oflags |= DB_RDONLY;
2298 if (dbi->dbi_mode & O_CREAT) {
2303 if (dbi->dbi_primary && (dbi->dbi_mode & O_TRUNC))
2304 oflags |= DB_TRUNCATE;
2315 if (dbi->dbi_use_dbenv) {
2317 if (access(dbhome,
W_OK) == -1) {
2325 dbi->dbi_eflags &= ~DB_JOINENV;
2327 dbi->dbi_eflags |= DB_JOINENV;
2333 dbi->dbi_use_dbenv = 0;
2337 if (dbi->dbi_temporary) {
2340 oflags &= ~DB_RDONLY;
2341 dbi->dbi_oflags &= ~DB_RDONLY;
2343 oflags |= DB_RDONLY;
2345 dbi->dbi_oflags |= DB_RDONLY;
2353 #if defined(RPM_VENDOR_OPENPKG)
2358 if (stat(dbf, &sb) == 0)
2359 size = (long)sb.st_size;
2360 if (access(dbf,
F_OK) == -1 || size == 0)
2362 if (access(dbf,
F_OK) == -1)
2367 dbi->dbi_eflags &= ~DB_JOINENV;
2371 dbi->dbi_eflags &= ~DB_JOINENV;
2373 dbi->dbi_eflags |= DB_JOINENV;
2391 if ((oflags &
DB_CREATE) && (oflags & DB_RDONLY)) {
2393 const char * dbfn = (dbfile ? dbfile : dbiBN);
2398 if (access(dbf,
F_OK) == -1) {
2400 oflags &= ~DB_RDONLY;
2403 oflags &= ~DB_CREATE;
2407 if (!(oflags & DB_RDONLY) && access(dbf,
W_OK) == 0) {
2408 dbi->dbi_oflags &= ~DB_RDONLY;
2410 dbi->dbi_oflags |= DB_RDONLY;
2418 if (oflags & (DB_CREATE|DB_TRUNCATE))
2419 dbi_type = (
DBTYPE) dbi->dbi_type;
2421 if (dbi->dbi_use_dbenv) {
2423 if (rpmdb->db_dbenv ==
NULL) {
2424 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2428 case DB_RUNRECOVERY:
2433 dbi->dbi_eflags |= DB_RECOVER;
2434 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2435 dbi->dbi_eflags &= ~DB_RECOVER;
2442 rpmdb->db_dbenv =
dbenv;
2443 rpmdb->db_opens = 1;
2446 #if defined(DB_VERSION_MISMATCH)
2447 case DB_VERSION_MISMATCH:
2452 {
char * filename = (
char *)
alloca(BUFSIZ);
2456 for (i = 0; i < 16; i++) {
2457 sprintf(filename,
"%s/__db.%03d", dbhome, i);
2459 if (
Stat(filename, &st)
2466 dbi->dbi_eflags &= ~DB_JOINENV;
2467 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2475 rpmdb->db_dbenv =
dbenv;
2476 rpmdb->db_opens = 1;
2480 assert(rpmdb && rpmdb->db_dbenv);
2481 dbenv = (
DB_ENV *) rpmdb->db_dbenv;
2488 dbhome, (dbfile ? dbfile : dbiBN),
2489 prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
2492 static int _lockdbfd = 0;
2495 rc = db_create(&db, dbenv, dbi->dbi_cflags);
2498 if (rc == 0 && db !=
NULL) {
2502 rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free)
2504 rc = db->set_alloc(db,
2505 rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free);
2514 if (rc == 0 && dbi->dbi_lorder) {
2515 rc = db->set_lorder(db, dbi->dbi_lorder);
2518 if (rc == 0 && dbi->dbi_pagesize) {
2519 rc = db->set_pagesize(db, dbi->dbi_pagesize);
2523 if (rc == 0 && oflags & DB_CREATE) {
2524 switch(dbi->dbi_type) {
2527 if (dbi->dbi_h_ffactor) {
2528 rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor);
2532 if (dbi->dbi_h_nelem) {
2533 rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
2537 if (dbi->dbi_h_flags) {
2538 rc = db->set_flags(db, dbi->dbi_h_flags);
2542 if (dbi->dbi_h_hash_fcn) {
2543 rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
2547 if (dbi->dbi_h_dup_compare_fcn) {
2548 rc = db->set_h_compare(db, dbi->dbi_h_dup_compare_fcn);
2555 if (dbi->dbi_bt_flags) {
2556 rc = db->set_flags(db, dbi->dbi_bt_flags);
2560 if (dbi->dbi_bt_minkey) {
2561 rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
2565 if (dbi->dbi_bt_compare_fcn) {
2566 rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
2570 if (dbi->dbi_bt_dup_compare_fcn) {
2571 rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
2575 if (dbi->dbi_bt_prefix_fcn) {
2576 rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
2583 if (dbi->dbi_re_delim) {
2584 rc = db->set_re_delim(db, dbi->dbi_re_delim);
2588 if (dbi->dbi_re_len) {
2589 rc = db->set_re_len(db, dbi->dbi_re_len);
2593 if (dbi->dbi_re_pad) {
2594 rc = db->set_re_pad(db, dbi->dbi_re_pad);
2598 if (dbi->dbi_re_source) {
2599 rc = db->set_re_source(db, dbi->dbi_re_source);
2605 if (dbi->dbi_q_extentsize) {
2606 rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize);
2611 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2) || (DB_VERSION_MAJOR >= 6)
2613 if (dbi->dbi_heapsize) {
2614 static uint32_t _gbytes = 0;
2615 uint32_t _bytes = dbi->dbi_heapsize;
2616 static uint32_t _flags = 0;
2617 assert(dbi->dbi_heapsize >= (3 * dbi->dbi_pagesize));
2618 rc = db->set_heapsize(db, _gbytes, _bytes, _flags);
2622 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 3) || (DB_VERSION_MAJOR >= 6)
2623 if (dbi->dbi_heap_regionsize) {
2624 uint32_t _npages = dbi->dbi_heap_regionsize;
2626 rc = db->set_heap_regionsize(db, _npages);
2637 const char * dbfullpath;
2638 const char * dbpath;
2642 nb = strlen(dbhome);
2643 if (dbfile) nb += 1 + strlen(dbfile);
2644 dbfullpath = t = (
char *)
alloca(nb + 1);
2650 dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary)
2651 ? dbfullpath : dbfile;
2655 dbpath = (!dbi->dbi_use_dbenv)
2656 ? dbfullpath : dbfile;
2658 dbpath = (!dbi->dbi_temporary)
2659 ? dbfullpath : dbfile;
2663 rc = (db->open)(db, _txnid, dbpath, dbsubfile,
2664 dbi_type, oflags, dbi->dbi_perms);
2667 xx = db->get_type(db, &dbi_type);
2669 dbi->dbi_type = dbi_type;
2674 _printit = (rc > 0 ? 0 :
_debug);
2675 xx =
cvtdberr(dbi,
"db->open", rc, _printit);
2695 if (rc == 0 && dbi->dbi_lockdbfd &&
2696 #
if defined(DB_RPCCLIENT)
2697 !((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) &&
2699 (!dbi->dbi_use_dbenv || _lockdbfd++ == 0))
2703 if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
2707 memset(&l, 0,
sizeof(l));
2711 l.l_type = (dbi->dbi_mode & (O_RDWR|O_WRONLY))
2712 ? F_WRLCK : F_RDLCK;
2715 rc = fcntl(fdno, F_SETLK, (
void *) &l);
2718 rc = ((dbi->dbi_use_dbenv &&
2719 (dbi->dbi_eflags & DB_INIT_CDB) &&
2723 _(
"cannot get %s lock on %s/%s\n"),
2724 ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
2725 ?
_(
"exclusive") :
_(
"shared")),
2726 dbhome, (dbfile ? dbfile :
""));
2727 }
else if (dbfile) {
2729 D_(
"locked db index %s/%s\n"),
2737 dbi->dbi_db = (
void *) db;
2741 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%p) dbi %p rc %d %s\n", __FUNCTION__, rpmdb,
tagName(rpmtag), dbip, dbi, rc,
_OFLAGS(dbi->dbi_oflags)));
2743 if (rc == 0 && dbi->dbi_db !=
NULL && dbip !=
NULL) {
2746 if (dbi->dbi_primary) {
2749 int (*_callback)(
DB *,
const DBT *,
const DBT *, DBT *)
2752 int _flags = DB_IMMUTABLE_KEY;
2757 Pdbi =
dbiOpen(rpmdb, Ptag, 0);
2759 if (oflags & (DB_CREATE|DB_TRUNCATE)) _flags |=
DB_CREATE;
2762 if (dbi->dbi_seq_id && !(oflags & DB_RDONLY)) {
2764 uint32_t
u = (uint32_t) strtoll(dbi->dbi_seq_id, &end, 0);
2767 if (oflags & (DB_CREATE|DB_TRUNCATE))
2768 dbi->dbi_seq_initial = rpmdb->db_maxkey + 1;
2777 if (dbip) *dbip =
dbi;
2783 if (dbip) *dbip =
dbi;
2786 urlfn =
_free(urlfn);
static int uint32Cmp(const void *_a, const void *_b)
qsort(mc->macroTable, mc->firstFree, sizeof(mc->macroTable[0]), compareMacroName)
static const char * fmtKDR(const DBT *K, const DBT *P, const DBT *D, const DBT *R)
static int db3associate(dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, const DBT *, DBT *), unsigned int flags)
static uint64_t _ntoh_ul(uint64_t ul)
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
rpmlog(RPMLOG_ERR,"%s\n", buf)
static int db3cpget(dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *pkey, DBT *data, unsigned int flags)
int pgpExtractPubkeyFingerprint(const char *b64pkt, rpmuint8_t *keyid)
Extract OpenPGP public key fingerprint from base64 encoded packet.
#define cvtdberr(_dbi, _msg, _error, _printit)
OpenPGP constants and structures from RFC-2440.
static int loadDBT(DBT *_r, rpmTag tag, const void *_s, size_t ns)
static int db3join(dbiIndex dbi, DBC **curslist, DBC **dbcp, unsigned int flags)
static const char * fmtDBCoflags(uint32_t flags)
char * xstrdup(const char *str)
char * rpmCleanPath(char *path)
Canonicalize file path.
static const char * fmtDBeflags(uint32_t flags)
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
static uint32_t _hton_ui(uint32_t ui)
static char *size_t nb
fgets(3) analogue that reads \ continuations.
static uint16_t _ntoh_us(uint16_t us)
static int db3ccount(dbiIndex dbi, DBC *dbcursor, unsigned int *countp, unsigned int flags)
int rpmioMkpath(const char *path, mode_t mode, uid_t uid, gid_t gid)
Insure that directories in path exist, creating as needed.
static unsigned char nibble(char c)
Convert hex to binary nibble.
static const char * fmtDBaflags(uint32_t flags)
int Stat(const char *path, struct stat *st)
stat(2) clone.
int Open(const char *path, int flags, mode_t mode)
open(2) clone.
static void rpmdbe_event_notify(DB_ENV *dbenv, u_int32_t event, void *event_info)
static int db3_fsync_disable(int fd)
static size_t ncores(void)
static const char * mapTagName(rpmdb rpmdb, dbiIndex dbi)
Return (possibly renamed) tagName.
#define _DBCFLAGS(_flags)
static int Xcvtdberr(dbiIndex dbi, const char *msg, int error, int printit, const char *func, const char *fn, unsigned ln)
static int db3exists(dbiIndex dbi, DBT *key, unsigned int flags)
static struct _events_s _events[]
static int db3stat(dbiIndex dbi, unsigned int flags)
static const char * fmtDBoflags(uint32_t flags)
static int db3cget(dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
rpmTag tagValue(const char *tagstr)
Return tag value from name.
static int db3cclose(dbiIndex dbi, DBC *dbcursor, unsigned int flags)
static int db3associate_foreign(dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, DBT *, const DBT *, int *), unsigned int flags)
sprintf(t," (%u)",(unsigned) dig->nbytes)
#define DBIDEBUG(_dbi, _list)
static uint64_t physmem(void)
static const char * fmtBits(uint32_t flags, KEY tbl[], size_t ntbl, char *t)
Yet Another syslog(3) API clone.
memset(_r, 0, sizeof(*_r))
static int xisprint(int c)
void * xcalloc(size_t nmemb, size_t size)
assert(key->size==sizeof(hdrNum))
static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex *dbip)
Return handle for an index database.
static const char * tblName(uint32_t v, KEY *tbl, size_t ntbl)
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
static int db3byteswapped(dbiIndex dbi)
static const char * fmtDBafflags(uint32_t flags)
static int db_fini(dbiIndex dbi, const char *dbhome, const char *dbfile, const char *dbsubfile)
static int uint64Cmp(const void *_a, const void *_b)
const char * tagName(rpmTag tag)
Return tag name from value.
const char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
struct tagStore_s * tagStore_t
static union _dbswap _endian
static uint64_t _hton_ul(uint64_t ul)
static int db3close(dbiIndex dbi, unsigned int flags)
Encapsulation of a "value".
struct __db_sequence DB_SEQUENCE
static const char *char c
Return text between pl and matching pr characters.
static uint16_t _hton_us(uint16_t us)
#define _DBCOFLAGS(_coflags)
static int db3cput(dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
static int snprintf(char *buf, int nb, const char *fmt,...)
dbiIndex dbiOpen(rpmdb db, rpmTag tag, unsigned int flags)
static int db3cdel(dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
char * stpcpy(char *dest, const char *src)
static const char * fmtDBCflags(uint32_t flags)
#define _AFFLAGS(_afflags)
static int db_init(dbiIndex dbi, const char *dbhome, const char *dbfile, const char *dbsubfile, DB_ENV **dbenvp)
static int seqid_init(dbiIndex dbi, const char *keyp, size_t keylen, DB_SEQUENCE **seqp)
static int db3seqno(dbiIndex dbi, int64_t *seqnop, unsigned int flags)
char * buf
Parse (and execute) macro undefinition.
int
Save source and expand field into target.
#define _KEYDATA(_K, _P, _D, _R)
Access RPM indices using Berkeley DB interface(s).
static int db3copen(dbiIndex dbi, DB_TXN *txnid, DBC **dbcp, unsigned int dbiflags)
static uint32_t _ntoh_ui(uint32_t ui)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
static int db3cdup(dbiIndex dbi, DBC *dbcursor, DBC **dbcp, unsigned int flags)
#define RPMDBI_PACKAGES
Pseudo-tags used by the rpmdb and rpmgi iterator API's.
static char * fmtDBT(const DBT *K, char *te)
struct _dbiIndex * dbiIndex
static int db3sync(dbiIndex dbi, unsigned int flags)
int Unlink(const char *path)
unlink(2) clone.