- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# RPMDB.

## Files
file | rpmlib.h
file | dbconfig.c
file | rpmdb.c
file | rpmdb.h
| Access RPM indices using Berkeley DB interface(s).

## Data Structures
struct | rpmdb_s
| Describes the collection of index databases used by rpm. More...
## RPMDB
typedef rpmdb_s * | rpmdb
typedef _dbiIndexSet * | dbiIndexSet
typedef _rpmdbMatchIterator * | rpmdbMatchIterator
int * | dbiTags
| Tags for which rpmdb indices will be built.
int | rpmdbOpen (const char *prefix, rpmdb *dbp, int mode, int perms)
| Open rpm database.
int | rpmdbInit (const char *prefix, int perms)
| Initialize database.
int | rpmdbVerify (const char *prefix)
| Verify 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 | rpmdbCountPackages (rpmdb db, const char *name)
| Return number of instances of package in rpm database.
rpmdbMatchIterator | rpmdbFreeIterator (rpmdbMatchIterator mi)
| Destroy rpm database iterator.
rpmdb | rpmdbGetIteratorRpmDB (rpmdbMatchIterator mi)
| Return rpm database used by iterator.
unsigned int | rpmdbGetIteratorOffset (rpmdbMatchIterator mi)
| Return join key for current position of rpm database iterator.
int | rpmdbGetIteratorCount (rpmdbMatchIterator mi)
| Return number of elements in rpm database iterator.
int | rpmdbAppendIterator (rpmdbMatchIterator mi, const int *hdrNums, int nHdrNums)
| Append items to set of package instances to iterate.
int | rpmdbPruneIterator (rpmdbMatchIterator mi, int *hdrNums, int nHdrNums, int sorted)
| Remove items from set of package instances to iterate.
int | rpmdbSetIteratorRE (rpmdbMatchIterator mi, rpmTag tag, rpmMireMode mode, const char *pattern)
| Add pattern to iterator selector.
int | rpmdbSetIteratorVersion (rpmdbMatchIterator mi, const char *version)
| Modify iterator to filter out headers that do not match version.
int | rpmdbSetIteratorRelease (rpmdbMatchIterator mi, const char *release)
| Modify iterator to filter out headers that do not match release.
int | rpmdbSetIteratorRewrite (rpmdbMatchIterator mi, int rewrite)
| Prepare iterator for lazy writes.
int | rpmdbSetIteratorModified (rpmdbMatchIterator mi, int modified)
| Modify iterator to mark header for lazy write.
Header | rpmdbNextIterator (rpmdbMatchIterator mi)
| Return next package header from iteration.
rpmdbMatchIterator | rpmdbInitIterator (rpmdb db, int rpmtag, const void *keyp, size_t keylen)
| Return database iterator.
int | rpmdbAdd (rpmdb db, int iid, Header h)
| Add package header to rpm database and indices.
int | rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum)
| Remove package header from rpm database and indices.
int | rpmdbRebuild (const char *prefix)
| Rebuild database indices from package headers.
## Enumerations
enum | rpmdbFlags { RPMDB_FLAG_JUSTCHECK = (1 << 0), RPMDB_FLAG_MINIMAL = (1 << 1), RPMDB_FLAG_CHROOT = (1 << 2) }
## Functions
int | rpmdbFindFpList (rpmdb db, fingerPrint *fpList, dbiIndexSet *matchList, int numItems)
| Find fingerprint matches in database.
unsigned int | rpmdbGetIteratorFileNum (rpmdbMatchIterator mi)

## Typedef Documentation

typedef struct _dbiIndexSet* dbiIndexSet

Definition at line 674 of file rpmlib.h.

typedef struct rpmdb_s* rpmdb

Definition at line 670 of file rpmlib.h.

typedef struct _rpmdbMatchIterator* rpmdbMatchIterator

Definition at line 754 of file rpmlib.h.

## Enumeration Type Documentation

enum rpmdbFlags

Enumerator:

  RPMDB_FLAG_JUSTCHECK |
  RPMDB_FLAG_MINIMAL |
  RPMDB_FLAG_CHROOT |

Definition at line 338 of file rpmdb.h.

## Function Documentation

int rpmdbAdd | ( | rpmdb | db,
|  | int | iid,
|  | Header | h |
| ) |  |  |

Add package header to rpm database and indices.

Parameters:

  | db | rpm database
  | iid | install transaction id (iid = 0 or -1 to skip)
  | h | header

Returns:
  0 on success

Definition at line 2592 of file rpmdb.c.

