rpm 5.3.7
Data Structures | Defines | Typedefs | Functions | Variables

rpmdb/db3.c File Reference

#include "system.h"
#include <rpmlog.h>
#include <rpmmacro.h>
#include <rpmbf.h>
#include <rpmpgp.h>
#include <rpmurl.h>
#include <rpmtag.h>
#include <rpmevr.h>
#include <rpmdb.h>
#include "debug.h"
Include dependency graph for db3.c:

Go to the source code of this file.

Data Structures

union  _dbswap
struct  key_s
struct  _events_s

Defines

#define _RPMTAG_INTERNAL
#define _RPMEVR_INTERNAL
#define _RPMDB_INTERNAL
#define DBIDEBUG(_dbi, _list)   if ((_dbi)->dbi_debug) fprintf _list
#define _ENTRY(_v)   { DB_##_v, #_v, }
#define _EFLAGS(_eflags)   fmtDBeflags(_eflags)
#define _OFLAGS(_oflags)   fmtDBoflags(_oflags)
#define _AFLAGS(_aflags)   fmtDBaflags(_aflags)
#define _AFFLAGS(_afflags)   fmtDBafflags(_afflags)
#define _DBCFLAGS(_flags)   fmtDBCflags(_flags)
#define _DBT_ENTRY(_v)   { DB_DBT_##_v, #_v, }
#define _KEYDATA(_K, _P, _D, _R)   fmtKDR(_K, _P, _D, _R)
#define cvtdberr(_dbi, _msg, _error, _printit)   Xcvtdberr(_dbi, _msg, _error, _printit, __FUNCTION__, __FILE__, __LINE__)
#define _TABLE(_v)   { #_v, DB_EVENT_##_v }
#define _RPMDB_NLOCKS   8192

Typedefs

typedef struct key_s KEY

Functions

static uint64_t _ntoh_ul (uint64_t ul)
static uint64_t _hton_ul (uint64_t ul)
static uint32_t _ntoh_ui (uint32_t ui)
static uint32_t _hton_ui (uint32_t ui)
static uint16_t _ntoh_us (uint16_t us)
static uint16_t _hton_us (uint16_t us)
static const char * tblName (uint32_t v, KEY *tbl, size_t ntbl)
static const char * fmtBits (uint32_t flags, KEY tbl[], size_t ntbl, char *t)
static const char * fmtDBeflags (uint32_t flags)
static const char * fmtDBoflags (uint32_t flags)
static const char * fmtDBaflags (uint32_t flags)
static const char * fmtDBafflags (uint32_t flags)
static const char * fmtDBCflags (uint32_t flags)
static char * fmtDBT (const DBT *K, char *te)
static const char * fmtKDR (const DBT *K, const DBT *P, const DBT *D, const DBT *R)
static int Xcvtdberr (dbiIndex dbi, const char *msg, int error, int printit, const char *func, const char *fn, unsigned ln)
static const char * mapTagName (rpmdb rpmdb, dbiIndex dbi)
 Return (possibly renamed) tagName.
