#include <rpm/rpmsw.h>
#include <rpm/rpmtypes.h>
#include <rpm/rpmutil.h>
-
-/**
- */
-typedef struct _dbiIndexItem * dbiIndexItem;
-
-/** \ingroup rpmdb
- * A single element (i.e. inverted list from tag values) of a database.
- */
-typedef struct _dbiIndexSet * dbiIndexSet;
-
-/**
- */
-typedef struct _dbiIndex * dbiIndex;
-
-/* this will break if sizeof(int) != 4 */
-/** \ingroup dbi
- * A single item from an index database (i.e. the "data returned").
- * Note: In rpm-3.0.4 and earlier, this structure was passed by value,
- * and was identical to the "data saved" structure below.
- */
-struct _dbiIndexItem {
- unsigned int hdrNum; /*!< header instance in db */
- unsigned int tagNum; /*!< tag index in header */
-};
-
-/** \ingroup dbi
- * Items retrieved from the index database.
- */
-struct _dbiIndexSet {
- struct _dbiIndexItem * recs; /*!< array of records */
- unsigned int count; /*!< number of records */
- size_t alloced; /*!< alloced size */
-};
-
-/** \ingroup dbi
- * Describes an index database (implemented on Berkeley db functionality).
- */
-struct _dbiIndex {
- char * dbi_file; /*!< file component of path */
-
- int dbi_ecflags; /*!< db_env_create flags */
- int dbi_cflags; /*!< db_create flags */
- int dbi_oeflags; /*!< common (db,dbenv}->open flags */
- int dbi_eflags; /*!< dbenv->open flags */
- int dbi_oflags; /*!< db->open flags */
- int dbi_tflags; /*!< dbenv->txn_begin flags */
-
- int dbi_type; /*!< db index type */
- unsigned dbi_mode; /*!< mode to use on open */
- int dbi_perms; /*!< file permission to use on open */
-
- int dbi_verify_on_close;
- int dbi_use_dbenv; /*!< use db environment? */
- int dbi_permit_dups; /*!< permit duplicate entries? */
- int dbi_no_fsync; /*!< no-op fsync for db */
- int dbi_no_dbsync; /*!< don't call dbiSync */
- int dbi_lockdbfd; /*!< do fcntl lock on db fd */
- int dbi_byteswapped;
-
- /* dbenv parameters */
- int dbi_lorder;
- /* XXX db-4.3.14 adds dbenv as 1st arg. */
- int dbi_verbose;
- /* mpool sub-system parameters */
- int dbi_mmapsize; /*!< (10Mb) */
- int dbi_cachesize; /*!< (128Kb) */
- /* dbinfo parameters */
- int dbi_pagesize; /*!< (fs blksize) */
- /* hash access parameters */
- unsigned int dbi_h_ffactor; /*!< */
- unsigned int (*dbi_h_hash_fcn) (DB *, const void *bytes,
- unsigned int length);
- unsigned int dbi_h_nelem; /*!< */
- unsigned int dbi_h_flags; /*!< DB_DUP, DB_DUPSORT */
- int (*dbi_h_dup_compare_fcn) (DB *, const DBT *, const DBT *);
- /* btree access parameters */
- int dbi_bt_flags;
- int dbi_bt_minkey;
- int (*dbi_bt_compare_fcn) (DB *, const DBT *, const DBT *);
- int (*dbi_bt_dup_compare_fcn) (DB *, const DBT *, const DBT *);
- size_t (*dbi_bt_prefix_fcn) (DB *, const DBT *, const DBT *);
- /* recno access parameters */
- int dbi_re_flags;
- int dbi_re_delim;
- unsigned int dbi_re_len;
- int dbi_re_pad;
- char * dbi_re_source;
- /* queue access parameters */
- unsigned int dbi_q_extentsize;
-
- rpmdb dbi_rpmdb; /*!< the parent rpm database */
- rpmTag dbi_rpmtag; /*!< rpm tag used for index */
- int dbi_jlen; /*!< size of join key */
-
- DB * dbi_db; /*!< Berkeley DB * handle */
- DB_TXN * dbi_txnid; /*!< Bekerley DB_TXN * transaction id */
- void * dbi_stats; /*!< Berkeley db statistics */
-};
-
-/** \ingroup rpmdb
- * Describes the collection of index databases used by rpm.
- */
-struct rpmdb_s {
- char * db_root;/*!< path prefix */
- char * db_home;/*!< directory path */
- char * db_fullpath; /*!< full db path including prefix */
- int db_flags;
- int db_mode; /*!< open mode */
- int db_perms; /*!< open permissions */
- int db_api; /*!< Berkeley API type */
- int db_remove_env;
- int db_chrootDone; /*!< If chroot(2) done, ignore db_root. */
- int db_mkdirDone; /*!< Has db_home been created? */
- unsigned char * db_bits; /*!< package instance bit mask. */
- int db_nbits; /*!< no. of bits in mask. */
- rpmdb db_next;
- int db_opens;
- void * db_dbenv; /*!< Berkeley DB_ENV handle. */
- int db_ndbi; /*!< No. of tag indices. */
- dbiIndex * _dbi; /*!< Tag indices. */
-
- struct rpmop_s db_getops;
- struct rpmop_s db_putops;
- struct rpmop_s db_delops;
-
- int nrefs; /*!< Reference count. */
-};
-
-/* for RPM's internal use only */
-
-/** \ingroup rpmdb
- */
-enum rpmdbFlags {
- RPMDB_FLAG_JUSTCHECK = (1 << 0),
- RPMDB_FLAG_MINIMAL = (1 << 1),
- RPMDB_FLAG_CHROOT = (1 << 2)
-};
+#include "lib/backend/dbi.h"
#ifdef __cplusplus
extern "C" {
#endif
-/** \ingroup dbi
- * Return new configured index database handle instance.
- * @param rpmdb rpm database
- * @param rpmtag rpm tag
- * @return index database handle
- */
-RPM_GNUC_INTERNAL
-dbiIndex dbiNew(rpmdb rpmdb, rpmTag rpmtag);
-
-/** \ingroup dbi
- * Destroy index database handle instance.
- * @param dbi index database handle
- * @return NULL always
- */
-RPM_GNUC_INTERNAL
-dbiIndex dbiFree( dbiIndex dbi);
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
+#define HASHTYPE removedHash
+#define HTKEYTYPE unsigned int
+#define HTDATATYPE struct rpmte_s *
+#include "rpmhash.H"
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
-/** \ingroup dbi
- * Format dbi open flags for debugging print.
- * @param dbflags db open flags
- * @param print_dbenv_flags format db env flags instead?
- * @return formatted flags (malloced)
- */
-RPM_GNUC_INTERNAL
-char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
-
-/** \ingroup dbi
- * Return handle for an index database.
+/** \ingroup rpmdb
+ * Reference a database instance.
* @param db rpm database
- * @param rpmtag rpm tag
- * @param flags (unused)
- * @return index database handle
+ * @return new rpm database reference
*/
-RPM_GNUC_INTERNAL
-dbiIndex dbiOpen(rpmdb db, rpmTag rpmtag,
- unsigned int flags);
-
+rpmdb rpmdbLink(rpmdb db);
-/** \ingroup dbi
- * Actually open the database of the index.
- * @param db rpm database
- * @param rpmtag rpm tag
- * @param dbiIndex address of index database handle
+/** \ingroup rpmdb
+ * Open rpm database.
+ * @param prefix path to top of install tree
+ * @retval dbp address of rpm database
+ * @param mode open(2) flags: O_RDWR or O_RDONLY (O_CREAT also)
+ * @param perms database permissions
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiOpenDB(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip);
-
+int rpmdbOpen (const char * prefix, rpmdb * dbp, int mode, int perms);
-/* FIX: vector annotations */
-/** \ingroup dbi
- * Open a database cursor.
- * @param dbi index database handle
- * @param txnid database transaction handle
- * @retval dbcp returned database cursor
- * @param flags DB_WRITECURSOR if writing, or 0
+/** \ingroup rpmdb
+ * Initialize database.
+ * @param prefix path to top of install tree
+ * @param perms database permissions
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiCopen(dbiIndex dbi, DB_TXN * txnid,
- DBC ** dbcp, unsigned int flags);
+int rpmdbInit(const char * prefix, int perms);
-/** \ingroup dbi
- * Close a database cursor.
- * @param dbi index database handle
- * @param dbcursor database cursor
- * @param flags (unused)
+/** \ingroup rpmdb
+ * Close all database indices and free rpmdb.
+ * @param db rpm database
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags);
+int rpmdbClose (rpmdb db);
-/** \ingroup dbi
- * Delete (key,data) pair(s) from index database.
- * @param dbi index database handle
- * @param dbcursor database cursor (NULL will use db->del)
- * @param key delete key value/length/flags
- * @param data delete data value/length/flags
- * @param flags (unused)
+/** \ingroup rpmdb
+ * Sync all database indices.
+ * @param db rpm database
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
- unsigned int flags);
+int rpmdbSync (rpmdb db);
-/** \ingroup dbi
- * Retrieve (key,data) pair from index database.
- * @param dbi index database handle
- * @param dbcursor database cursor (NULL will use db->get)
- * @param key retrieve key value/length/flags
- * @param data retrieve data value/length/flags
- * @param flags (unused)
+/** \ingroup rpmdb
+ * Rebuild database indices from package headers.
+ * @param prefix path to top of install tree
+ * @param ts transaction set (or NULL)
+ * @param (*hdrchk) headerCheck() vector (or NULL)
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
- unsigned int flags);
+int rpmdbRebuild(const char * prefix, rpmts ts,
+ rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, char ** msg));
-/** \ingroup dbi
- * Store (key,data) pair in index database.
- * @param dbi index database handle
- * @param dbcursor database cursor (NULL will use db->put)
- * @param key store key value/length/flags
- * @param data store data value/length/flags
- * @param flags (unused)
+/** \ingroup rpmdb
+ * Verify database components.
+ * @param prefix path to top of install tree
* @return 0 on success
*/
RPM_GNUC_INTERNAL
-int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
- unsigned int flags);
-
-/** \ingroup dbi
- * Retrieve count of (possible) duplicate items.
- * @param dbi index database handle
- * @param dbcursor database cursor
- * @param countp address of count
- * @param flags (unused)
- * @return 0 on success
- */
-int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
- unsigned int flags);
-
-/** \ingroup dbi
- * Close index database.
- * @param dbi index database handle
- * @param flags (unused)
- * @return 0 on success
- */
-int dbiClose(dbiIndex dbi, unsigned int flags);
+int rpmdbVerify(const char * prefix);
-/** \ingroup dbi
- * Flush pending operations to disk.
- * @param dbi index database handle
- * @param flags (unused)
- * @return 0 on success
- */
-int dbiSync (dbiIndex dbi, unsigned int flags);
-
-/** \ingroup dbi
- * Verify (and close) index database.
- * @param dbi index database handle
- * @param flags (unused)
- * @return 0 on success
- */
-static inline
-int dbiVerify(dbiIndex dbi, unsigned int flags)
-{
- dbi->dbi_verify_on_close = 1;
- return dbiClose(dbi, flags);
-}
-
-
-/** \ingroup dbi
- * Is database byte swapped?
- * @param dbi index database handle
- * @return 0 same order, 1 swapped order
- */
-int dbiByteSwapped(dbiIndex dbi);
-
-/** \ingroup dbi
- * Is database byte swapped?
- * @param dbi index database handle
- * @param flags DB_FAST_STAT or 0
+/** \ingroup rpmdb
+ * Add package header to rpm database and indices.
+ * @param db rpm database
+ * @param h header
* @return 0 on success
*/
-int dbiStat(dbiIndex dbi, unsigned int flags);
-
-/** \ingroup dbi
- * Destroy set of index database items.
- * @param set set of index database items
- * @return NULL always
- */
-RPM_GNUC_INTERNAL
-dbiIndexSet dbiFreeIndexSet(dbiIndexSet set);
-
-/** \ingroup dbi
- * Count items in index database set.
- * @param set set of index database items
- * @return number of items
- */
-RPM_GNUC_INTERNAL
-unsigned int dbiIndexSetCount(dbiIndexSet set);
-
-/** \ingroup dbi
- * Return record offset of header from element in index database set.
- * @param set set of index database items
- * @param recno index of item in set
- * @return record offset of header
- */
RPM_GNUC_INTERNAL
-unsigned int dbiIndexRecordOffset(dbiIndexSet set, int recno);
+int rpmdbAdd(rpmdb db, Header h);
-/** \ingroup dbi
- * Return file index from element in index database set.
- * @param set set of index database items
- * @param recno index of item in set
- * @return file index
+/** \ingroup rpmdb
+ * Remove package header from rpm database and indices.
+ * @param db rpm database
+ * @param hdrNum package instance number in database
+ * @return 0 on success
*/
RPM_GNUC_INTERNAL
-unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno);
+int rpmdbRemove(rpmdb db, unsigned int hdrNum);
/** \ingroup rpmdb
* Return rpmdb home directory (depending on chroot state)
*/
void rpmdbSortIterator(rpmdbMatchIterator mi);
+/** \ingroup rpmdb
+ * Remove items from set of package instances to iterate.
+ * @note Sorted hdrNums are always passed in rpmlib.
+ * @param mi rpm database iterator
+ * @param hdrNums hash of package instances
+ * @return 0 on success, 1 on failure (bad args)
+ */
+int rpmdbPruneIterator(rpmdbMatchIterator mi, removedHash hdrNums);
+
+/** \ingroup rpmdb
+ * Create a new, empty match iterator (for purposes of extending it
+ * through other means)
+ * @param db rpm database
+ * @param dbitag database index tag
+ * @return empty match iterator
+ */
+RPM_GNUC_INTERNAL
+rpmdbMatchIterator rpmdbNewIterator(rpmdb db, rpmDbiTagVal dbitag);
+
#ifndef __APPLE__
/**
* * Mergesort, same arguments as qsort(2).
/* mergesort is defined in stdlib.h on Mac OS X */
#endif /* __APPLE__ */
+#ifdef __cplusplus
+}
+#endif
+
#endif