References _, _free(), _noDirTokens, addIndexEntry(), blockSignals(), DBC, _dbiIndex::dbi_no_dbsync, _dbiIndex::dbi_rpmtag, DBI_WRITECURSOR, dbiCclose(), dbiCopen(), dbiGet(), dbiIndexNewItem(), dbiOpen(), dbiPut(), dbiSync(), dbiTags, dbiTagsMax, dbiUpdateRecord(), expandFilelist(), HEADER_MAGIC_NO, headerAddEntry(), headerFreeData(), headerGetEntryMinMemory(), headerIsEntry(), headerNVR(), headerRemoveEntry(), headerSizeof(), isInstallPreReq, RPM_BIN_TYPE, RPM_CHAR_TYPE, RPM_I18NSTRING_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT8_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_PACKAGES, RPMDBI_REMOVED, RPMERR_DBCORRUPT, rpmError, RPMMESS_DEBUG, rpmMessage, RPMTAG_BASENAMES, RPMTAG_GROUP, RPMTAG_INSTALLTID, RPMTAG_REMOVETID, RPMTAG_REQUIREFLAGS, RPMTAG_REQUIRENAME, RPMTAG_TRIGGERNAME, tagName(), and _dbiIndexItem::tagNum.

Referenced by rpmdbRebuild().

int rpmdbAppendIterator | ( | rpmdbMatchIterator | mi,
|  | const int * | hdrNums,
|  | int | nHdrNums |
| ) |  |  |

Append items to set of package instances to iterate.

Parameters:

  | mi | rpm database iterator
  | hdrNums | array of package instances
  | nHdrNums | number of elements in array

Returns:
  0 on success, 1 on failure (bad args)

Definition at line 2217 of file rpmdb.c.

References dbiAppendSet(), and xcalloc().

Referenced by markReplacedFiles(), rpmdepCheck(), and rpmRunTransactions().

int rpmdbClose | ( | rpmdb | db | ) |

Close all database indices and free rpmdb.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 813 of file rpmdb.c.

References _free(), and dbiClose().

Referenced by checkSpec(), main(), openDatabase(), rpmdbDealloc(), rpmdbInit(), rpmdbRebuild(), rpmdbVerify(), rpmErase(), rpmQuery(), rpmRollback(), rpmVerify(), and ugFindUpgradePackages().

int rpmdbCountPackages | ( | rpmdb | db,
|  | const char * | name |
| ) |  |  |

Return number of instances of package in rpm database.

Parameters:

  | db | rpm database
  | name | rpm package name

Returns:
  number of instances

Definition at line 1249 of file rpmdb.c.

References _, DBC, dbiCclose(), dbiCopen(), dbiFreeIndexSet(), dbiIndexSetCount(), dbiOpen(), dbiSearch(), RPMERR_DBCORRUPT, rpmError, and RPMTAG_NAME.

Referenced by findPackagesWithObsoletes(), handleOneTrigger(), psmStage(), and runTriggers().

int rpmdbFindFpList | ( | rpmdb | db,
|  | fingerPrint * | fpList,
|  | dbiIndexSet * | matchList,
|  | int | numItems |
| ) |  |  |

Find fingerprint matches in database.

Parameters:

  | db | rpm database
  | fpList | fingerprint array

Return values:

  | matchList | returned fingerprint matches

Parameters:

  | numItems | number of fingerprint items

Returns:
  0 always

Definition at line 2876 of file rpmdb.c.

References _free(), dbiAppendSet(), FP_EQUAL, fpCacheCreate(), fpLookupList(), _dbiIndexItem::fpNum, _dbiIndexItem::hdrNum, headerFreeData(), headerGetEntryMinMemory(), rpmdbFreeIterator(), rpmdbGetIteratorCount(), rpmdbGrowIterator(), rpmdbInitIterator(), rpmdbNextIterator(), rpmdbSortIterator(), RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, _dbiIndexItem::tagNum, and xcalloc().

Referenced by rpmRunTransactions().

rpmdbMatchIterator rpmdbFreeIterator | ( | rpmdbMatchIterator | mi | ) |

Destroy rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  NULL always

Definition at line 1548 of file rpmdb.c.

References _free(), _dbiIndex::dbi_rmw, dbiCclose(), dbiOpen(), dbiUpdateRecord(), headerFree(), and RPMDBI_PACKAGES.