static int db_fini (dbiIndex dbi, const char *dbhome, const char *dbfile, const char *dbsubfile)
static int db3_fsync_disable (int fd)
static uint64_t physmem (void)
static size_t ncores (void)
static void rpmdbe_event_notify (DB_ENV *dbenv, u_int32_t event, void *event_info)
static void rpmdbe_feedback (DB_ENV *dbenv, int opcode, int percent)
static int db_init (dbiIndex dbi, const char *dbhome, const char *dbfile, const char *dbsubfile, DB_ENV **dbenvp)
static int db3sync (dbiIndex dbi, unsigned int flags)
static int db3exists (dbiIndex dbi, DBT *key, unsigned int flags)
static int db3seqno (dbiIndex dbi, int64_t *seqnop, unsigned int flags)
static int db3cdup (dbiIndex dbi, DBC *dbcursor, DBC **dbcp, unsigned int flags)
static int db3cclose (dbiIndex dbi, DBC *dbcursor, unsigned int flags)
static int db3copen (dbiIndex dbi, DB_TXN *txnid, DBC **dbcp, unsigned int dbiflags)
static int db3cput (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
static int db3cget (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
static int db3cpget (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *pkey, DBT *data, unsigned int flags)
static int db3cdel (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags)
static int db3ccount (dbiIndex dbi, DBC *dbcursor, unsigned int *countp, unsigned int flags)
static int db3byteswapped (dbiIndex dbi)
static int db3stat (dbiIndex dbi, unsigned int flags)
static int db3associate (dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, const DBT *, DBT *), unsigned int flags)
static int db3associate_foreign (dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, DBT *, const DBT *, int *), unsigned int flags)
static int db3join (dbiIndex dbi, DBC **curslist, DBC **dbcp, unsigned int flags)
static int db3close (dbiIndex dbi, unsigned int flags)
static unsigned char nibble (char c)
 Convert hex to binary nibble.
static int loadDBT (DBT *_r, rpmTag tag, const void *_s, size_t ns)
static int uint32Cmp (const void *_a, const void *_b)
static int uint64Cmp (const void *_a, const void *_b)
static int db3Acallback (DB *db, const DBT *key, const DBT *data, DBT *_r)
static int seqid_init (dbiIndex dbi, const char *keyp, size_t keylen, DB_SEQUENCE **seqp)
static int db3open (rpmdb rpmdb, rpmTag rpmtag, dbiIndex *dbip)
 Return handle for an index database.

Variables

static int _debug = 1
static union _dbswap _endian = { .ui = 0x11223344 }
static KEY DBeflags []
static size_t nDBeflags = sizeof(DBeflags) / sizeof(DBeflags[0])
static KEY DBoflags []
static size_t nDBoflags = sizeof(DBoflags) / sizeof(DBoflags[0])
static KEY DBaflags []
static size_t nDBaflags = sizeof(DBaflags) / sizeof(DBaflags[0])
static KEY DBafflags []
static size_t nDBafflags = sizeof(DBafflags) / sizeof(DBafflags[0])
static KEY DBCflags []
static size_t nDBCflags = sizeof(DBCflags) / sizeof(DBCflags[0])
static KEY DBTflags []
static size_t nDBTflags = sizeof(DBTflags) / sizeof(DBTflags[0])
static struct _events_s _events []
struct _dbiVec db3vec

Detailed Description

Definition in file db3.c.


Define Documentation

#define _AFFLAGS (   _afflags)    fmtDBafflags(_afflags)

Definition at line 337 of file db3.c.

Referenced by db3associate_foreign().

#define _AFLAGS (   _aflags)    fmtDBaflags(_aflags)

Definition at line 317 of file db3.c.

Referenced by db3associate().

#define _DBCFLAGS (   _flags)    fmtDBCflags(_flags)

Definition at line 406 of file db3.c.

Referenced by db3cdel(), db3cget(), db3cpget(), and db3cput().

#define _DBT_ENTRY (   _v)    { DB_DBT_##_v, #_v, }

Definition at line 408 of file db3.c.

#define _EFLAGS (   _eflags)    fmtDBeflags(_eflags)

Definition at line 272 of file db3.c.

Referenced by db_init().

#define _ENTRY (   _v)    { DB_##_v, #_v, }

Definition at line 236 of file db3.c.

#define _KEYDATA (   _K,
  _P,
  _D,
  _R 
)    fmtKDR(_K, _P, _D, _R)

Definition at line 494 of file db3.c.

Referenced by db3Acallback(), db3cdel(), db3cget(), db3cpget(), db3cput(), db3exists(), and seqid_init().

#define _OFLAGS (   _oflags)    fmtDBoflags(_oflags)

Definition at line 298 of file db3.c.

Referenced by db3open().

#define _RPMDB_INTERNAL

