Main Page Modules Data Structures File List Data Fields Globals Related Pages

# RPM database API.

## Files

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

file | rpmlib.h

## Data Structures

struct | rpmdb_s

## Typedefs

typedef rpmdb_s * | rpmdb
typedef _rpmdbMatchIterator * | rpmdbMatchIterator
typedef _dbiIndexSet * | dbiIndexSet

## 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)
unsigned int | rpmdbGetIteratorFileNum (rpmdbMatchIterator mi)
rpmdb | rpmdbUnlink (rpmdb db, const char *msg)
rpmdb | rpmdbLink (rpmdb db, const char *msg)
int | rpmdbOpen (const char *prefix, rpmdb *dbp, int mode, int perms)
int | rpmdbInit (const char *prefix, int perms)
int | rpmdbVerify (const char *prefix)
int | rpmdbClose (rpmdb db)
int | rpmdbSync (rpmdb db)
int | rpmdbOpenAll (rpmdb db)
int | rpmdbCountPackages (rpmdb db, const char *name)
unsigned int | rpmdbGetIteratorOffset (rpmdbMatchIterator mi)
int | rpmdbGetIteratorCount (rpmdbMatchIterator mi)
int | rpmdbAppendIterator (rpmdbMatchIterator mi, const int *hdrNums, int nHdrNums)
int | rpmdbPruneIterator (rpmdbMatchIterator mi, int *hdrNums, int nHdrNums, int sorted)
int | rpmdbSetIteratorRE (rpmdbMatchIterator mi, rpmTag tag, rpmMireMode mode, const char *pattern)
int | rpmdbSetIteratorRewrite (rpmdbMatchIterator mi, int rewrite)
int | rpmdbSetIteratorModified (rpmdbMatchIterator mi, int modified)
int | rpmdbSetHdrChk (rpmdbMatchIterator mi, rpmts ts, rpmRC(*hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg))
rpmdbMatchIterator | rpmdbInitIterator (rpmdb db, rpmTag rpmtag, const void *keyp, size_t keylen)
Header | rpmdbNextIterator (rpmdbMatchIterator mi)
int | rpmdbCheckSignals (void)
rpmdbMatchIterator | rpmdbFreeIterator (rpmdbMatchIterator mi)
int | rpmdbAdd (rpmdb db, int iid, Header h, rpmts ts, rpmRC(*hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg))
int | rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum, rpmts ts, rpmRC(*hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg))
int | rpmdbRebuild (const char *prefix, rpmts ts, rpmRC(*hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg))

## Variables

int * | dbiTags

## Typedef Documentation

typedef struct _dbiIndexSet* dbiIndexSet

| A single element (i.e. inverted list from tag values) of a database. Definition at line 48 of file rpmdb.h.

typedef struct rpmdb_s* rpmdb

| Database of headers and tag value indices. Definition at line 101 of file rpmlib.h.

typedef struct _rpmdbMatchIterator* rpmdbMatchIterator

| Database iterator. Definition at line 106 of file rpmlib.h.

## Enumeration Type Documentation

enum rpmdbFlags

Enumeration values:

  RPMDB_FLAG_JUSTCHECK |
  RPMDB_FLAG_MINIMAL |
  RPMDB_FLAG_CHROOT |

Definition at line 440 of file rpmdb.h.

## Function Documentation

int rpmdbAdd | ( | rpmdb | db,
|  | int | iid,
|  | Header | h,
|  | rpmts | ts,
|  | rpmRC(* | hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg)
| ) |

Add package header to rpm database and indices.

Parameters:

  db | rpm database
  iid | install transaction id (iid = 0 or -1 to skip)
  h | header
  ts | (unused) transaction set (or NULL)
  hdrchk | ) (unused) headerCheck() vector (or NULL)

Returns:
  0 on success

Definition at line 2848 of file rpmdb.c.

Referenced by ftsCacheUpdate, rpmcliImportPubkey, and 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 2413 of file rpmdb.c.

int rpmdbCheckSignals | ( | void |  | ) |

| Check rpmdb signal handler for trapped signal exit. Definition at line 692 of file rpmdb.c. References _dbiVec::associate, callback, and _dbiIndex::dbi_vec.

int rpmdbClose | ( | rpmdb | db | ) |

Close all database indices and free rpmdb.

Parameters:

  db | rpm database

Returns:
  0 on success

Definition at line 840 of file rpmdb.c.

Referenced by main, openDatabase, rpmdb_dealloc, rpmdbCheckSignals, rpmdbInit, rpmdbRebuild, rpmdbVerify, rpmtsCloseDB, rpmtsCloseSDB, 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 1304 of file rpmdb.c.

Referenced by findPackagesWithObsoletes.

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 3301 of file rpmdb.c.

rpmdbMatchIterator rpmdbFreeIterator | ( | rpmdbMatchIterator | mi | ) |

Destroy rpm database iterator.

Parameters:

  mi | rpm database iterator

Returns:
  NULL always

Definition at line 1662 of file rpmdb.c.

Referenced by addLostFiles, checkPackageSet, dbiFindMatches, findUpgradePackages, ftsCacheUpdate, IDTXload, main, rpmcliShowMatches, rpmdb_length, rpmdb_subscript, rpmdbFindByFile, rpmdbFindFpList, rpmdbRebuild, rpmdbRemove, rpmErase, rpmInstall, rpmmi_dealloc, rpmmi_iternext, rpmQueryVerify, rpmts_AddErase, rpmtsAddInstallElement, rpmtsCheck, rpmtsFindPubkey, rpmtsSolve, 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 1712 of file rpmdb.c.