Referenced by addLostFiles(), checkPackageSet(), dbiFindMatches(), findUpgradePackages(), handleDbResult(), handleInstInstalledFiles(), handleRmvdInstalledFiles(), IDTXload(), main(), markReplacedFiles(), psmStage(), rpmdbFindByFile(), rpmdbFindFpList(), rpmdbFirst(), rpmdbLength(), rpmdbMIDealloc(), rpmdbRebuild(), rpmdbRemove(), rpmdbSubscript(), rpmdepCheck(), rpmErase(), rpmInstall(), rpmQueryVerify(), rpmRunTransactions(), rpmtransAddPackage(), rpmtransRemove(), runImmedTriggers(), runTriggers(), showMatches(), unmarkPackagesAlreadyInstalled(), and unsatisfiedDepend().

int rpmdbGetIteratorCount | ( | rpmdbMatchIterator | mi | ) |

Return number of elements in rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  number of elements

Definition at line 1618 of file rpmdb.c.

Referenced by rpmdbFindFpList(), rpmErase(), rpmInstall(), rpmtransRemove(), and runImmedTriggers().

unsigned int rpmdbGetIteratorFileNum | ( | rpmdbMatchIterator | mi | ) |

Definition at line 1612 of file rpmdb.c.

unsigned int rpmdbGetIteratorOffset | ( | rpmdbMatchIterator | mi | ) |

Return join key for current position of rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  current join key

Definition at line 1606 of file rpmdb.c.

Referenced by handleDbResult(), IDTXload(), markReplacedFiles(), psmStage(), rpmdbFirst(), rpmErase(), rpmtransAddPackage(), and rpmtransRemove().

rpmdb rpmdbGetIteratorRpmDB | ( | rpmdbMatchIterator | mi | ) |

Return rpm database used by iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  rpm database handle

Definition at line 1598 of file rpmdb.c.

Referenced by showMatches().

int rpmdbInit | ( | const char * | prefix,
|  | int | perms |
| ) |  |  |

Initialize database.

Parameters:

  | prefix | path to top of install tree
  | perms | database permissions

Returns:
  0 on success

Definition at line 1067 of file rpmdb.c.

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

Referenced by main(), and rpmInitDB().

rpmdbMatchIterator rpmdbInitIterator | ( | rpmdb | db,
|  | int | rpmtag,
|  | const void * | keyp,
|  | size_t | keylen |
| ) |  |  |

Return database iterator.

Parameters:

  | db | rpm database
  | rpmtag | rpm tag
  | keyp | key data (NULL for sequential access)
  | keylen | key data length (0 will use strlen(keyp))

Returns:
  NULL on failure

Definition at line 2228 of file rpmdb.c.

References DBC, _dbiIndex::dbi_lastoffset, _dbiIndex::dbi_rmw, dbiCclose(), dbiCopen(), dbiFindByLabel(), dbiFreeIndexSet(), dbiOpen(), dbiSearch(), rpmdbFindByFile(), RPMDBI_LABEL, RPMDBI_PACKAGES, RPMTAG_BASENAMES, RPMTAG_NAME, tagName(), xcalloc(), and xmalloc().

Referenced by addLostFiles(), checkDependentConflicts(), checkDependentPackages(), dbiFindMatches(), findUpgradePackages(), handleInstInstalledFiles(), handleRmvdInstalledFiles(), IDTXload(), main(), markReplacedFiles(), psmStage(), py_rpmdbInitIterator(), rpmdbByFile(), rpmdbByName(), rpmdbByProvides(), rpmdbFindByFile(), rpmdbFindFpList(), rpmdbFirst(), rpmdbLength(), rpmdbRebuild(), rpmdbRemove(), rpmdbSubscript(), rpmdepCheck(), rpmErase(), rpmInstall(), rpmQueryVerify(), rpmRunTransactions(), rpmtransAddPackage(), rpmtransRemove(), runImmedTriggers(), runTriggers(), unmarkPackagesAlreadyInstalled(), and unsatisfiedDepend().

Header rpmdbNextIterator | ( | rpmdbMatchIterator | mi | ) |

Return next package header from iteration.

Parameters:

  | mi | rpm database iterator

Returns:
  NULL on end of iteration.

Definition at line 2019 of file rpmdb.c.

References _, _free(), _dbiIndex::dbi_api, DBI_ITERATOR, _dbiIndex::dbi_lastoffset, _dbiIndex::dbi_rpmtag, dbiCopen(), dbiGet(), dbiIndexRecordFileNumber(), dbiIndexRecordOffset(), dbiOpen(), dbiUpdateRecord(), headerCopyLoad(), headerFree(), headerIsEntry(), headerNVR(), mireSkip(), RPMDBI_PACKAGES, RPMERR_BADHEADER, RPMERR_INTERNAL, rpmError, RPMMESS_DEBUG, rpmMessage, and RPMTAG_NAME.