Definition at line 27 of file db3.c.

#define _RPMDB_NLOCKS   8192

Referenced by db_init().

#define _RPMEVR_INTERNAL

Definition at line 24 of file db3.c.

#define _RPMTAG_INTERNAL

Definition at line 21 of file db3.c.

#define _TABLE (   _v)    { #_v, DB_EVENT_##_v }

Definition at line 682 of file db3.c.

#define cvtdberr (   _dbi,
  _msg,
  _error,
  _printit 
)    Xcvtdberr(_dbi, _msg, _error, _printit, __FUNCTION__, __FILE__, __LINE__)
#define DBIDEBUG (   _dbi,
  _list 
)    if ((_dbi)->dbi_debug) fprintf _list

Typedef Documentation

typedef struct key_s KEY

Function Documentation

static uint32_t _hton_ui ( uint32_t  ui) [inline, static]

Definition at line 86 of file db3.c.

References _ntoh_ui().

Referenced by db3Acallback().

static uint64_t _hton_ul ( uint64_t  ul) [inline, static]

Definition at line 68 of file db3.c.

References _ntoh_ul().

Referenced by db3Acallback().

static uint16_t _hton_us ( uint16_t  us) [inline, static]

Definition at line 103 of file db3.c.

References _ntoh_us().

static uint32_t _ntoh_ui ( uint32_t  ui) [inline, static]

Definition at line 74 of file db3.c.

References _dbswap::uc, and _dbswap::ui.

Referenced by _hton_ui(), and db3Acallback().

static uint64_t _ntoh_ul ( uint64_t  ul) [inline, static]

Definition at line 54 of file db3.c.

References _dbswap::uc, and _dbswap::ul.

Referenced by _hton_ul().

static uint16_t _ntoh_us ( uint16_t  us) [inline, static]

Definition at line 92 of file db3.c.

References _dbswap::uc, and _dbswap::us.

Referenced by _hton_us().

static int db3_fsync_disable ( int  fd) [static]

Definition at line 587 of file db3.c.

Referenced by db_init().

static int db3Acallback ( DB db,
const DBT key,
const DBT data,
DBT _r 
) [static]
static int db3associate ( dbiIndex  dbi,
dbiIndex  dbisecondary,
int(*)(DB *, const DBT *, const DBT *, DBT *)  callback,
unsigned int  flags 
) [static]

Definition at line 1430 of file db3.c.

References _AFLAGS, _debug, _free(), cvtdberr, tagName(), and xstrdup().

Referenced by db3open().

static int db3associate_foreign ( dbiIndex  dbi,
dbiIndex  dbisecondary,
int(*)(DB *, const DBT *, DBT *, const DBT *, int *)  callback,
unsigned int  flags 
) [static]

Definition at line 1459 of file db3.c.

References _AFFLAGS, _debug, _free(), cvtdberr, tagName(), and xstrdup().

static int db3byteswapped ( dbiIndex  dbi) [static]

Definition at line 1383 of file db3.c.

static int db3cclose ( dbiIndex  dbi,
DBC dbcursor,
unsigned int  flags 
) [static]

Definition at line 1160 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

Referenced by db3copen().

static int db3ccount ( dbiIndex  dbi,
DBC dbcursor,
unsigned int *  countp,
unsigned int  flags 
) [static]

Definition at line 1359 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

static int db3cdel ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Definition at line 1325 of file db3.c.

References _DBCFLAGS, _debug, _KEYDATA, cvtdberr, db3cget(), DB_SET, and DBIDEBUG.

static int db3cdup ( dbiIndex  dbi,
DBC dbcursor,
DBC **  dbcp,
unsigned int  flags 
) [static]

Definition at line 1138 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

static int db3cget ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Definition at line 1245 of file db3.c.

References _DBCFLAGS, _debug, _KEYDATA, cvtdberr, DB_NOTFOUND, and DBIDEBUG.

