rpm  5.2.1
Files | Typedefs | Enumerations | Functions
RPMDB Database API.
Collaboration diagram for RPMDB Database API.:

Files

file  rpmlib.h
 In Memoriam: Steve Taylor stayl.nosp@m.or@r.nosp@m.edhat.nosp@m..com was here, now he's not.
 
file  dbconfig.c
 
file  hdrNVR.c
 
file  rpmdb.c
 
file  rpmdb.h
 Access RPM indices using Berkeley DB interface(s).
 

Typedefs

typedef struct _dbiIndexSet * dbiIndexSet
 A single element (i.e.
 
typedef struct tagStore_s * tagStore_t
 
typedef struct rpmdb_s * rpmdb
 Database of headers and tag value indices.
 
typedef struct rpmmi_srpmmi
 Database iterator.
 

Enumerations

enum  rpmdbFlags { RPMDB_FLAG_JUSTCHECK = (1 << 0), RPMDB_FLAG_MINIMAL = (1 << 1), RPMDB_FLAG_CHROOT = (1 << 2) }
 

Functions

int rpmdbFindFpList (void *_db, fingerPrint *fpList, void *_matchList, int numItems, unsigned int exclude)
 Find fingerprint matches in database.
 
rpmdb rpmdbUnlink (rpmdb db, const char *msg)
 Unreference a database instance.
 
rpmdb rpmdbLink (rpmdb db, const char *msg)
 Reference a database instance.
 
int rpmdbOpen (const char *prefix, rpmdb *dbp, int mode, int perms)
 Open rpm database.
 
int rpmdbInit (const char *prefix, int perms)
 Initialize database.
 
int rpmdbVerifyAllDBI (rpmdb db)
 Verify all database components.
 
int rpmdbVerify (const char *prefix)
 Open and verify all database components.
 
int rpmdbClose (rpmdb db)
 Close all database indices and free rpmdb.
 
int rpmdbSync (rpmdb db)
 Sync all database indices.
 
int rpmdbOpenAll (rpmdb db)
 Open all database indices.
 
int rpmdbCount (rpmdb db, rpmTag tag, const void *keyp, size_t keylen)
 Return number of instances of key in a tag index.
 
int rpmdbCountPackages (rpmdb db, const char *name)
 Return number of instances of package in Name index.
 
unsigned int rpmmiInstance (rpmmi mi)
 Return header instance join key for current position of rpmdb iterator.
 
unsigned int rpmmiFilenum (rpmmi mi)
 Return header tag index join key for current position of rpmdb iterator.
 
int rpmmiCount (rpmmi mi)
 Return number of elements in rpm database iterator.
 
int rpmmiGrow (rpmmi mi, const int *hdrNums, int nHdrNums)
 Append items to set of package instances to iterate.
 
int rpmmiPrune (rpmmi mi, int *hdrNums, int nHdrNums, int sorted)
 Remove items from set of package instances to iterate.
 
int rpmmiAddPattern (rpmmi mi, rpmTag tag, rpmMireMode mode, const char *pattern)
 Add pattern to iterator selector.
 
int rpmmiSetRewrite (rpmmi mi, int rewrite)
 Prepare iterator for lazy writes.
 
int rpmmiSetModified (rpmmi mi, int modified)
 Modify iterator to mark header for lazy write on release.
 
int rpmmiSetHdrChk (rpmmi mi, rpmts ts)
 Modify iterator to verify retrieved header blobs.
 
rpmmi rpmmiInit (rpmdb db, rpmTag tag, const void *keyp, size_t keylen)
 Return database iterator.
 
Header rpmmiNext (rpmmi mi)
 Return next package header from iteration.
 
int rpmdbCheckTerminate (int terminate)
 Check rpmdb signal handler for trapped signal and/or requested exit.
 
int rpmdbCheckSignals (void)
 Check for and exit on termination signals.
 
rpmmi rpmmiUnlink (rpmmi mi)
 Unreference a rpm database iterator.
 
rpmmi rpmmiLink (rpmmi mi)
 Reference a rpm database iterator.
 
rpmmi rpmmiFree (rpmmi mi)
 Destroy rpm database iterator.
 
int rpmdbMireApply (rpmdb db, rpmTag tag, rpmMireMode mode, const char *pat, const char ***argvp)
 Return array of keys matching a pattern.
 
int rpmdbAdd (rpmdb db, int iid, Header h, rpmts ts)
 Add package header to rpm database and indices.
 
int rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum, rpmts ts)
 Remove package header from rpm database and indices.
 
int rpmdbRebuild (const char *prefix, rpmts ts)
 Rebuild database indices from package headers.
 

