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 char * dbi_tmpdir; /*!< temporary directory */
52 int dbi_ecflags; /*!< db_env_create flags */
53 int dbi_cflags; /*!< db_create flags */
54 int dbi_oeflags; /*!< common (db,dbenv}->open flags */
55 int dbi_eflags; /*!< dbenv->open flags */
56 int dbi_oflags; /*!< db->open flags */
57 int dbi_tflags; /*!< dbenv->txn_begin flags */
59 int dbi_type; /*!< db index type */
60 unsigned dbi_mode; /*!< mode to use on open */
61 int dbi_perms; /*!< file permission to use on open */
62 long dbi_shmkey; /*!< shared memory base key */
64 int dbi_verify_on_close;
65 int dbi_use_dbenv; /*!< use db environment? */
66 int dbi_permit_dups; /*!< permit duplicate entries? */
67 int dbi_no_fsync; /*!< no-op fsync for db */
68 int dbi_no_dbsync; /*!< don't call dbiSync */
69 int dbi_lockdbfd; /*!< do fcntl lock on db fd */
70 int dbi_temporary; /*!< non-persistent */
74 /* dbenv parameters */
76 /* XXX db-4.3.14 adds dbenv as 1st arg. */
77 void (*db_errcall) (void * dbenv, const char *db_errpfx, char *buffer);
83 /* mpool sub-system parameters */
84 int dbi_mmapsize; /*!< (10Mb) */
85 int dbi_cachesize; /*!< (128Kb) */
86 /* lock sub-system parameters */
87 unsigned int dbi_lk_max;
88 unsigned int dbi_lk_detect;
90 unsigned char * dbi_lk_conflicts;
91 /* log sub-system parameters */
92 unsigned int dbi_lg_max;
93 unsigned int dbi_lg_bsize;
94 /* transaction sub-system parameters */
95 unsigned int dbi_tx_max;
97 int (*dbi_tx_recover) (DB_ENV *dbenv, DBT *log_rec,
98 DB_LSN *lsnp, int redo, void *info);
100 /* dbinfo parameters */
101 int dbi_pagesize; /*!< (fs blksize) */
102 void * (*dbi_malloc) (size_t nbytes);
103 /* hash access parameters */
104 unsigned int dbi_h_ffactor; /*!< */
105 unsigned int (*dbi_h_hash_fcn) (DB *, const void *bytes,
106 unsigned int length);
107 unsigned int dbi_h_nelem; /*!< */
108 unsigned int dbi_h_flags; /*!< DB_DUP, DB_DUPSORT */
109 int (*dbi_h_dup_compare_fcn) (DB *, const DBT *, const DBT *);
110 /* btree access parameters */
113 int (*dbi_bt_compare_fcn) (DB *, const DBT *, const DBT *);
114 int (*dbi_bt_dup_compare_fcn) (DB *, const DBT *, const DBT *);
115 size_t (*dbi_bt_prefix_fcn) (DB *, const DBT *, const DBT *);
116 /* recno access parameters */
119 unsigned int dbi_re_len;
121 char * dbi_re_source;
122 /* queue access parameters */
123 unsigned int dbi_q_extentsize;
125 rpmdb dbi_rpmdb; /*!< the parent rpm database */
126 rpmTag dbi_rpmtag; /*!< rpm tag used for index */
127 int dbi_jlen; /*!< size of join key */
129 DB * dbi_db; /*!< Berkeley DB * handle */
130 DB_TXN * dbi_txnid; /*!< Bekerley DB_TXN * transaction id */
131 void * dbi_stats; /*!< Berkeley db statistics */
135 * Describes the collection of index databases used by rpm.
138 char * db_root;/*!< path prefix */
139 char * db_home;/*!< directory path */
140 char * db_fullpath; /*!< full db path including prefix */
142 int db_mode; /*!< open mode */
143 int db_perms; /*!< open permissions */
144 int db_api; /*!< Berkeley API type */
147 int db_chrootDone; /*!< If chroot(2) done, ignore db_root. */
148 int db_mkdirDone; /*!< Has db_home been created? */
149 void (*db_errcall) (const char *db_errpfx, char *buffer);
151 void * (*db_malloc) (size_t nbytes);
152 void * (*db_realloc) (void * ptr,
154 void (*db_free) (void * ptr);
155 unsigned char * db_bits; /*!< package instance bit mask. */
156 int db_nbits; /*!< no. of bits in mask. */
159 void * db_dbenv; /*!< Berkeley DB_ENV handle. */
160 dbiIndex * _dbi; /*!< Tag indices. */
162 struct rpmop_s db_getops;
163 struct rpmop_s db_putops;
164 struct rpmop_s db_delops;
166 int nrefs; /*!< Reference count. */
169 /* for RPM's internal use only */
174 RPMDB_FLAG_JUSTCHECK = (1 << 0),
175 RPMDB_FLAG_MINIMAL = (1 << 1),
176 RPMDB_FLAG_CHROOT = (1 << 2)
184 * Return new configured index database handle instance.
185 * @param rpmdb rpm database
186 * @param rpmtag rpm tag
187 * @return index database handle
190 dbiIndex dbiNew(rpmdb rpmdb, rpmTag rpmtag);
193 * Destroy index database handle instance.
194 * @param dbi index database handle
195 * @return NULL always
198 dbiIndex dbiFree( dbiIndex dbi);
201 * Format dbi open flags for debugging print.
202 * @param dbflags db open flags
203 * @param print_dbenv_flags format db env flags instead?
204 * @return formatted flags (malloced)
207 char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
210 * Return handle for an index database.
211 * @param db rpm database
212 * @param rpmtag rpm tag
213 * @param flags (unused)
214 * @return index database handle
217 dbiIndex dbiOpen(rpmdb db, rpmTag rpmtag,
222 * Actually open the database of the index.
223 * @param db rpm database
224 * @param rpmtag rpm tag
225 * @param dbiIndex address of index database handle
226 * @return 0 on success
229 int dbiOpenDB(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip);
232 /* FIX: vector annotations */
234 * Open a database cursor.
235 * @param dbi index database handle
236 * @param txnid database transaction handle
237 * @retval dbcp returned database cursor
238 * @param flags DB_WRITECURSOR if writing, or 0
239 * @return 0 on success
242 int dbiCopen(dbiIndex dbi, DB_TXN * txnid,
243 DBC ** dbcp, unsigned int flags);
246 * Close a database cursor.
247 * @param dbi index database handle
248 * @param dbcursor database cursor
249 * @param flags (unused)
250 * @return 0 on success
253 int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags);
256 * Delete (key,data) pair(s) from index database.
257 * @param dbi index database handle
258 * @param dbcursor database cursor (NULL will use db->del)
259 * @param key delete key value/length/flags
260 * @param data delete data value/length/flags
261 * @param flags (unused)
262 * @return 0 on success
265 int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
269 * Retrieve (key,data) pair from index database.
270 * @param dbi index database handle
271 * @param dbcursor database cursor (NULL will use db->get)
272 * @param key retrieve key value/length/flags
273 * @param data retrieve data value/length/flags
274 * @param flags (unused)
275 * @return 0 on success
278 int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
282 * Store (key,data) pair in index database.
283 * @param dbi index database handle
284 * @param dbcursor database cursor (NULL will use db->put)
285 * @param key store key value/length/flags
286 * @param data store data value/length/flags
287 * @param flags (unused)
288 * @return 0 on success
291 int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
295 * Retrieve count of (possible) duplicate items.
296 * @param dbi index database handle
297 * @param dbcursor database cursor
298 * @param countp address of count
299 * @param flags (unused)
300 * @return 0 on success
302 int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
306 * Close index database.
307 * @param dbi index database handle
308 * @param flags (unused)
309 * @return 0 on success
311 int dbiClose(dbiIndex dbi, unsigned int flags);
314 * Flush pending operations to disk.
315 * @param dbi index database handle
316 * @param flags (unused)
317 * @return 0 on success
319 int dbiSync (dbiIndex dbi, unsigned int flags);
322 * Verify (and close) index database.
323 * @param dbi index database handle
324 * @param flags (unused)
325 * @return 0 on success
328 int dbiVerify(dbiIndex dbi, unsigned int flags)
330 dbi->dbi_verify_on_close = 1;
331 return dbiClose(dbi, flags);
336 * Is database byte swapped?
337 * @param dbi index database handle
338 * @return 0 same order, 1 swapped order
340 int dbiByteSwapped(dbiIndex dbi);
343 * Is database byte swapped?
344 * @param dbi index database handle
345 * @param flags DB_FAST_STAT or 0
346 * @return 0 on success
348 int dbiStat(dbiIndex dbi, unsigned int flags);
351 * Destroy set of index database items.
352 * @param set set of index database items
353 * @return NULL always
356 dbiIndexSet dbiFreeIndexSet(dbiIndexSet set);
359 * Count items in index database set.
360 * @param set set of index database items
361 * @return number of items
364 unsigned int dbiIndexSetCount(dbiIndexSet set);
367 * Return record offset of header from element in index database set.
368 * @param set set of index database items
369 * @param recno index of item in set
370 * @return record offset of header
373 unsigned int dbiIndexRecordOffset(dbiIndexSet set, int recno);
376 * Return file index from element in index database set.
377 * @param set set of index database items
378 * @param recno index of item in set
382 unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno);
385 * Return rpmdb home directory (depending on chroot state)
386 * param db rpmdb handle
387 * return db home directory (or NULL on error)
390 const char *rpmdbHome(rpmdb db);
393 * Return database iterator.
394 * @param mi rpm database iterator
395 * @param keyp key data (NULL for sequential access)
396 * @param keylen key data length (0 will use strlen(keyp))
397 * @return 0 on success
399 int rpmdbExtendIterator(rpmdbMatchIterator mi,
400 const void * keyp, size_t keylen);
403 * sort the iterator by (recnum, filenum)
404 * Return database iterator.
405 * @param mi rpm database iterator
407 void rpmdbSortIterator(rpmdbMatchIterator mi);
411 * * Mergesort, same arguments as qsort(2).
414 int mergesort(void *base, size_t nmemb, size_t size,
415 int (*cmp) (const void *, const void *));
417 /* mergesort is defined in stdlib.h on Mac OS X */
418 #endif /* __APPLE__ */