Referenced by db3cdel().

static int db3close ( dbiIndex  dbi,
unsigned int  flags 
) [static]

Definition at line 1509 of file db3.c.

References _debug, _free(), cvtdberr, D_, db_fini(), DBIDEBUG, mapTagName(), rpmGenPath(), rpmlog(), RPMLOG_DEBUG, and urlPath().

Referenced by db3open().

static int db3copen ( dbiIndex  dbi,
DB_TXN txnid,
DBC **  dbcp,
unsigned int  dbiflags 
) [static]

Definition at line 1184 of file db3.c.

References _debug, cvtdberr, db3cclose(), DB_WRITECURSOR, and DBIDEBUG.

static int db3cpget ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT pkey,
DBT data,
unsigned int  flags 
) [static]

Definition at line 1286 of file db3.c.

References _DBCFLAGS, _debug, _KEYDATA, cvtdberr, DB_NOTFOUND, and DBIDEBUG.

static int db3cput ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Definition at line 1215 of file db3.c.

References _DBCFLAGS, _debug, _KEYDATA, cvtdberr, DB_KEYLAST, and DBIDEBUG.

static int db3exists ( dbiIndex  dbi,
DBT key,
unsigned int  flags 
) [static]

Definition at line 1085 of file db3.c.

References _debug, _KEYDATA, cvtdberr, DB_NOTFOUND, and DBIDEBUG.

static int db3join ( dbiIndex  dbi,
DBC **  curslist,
DBC **  dbcp,
unsigned int  flags 
) [static]

Definition at line 1490 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

static int db3open ( rpmdb  rpmdb,
rpmTag  rpmtag,
dbiIndex dbip 
) [static]

Return handle for an index database.

Parameters:
rpmdbrpm database
rpmtagrpm tag
Return values:
*dbipindex database handle
Returns:
0 on success

Definition at line 2012 of file db3.c.

References _, _debug, _free(), _OFLAGS, alloca(), __db::app_private, cvtdberr, D_, db3Acallback(), db3associate(), db3close(), db3vec, DB_EXCL, db_init(), DB_PRIVATE, DB_VERSION_MAJOR, DBIDEBUG, dbiOpen(), errno, EXIT_FAILURE, F_OK, mapTagName(), rpmCleanPath(), RPMDBI_PACKAGES, rpmGenPath(), rpmGetPath(), rpmioMkpath(), rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMLOG_NOTICE, RPMLOG_WARNING, seqid_init(), Stat(), stpcpy(), tagName(), tagValue(), Unlink(), urlPath(), and W_OK.

static int db3seqno ( dbiIndex  dbi,
int64_t *  seqnop,
unsigned int  flags 
) [static]

Definition at line 1107 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

static int db3stat ( dbiIndex  dbi,
unsigned int  flags 
) [static]

Definition at line 1398 of file db3.c.

References _debug, _free(), cvtdberr, DB_FAST_STAT, and DBIDEBUG.

static int db3sync ( dbiIndex  dbi,
unsigned int  flags 
) [static]

Definition at line 1066 of file db3.c.

References _debug, cvtdberr, and DBIDEBUG.

static int db_fini ( dbiIndex  dbi,
const char *  dbhome,
const char *  dbfile,
const char *  dbsubfile 
) [static]

Definition at line 544 of file db3.c.

References _debug, cvtdberr, D_, DBIDEBUG, rpmlog(), and RPMLOG_DEBUG.

Referenced by db3close().

static int db_init ( dbiIndex  dbi,
const char *  dbhome,
const char *  dbfile,
const char *  dbsubfile,
DB_ENV **  dbenvp 
) [static]
static const char* fmtBits ( uint32_t  flags,
KEY  tbl[],
size_t  ntbl,
char *  t 
) [static]

Definition at line 209 of file db3.c.

References name, stpcpy(), and tblName().