Referenced by addLostFiles(), checkPackageSet(), dbiFindMatches(), findUpgradePackages(), handleDbResult(), handleInstInstalledFiles(), handleRmvdInstalledFiles(), IDTXload(), main(), markReplacedFiles(), psmStage(), rpmdbFindByFile(), rpmdbFindFpList(), rpmdbFirst(), rpmdbLength(), rpmdbMINext(), rpmdbRebuild(), rpmdbRemove(), rpmdbSubscript(), rpmdepCheck(), rpmErase(), rpmInstall(), rpmRunTransactions(), rpmtransAddPackage(), rpmtransRemove(), runImmedTriggers(), runTriggers(), showMatches(), unmarkPackagesAlreadyInstalled(), unsatisfiedDepend(), and XrpmdbNextIterator().

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

Open rpm database.

Parameters:

  | prefix | path to top of install tree

Return values:

  | dbp | address of rpm database

Parameters:

  | mode | open(2) flags: O_RDWR or O_RDONLY (O_CREAT also)
  | perms | database permissions

Returns:
  0 on success

Definition at line 1059 of file rpmdb.c.

References openDatabase(), and rpmExpandNumeric().

Referenced by checkSpec(), main(), rpmErase(), rpmInstall(), rpmOpenDB(), rpmQuery(), rpmRollback(), rpmVerify(), and ugFindUpgradePackages().

int rpmdbOpenAll | ( | rpmdb | db | ) |

Open all database indices.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 796 of file rpmdb.c.

References dbiOpen(), dbiTags, and dbiTagsMax.

Referenced by rpmdbInit(), and rpmdbVerify().

int rpmdbPruneIterator | ( | rpmdbMatchIterator | 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:

  | mi | rpm database iterator
  | hdrNums | array of package instances
  | nHdrNums | number of elements in array
  | sorted | is the array sorted? (array will be sorted on return)

Returns:
  0 on success, 1 on failure (bad args)

Definition at line 2206 of file rpmdb.c.

References dbiPruneSet().

Referenced by checkPackageSet(), rpmtransAddPackage(), and unsatisfiedDepend().

int rpmdbRebuild | ( | const char * | prefix | ) |

Rebuild database indices from package headers.

Parameters:

  | prefix | path to top of install tree

Returns:
  0 on success

Definition at line 3230 of file rpmdb.c.

References _, _db_filter_dups, _free(), _rebuildinprogress, _RECNUM, errno, F_OK, headerCopy(), headerFree(), headerIsEntry(), headerNVR(), Mkdir(), name, openDatabase(), Rmdir(), RPMDB_FLAG_MINIMAL, rpmdbAdd(), rpmdbClose(), rpmdbFreeIterator(), RPMDBI_PACKAGES, rpmdbInitIterator(), rpmdbMoveDatabase(), rpmdbNextIterator(), rpmdbRemoveDatabase(), rpmdbSetIteratorRE(), rpmDefineMacro(), RPMERR_INTERNAL, RPMERR_MKDIR, rpmError, rpmExpandNumeric(), rpmGetPath(), RPMMESS_DEBUG, RPMMESS_ERROR, RPMMESS_NORMAL, rpmMessage, RPMMIRE_DEFAULT, RPMTAG_BUILDTIME, RPMTAG_HEADERIMAGE, RPMTAG_NAME, RPMTAG_RELEASE, RPMTAG_VERSION, stpcpy(), strerror(), and xmalloc().

Referenced by main(), and rebuildDB().

int rpmdbRemove | ( | rpmdb | db,
|  | int | rid,
|  | unsigned int | hdrNum |
| ) |  |  |

Remove package header from rpm database and indices.

Parameters:

  | db | rpm database
  | rid | remove transaction id (rid = 0 or -1 to skip)
  | hdrNum | package instance number in database

Returns:
  0 on success

Definition at line 2368 of file rpmdb.c.

References _, _free(), blockSignals(), DBC, DBI_WRITECURSOR, dbiCclose(), dbiCopen(), dbiDel(), dbiIndexNewItem(), dbiOpen(), dbiSync(), dbiTags, dbiTagsMax, headerAddEntry(), headerFree(), headerFreeData(), headerGetEntryMinMemory(), headerLink(), headerNVR(), removeIndexEntry(), RPM_BIN_TYPE, RPM_CHAR_TYPE, RPM_I18NSTRING_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT8_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, rpmdbFreeIterator(), RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_PACKAGES, RPMDBI_REMOVED, rpmdbInitIterator(), rpmdbNextIterator(), RPMERR_DBCORRUPT, rpmError, RPMMESS_DEBUG, rpmMessage, RPMTAG_REMOVETID, tagName(), and unblockSignals().

int rpmdbSetIteratorModified | ( | rpmdbMatchIterator | mi,
|  | int | modified |
| ) |  |  |

Modify iterator to mark header for lazy write.

Parameters:

  | mi | rpm database iterator
  | modified | new value of modified

Returns:
  previous value

Definition at line 2004 of file rpmdb.c.

Referenced by markReplacedFiles().

int rpmdbSetIteratorRE | ( | rpmdbMatchIterator | mi,
|  | rpmTag | tag,
|  | rpmMireMode | mode,
|  | const char * | pattern |
| ) |  |  |

Add pattern to iterator selector.

Parameters:

  | mi | rpm database iterator
  | tag | rpm tag
  | mode | type of pattern match
  | pattern | pattern to match

Returns:
  0 on success

Definition at line 1774 of file rpmdb.c.

References _free(), miRE_s::cflags, miRE_s::eflags, miRE_s::fnflags, mireCmp(), mireDup(), miRE_s::mode, miRE_s::notmatch, miRE_s::pattern, miRE_s::preg, RPMERR_REGCOMP, rpmError, rpmExpand(), RPMMIRE_DEFAULT, RPMMIRE_GLOB, RPMMIRE_REGEX, RPMMIRE_STRCMP, miRE_s::tag, xcalloc(), and xrealloc().

Referenced by dbiFindMatches(), psmStage(), rpmdbRebuild(), rpmdbSetIteratorRelease(), rpmdbSetIteratorVersion(), rpmQueryVerify(), and rpmRunTransactions().

int rpmdbSetIteratorRelease | ( | rpmdbMatchIterator | mi,
|  | const char * | release |
| ) |  |  |

Modify iterator to filter out headers that do not match release.

Deprecated:
  Use rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT, release) instead.