Detailed Description

Typedef Documentation

typedef struct _dbiIndexSet* dbiIndexSet

A single element (i.e.

inverted list from tag values) of a database.

Definition at line 49 of file rpmdb.h.

typedef struct rpmdb_s* rpmdb

Database of headers and tag value indices.

Definition at line 38 of file rpmtypes.h.

typedef struct rpmmi_s* rpmmi

Database iterator.

Definition at line 43 of file rpmtypes.h.

typedef struct tagStore_s* tagStore_t

Definition at line 503 of file rpmtag.h.

Enumeration Type Documentation

enum rpmdbFlags
Enumerator:
RPMDB_FLAG_JUSTCHECK 
RPMDB_FLAG_MINIMAL 
RPMDB_FLAG_CHROOT 

Definition at line 481 of file rpmdb.h.

Function Documentation

int rpmdbAdd ( rpmdb  db,
int  iid,
Header  h,
rpmts  ts 
)

Add package header to rpm database and indices.

Parameters
dbrpm database
iidinstall transaction id (iid = 0 or -1 to skip)
hheader
ts(unused) transaction set (or NULL)
Returns
0 on success

Definition at line 3306 of file rpmdb.c.

References _, _db_tagged_file_indices, _DBSWAP, _free(), alloca(), rpmDataType_u::argv, blockSignals(), _HE_s::c, D_, __db_dbt::data, DB_KEYLAST, DB_NOTFOUND, DB_SET, DB_WRITECURSOR, dbiAppendSet(), dbiFreeIndexSet(), dbiIndexNewItem(), dbiOpen(), dbt2set(), headerCheck(), headerDel(), headerGet(), headerIsEntry(), headerPut(), headerSetInstance(), headerUnload(), hGetColor(), nibble(), _HE_s::p, pgpExtractPubkeyFingerprint(), rpmDataType_u::ptr, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, RPM_UINT16_TYPE, RPM_UINT32_TYPE, RPM_UINT64_TYPE, RPM_UINT8_TYPE, RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_PACKAGES, RPMDBI_REMOVED, rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMRC_FAIL, RPMRC_NOTFOUND, RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, RPMTAG_FILEDIGESTS, RPMTAG_INSTALLTID, RPMTAG_PACKAGECOLOR, RPMTAG_PUBKEYS, RPMTAG_REMOVETID, RPMTAG_REQUIREFLAGS, RPMTAG_REQUIRENAME, RPMTAG_TRIGGERNAME, rpmtsCleanDig(), rpmtsDig(), set2dbt(), __db_dbt::size, rpmDataType_u::str, _HE_s::t, _HE_s::tag, taghash(), tagName(), _dbswap::ui, rpmDataType_u::ui16p, rpmDataType_u::ui32p, rpmDataType_u::ui64p, rpmDataType_u::ui8p, UINT32_T, unblockSignals(), and xcalloc().

Referenced by ftsCacheUpdate(), rpmcliImportPubkey(), rpmdbRebuild(), and rpmpsmStage().

int rpmdbCheckSignals ( void  )

Check for and exit on termination signals.

Definition at line 804 of file rpmdb.c.

References D_, EXIT_FAILURE, rpmdbCheckTerminate(), rpmlog(), RPMLOG_DEBUG, and rpmsqCaught.

Referenced by checkSignals(), rpmdbClose(), rpmgiShowMatches(), rpmmiFini(), rpmmiInit(), rpmQueryVerify(), rpmtsRun(), and unblockSignals().

int rpmdbCheckTerminate ( int  terminate)

Check rpmdb signal handler for trapped signal and/or requested exit.

Clean up any open iterators and databases on termination condition. On non-zero exit any open references to rpmdb are invalid and cannot be accessed anymore, calling process should terminate immediately.

Parameters
terminate0 to only check for signals, 1 to terminate anyway
Returns
0 to continue, 1 if termination cleanup was done.

Definition at line 757 of file rpmdb.c.

References rpmmi_s::mi_next, rpmdbClose(), rpmmiFree(), and rpmsqCaught.

Referenced by rpm_exithook(), rpmdbCheckSignals(), and rpmts_Die().

int rpmdbClose ( rpmdb  db)

Close all database indices and free rpmdb.

Parameters
dbrpm database
Returns
0 on success

Definition at line 1019 of file rpmdb.c.

References _free(), _rpmdb_debug, L, PBM_FREE, rpmdbCheckSignals(), rpmdbRock, rpmioPutPool(), rpmsqEnable(), and tagStoreFree().

