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 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 */
40 /* XXX db-4.3.14 adds dbenv as 1st arg. */
42 /* mpool sub-system parameters */
43 int dbi_mmapsize; /*!< (10Mb) */
44 int dbi_cachesize; /*!< (128Kb) */
45 /* dbinfo parameters */
46 int dbi_pagesize; /*!< (fs blksize) */
48 rpmdb dbi_rpmdb; /*!< the parent rpm database */
49 rpmTag dbi_rpmtag; /*!< rpm tag used for index */
50 int dbi_jlen; /*!< size of join key */
52 DB * dbi_db; /*!< Berkeley DB * handle */
53 DB_TXN * dbi_txnid; /*!< Bekerley DB_TXN * transaction id */
54 void * dbi_stats; /*!< Berkeley db statistics */
58 * Describes the collection of index databases used by rpm.
61 char * db_root;/*!< path prefix */
62 char * db_home;/*!< directory path */
63 char * db_fullpath; /*!< full db path including prefix */
65 int db_mode; /*!< open mode */
66 int db_perms; /*!< open permissions */
67 int db_api; /*!< Berkeley API type */
69 int db_chrootDone; /*!< If chroot(2) done, ignore db_root. */
70 int db_mkdirDone; /*!< Has db_home been created? */
71 unsigned char * db_bits; /*!< package instance bit mask. */
72 int db_nbits; /*!< no. of bits in mask. */
75 void * db_dbenv; /*!< Berkeley DB_ENV handle. */
76 int db_ndbi; /*!< No. of tag indices. */
77 dbiIndex * _dbi; /*!< Tag indices. */
79 struct rpmop_s db_getops;
80 struct rpmop_s db_putops;
81 struct rpmop_s db_delops;
83 int nrefs; /*!< Reference count. */
86 /* for RPM's internal use only */
91 RPMDB_FLAG_JUSTCHECK = (1 << 0),
92 RPMDB_FLAG_MINIMAL = (1 << 1),
93 RPMDB_FLAG_CHROOT = (1 << 2)
101 * Return new configured index database handle instance.
102 * @param rpmdb rpm database
103 * @param rpmtag rpm tag
104 * @return index database handle
107 dbiIndex dbiNew(rpmdb rpmdb, rpmTag rpmtag);
110 * Destroy index database handle instance.
111 * @param dbi index database handle
112 * @return NULL always
115 dbiIndex dbiFree( dbiIndex dbi);
118 * Format dbi open flags for debugging print.
119 * @param dbflags db open flags
120 * @param print_dbenv_flags format db env flags instead?
121 * @return formatted flags (malloced)
124 char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
127 * Return handle for an index database.
128 * @param db rpm database
129 * @param rpmtag rpm tag
130 * @param flags (unused)
131 * @return index database handle
134 dbiIndex dbiOpen(rpmdb db, rpmTag rpmtag,
139 * Actually open the database of the index.
140 * @param db rpm database
141 * @param rpmtag rpm tag
142 * @param dbiIndex address of index database handle
143 * @return 0 on success
146 int dbiOpenDB(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip);
149 /* FIX: vector annotations */
151 * Open a database cursor.
152 * @param dbi index database handle
153 * @param txnid database transaction handle
154 * @retval dbcp returned database cursor
155 * @param flags DB_WRITECURSOR if writing, or 0
156 * @return 0 on success
159 int dbiCopen(dbiIndex dbi, DB_TXN * txnid,
160 DBC ** dbcp, unsigned int flags);
163 * Close a database cursor.
164 * @param dbi index database handle
165 * @param dbcursor database cursor
166 * @param flags (unused)
167 * @return 0 on success
170 int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags);
173 * Delete (key,data) pair(s) from index database.
174 * @param dbi index database handle
175 * @param dbcursor database cursor (NULL will use db->del)
176 * @param key delete key value/length/flags
177 * @param data delete data value/length/flags
178 * @param flags (unused)
179 * @return 0 on success
182 int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
186 * Retrieve (key,data) pair from index database.
187 * @param dbi index database handle
188 * @param dbcursor database cursor (NULL will use db->get)
189 * @param key retrieve key value/length/flags
190 * @param data retrieve data value/length/flags
191 * @param flags (unused)
192 * @return 0 on success
195 int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
199 * Store (key,data) pair in index database.
200 * @param dbi index database handle
201 * @param dbcursor database cursor (NULL will use db->put)
202 * @param key store key value/length/flags
203 * @param data store data value/length/flags
204 * @param flags (unused)
205 * @return 0 on success
208 int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
212 * Retrieve count of (possible) duplicate items.
213 * @param dbi index database handle
214 * @param dbcursor database cursor
215 * @param countp address of count
216 * @param flags (unused)
217 * @return 0 on success
219 int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
223 * Close index database.
224 * @param dbi index database handle
225 * @param flags (unused)
226 * @return 0 on success
228 int dbiClose(dbiIndex dbi, unsigned int flags);
231 * Flush pending operations to disk.
232 * @param dbi index database handle
233 * @param flags (unused)
234 * @return 0 on success
236 int dbiSync (dbiIndex dbi, unsigned int flags);
239 * Verify (and close) index database.
240 * @param dbi index database handle
241 * @param flags (unused)
242 * @return 0 on success
245 int dbiVerify(dbiIndex dbi, unsigned int flags)
247 dbi->dbi_verify_on_close = 1;
248 return dbiClose(dbi, flags);
253 * Is database byte swapped?
254 * @param dbi index database handle
255 * @return 0 same order, 1 swapped order
257 int dbiByteSwapped(dbiIndex dbi);
260 * Is database byte swapped?
261 * @param dbi index database handle
262 * @param flags DB_FAST_STAT or 0
263 * @return 0 on success
265 int dbiStat(dbiIndex dbi, unsigned int flags);
268 * Return rpmdb home directory (depending on chroot state)
269 * param db rpmdb handle
270 * return db home directory (or NULL on error)
273 const char *rpmdbHome(rpmdb db);
276 * Return database iterator.
277 * @param mi rpm database iterator
278 * @param keyp key data (NULL for sequential access)
279 * @param keylen key data length (0 will use strlen(keyp))
280 * @return 0 on success
282 int rpmdbExtendIterator(rpmdbMatchIterator mi,
283 const void * keyp, size_t keylen);
286 * sort the iterator by (recnum, filenum)
287 * Return database iterator.
288 * @param mi rpm database iterator
290 void rpmdbSortIterator(rpmdbMatchIterator mi);
294 * * Mergesort, same arguments as qsort(2).
297 int mergesort(void *base, size_t nmemb, size_t size,
298 int (*cmp) (const void *, const void *));
300 /* mergesort is defined in stdlib.h on Mac OS X */
301 #endif /* __APPLE__ */