Todo:
  Eliminate from API.

Parameters:

  | mi | rpm database iterator
  | release | release to match (can be a regex pattern)

Returns:
  0 on success

Definition at line 1984 of file rpmdb.c.

References rpmdbSetIteratorRE(), RPMMIRE_DEFAULT, and RPMTAG_RELEASE.

int rpmdbSetIteratorRewrite | ( | rpmdbMatchIterator | mi,
|  | int | rewrite |
| ) |  |  |

Prepare iterator for lazy writes.

Note:
  Must be called before rpmdbNextIterator() in CDB model database.

Parameters:

  | mi | rpm database iterator
  | rewrite | new value of rewrite

Returns:
  previous value

Definition at line 1992 of file rpmdb.c.

References DBI_WRITECURSOR.

Referenced by markReplacedFiles().

int rpmdbSetIteratorVersion | ( | rpmdbMatchIterator | mi,
|  | const char * | version |
| ) |  |  |

Modify iterator to filter out headers that do not match version.

Deprecated:
  Use rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT, version) instead.

Todo:
  Eliminate from API.

Parameters:

  | mi | rpm database iterator
  | version | version to match (can be a regex pattern)

Returns:
  0 on success

Definition at line 1988 of file rpmdb.c.

References rpmdbSetIteratorRE(), RPMMIRE_DEFAULT, and RPMTAG_VERSION.

int rpmdbSync | ( | rpmdb | db | ) |

Sync all database indices.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 840 of file rpmdb.c.

References dbiSync().

int rpmdbVerify | ( | const char * | prefix | ) |

Verify database components.

Parameters:

  | prefix | path to top of install tree

Returns:
  0 on success

Definition at line 1088 of file rpmdb.c.

References dbiVerify(), openDatabase(), rpmdbClose(), rpmdbOpenAll(), and rpmExpandNumeric().

Referenced by main().

## Variable Documentation

int* dbiTags

Tags for which rpmdb indices will be built.

Definition at line 61 of file rpmdb.c.

Referenced by dbiTagsInit(), dbiTagToDbix(), main(), openDatabase(), rpmdbAdd(), rpmdbCloseDBI(), rpmdbMoveDatabase(), rpmdbOpenAll(), rpmdbRemove(), and rpmdbRemoveDatabase().