Referenced by rpmdb_dealloc(), rpmdbCheckTerminate(), rpmdbInit(), rpmdbOpenDatabase(), rpmdbRebuild(), rpmdbVerifyAllDBI(), rpmmiFini(), rpmtsCloseDB(), and rpmtsCloseSDB().

int rpmdbCount ( rpmdb  db,
rpmTag  tag,
const void *  keyp,
size_t  keylen 
)

Return number of instances of key in a tag index.

Parameters
dbrpm database
tagrpm tag
keypkey data
keylenkey data length (0 will use strlen(keyp))
Returns
number of instances

Definition at line 1676 of file rpmdb.c.

References _, __db_dbt::data, DB_NOTFOUND, DB_SET, dbiFreeIndexSet(), dbiIndexSetCount(), dbiOpen(), dbt2set(), rpmlog(), RPMLOG_ERR, __db_dbt::size, tagName(), and UINT32_T.

Referenced by rpmdbCountPackages().

int rpmdbCountPackages ( rpmdb  db,
const char *  name 
)

Return number of instances of package in Name index.

Parameters
dbrpm database
namerpm package name
Returns
number of instances

Definition at line 1736 of file rpmdb.c.

References rpmdbCount(), and RPMTAG_NAME.

Referenced by handleOneTrigger(), rpmpsmStage(), and runTriggers().

int rpmdbFindFpList ( void *  _db,
fingerPrint fpList,
void *  _matchList,
int  numItems,
unsigned int  exclude 
)

Find fingerprint matches in database.

Parameters
_dbrpm database
fpListfingerprint array
Return values
_matchListreturned fingerprint matches
Parameters
numItemsnumber of fingerprint items
excludeexcluded header instance (0 to disable)
Returns
0 always

Definition at line 3744 of file rpmdb.c.

References _db_tagged_file_indices, _free(), alloca(), rpmDataType_u::argv, __db_dbt::data, dbiAppendSet(), FP_EQUAL, fpCacheCreate(), fpCacheFree(), fpLookupList(), headerGet(), rpmmi_s::mi_data, rpmmi_s::mi_key, rpmmi_s::mi_set, rpmmi_s::mi_setx, _HE_s::p, rpmdbGrowIterator(), rpmdbSortIterator(), rpmmiCount(), rpmmiFree(), rpmmiInit(), rpmmiNext(), RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, __db_dbt::size, _HE_s::tag, taghash(), rpmDataType_u::ui32p, UINT32_T, and xcalloc().

Referenced by rpmtsRun().

int rpmdbInit ( const char *  prefix,
int  perms 
)

Initialize database.

Parameters
prefixpath to top of install tree
permsdatabase permissions
Returns
0 on success

Definition at line 1337 of file rpmdb.c.

References RPMDB_FLAG_JUSTCHECK, rpmdbClose(), rpmdbOpenAll(), rpmdbOpenDatabase(), and rpmExpandNumeric().

Referenced by rpmtsInitDB().

rpmdb rpmdbLink ( rpmdb  db,
const char *  msg 
)

Reference a database instance.

Parameters
dbrpm database
msg
Returns
new rpm database reference

Referenced by db3open(), rpmdbNew(), and rpmmiInit().

int rpmdbMireApply ( rpmdb  db,
rpmTag  tag,
rpmMireMode  mode,
const char *  pat,
const char ***  argvp 
)

Return array of keys matching a pattern.

Parameters
dbrpm database
tagrpm tag
modetype of pattern match
patpattern to match
Return values
*argvparray of keys that match
Returns
0 on success

Definition at line 2935 of file rpmdb.c.

References _, _free(), alloca(), argvAdd(), argvAppend(), argvFree(), __db_dbt::data, DB_NEXT, dbiOpen(), mireFree(), mireNew(), mireRegcomp(), mireRegexec(), rpmlog(), RPMLOG_ERR, __db_dbt::size, tagName(), and xmalloc().

Referenced by rpmdbTriggerGlobs(), and runImmedTriggers().

int rpmdbOpen ( const char *  prefix,
rpmdb dbp,
int  mode,
int  perms 
)

Open rpm database.

Parameters
prefixpath to top of install tree
Return values
dbpaddress of rpm database
Parameters
modeopen(2) flags: O_RDWR or O_RDONLY (O_CREAT also)
permsdatabase permissions
Returns
0 on success

Definition at line 1331 of file rpmdb.c.

References rpmdbOpenDatabase(), and rpmExpandNumeric().

Referenced by rpmtsFindPubkey(), rpmtsOpenDB(), and rpmtsOpenSDB().

int rpmdbOpenAll ( rpmdb  db)

Open all database indices.

