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";
181 typedef struct key_s {
192 const char * n = NULL;
196 for (i = 0; i < ntbl; i++) {
203 (void)
snprintf(buf,
sizeof(buf),
"0x%x", (unsigned)v);
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, }
244 #if defined(DB_INIT_MUTEX)
255 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR >= 5)
269 static char buf[BUFSIZ];
271 te =
stpcpy(te,
"\n\tflags: ");
272 (void)
fmtBits(flags, DBeflags, nDBeflags, te);
275 #define _EFLAGS(_eflags) fmtDBeflags(_eflags)
295 static char buf[BUFSIZ];
297 te =
stpcpy(te,
"\n\tflags: ");
298 (void)
fmtBits(flags, DBoflags, nDBoflags, te);
301 #define _OFLAGS(_oflags) fmtDBoflags(_oflags)
314 static char buf[BUFSIZ];
316 te =
stpcpy(te,
"\n\tflags: ");
317 (void)
fmtBits(flags, DBaflags, nDBaflags, te);
320 #define _AFLAGS(_aflags) fmtDBaflags(_aflags)
334 static char buf[BUFSIZ];
336 te =
stpcpy(te,
"\n\tflags: ");
337 (void)
fmtBits(flags, DBafflags, nDBafflags, te);
340 #define _AFFLAGS(_afflags) fmtDBafflags(_afflags)
345 #if defined(DB_CURSOR_BULK)
359 static char buf[BUFSIZ];
361 (void)
fmtBits(flags, DBCoflags, nDBCoflags, te);
364 #define _DBCOFLAGS(_coflags) fmtDBCoflags(_coflags)
389 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR >= 5)
400 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR >= 5)
420 static char buf[BUFSIZ];
422 uint32_t
op = (flags & DB_OPFLAGS_MASK);
423 flags &= ~DB_OPFLAGS_MASK;
425 te =
stpcpy(te,
"\n\tflags: ");
432 (void)
fmtBits(flags, DBCflags, nDBCflags, te);
435 #define _DBCFLAGS(_flags) fmtDBCflags(_flags)
437 #define _DBT_ENTRY(_v) { DB_DBT_##_v, #_v, }
446 #if defined(DB_DBT_READONLY)
449 #if defined(DB_DBT_ISSET)
452 #if defined(DB_DBT_USERCOPY)
455 #if defined(DB_DBT_USERMEM)
458 #if defined(DB_DBT_BLOB)
461 #if defined(DB_DBT_BLOB_REC)
464 #if defined(DB_DBT_STREAMING)
467 #if defined(DB_DBT_BULK)
470 #if defined(DB_DBT_DUPOK)
482 static size_t keymax = 35;
486 sprintf(te,
"%p[%u]\t", K->
data, (
unsigned)K->
size);
505 for (i = 0; i < _nu; i++)
510 size_t nb = (_nu < keymax ? _nu : keymax);
511 char * ellipsis = (_nu < keymax ?
"" :
"...");
512 sprintf(te,
"\t\"%.*s%s\"", (
int)nb, (
char *)_u, ellipsis);
516 case 4: sprintf(te,
"\t0x%08x", (
unsigned)*(uint32_t *)_u);
break;
529 static char buf[BUFSIZ];
533 te =
stpcpy(te,
"\n\t key: ");
537 te =
stpcpy(te,
"\n\t pkey: ");
541 te =
stpcpy(te,
"\n\t data: ");
545 te =
stpcpy(te,
"\n\t res: ");
552 #define _KEYDATA(_K, _P, _D, _R) fmtKDR(_K, _P, _D, _R)
556 int error,
int printit,
557 const char * func,
const char * fn,
unsigned ln)
566 func, fn, ln, msg, rc, db_strerror(error));
573 #define cvtdberr(_dbi, _msg, _error, _printit) \
574 Xcvtdberr(_dbi, _msg, _error, _printit, __FUNCTION__, __FILE__, __LINE__)
590 while (dbix < rpmdb->db_ndbi) {
591 if (dbi->dbi_rpmtag == dbiTags->tag)
597 return tagName(dbi->dbi_rpmtag);
602 const char * dbsubfile)
607 DB_ENV * dbenv = rpmdb->db_dbenv;
610 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%s,%s,%s)\n", __FUNCTION__, dbi, dbhome, dbfile, dbsubfile));
615 rc = dbenv->close(dbenv, 0);
617 rpmdb->db_dbenv = NULL;
623 if (rpmdb->db_remove_env) {
627 xx = db_env_create(&dbenv, 0);
629 if (!xx && dbenv != NULL) {
631 xx = dbenv->remove(dbenv, dbhome, DB_FORCE);
649 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
658 static int db3is_alive(
DB_ENV *dbenv, pid_t pid,
666 case DB_MUTEX_PROCESS_ONLY:
669 is_alive = (!(kill(pid, 0) < 0 &&
errno == ESRCH));
679 #if defined(HAVE_PHYSMEM_SYSCTL) || defined(HAVE_NCPU_SYSCTL)
680 #include <sys/sysctl.h>
686 static uint64_t _physmem = 0;
687 static int oneshot = 0;
690 #if defined(HAVE_PHYSMEM_SYSCONF)
691 const long _pagesize = sysconf(_SC_PAGESIZE);
692 const long _pages = sysconf(_SC_PHYS_PAGES);
693 if (_pagesize != -1 || _pages != -1)
694 _physmem = (uint64_t)(_pagesize) * (uint64_t)(_pages);
695 #elif defined(HAVE_PHYSMEM_SYSCTL)
696 int name[2] = { CTL_HW, HW_PHYSMEM };
698 size_t mem_ptr_size =
sizeof(mem);
699 if (!sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0)) {
700 if (mem_ptr_size !=
sizeof(mem)) {
701 if (mem_ptr_size ==
sizeof(
unsigned int))
702 _physmem = *(
unsigned int *)(&mem);
716 static size_t _ncores = 1;
717 static int oneshot = 0;
720 #if defined(HAVE_NCPU_SYSCONF)
721 const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
722 #elif defined(HAVE_NCPU_SYSCTL)
723 int name[2] = { CTL_HW, HW_NCPU };
725 size_t cpus_size =
sizeof(cpus);
726 if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0)
727 || cpus_size !=
sizeof(cpus))
730 if (cpus > (
int)_ncores)
731 _ncores = (
size_t)(cpus);
738 #define _TABLE(_v) { #_v, DB_EVENT_##_v }
743 #if (DB_VERSION_MAJOR == 6 && DB_VERSION_MINOR >= 1)
747 _TABLE(REP_AUTOTAKEOVER_FAILED),
749 _TABLE(REP_CONNECT_BROKEN),
751 _TABLE(REP_CONNECT_TRY_FAILED),
754 _TABLE(REP_ELECTION_FAILED),
758 _TABLE(REP_LOCAL_SITE_REMOVED),
760 _TABLE(REP_MASTER_FAILURE),
766 _TABLE(REP_WOULD_ROLLBACK),
776 #elif (DB_VERSION_MAJOR == 6 && DB_VERSION_MINOR >= 0)
780 _TABLE(REP_AUTOTAKEOVER_FAILED),
782 _TABLE(REP_CONNECT_BROKEN),
784 _TABLE(REP_CONNECT_TRY_FAILED),
787 _TABLE(REP_ELECTION_FAILED),
790 _TABLE(REP_LOCAL_SITE_REMOVED),
792 _TABLE(REP_MASTER_FAILURE),
798 _TABLE(REP_WOULD_ROLLBACK),
809 #elif (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
814 _TABLE(REP_CONNECT_BROKEN),
816 _TABLE(REP_CONNECT_TRY_FAILED),
819 _TABLE(REP_ELECTION_FAILED),
822 _TABLE(REP_LOCAL_SITE_REMOVED),
824 _TABLE(REP_MASTER_FAILURE),
830 _TABLE(REP_WOULD_ROLLBACK),
842 #elif (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR < 2) || (DB_VERSION_MAJOR >= 6)
850 _TABLE(REP_ELECTION_FAILED),
853 _TABLE(REP_MASTER_FAILURE),
879 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8)
922 fprintf(stderr,
"==> %s(%p, %s(%u), %p) app_private %p\n", __FUNCTION__, dbenv,
_events[event & 0x1f].n, event, event_info, o);
933 fprintf(stderr,
"\rrecovery %d%% complete", percent);
934 (void)fflush(stderr);
944 const char * dbsubfile,
950 static int oneshot = 0;
952 size_t _ncores =
ncores();
961 (
unsigned)_ncores, (
unsigned)(_physmem/(1024 * 1024)));
962 xx = db_env_set_func_open((
int (*)(
const char *,
int, ...))
Open);
972 if (rpmdb->db_errfile == NULL)
973 rpmdb->db_errfile = stderr;
976 eflags = (dbi->dbi_oeflags | dbi->dbi_eflags);
979 if (eflags & DB_JOINENV) eflags &= DB_JOINENV;
981 if (!(eflags &
DB_INIT_TXN)) eflags &= ~DB_RECOVER;
985 dbhome, dbfile, prDbiOpenFlags(eflags, 1));
988 #if defined(DB_RPCCLIENT)
989 if (dbi->dbi_host == NULL)
990 dbi->dbi_ecflags &= ~DB_RPCCLIENT;
994 rc = db_env_create(&dbenv, dbi->dbi_ecflags);
996 if (dbenv == NULL || rc)
1001 dbenv->set_errcall(dbenv, (
void *)rpmdb->db_errcall);
1003 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
1004 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
1027 #if defined(DB_RPCCLIENT)
1028 if ((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) {
1032 if ((home = strrchr(dbhome,
'/')) != NULL)
1035 while (retry++ < 5) {
1037 xx = dbenv->set_rpc_server(dbenv, NULL, dbi->dbi_host,
1038 dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0);
1048 {
size_t _lo = 16 * 1024 * 1024;
1049 size_t _hi = 512 * 1024 * 1024;
1050 size_t _mp_mmapsize = _physmem;
1051 if (_mp_mmapsize < _lo) _mp_mmapsize = _lo;
1052 if (_mp_mmapsize > _hi) _mp_mmapsize = _hi;
1053 xx = dbenv->set_mp_mmapsize(dbenv, _mp_mmapsize);
1057 if (dbi->dbi_tmpdir) {
1059 const char * tmpdir;
1061 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1062 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1065 tmpdir =
rpmGenPath(root, dbi->dbi_tmpdir, NULL);
1067 xx = dbenv->set_tmp_dir(dbenv, tmpdir);
1069 tmpdir =
_free(tmpdir);
1074 #define _RPMDB_NLOCKS 16384
1080 xx = dbenv->set_lk_max_lockers(dbenv, _lk_max_lockers);
1082 xx = dbenv->set_lk_max_locks(dbenv, _lk_max_locks);
1084 xx = dbenv->set_lk_max_objects(dbenv, _lk_max_objects);
1088 xx = dbenv->mutex_set_max(dbenv, _max);
1097 logdir =
rpmGetPath(dbhome,
"/",
"log", NULL);
1103 xx = dbenv->set_lg_dir(dbenv, logdir);
1110 uint32_t _lo = 16 * 1024 * 1024;
1111 uint32_t _hi = 512 * 1024 * 1024;
1113 uint32_t _bytes = _physmem;
1115 if (_bytes < _lo) _bytes = _lo;
1116 if (_bytes > _hi) _bytes = _hi;
1117 xx = dbenv->set_cache_max(dbenv, _gb, _hi);
1121 xx = dbenv->set_cachesize(dbenv, _gb, _bytes, _ncache);
1130 if (eflags & DB_INIT_TXN) {
1131 xx = dbenv->set_app_dispatch(dbenv, logio_dispatch);
1137 if (dbi->dbi_no_fsync) {
1143 if ((eflags & DB_SYSTEM_MEM) && dbi->dbi_shmkey == 0) {
1144 #if defined(HAVE_FTOK)
1145 dbi->dbi_shmkey = ftok(dbhome, 0);
1147 dbi->dbi_shmkey = 0x44631380;
1150 if (dbi->dbi_shmkey) {
1151 xx = dbenv->set_shm_key(dbenv, dbi->dbi_shmkey);
1155 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
1158 dbenv->set_msgfile(dbenv, rpmdb->db_errfile);
1160 if (dbi->dbi_thread_count >= 8) {
1161 xx = dbenv->set_thread_count(dbenv, dbi->dbi_thread_count);
1167 if (eflags & DB_RECOVER) {
1169 xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
1173 rc = (dbenv->open)(dbenv, dbhome, eflags, dbi->dbi_perms);
1175 #if defined(DB_VERSION_MISMATCH)
1176 if (rc == DB_VERSION_MISMATCH) xx = 0;
1178 if (rc == EINVAL) xx = 0;
1179 rc =
cvtdberr(dbi,
"dbenv->open", rc, xx);
1183 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5) || (DB_VERSION_MAJOR >= 5)
1184 if (dbi->dbi_thread_count >= 8) {
1186 xx = dbenv->set_isalive(dbenv, db3is_alive);
1189 xx = dbenv->failchk(dbenv, 0);
1191 if (xx == DB_RUNRECOVERY) {
1200 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)));
1206 xx = dbenv->close(dbenv, 0);
1215 static int db3remove(
dbiIndex dbi,
const char * dbfile,
1216 const char * dbsubfile,
1221 DB *
db = (
DB *) dbi->dbi_db;
1225 rc = db->remove(db, dbfile, dbsubfile, flags);
1228 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, dbsubfile, flags, rc));
1235 static int db3rename(
dbiIndex dbi,
const char * dbfile,
1236 const char * dbsubfile,
1237 const char * newname,
1242 DB * db = (
DB *) dbi->dbi_db;
1246 rc = db->rename(db, dbfile, dbsubfile, newname, flags);
1249 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%s,%s,0x%x) rc %d %s\n", __FUNCTION__, dbi, dbfile, dbsubfile, newname, flags, rc,
_DBCFLAGS(flags)));
1256 static int db3truncate(
dbiIndex dbi,
unsigned int * countp,
unsigned int flags)
1260 DB * db = (
DB *) dbi->dbi_db;
1261 DB_TXN * _txnid = dbiTxnid(dbi);
1265 rc = db->truncate(db, _txnid, countp, flags);
1268 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, countp, flags, rc));
1275 static int db3upgrade(
dbiIndex dbi,
const char * dbfile,
1280 DB * db = (
DB *) dbi->dbi_db;
1284 rc = db->upgrade(db, dbfile, flags);
1287 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,0x%x) rc %d\n", __FUNCTION__, dbi, dbfile, flags, rc));
1298 DB * db = (
DB *) dbi->dbi_db;
1303 rc = db->sync(db, flags);
1305 rc =
cvtdberr(dbi,
"db->sync", rc, _printit);
1307 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1317 DB * db = (
DB *) dbi->dbi_db;
1318 DB_TXN * _txnid = dbiTxnid(dbi);
1323 rc = db->exists(db, _txnid, key, flags);
1326 rc =
cvtdberr(dbi,
"db->exists", rc, _printit);
1328 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d %s\n", __FUNCTION__, dbi, key, flags, rc,
_KEYDATA(key, NULL, NULL, NULL)));
1339 DB * db = (
DB *) dbi->dbi_db;
1340 DB_TXN * _txnid = dbiTxnid(dbi);
1347 assert(seq != NULL);
1349 if (seqnop && *seqnop)
1352 rc = seq->get(seq, _txnid, _delta, &seqno, 0);
1360 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) seqno %lld rc %d\n", __FUNCTION__, dbi, seqnop, flags, (
long long)seqno, rc));
1373 if (dbcp) *dbcp = NULL;
1374 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1375 rc = dbcursor->dup(dbcursor, dbcp, flags);
1378 rc = dbcursor->c_dup(dbcursor, dbcp, flags);
1382 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, dbcp, flags, rc));
1396 if (dbcursor != NULL) {
1397 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1398 rc = dbcursor->close(dbcursor);
1401 rc = dbcursor->c_close(dbcursor);
1406 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,0x%x) rc %d\n", __FUNCTION__, dbi, dbcursor, flags, rc));
1413 DBC ** dbcp,
unsigned int dbiflags)
1417 DB * db = (
DB *) dbi->dbi_db;
1418 DBC * dbcursor = NULL;
1425 (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
1431 rc = db->cursor(db, txnid, &dbcursor, flags);
1439 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) dbc %p %s rc %d\n", __FUNCTION__, dbi, txnid, dbcp, dbiflags, dbcursor,
_DBCOFLAGS(flags), rc));
1448 DB * db = (
DB *) dbi->dbi_db;
1449 DB_TXN * _txnid = dbiTxnid(dbi);
1453 if (dbcursor == NULL) {
1455 rc = db->put(db, _txnid, key, data, flags);
1459 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1460 rc = dbcursor->put(dbcursor, key, data, flags);
1463 rc = dbcursor->c_put(dbcursor, key, data, flags);
1468 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)));
1478 DB * db = (
DB *) dbi->dbi_db;
1479 DB_TXN * _txnid = dbiTxnid(dbi);
1484 if (dbcursor == NULL) {
1486 rc = db->get(db, _txnid, key, data, flags);
1489 rc =
cvtdberr(dbi,
"db->get", rc, _printit);
1491 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1493 rc = dbcursor->get(dbcursor, key, data, flags);
1498 rc =
cvtdberr(dbi,
"dbcursor->get", rc, _printit);
1501 rc = dbcursor->c_get(dbcursor, key, data, flags);
1504 rc =
cvtdberr(dbi,
"dbcursor->c_get", rc, _printit);
1508 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)));
1515 DBT *
data,
unsigned int flags)
1519 DB * db = (
DB *) dbi->dbi_db;
1520 DB_TXN * _txnid = dbiTxnid(dbi);
1525 if (dbcursor == NULL) {
1527 rc = db->pget(db, _txnid, key, pkey, data, flags);
1530 rc =
cvtdberr(dbi,
"db->pget", rc, _printit);
1532 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1534 rc = dbcursor->pget(dbcursor, key, pkey, data, flags);
1537 rc =
cvtdberr(dbi,
"dbcursor->pget", rc, _printit);
1540 rc = dbcursor->c_pget(dbcursor, key, pkey, data, flags);
1543 rc =
cvtdberr(dbi,
"dbcursor->c_pget", rc, _printit);
1547 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)));
1558 DB * db = (
DB *) dbi->dbi_db;
1559 DB_TXN * _txnid = dbiTxnid(dbi);
1563 if (dbcursor == NULL) {
1564 rc = db->del(db, _txnid, key, flags);
1572 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1573 rc = dbcursor->del(dbcursor, flags);
1576 rc = dbcursor->c_del(dbcursor, flags);
1582 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)));
1588 unsigned int * countp,
1593 db_recno_t count = 0;
1597 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6) || (DB_VERSION_MAJOR >= 5)
1598 rc = dbcursor->count(dbcursor, &count, flags);
1601 rc = dbcursor->c_count(dbcursor, &count, flags);
1604 if (countp) *countp = (!rc ? count : 0);
1606 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%p,%p,0x%x) count %d\n", __FUNCTION__, dbi, dbcursor, countp, flags, count));
1613 DB * db = (
DB *) dbi->dbi_db;
1618 rc = db->get_byteswapped(db, &isswapped);
1630 DB * db = (
DB *) dbi->dbi_db;
1632 DB_TXN * _txnid = dbiTxnid(dbi);
1637 #if defined(DB_FAST_STAT)
1639 flags = DB_FAST_STAT;
1643 dbi->dbi_stats =
_free(dbi->dbi_stats);
1645 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3) || (DB_VERSION_MAJOR >= 5)
1646 rc = db->stat(db, _txnid, &dbi->dbi_stats, flags);
1648 rc = db->stat(db, &dbi->dbi_stats, flags);
1652 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1659 int (*callback)(
DB *,
const DBT *,
const DBT *,
DBT *),
1664 DB * db = (
DB *) dbi->dbi_db;
1665 DB * secondary = (
DB *) dbisecondary->dbi_db;
1666 DB_TXN * _txnid = dbiTxnid(dbi);
1672 rc = db->associate(db, _txnid, secondary, callback, flags);
1676 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1678 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));
1688 int (*callback)(
DB *,
const DBT *,
DBT *,
const DBT *,
int *),
1695 #if !defined(__LCLINT__)
1697 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || (DB_VERSION_MAJOR >= 5)
1698 DB * db = (
DB *) dbi->dbi_db;
1699 DB * secondary = (
DB *) dbisecondary->dbi_db;
1701 rc = db->associate_foreign(db, secondary, callback, flags);
1707 if (dbi->dbi_debug || dbisecondary->dbi_debug) {
1709 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));
1723 DB * db = (
DB *) dbi->dbi_db;
1726 DBIDEBUG(dbi, (stderr,
"--> %s(%p,%p,%p,0x%x)\n", __FUNCTION__, dbi, curslist, dbcp, flags));
1729 rc = db->join(db, curslist, dbcp, flags);
1743 const char * urlfn = NULL;
1746 const char * dbhome;
1747 const char * dbfile;
1748 const char * dbsubfile;
1749 DB * db = (
DB *) dbi->dbi_db;
1760 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1761 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1763 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
1772 (void)
urlPath(urlfn, &dbhome);
1773 if (dbi->dbi_temporary) {
1778 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
1779 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
1781 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
1787 rc = seq->close(seq, 0);
1789 seq = dbi->dbi_seq = NULL;
1792 dbhome, (dbfile ? dbfile : dbiBN));
1796 rc = db->close(db, 0);
1798 _printit = (rc == ENOENT ? 0 :
_debug);
1799 rc =
cvtdberr(dbi,
"db->close", rc, _printit);
1800 db = dbi->dbi_db = NULL;
1803 dbhome, (dbfile ? dbfile : dbiBN));
1808 if (rpmdb->db_dbenv != NULL && dbi->dbi_use_dbenv && !dbi->dbi_temporary) {
1809 if (rpmdb->db_opens == 1) {
1811 xx =
db_fini(dbi, (dbhome ? dbhome :
""), dbfile, dbsubfile);
1813 rpmdb->db_dbenv = NULL;
1818 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,0x%x) rc %d\n", __FUNCTION__, dbi, flags, rc));
1822 urlfn =
_free(urlfn);
1838 if (c >=
'0' && c <=
'9')
1839 return (
unsigned char)(c -
'0');
1840 if (c >=
'A' && c <=
'F')
1841 return (
unsigned char)((int)(c -
'A') + 10);
1842 if (c >=
'a' && c <=
'f')
1843 return (
unsigned char)((int)(c -
'a') + 10);
1850 const char * s = _s;
1857 if (ns == 0) ns = strlen(s);
1861 if (ns > 0 && !(ns & 1)) {
1864 for (i = 0; i <
ns; i++, t++, s += 2) {
1865 if (!(isxdigit(s[0]) && isxdigit(s[1])))
1885 data = (
void *) memcpy(
xmalloc(ns), _s,
ns);
1890 return (_r->
size = size);
1896 const uint32_t * a = _a;
1897 const uint32_t *
b = _b;
1898 return ((*a < *b) ? -1 :
1899 ((*a > *b) ? 1 : 0));
1905 const uint64_t * a = _a;
1906 const uint64_t *
b = _b;
1907 return ((*a < *b) ? -1 :
1908 ((*a > *b) ? 1 : 0));
1919 HE_t FMhe = (
HE_t) memset(
alloca(
sizeof(*FMhe)), 0,
sizeof(*FMhe));
1926 const char * s = NULL;
1928 int rc = DB_DONOTINDEX;
1932 assert(key->
size ==
sizeof(hdrNum));
1933 memcpy(&hdrNum, key->
data, key->
size);
1941 rpmdb = dbi->dbi_rpmdb;
1945 if (hdrNum > rpmdb->db_maxkey)
1946 rpmdb->db_maxkey = hdrNum;
1954 _(
"db3: header #%u cannot be loaded -- skipping.\n"),
1960 memset(_r, 0,
sizeof(*_r));
1962 he->
tag = dbi->dbi_rpmtag;
1967 assert(he->
p.
ptr != NULL && he->
c > 0);
1994 { uint8_t * _u = (uint8_t *) he->
p.
ui8p;
1996 for (i = 0; i < he->
c; i++)
2002 { uint16_t * _u = (uint16_t *) he->
p.
ui16p;
2004 for (i = 0; i < he->
c; i++)
2011 { uint32_t * _u = (uint32_t *) he->
p.
ui32p;
2012 size_t _ulen =
sizeof(*_u);
2035 for (i = 0; i < he->
c; i++, _u++) {
2037 if (i > 0 && _u[-1] == _u[0])
2047 { uint64_t * _u = (uint64_t *) he->
p.
ui64p;
2048 size_t _ulen =
sizeof(*_u);
2062 for (i = 0; i < he->
c; i++, _u++) {
2064 if (i > 0 && _u[-1] == _u[0])
2074 s = (
char *) he->
p.
ptr; ns = he->
c;
2081 s = he->
p.
str; ns = strlen(s);
2088 s = he->
p.
argv[0]; ns = strlen(s);
2092 static double e = 1.0e-5;
2093 static size_t nmin = 16;
2094 size_t n = 2 * (he->
c > nmin ? he->
c : nmin);
2104 for (i = 0; i < he->
c; i++) {
2105 s = he->
p.
argv[
i]; ns = strlen(s);
2108 if (s[0] ==
'-' && s[1] ==
' ') {
2114 if (FMhe->
p.
ui16p && !S_ISREG((mode_t)FMhe->
p.
ui16p[i])) {
2145 memset(_r, 0,
sizeof(*_r));
2149 if (!dbi->dbi_no_dbsync && rc != DB_DONOTINDEX)
2150 xx = dbiSync(dbi, 0);
2158 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)));
2167 DB * db = (
DB *) dbi->dbi_db;
2169 DB_TXN * _txnid = dbiTxnid(dbi);
2171 db_seq_t _rangemin = -922337203685477600LL;
2172 db_seq_t _rangemax = 922337203685477600LL;
2174 int32_t _cachesize = 0;
2175 uint32_t _flags = DB_SEQ_INC;
2180 if (seqp) *seqp = NULL;
2183 rc = db_sequence_create(&seq, db, 0);
2187 assert(seq != NULL);
2189 if (dbi->dbi_seq_cachesize) {
2190 _cachesize = dbi->dbi_seq_cachesize;
2191 rc = seq->set_cachesize(seq, _cachesize);
2196 if (dbi->dbi_seq_initial)
2197 _value = dbi->dbi_seq_initial;
2198 if (_value <= 0) _value = 1;
2199 rc = seq->initial_value(seq, _value);
2203 if (dbi->dbi_seq_min)
2204 _rangemin = dbi->dbi_seq_min;
2205 if (dbi->dbi_seq_max)
2206 _rangemax = dbi->dbi_seq_max;
2207 rc = seq->set_range(seq, _rangemin, _rangemax);
2211 if (dbi->dbi_seq_flags)
2212 _flags = dbi->dbi_seq_flags;
2213 rc = seq->set_flags(seq, _flags);
2217 k.data = (
void *)keyp;
2218 k.size = (u_int32_t) (keylen > 0 ? keylen : strlen(keyp));
2219 rc = seq->open(seq, _txnid, &k, _oflags);
2224 if (rc == 0 && seqp != NULL)
2227 int xx = seq->close(seq, 0);
2231 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)));
2249 extern struct _dbiVec db3vec;
2251 const char * urlfn = NULL;
2254 const char * dbhome;
2255 const char * dbfile;
2256 const char * dbsubfile;
2276 if ((dbi = db3New(rpmdb, rpmtag)) == NULL)
2283 dbi->dbi_txnid = NULL;
2289 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
2290 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
2292 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
2301 (void)
urlPath(urlfn, &dbhome);
2302 if (dbi->dbi_temporary) {
2307 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
2308 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
2310 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
2315 oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
2317 if (dbi->dbi_primary) oflags &= ~DB_TRUNCATE;
2320 if ( dbi->dbi_mode & O_EXCL) oflags |=
DB_EXCL;
2326 if (dbi->dbi_temporary) {
2329 oflags &= ~DB_RDONLY;
2330 dbi->dbi_oflags &= ~DB_RDONLY;
2332 if (!(dbi->dbi_mode & (O_RDWR|O_WRONLY))) oflags |= DB_RDONLY;
2333 if (dbi->dbi_mode & O_CREAT) {
2338 if (dbi->dbi_primary && (dbi->dbi_mode & O_TRUNC))
2339 oflags |= DB_TRUNCATE;
2345 (void)
rpmioMkpath(dbhome, 0755, getuid(), getgid());
2350 if (dbi->dbi_use_dbenv) {
2352 if (access(dbhome,
W_OK) == -1) {
2360 dbi->dbi_eflags &= ~DB_JOINENV;
2362 dbi->dbi_eflags |= DB_JOINENV;
2368 dbi->dbi_use_dbenv = 0;
2372 if (dbi->dbi_temporary) {
2375 oflags &= ~DB_RDONLY;
2376 dbi->dbi_oflags &= ~DB_RDONLY;
2378 oflags |= DB_RDONLY;
2380 dbi->dbi_oflags |= DB_RDONLY;
2385 const char * dbf =
rpmGetPath(dbhome,
"/__db.001", NULL);
2388 #if defined(RPM_VENDOR_OPENPKG)
2393 if (stat(dbf, &sb) == 0)
2394 size = (long)sb.st_size;
2395 if (access(dbf,
F_OK) == -1 || size == 0)
2397 if (access(dbf,
F_OK) == -1)
2402 dbi->dbi_eflags &= ~DB_JOINENV;
2406 dbi->dbi_eflags &= ~DB_JOINENV;
2408 dbi->dbi_eflags |= DB_JOINENV;
2426 if ((oflags &
DB_CREATE) && (oflags & DB_RDONLY)) {
2428 const char * dbfn = (dbfile ? dbfile : dbiBN);
2430 const char * dbf =
rpmGetPath(dbhome,
"/", dbfn, NULL);
2433 if (access(dbf,
F_OK) == -1) {
2435 oflags &= ~DB_RDONLY;
2438 oflags &= ~DB_CREATE;
2442 if (!(oflags & DB_RDONLY) && access(dbf,
W_OK) == 0) {
2443 dbi->dbi_oflags &= ~DB_RDONLY;
2445 dbi->dbi_oflags |= DB_RDONLY;
2453 if (oflags & (DB_CREATE|DB_TRUNCATE))
2454 dbi_type = (
DBTYPE) dbi->dbi_type;
2456 if (dbi->dbi_use_dbenv) {
2458 if (rpmdb->db_dbenv == NULL) {
2459 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2463 case DB_RUNRECOVERY:
2468 dbi->dbi_eflags |= DB_RECOVER;
2469 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2470 dbi->dbi_eflags &= ~DB_RECOVER;
2477 rpmdb->db_dbenv = dbenv;
2478 rpmdb->db_opens = 1;
2481 #if defined(DB_VERSION_MISMATCH)
2482 case DB_VERSION_MISMATCH:
2487 {
char * filename = (
char *)
alloca(BUFSIZ);
2491 for (i = 0; i < 16; i++) {
2492 sprintf(filename,
"%s/__db.%03d", dbhome, i);
2494 if (
Stat(filename, &st)
2501 dbi->dbi_eflags &= ~DB_JOINENV;
2502 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
2510 rpmdb->db_dbenv = dbenv;
2511 rpmdb->db_opens = 1;
2515 assert(rpmdb && rpmdb->db_dbenv);
2516 dbenv = (
DB_ENV *) rpmdb->db_dbenv;
2523 dbhome, (dbfile ? dbfile : dbiBN),
2524 prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
2527 static int _lockdbfd = 0;
2530 rc = db_create(&db, dbenv, dbi->dbi_cflags);
2533 if (rc == 0 && db != NULL) {
2537 rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free)
2539 rc = db->set_alloc(db,
2540 rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free);
2549 if (rc == 0 && dbi->dbi_lorder) {
2550 rc = db->set_lorder(db, dbi->dbi_lorder);
2553 if (rc == 0 && dbi->dbi_pagesize) {
2554 rc = db->set_pagesize(db, dbi->dbi_pagesize);
2558 if (rc == 0 && oflags & DB_CREATE) {
2559 switch(dbi->dbi_type) {
2562 if (dbi->dbi_h_ffactor) {
2563 rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor);
2567 if (dbi->dbi_h_nelem) {
2568 rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
2572 if (dbi->dbi_h_flags) {
2573 rc = db->set_flags(db, dbi->dbi_h_flags);
2577 if (dbi->dbi_h_hash_fcn) {
2578 rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
2582 #if defined(DB_INIT_MUTEX)
2583 if (dbi->dbi_h_dup_compare_fcn) {
2584 rc = db->set_h_compare(db, dbi->dbi_h_dup_compare_fcn);
2592 if (dbi->dbi_bt_flags) {
2593 rc = db->set_flags(db, dbi->dbi_bt_flags);
2597 if (dbi->dbi_bt_minkey) {
2598 rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
2602 #if defined(DB_INIT_MUTEX)
2603 if (dbi->dbi_bt_compare_fcn) {
2604 rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
2608 if (dbi->dbi_bt_dup_compare_fcn) {
2609 rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
2614 if (dbi->dbi_bt_prefix_fcn) {
2615 rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
2622 if (dbi->dbi_re_delim) {
2623 rc = db->set_re_delim(db, dbi->dbi_re_delim);
2627 if (dbi->dbi_re_len) {
2628 rc = db->set_re_len(db, dbi->dbi_re_len);
2632 if (dbi->dbi_re_pad) {
2633 rc = db->set_re_pad(db, dbi->dbi_re_pad);
2637 if (dbi->dbi_re_source) {
2638 rc = db->set_re_source(db, dbi->dbi_re_source);
2644 if (dbi->dbi_q_extentsize) {
2645 rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize);
2650 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2) || (DB_VERSION_MAJOR >= 6)
2652 if (dbi->dbi_heapsize) {
2653 static uint32_t _gbytes = 0;
2654 uint32_t _bytes = dbi->dbi_heapsize;
2655 static uint32_t _flags = 0;
2656 assert(dbi->dbi_heapsize >= (3 * dbi->dbi_pagesize));
2657 rc = db->set_heapsize(db, _gbytes, _bytes, _flags);
2661 #if (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 3) || (DB_VERSION_MAJOR >= 6)
2662 if (dbi->dbi_heap_regionsize) {
2663 uint32_t _npages = dbi->dbi_heap_regionsize;
2665 rc = db->set_heap_regionsize(db, _npages);
2676 const char * dbfullpath;
2677 const char * dbpath;
2681 nb = strlen(dbhome);
2682 if (dbfile) nb += 1 + strlen(dbfile);
2683 dbfullpath = t = (
char *)
alloca(nb + 1);
2689 dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary)
2690 ? dbfullpath : dbfile;
2694 dbpath = (!dbi->dbi_use_dbenv)
2695 ? dbfullpath : dbfile;
2697 dbpath = (!dbi->dbi_temporary)
2698 ? dbfullpath : dbfile;
2702 rc = (db->open)(db, _txnid, dbpath, dbsubfile,
2703 dbi_type, oflags, dbi->dbi_perms);
2706 xx = db->get_type(db, &dbi_type);
2708 dbi->dbi_type = dbi_type;
2713 _printit = (rc > 0 ? 0 :
_debug);
2714 xx =
cvtdberr(dbi,
"db->open", rc, _printit);
2734 if (rc == 0 && dbi->dbi_lockdbfd &&
2735 #
if defined(DB_RPCCLIENT)
2736 !((dbi->dbi_ecflags & DB_RPCCLIENT) && dbi->dbi_host) &&
2738 (!dbi->dbi_use_dbenv || _lockdbfd++ == 0))
2742 if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
2746 memset(&l, 0,
sizeof(l));
2750 l.l_type = (dbi->dbi_mode & (O_RDWR|O_WRONLY))
2751 ? F_WRLCK : F_RDLCK;
2754 rc = fcntl(fdno, F_SETLK, (
void *) &l);
2757 rc = ((dbi->dbi_use_dbenv &&
2758 (dbi->dbi_eflags & DB_INIT_CDB) &&
2762 _(
"cannot get %s lock on %s/%s\n"),
2763 ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
2764 ?
_(
"exclusive") :
_(
"shared")),
2765 dbhome, (dbfile ? dbfile :
""));
2766 }
else if (dbfile) {
2768 D_(
"locked db index %s/%s\n"),
2776 dbi->dbi_db = (
void *) db;
2780 DBIDEBUG(dbi, (stderr,
"<-- %s(%p,%s,%p) dbi %p rc %d %s\n", __FUNCTION__, rpmdb,
tagName(rpmtag), dbip, dbi, rc,
_OFLAGS(dbi->dbi_oflags)));
2782 if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) {
2785 if (dbi->dbi_primary) {
2788 int (*_callback)(
DB *,
const DBT *,
const DBT *, DBT *)
2791 int _flags = DB_IMMUTABLE_KEY;
2796 Pdbi =
dbiOpen(rpmdb, Ptag, 0);
2797 assert(Pdbi != NULL);
2798 if (oflags & (DB_CREATE|DB_TRUNCATE)) _flags |=
DB_CREATE;
2801 if (dbi->dbi_seq_id && !(oflags & DB_RDONLY)) {
2803 uint32_t u = (uint32_t) strtoll(dbi->dbi_seq_id, &end, 0);
2806 if (oflags & (DB_CREATE|DB_TRUNCATE))
2807 dbi->dbi_seq_initial = rpmdb->db_maxkey + 1;
2816 if (dbip) *dbip = dbi;
2822 if (dbip) *dbip = dbi;
2825 urlfn =
_free(urlfn);
static int db3Acallback(DB *db, const DBT *key, const DBT *data, DBT *_r)
static int uint32Cmp(const void *_a, const void *_b)
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)
static int db3cpget(dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *pkey, DBT *data, unsigned int flags)
#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)
rpmbf rpmbfNew(size_t m, size_t k, unsigned flags)
Create a Bloom filter.
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)
int pgpExtractPubkeyFingerprint(const char *b64pkt, rpmuint8_t *keyid)
Extract OpenPGP public key fingerprint from base64 encoded packet.
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 void rpmlog(int code, const char *fmt,...)
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)
#define DBIDEBUG(_dbi, _list)
static uint64_t physmem(void)
void rpmbfParams(size_t n, double e, size_t *mp, size_t *kp)
Return optimal {m, k} for given n and e.
static const char * fmtBits(uint32_t flags, KEY tbl[], size_t ntbl, char *t)
Yet Another syslog(3) API clone.
static int xisprint(int c)
void * xcalloc(size_t nmemb, size_t size)
const char const bson_bool_t v
rpmbf rpmbfFree(rpmbf bf)
Destroy a Bloom filter.
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)
static int db3byteswapped(dbiIndex dbi)
static const char * fmtDBafflags(uint32_t flags)
const char const bson * data
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.
struct tagStore_s * tagStore_t
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 rpmdb_s * rpmdb
Database of headers and tag value indices.
Header headerFree(Header h)
Dereference a header instance.
static union _dbswap _endian
const char const bson const bson * op
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
const char const bson int mongo_write_concern int flags
Header headerLink(Header h)
Reference a header instance.
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,...)
const char const bson * key
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)
const char const char size_t size
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
static void rpmdbe_feedback(DB_ENV *dbenv, int opcode, int percent)
static const char * fmtDBCflags(uint32_t flags)
#define _AFFLAGS(_afflags)
Structure(s) and routine(s) used for EVR parsing and comparison.
static int db_init(dbiIndex dbi, const char *dbhome, const char *dbfile, const char *dbsubfile, DB_ENV **dbenvp)
int rpmbfAdd(rpmbf bf, const void *_s, size_t ns)
Add item to a Bloom filter.
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)
#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 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)
int rpmbfChk(rpmbf bf, const void *_s, size_t ns)
Check for item in a Bloom filter.
struct _dbiIndex * dbiIndex
static int db3sync(dbiIndex dbi, unsigned int flags)
int Unlink(const char *path)
unlink(2) clone.