Referenced by fmtDBafflags(), fmtDBaflags(), fmtDBCflags(), fmtDBeflags(), fmtDBoflags(), and fmtDBT().

static const char* fmtDBafflags ( uint32_t  flags) [static]

Definition at line 328 of file db3.c.

References fmtBits(), and stpcpy().

static const char* fmtDBaflags ( uint32_t  flags) [static]

Definition at line 308 of file db3.c.

References fmtBits(), and stpcpy().

static const char* fmtDBCflags ( uint32_t  flags) [static]

Definition at line 388 of file db3.c.

References fmtBits(), stpcpy(), and tblName().

static const char* fmtDBeflags ( uint32_t  flags) [static]

Definition at line 263 of file db3.c.

References fmtBits(), and stpcpy().

static const char* fmtDBoflags ( uint32_t  flags) [static]

Definition at line 289 of file db3.c.

References fmtBits(), and stpcpy().

static char* fmtDBT ( const DBT K,
char *  te 
) [static]

Definition at line 421 of file db3.c.

References __db_dbt::data, __db_dbt::flags, fmtBits(), __db_dbt::size, and xisprint().

Referenced by fmtKDR().

static const char* fmtKDR ( const DBT K,
const DBT P,
const DBT D,
const DBT R 
) [static]

Definition at line 468 of file db3.c.

References fmtDBT(), and stpcpy().

static int loadDBT ( DBT _r,
rpmTag  tag,
const void *  _s,
size_t  ns 
) [static]
static const char* mapTagName ( rpmdb  rpmdb,
dbiIndex  dbi 
) [static]

Return (possibly renamed) tagName.

Handles arbitrary tags.

Parameters:
rpmdbrpm database
dbirpm database index
Returns:
tag string

Definition at line 527 of file db3.c.

References tagName().

Referenced by db3close(), and db3open().

static size_t ncores ( void  ) [static]

Definition at line 657 of file db3.c.

References name.

Referenced by db_init().

static unsigned char nibble ( char  c) [inline, static]

Convert hex to binary nibble.

Parameters:
chex character
Returns:
binary nibble

Definition at line 1606 of file db3.c.

Referenced by loadDBT().

static uint64_t physmem ( void  ) [static]

Definition at line 627 of file db3.c.

References name.

Referenced by db_init().

static void rpmdbe_event_notify ( DB_ENV dbenv,
u_int32_t  event,
void *  event_info 
) [static]

Definition at line 712 of file db3.c.

References _events, and __db_env::app_private.

Referenced by db_init().

static void rpmdbe_feedback ( DB_ENV dbenv,
int  opcode,
int  percent 
) [static]

Definition at line 719 of file db3.c.

Referenced by db_init().

static int seqid_init ( dbiIndex  dbi,
const char *  keyp,
size_t  keylen,
DB_SEQUENCE **  seqp 
) [static]

Definition at line 1932 of file db3.c.

References _debug, _KEYDATA, cvtdberr, __db_dbt::data, DBIDEBUG, and __db_dbt::size.

Referenced by db3open().

static const char* tblName ( uint32_t  v,
KEY tbl,
size_t  ntbl 
) [static]

Definition at line 189 of file db3.c.

References key_s::n, and snprintf().

Referenced by fmtBits(), and fmtDBCflags().

static int uint32Cmp ( const void *  _a,
const void *  _b 
) [static]

Definition at line 1664 of file db3.c.

Referenced by db3Acallback().

static int uint64Cmp ( const void *  _a,
const void *  _b 
) [static]

Definition at line 1673 of file db3.c.

Referenced by db3Acallback().

static int Xcvtdberr ( dbiIndex  dbi,
const char *  msg,
int  error,
int  printit,
const char *  func,
const char *  fn,
unsigned  ln 
) [static]

Definition at line 499 of file db3.c.

References rpmlog(), and RPMLOG_ERR.


Variable Documentation

int _debug = 1 [static]
union _dbswap _endian = { .ui = 0x11223344 } [static]