Parameters
dbrpm database
Returns
0 on success

Definition at line 944 of file rpmdb.c.

References dbiOpen(), RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, and RPMDBI_REMOVED.

Referenced by rpmdbInit(), rpmdbVerifyAllDBI(), and rpmtsRun().

int rpmdbRebuild ( const char *  prefix,
rpmts  ts 
)
int rpmdbRemove ( rpmdb  db,
int  rid,
unsigned int  hdrNum,
rpmts  ts 
)
int rpmdbSync ( rpmdb  db)

Sync all database indices.

Parameters
dbrpm database
Returns
0 on success

Definition at line 1089 of file rpmdb.c.

Referenced by rpmtsRun().

rpmdb rpmdbUnlink ( rpmdb  db,
const char *  msg 
)

Unreference a database instance.

Parameters
dbrpm database
msg
Returns
NULL always
int rpmdbVerify ( const char *  prefix)

Open and verify all database components.

Parameters
prefixpath to top of install tree
Returns
0 on success

Definition at line 1390 of file rpmdb.c.

References rpmdbOpenDatabase(), rpmdbVerifyAllDBI(), and rpmExpandNumeric().

Referenced by rpmtsVerifyDB().

int rpmdbVerifyAllDBI ( rpmdb  db)

Verify all database components.

Parameters
dbrpm database
Returns
0 on success

Definition at line 1358 of file rpmdb.c.

References rpmdbClose(), and rpmdbOpenAll().

Referenced by db3open(), and rpmdbVerify().

int rpmmiAddPattern ( rpmmi  mi,
rpmTag  tag,
rpmMireMode  mode,
const char *  pattern 
)

Add pattern to iterator selector.

Parameters
mirpm database iterator
tagrpm tag
modetype of pattern match
patternpattern to match
Returns
0 on success

Definition at line 2207 of file rpmdb.c.

References _free(), _mirePool, rpmmi_s::mi_nre, rpmmi_s::mi_re, mireCmp(), mireDup(), mireFree(), mireGetPool(), mireNew(), mireRegcomp(), rpmExpand(), RPMMIRE_DEFAULT, RPMMIRE_GLOB, RPMMIRE_REGEX, RPMMIRE_STRCMP, and xrealloc().

Referenced by dbiFindMatches(), IDTXload(), rpmdbRebuild(), rpmgiInitFilter(), rpmmi_Pattern(), rpmpsmStage(), rpmtsInitIterator(), and rpmtsRun().

int rpmmiCount ( rpmmi  mi)

Return number of elements in rpm database iterator.

Parameters
mirpm database iterator
Returns
number of elements

Definition at line 2090 of file rpmdb.c.

References rpmmi_s::mi_set.

Referenced by ftsCacheUpdate(), rpmcliInstall(), rpmdbFindFpList(), rpmmi_Count(), rpmts_AddErase(), and runImmedTriggers().

unsigned int rpmmiFilenum ( rpmmi  mi)

Return header tag index join key for current position of rpmdb iterator.

Parameters
mirpm database iterator

Definition at line 2086 of file rpmdb.c.

References rpmmi_s::mi_filenum.

Referenced by rpmtsFindPubkey().

rpmmi rpmmiFree ( rpmmi  mi)
int rpmmiGrow ( rpmmi  mi,
const int *  hdrNums,
int  nHdrNums 
)

Append items to set of package instances to iterate.

Parameters
mirpm database iterator
hdrNumsarray of package instances
nHdrNumsnumber of elements in array
Returns
0 on success, 1 on failure (bad args)

Definition at line 2798 of file rpmdb.c.

References dbiAppendSet(), rpmmi_s::mi_set, and xcalloc().

Referenced by markReplacedFiles().

rpmmi rpmmiInit ( rpmdb  db,
rpmTag  tag,
const void *  keyp,
size_t  keylen 
)
unsigned int rpmmiInstance ( rpmmi  mi)

Return header instance join key for current position of rpmdb iterator.

Parameters
mirpm database iterator
Returns
current header join key

Definition at line 2082 of file rpmdb.c.

References rpmmi_s::mi_offset.

Referenced by IDTXload(), markReplacedFiles(), nwlookupTag(), rpmcliEraseElement(), rpmdbFindByFile(), rpmErase(), rpmgiNext(), rpmmi_Instance(), rpmpsmStage(), rpmts_AddErase(), rpmtsAddObsoletes(), rpmtsAddUpgrades(), rpmtsEraseDebuginfo(), rpmtsFindPubkey(), runImmedTriggers(), runTriggersLoop(), and wnlookupTag().

