1 #ifndef H_RPMDB_INTERNAL
2 #define H_RPMDB_INTERNAL
8 #include <rpm/rpmtypes.h>
9 #include <rpm/rpmutil.h>
11 typedef struct _dbiIndex * dbiIndex;
14 * Describes an index database (implemented on Berkeley db functionality).
17 const char * dbi_file; /*!< file component of path */
19 int dbi_ecflags; /*!< db_env_create flags */
20 int dbi_cflags; /*!< db_create flags */
21 int dbi_oeflags; /*!< common (db,dbenv}->open flags */
22 int dbi_eflags; /*!< dbenv->open flags */
23 int dbi_oflags; /*!< db->open flags */
24 int dbi_tflags; /*!< dbenv->txn_begin flags */
26 int dbi_type; /*!< db index type */
27 unsigned dbi_mode; /*!< mode to use on open */
28 int dbi_perms; /*!< file permission to use on open */
30 int dbi_verify_on_close;
31 int dbi_use_dbenv; /*!< use db environment? */
32 int dbi_permit_dups; /*!< permit duplicate entries? */
33 int dbi_no_fsync; /*!< no-op fsync for db */
34 int dbi_no_dbsync; /*!< don't call dbiSync */
35 int dbi_lockdbfd; /*!< do fcntl lock on db fd */
38 /* dbenv parameters */
39 /* XXX db-4.3.14 adds dbenv as 1st arg. */
41 /* mpool sub-system parameters */
42 int dbi_mmapsize; /*!< (10Mb) */
43 int dbi_cachesize; /*!< (128Kb) */
44 /* dbinfo parameters */
45 int dbi_pagesize; /*!< (fs blksize) */
47 rpmdb dbi_rpmdb; /*!< the parent rpm database */
48 rpmTag dbi_rpmtag; /*!< rpm tag used for index */
49 int dbi_jlen; /*!< size of join key */
51 DB * dbi_db; /*!< Berkeley DB * handle */
52 DB_TXN * dbi_txnid; /*!< Bekerley DB_TXN * transaction id */
53 void * dbi_stats; /*!< Berkeley db statistics */
57 * Describes the collection of index databases used by rpm.
60 char * db_root;/*!< path prefix */
61 char * db_home;/*!< directory path */
62 char * db_fullpath; /*!< full db path including prefix */
64 int db_mode; /*!< open mode */
65 int db_perms; /*!< open permissions */
66 int db_api; /*!< Berkeley API type */
68 int db_chrootDone; /*!< If chroot(2) done, ignore db_root. */
69 int db_mkdirDone; /*!< Has db_home been created? */
70 unsigned char * db_bits; /*!< package instance bit mask. */
71 int db_nbits; /*!< no. of bits in mask. */
74 void * db_dbenv; /*!< Berkeley DB_ENV handle. */
75 int db_ndbi; /*!< No. of tag indices. */
76 dbiIndex * _dbi; /*!< Tag indices. */
78 struct rpmop_s db_getops;
79 struct rpmop_s db_putops;
80 struct rpmop_s db_delops;
82 int nrefs; /*!< Reference count. */
85 /* for RPM's internal use only */
90 RPMDB_FLAG_JUSTCHECK = (1 << 0),
91 RPMDB_FLAG_MINIMAL = (1 << 1),
92 RPMDB_FLAG_CHROOT = (1 << 2)
100 * Return new configured index database handle instance.
101 * @param rpmdb rpm database
102 * @param rpmtag rpm tag
103 * @return index database handle
106 dbiIndex dbiNew(rpmdb rpmdb, rpmTag rpmtag);
109 * Destroy index database handle instance.
110 * @param dbi index database handle
111 * @return NULL always
114 dbiIndex dbiFree( dbiIndex dbi);
117 * Format dbi open flags for debugging print.
118 * @param dbflags db open flags
119 * @param print_dbenv_flags format db env flags instead?
120 * @return formatted flags (malloced)
123 char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
126 * Actually open the database of the index.
127 * @param db rpm database
128 * @param rpmtag rpm tag
129 * @param dbiIndex address of index database handle
130 * @return 0 on success
133 int dbiOpenDB(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip);
136 /* FIX: vector annotations */
138 * Open a database cursor.
139 * @param dbi index database handle
140 * @retval dbcp returned database cursor
141 * @param flags DB_WRITECURSOR if writing, or 0
142 * @return 0 on success
145 int dbiCopen(dbiIndex dbi, DBC ** dbcp, unsigned int flags);
148 * Close a database cursor.
149 * @param dbi index database handle
150 * @param dbcursor database cursor
151 * @param flags (unused)
152 * @return 0 on success
155 int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags);
158 * Delete (key,data) pair(s) from index database.
159 * @param dbi index database handle
160 * @param dbcursor database cursor (NULL will use db->del)
161 * @param key delete key value/length/flags
162 * @param data delete data value/length/flags
163 * @param flags (unused)
164 * @return 0 on success
167 int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
171 * Retrieve (key,data) pair from index database.
172 * @param dbi index database handle
173 * @param dbcursor database cursor (NULL will use db->get)
174 * @param key retrieve key value/length/flags
175 * @param data retrieve data value/length/flags
176 * @param flags (unused)
177 * @return 0 on success
180 int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
184 * Store (key,data) pair in index database.
185 * @param dbi index database handle
186 * @param dbcursor database cursor (NULL will use db->put)
187 * @param key store key value/length/flags
188 * @param data store data value/length/flags
189 * @param flags (unused)
190 * @return 0 on success
193 int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
197 * Retrieve count of (possible) duplicate items.
198 * @param dbi index database handle
199 * @param dbcursor database cursor
200 * @param countp address of count
201 * @param flags (unused)
202 * @return 0 on success
204 int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
208 * Close index database.
209 * @param dbi index database handle
210 * @param flags (unused)
211 * @return 0 on success
213 int dbiClose(dbiIndex dbi, unsigned int flags);
216 * Flush pending operations to disk.
217 * @param dbi index database handle
218 * @param flags (unused)
219 * @return 0 on success
221 int dbiSync (dbiIndex dbi, unsigned int flags);
225 * Is database byte swapped?
226 * @param dbi index database handle
227 * @return 0 same order, 1 swapped order
229 int dbiByteSwapped(dbiIndex dbi);
232 * Is database byte swapped?
233 * @param dbi index database handle
234 * @param flags DB_FAST_STAT or 0
235 * @return 0 on success
237 int dbiStat(dbiIndex dbi, unsigned int flags);
240 * Return rpmdb home directory (depending on chroot state)
241 * param db rpmdb handle
242 * return db home directory (or NULL on error)
245 const char *rpmdbHome(rpmdb db);
248 * Return database iterator.
249 * @param mi rpm database iterator
250 * @param keyp key data (NULL for sequential access)
251 * @param keylen key data length (0 will use strlen(keyp))
252 * @return 0 on success
254 int rpmdbExtendIterator(rpmdbMatchIterator mi,
255 const void * keyp, size_t keylen);
258 * sort the iterator by (recnum, filenum)
259 * Return database iterator.
260 * @param mi rpm database iterator
262 void rpmdbSortIterator(rpmdbMatchIterator mi);
266 * * Mergesort, same arguments as qsort(2).
269 int mergesort(void *base, size_t nmemb, size_t size,
270 int (*cmp) (const void *, const void *));
272 /* mergesort is defined in stdlib.h on Mac OS X */
273 #endif /* __APPLE__ */