Definition at line 52 of file db3.c.

struct _events_s _events[] [static]

Referenced by rpmdbe_event_notify().

KEY DBafflags[] [static]
Initial value:
 {
    { DB_FOREIGN_ABORT , "FOREIGN_ABORT", },
    { DB_FOREIGN_CASCADE , "FOREIGN_CASCADE", },
    { DB_FOREIGN_NULLIFY , "FOREIGN_NULLIFY", },
}

Definition at line 320 of file db3.c.

KEY DBaflags[] [static]
Initial value:
 {
    { DB_CREATE , "CREATE", },
    { DB_IMMUTABLE_KEY , "IMMUTABLE_KEY", },
}

Definition at line 301 of file db3.c.

KEY DBCflags[] [static]

Definition at line 340 of file db3.c.

KEY DBeflags[] [static]
Initial value:
 {
    { DB_INIT_CDB , "INIT_CDB", },
    { DB_INIT_LOCK , "INIT_LOCK", },
    { DB_INIT_LOG , "INIT_LOG", },
    { DB_INIT_MPOOL , "INIT_MPOOL", },
    { DB_INIT_REP , "INIT_REP", },
    { DB_INIT_TXN , "INIT_TXN", },
    { DB_RECOVER , "RECOVER", },
    { DB_RECOVER_FATAL , "RECOVER_FATAL", },
    { DB_USE_ENVIRON , "USE_ENVIRON", },
    { DB_USE_ENVIRON_ROOT , "USE_ENVIRON_ROOT", },
    { DB_CREATE , "CREATE", },
    { DB_LOCKDOWN , "LOCKDOWN", },



    { DB_PRIVATE , "PRIVATE", },
    { DB_REGISTER , "REGISTER", },
    { DB_SYSTEM_MEM , "SYSTEM_MEM", },
    { DB_THREAD , "THREAD", },
}

Definition at line 239 of file db3.c.

KEY DBoflags[] [static]
Initial value:
 {
    { DB_AUTO_COMMIT , "AUTO_COMMIT", },
    { DB_CREATE , "CREATE", },
    { DB_EXCL , "EXCL", },
    { DB_MULTIVERSION , "MULTIVERSION", },
    { DB_NOMMAP , "NOMMAP", },
    { DB_RDONLY , "RDONLY", },
    { DB_READ_UNCOMMITTED , "READ_UNCOMMITTED", },
    { DB_THREAD , "THREAD", },
    { DB_TRUNCATE , "TRUNCATE", },
}

Definition at line 275 of file db3.c.

KEY DBTflags[] [static]
Initial value:
 {
    { DB_DBT_MALLOC , "MALLOC", },
    { DB_DBT_REALLOC , "REALLOC", },
    { DB_DBT_USERMEM , "USERMEM", },
    { DB_DBT_PARTIAL , "PARTIAL", },
    { DB_DBT_APPMALLOC , "APPMALLOC", },
    { DB_DBT_MULTIPLE , "MULTIPLE", },
}

Definition at line 410 of file db3.c.

size_t nDBafflags = sizeof(DBafflags) / sizeof(DBafflags[0]) [static]

Definition at line 326 of file db3.c.

size_t nDBaflags = sizeof(DBaflags) / sizeof(DBaflags[0]) [static]

Definition at line 306 of file db3.c.

size_t nDBCflags = sizeof(DBCflags) / sizeof(DBCflags[0]) [static]

Definition at line 386 of file db3.c.

size_t nDBeflags = sizeof(DBeflags) / sizeof(DBeflags[0]) [static]

Definition at line 261 of file db3.c.

size_t nDBoflags = sizeof(DBoflags) / sizeof(DBoflags[0]) [static]

Definition at line 287 of file db3.c.

size_t nDBTflags = sizeof(DBTflags) / sizeof(DBTflags[0]) [static]

Definition at line 419 of file db3.c.