rpmmi rpmmiLink ( rpmmi  mi)

Reference a rpm database iterator.

Parameters
mirpm database iterator
Returns
NULL on last dereference
Header rpmmiNext ( rpmmi  mi)

Return next package header from iteration.

Parameters
mirpm database iterator
Returns
NULL on end of iteration.

< Is 1st header region mmap'd?

< Is 1st header region rdonly?

Definition at line 2501 of file rpmdb.c.

References _, _DBSWAP, _free(), _rpmmi_usermem, __db_dbt::data, DB_NEXT, DB_SET, dbiIndexRecordFileNumber(), dbiIndexRecordOffset(), dbiOpen(), headerToken_s::flags, headerCheck(), headerCopyLoad(), HEADERFLAG_MAPPED, HEADERFLAG_RDONLY, headerFree(), headerIsEntry(), headerLoad(), headerSetInstance(), headerSetOrigin(), rpmmi_s::mi_cflags, rpmmi_s::mi_db, rpmmi_s::mi_dbc, rpmmi_s::mi_filenum, rpmmi_s::mi_h, rpmmi_s::mi_modified, rpmmi_s::mi_offset, rpmmi_s::mi_prevoffset, rpmmi_s::mi_rpmtag, rpmmi_s::mi_set, rpmmi_s::mi_setx, rpmmi_s::mi_ts, miFreeHeader(), mireSkip(), PBM_ISSET, PBM_REALLOC(), PBM_SET, RPMDBI_PACKAGES, rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, rpmmiGet(), RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, RPMTAG_NAME, rpmtsCleanDig(), rpmtsDig(), __db_dbt::size, and _dbswap::ui.

Referenced by checkPackageSet(), dbiFindMatches(), handleInstInstalledFiles(), handleRmvdInstalledFiles(), IDTXload(), markReplacedFiles(), nwlookupTag(), rpmcliEraseElement(), rpmcliInstall(), rpmcliShowMatches(), rpmdb_length(), rpmdb_subscript(), rpmdbFindByFile(), rpmdbFindFpList(), rpmdbRebuild(), rpmdbRemove(), rpmErase(), rpmgiNext(), rpmmi_iternext(), rpmpsmStage(), rpmts_AddErase(), rpmtsAddObsoletes(), rpmtsAddUpgrades(), rpmtsEraseDebuginfo(), rpmtsFindPubkey(), rpmtsRun(), rpmtsSolve(), runImmedTriggers(), runTriggersLoop(), unsatisfiedDepend(), and wnlookupTag().

int rpmmiPrune ( rpmmi  mi,
int *  hdrNums,
int  nHdrNums,
int  sorted 
)

Remove items from set of package instances to iterate.

Note
Sorted hdrNums are always passed in rpmlib.
Parameters
mirpm database iterator
hdrNumsarray of package instances
nHdrNumsnumber of elements in array
sortedis the array sorted? (array will be sorted on return)
Returns
0 on success, 1 on failure (bad args)

Definition at line 2788 of file rpmdb.c.

References dbiPruneSet(), and rpmmi_s::mi_set.

Referenced by checkPackageSet(), nwlookupTag(), rpmtsAddObsoletes(), rpmtsEraseDebuginfo(), runImmedTriggers(), runTriggersLoop(), unsatisfiedDepend(), and wnlookupTag().

int rpmmiSetHdrChk ( rpmmi  mi,
rpmts  ts 
)

Modify iterator to verify retrieved header blobs.

Parameters
mirpm database iterator
tstransaction set
Returns
0 always

Definition at line 2441 of file rpmdb.c.

References rpmmi_s::mi_ts.

Referenced by rpmdbRebuild(), and rpmtsInitIterator().

int rpmmiSetModified ( rpmmi  mi,
int  modified 
)

Modify iterator to mark header for lazy write on release.

Parameters
mirpm database iterator
modifiednew value of modified
Returns
previous value

Definition at line 2431 of file rpmdb.c.

References rpmmi_s::mi_modified.

Referenced by markReplacedFiles().

int rpmmiSetRewrite ( rpmmi  mi,
int  rewrite 
)

Prepare iterator for lazy writes.

Note
Must be called before rpmmiNext() with CDB model database.
Parameters
mirpm database iterator
rewritenew value of rewrite
Returns
previous value

Definition at line 2418 of file rpmdb.c.

References DB_WRITECURSOR, and rpmmi_s::mi_cflags.

Referenced by markReplacedFiles().

rpmmi rpmmiUnlink ( rpmmi  mi)

Unreference a rpm database iterator.

Parameters
mirpm database iterator
Returns
NULL on last dereference