Referenced by ftsCacheUpdate, rpmdbFindFpList, rpmErase, rpmInstall, rpmmi_Count, and rpmts_AddErase.

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

| Definition at line 1708 of file rpmdb.c. Referenced by rpmtsFindPubkey.

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

Return header join key for current position of rpm database iterator.

Parameters:

  mi | rpm database iterator

Returns:
  current header join key

Definition at line 1704 of file rpmdb.c.

Referenced by IDTXload, rpmErase, rpmmi_Instance, rpmts_AddErase, and rpmtsAddInstallElement.

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 1092 of file rpmdb.c.

Referenced by rpmtsInitDB.

rpmdbMatchIterator rpmdbInitIterator | ( | rpmdb | db,
|  | rpmTag | 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 2424 of file rpmdb.c.

Referenced by addLostFiles, dbiFindMatches, findUpgradePackages, main, rpmdb_length, rpmdb_Match, rpmdb_subscript, rpmdbFindByFile, rpmdbFindFpList, rpmdbRebuild, rpmdbRemove, rpmtsInitIterator, rpmtsSolve, and unmarkPackagesAlreadyInstalled.

rpmdb rpmdbLink | ( | rpmdb | db,
|  | const char * | msg
| ) |

Reference a database instance.

Parameters:

  db | rpm database
  msg |

Returns:
  new rpm database reference

Header rpmdbNextIterator | ( | rpmdbMatchIterator | mi | ) |

Return next package header from iteration.

Parameters:

  mi | rpm database iterator

Returns:
  NULL on end of iteration.

Definition at line 2126 of file rpmdb.c.

Referenced by addLostFiles, checkPackageSet, dbiFindMatches, findUpgradePackages, IDTXload, main, rpmcliShowMatches, rpmdb_length, rpmdb_subscript, rpmdbFindByFile, rpmdbFindFpList, rpmdbRebuild, rpmdbRemove, rpmErase, rpmInstall, rpmmi_iternext, rpmts_AddErase, rpmtsAddInstallElement, rpmtsFindPubkey, rpmtsSolve, unmarkPackagesAlreadyInstalled, and unsatisfiedDepend.

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 1084 of file rpmdb.c.

Referenced by main, rpmtsOpenDB, rpmtsOpenSDB, 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.

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 2402 of file rpmdb.c.

Referenced by checkPackageSet, rpmtsAddInstallElement, and unsatisfiedDepend.

int rpmdbRebuild | ( | const char * | prefix,
|  | rpmts | ts,
|  | rpmRC(* | hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg)
| ) |

Rebuild database indices from package headers.

Parameters:

  prefix | path to top of install tree
  ts | transaction set (or NULL)
  hdrchk | ) headerCheck() vector (or NULL)

Returns:
  0 on success

Definition at line 3635 of file rpmdb.c.

Referenced by rpmtsRebuildDB.

int rpmdbRemove | ( | rpmdb | db,
|  | int | rid,
|  | unsigned int | hdrNum,
|  | rpmts | ts,
|  | rpmRC(* | hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg)
| ) |

Remove package header from rpm database and indices.

Parameters:

  db | rpm database
  rid | (unused) remove transaction id (rid = 0 or -1 to skip)
  hdrNum | package instance number in database
  ts | (unused) transaction set (or NULL)
  hdrchk | ) (unused) headerCheck() vector (or NULL)

Returns:
  0 on success

Definition at line 2542 of file rpmdb.c.

int rpmdbSetHdrChk | ( | rpmdbMatchIterator | mi,
|  | rpmts | ts,
|  | rpmRC(* | hdrchk)(rpmts ts, const void *uh, size_t uc, const char **msg)
| ) |

Modify iterator to verify retrieved header blobs.

Parameters:

  mi | rpm database iterator
  ts | transaction set
  hdrchk | ) headerCheck() vector

Returns:
  0 always

Definition at line 2111 of file rpmdb.c.

Referenced by rpmdbRebuild, and rpmtsInitIterator.

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

Modify iterator to mark header for lazy write on release.

Parameters:

  mi | rpm database iterator
  modified | new value of modified

Returns:
  previous value

Definition at line 2101 of file rpmdb.c.

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 1869 of file rpmdb.c.

Referenced by dbiFindMatches, rpmdbRebuild, rpmmi_Pattern, and rpmQueryVerify.

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

Prepare iterator for lazy writes.

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

Parameters:

  mi | rpm database iterator
  rewrite | new value of rewrite

Returns:
  previous value

Definition at line 2088 of file rpmdb.c.

int rpmdbSync | ( | rpmdb | db | ) |

Sync all database indices.

Parameters:

  db | rpm database

Returns:
  0 on success

Definition at line 893 of file rpmdb.c.

rpmdb rpmdbUnlink | ( | rpmdb | db,
|  | const char * | msg
| ) |

Unreference a database instance.

Parameters:

  db | rpm database
  msg |

Returns:
  NULL always

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

Verify database components.

Parameters:

  prefix | path to top of install tree

Returns:
  0 on success

Definition at line 1113 of file rpmdb.c.

Referenced by rpmtsVerifyDB.

## Variable Documentation

int* dbiTags

| Tags for which rpmdb indices will be built. Definition at line 791 of file rpmdb.h.