1 #ifndef H_RPMDB_INTERNAL
2 #define H_RPMDB_INTERNAL
8 #include <rpm/rpmtypes.h>
9 #include <rpm/rpmutil.h>
13 typedef struct _dbiIndexItem * dbiIndexItem;
16 * A single element (i.e. inverted list from tag values) of a database.
18 typedef struct _dbiIndexSet * dbiIndexSet;
22 typedef struct _dbiIndex * dbiIndex;
24 /* this will break if sizeof(int) != 4 */
26 * A single item from an index database (i.e. the "data returned").
27 * Note: In rpm-3.0.4 and earlier, this structure was passed by value,
28 * and was identical to the "data saved" structure below.
30 struct _dbiIndexItem {
31 unsigned int hdrNum; /*!< header instance in db */
32 unsigned int tagNum; /*!< tag index in header */
36 * Items retrieved from the index database.
39 struct _dbiIndexItem * recs; /*!< array of records */
40 unsigned int count; /*!< number of records */
41 size_t alloced; /*!< alloced size */
45 * Describes an index database (implemented on Berkeley db functionality).
48 char * dbi_file; /*!< file component of path */
50 int dbi_ecflags; /*!< db_env_create flags */
51 int dbi_cflags; /*!< db_create flags */
52 int dbi_oeflags; /*!< common (db,dbenv}->open flags */
53 int dbi_eflags; /*!< dbenv->open flags */
54 int dbi_oflags; /*!< db->open flags */
55 int dbi_tflags; /*!< dbenv->txn_begin flags */
57 int dbi_type; /*!< db index type */
58 unsigned dbi_mode; /*!< mode to use on open */
59 int dbi_perms; /*!< file permission to use on open */
61 int dbi_verify_on_close;
62 int dbi_use_dbenv; /*!< use db environment? */
63 int dbi_permit_dups; /*!< permit duplicate entries? */
64 int dbi_no_fsync; /*!< no-op fsync for db */
65 int dbi_no_dbsync; /*!< don't call dbiSync */
66 int dbi_lockdbfd; /*!< do fcntl lock on db fd */
69 /* dbenv parameters */
71 /* XXX db-4.3.14 adds dbenv as 1st arg. */
73 /* mpool sub-system parameters */
74 int dbi_mmapsize; /*!< (10Mb) */
75 int dbi_cachesize; /*!< (128Kb) */
76 /* dbinfo parameters */
77 int dbi_pagesize; /*!< (fs blksize) */
78 /* hash access parameters */
79 unsigned int dbi_h_ffactor; /*!< */
80 unsigned int (*dbi_h_hash_fcn) (DB *, const void *bytes,
82 unsigned int dbi_h_nelem; /*!< */
83 unsigned int dbi_h_flags; /*!< DB_DUP, DB_DUPSORT */
84 int (*dbi_h_dup_compare_fcn) (DB *, const DBT *, const DBT *);
85 /* btree access parameters */
88 int (*dbi_bt_compare_fcn) (DB *, const DBT *, const DBT *);
89 int (*dbi_bt_dup_compare_fcn) (DB *, const DBT *, const DBT *);
90 size_t (*dbi_bt_prefix_fcn) (DB *, const DBT *, const DBT *);
91 /* recno access parameters */
94 unsigned int dbi_re_len;
97 /* queue access parameters */
98 unsigned int dbi_q_extentsize;
100 rpmdb dbi_rpmdb; /*!< the parent rpm database */
101 rpmTag dbi_rpmtag; /*!< rpm tag used for index */
102 int dbi_jlen; /*!< size of join key */
104 DB * dbi_db; /*!< Berkeley DB * handle */
105 DB_TXN * dbi_txnid; /*!< Bekerley DB_TXN * transaction id */
106 void * dbi_stats; /*!< Berkeley db statistics */
110 * Describes the collection of index databases used by rpm.
113 char * db_root;/*!< path prefix */
114 char * db_home;/*!< directory path */
115 char * db_fullpath; /*!< full db path including prefix */
117 int db_mode; /*!< open mode */
118 int db_perms; /*!< open permissions */
119 int db_api; /*!< Berkeley API type */
121 int db_chrootDone; /*!< If chroot(2) done, ignore db_root. */
122 int db_mkdirDone; /*!< Has db_home been created? */
123 unsigned char * db_bits; /*!< package instance bit mask. */
124 int db_nbits; /*!< no. of bits in mask. */
127 void * db_dbenv; /*!< Berkeley DB_ENV handle. */
128 int db_ndbi; /*!< No. of tag indices. */
129 dbiIndex * _dbi; /*!< Tag indices. */
131 struct rpmop_s db_getops;
132 struct rpmop_s db_putops;
133 struct rpmop_s db_delops;
135 int nrefs; /*!< Reference count. */
138 /* for RPM's internal use only */
143 RPMDB_FLAG_JUSTCHECK = (1 << 0),
144 RPMDB_FLAG_MINIMAL = (1 << 1),
145 RPMDB_FLAG_CHROOT = (1 << 2)
153 * Return new configured index database handle instance.
154 * @param rpmdb rpm database
155 * @param rpmtag rpm tag
156 * @return index database handle
159 dbiIndex dbiNew(rpmdb rpmdb, rpmTag rpmtag);
162 * Destroy index database handle instance.
163 * @param dbi index database handle
164 * @return NULL always
167 dbiIndex dbiFree( dbiIndex dbi);
170 * Format dbi open flags for debugging print.
171 * @param dbflags db open flags
172 * @param print_dbenv_flags format db env flags instead?
173 * @return formatted flags (malloced)
176 char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
179 * Return handle for an index database.
180 * @param db rpm database
181 * @param rpmtag rpm tag
182 * @param flags (unused)
183 * @return index database handle
186 dbiIndex dbiOpen(rpmdb db, rpmTag rpmtag,
191 * Actually open the database of the index.
192 * @param db rpm database
193 * @param rpmtag rpm tag
194 * @param dbiIndex address of index database handle
195 * @return 0 on success
198 int dbiOpenDB(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip);
201 /* FIX: vector annotations */
203 * Open a database cursor.
204 * @param dbi index database handle
205 * @param txnid database transaction handle
206 * @retval dbcp returned database cursor
207 * @param flags DB_WRITECURSOR if writing, or 0
208 * @return 0 on success
211 int dbiCopen(dbiIndex dbi, DB_TXN * txnid,
212 DBC ** dbcp, unsigned int flags);
215 * Close a database cursor.
216 * @param dbi index database handle
217 * @param dbcursor database cursor
218 * @param flags (unused)
219 * @return 0 on success
222 int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags);
225 * Delete (key,data) pair(s) from index database.
226 * @param dbi index database handle
227 * @param dbcursor database cursor (NULL will use db->del)
228 * @param key delete key value/length/flags
229 * @param data delete data value/length/flags
230 * @param flags (unused)
231 * @return 0 on success
234 int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
238 * Retrieve (key,data) pair from index database.
239 * @param dbi index database handle
240 * @param dbcursor database cursor (NULL will use db->get)
241 * @param key retrieve key value/length/flags
242 * @param data retrieve data value/length/flags
243 * @param flags (unused)
244 * @return 0 on success
247 int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
251 * Store (key,data) pair in index database.
252 * @param dbi index database handle
253 * @param dbcursor database cursor (NULL will use db->put)
254 * @param key store key value/length/flags
255 * @param data store data value/length/flags
256 * @param flags (unused)
257 * @return 0 on success
260 int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
264 * Retrieve count of (possible) duplicate items.
265 * @param dbi index database handle
266 * @param dbcursor database cursor
267 * @param countp address of count
268 * @param flags (unused)
269 * @return 0 on success
271 int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
275 * Close index database.
276 * @param dbi index database handle
277 * @param flags (unused)
278 * @return 0 on success
280 int dbiClose(dbiIndex dbi, unsigned int flags);
283 * Flush pending operations to disk.
284 * @param dbi index database handle
285 * @param flags (unused)
286 * @return 0 on success
288 int dbiSync (dbiIndex dbi, unsigned int flags);
291 * Verify (and close) index database.
292 * @param dbi index database handle
293 * @param flags (unused)
294 * @return 0 on success
297 int dbiVerify(dbiIndex dbi, unsigned int flags)
299 dbi->dbi_verify_on_close = 1;
300 return dbiClose(dbi, flags);
305 * Is database byte swapped?
306 * @param dbi index database handle
307 * @return 0 same order, 1 swapped order
309 int dbiByteSwapped(dbiIndex dbi);
312 * Is database byte swapped?
313 * @param dbi index database handle
314 * @param flags DB_FAST_STAT or 0
315 * @return 0 on success
317 int dbiStat(dbiIndex dbi, unsigned int flags);
320 * Destroy set of index database items.
321 * @param set set of index database items
322 * @return NULL always
325 dbiIndexSet dbiFreeIndexSet(dbiIndexSet set);
328 * Count items in index database set.
329 * @param set set of index database items
330 * @return number of items
333 unsigned int dbiIndexSetCount(dbiIndexSet set);
336 * Return record offset of header from element in index database set.
337 * @param set set of index database items
338 * @param recno index of item in set
339 * @return record offset of header
342 unsigned int dbiIndexRecordOffset(dbiIndexSet set, int recno);
345 * Return file index from element in index database set.
346 * @param set set of index database items
347 * @param recno index of item in set
351 unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno);
354 * Return rpmdb home directory (depending on chroot state)
355 * param db rpmdb handle
356 * return db home directory (or NULL on error)
359 const char *rpmdbHome(rpmdb db);
362 * Return database iterator.
363 * @param mi rpm database iterator
364 * @param keyp key data (NULL for sequential access)
365 * @param keylen key data length (0 will use strlen(keyp))
366 * @return 0 on success
368 int rpmdbExtendIterator(rpmdbMatchIterator mi,
369 const void * keyp, size_t keylen);
372 * sort the iterator by (recnum, filenum)
373 * Return database iterator.
374 * @param mi rpm database iterator
376 void rpmdbSortIterator(rpmdbMatchIterator mi);
380 * * Mergesort, same arguments as qsort(2).
383 int mergesort(void *base, size_t nmemb, size_t size,
384 int (*cmp) (const void *, const void *));
386 /* mergesort is defined in stdlib.h on Mac OS X */
387 #endif /* __APPLE__ */