1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
#ifndef H_RPMDB
#define H_RPMDB
/** \ingroup rpmdb dbi db1 db3
* \file rpmdb/rpmdb.h
* Access RPM indices using Berkeley DB interface(s).
*/
#include <rpm/rpmtypes.h>
#include <rpm/rpmsw.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int _rpmdb_debug;
#ifdef NOTYET
/** \ingroup rpmdb
* Database of headers and tag value indices.
*/
typedef struct rpmdb_s * rpmdb;
/** \ingroup rpmdb
* Database iterator.
*/
typedef struct _rpmdbMatchIterator * rpmdbMatchIterator;
#endif
/**
* Tag value pattern match mode.
*/
typedef enum rpmMireMode_e {
RPMMIRE_DEFAULT = 0, /*!< regex with \., .* and ^...$ added */
RPMMIRE_STRCMP = 1, /*!< strings using strcmp(3) */
RPMMIRE_REGEX = 2, /*!< regex(7) patterns through regcomp(3) */
RPMMIRE_GLOB = 3 /*!< glob(7) patterns through fnmatch(3) */
} rpmMireMode;
typedef enum rpmdbOpX_e {
RPMDB_OP_DBGET = 1,
RPMDB_OP_DBPUT = 2,
RPMDB_OP_DBDEL = 3,
RPMDB_OP_MAX = 4
} rpmdbOpX;
/** \ingroup rpmdb
* Retrieve operation timestamp from rpm database.
* @param db rpm database
* @param opx operation timestamp index
* @return pointer to operation timestamp.
*/
rpmop rpmdbOp(rpmdb db, rpmdbOpX opx);
/** \ingroup rpmdb
* Set chrootDone flag, i.e. has chroot(2) been performed?
* @param db rpm database
* @param chrootDone new chrootDone flag
* @return previous chrootDone flag
*/
int rpmdbSetChrootDone(rpmdb db, int chrootDone);
/** \ingroup rpmdb
* Unreference a database instance.
* @param db rpm database
* @param msg
* @return NULL always
*/
rpmdb rpmdbUnlink (rpmdb db, const char * msg);
/** @todo Remove debugging entry from the ABI. */
rpmdb XrpmdbUnlink (rpmdb db, const char * msg,
const char * fn, unsigned ln);
#define rpmdbUnlink(_db, _msg) XrpmdbUnlink(_db, _msg, __FILE__, __LINE__)
/** \ingroup rpmdb
* Reference a database instance.
* @param db rpm database
* @param msg
* @return new rpm database reference
*/
rpmdb rpmdbLink (rpmdb db, const char * msg);
/** @todo Remove debugging entry from the ABI. */
rpmdb XrpmdbLink (rpmdb db, const char * msg,
const char * fn, unsigned ln);
#define rpmdbLink(_db, _msg) XrpmdbLink(_db, _msg, __FILE__, __LINE__)
/** \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
*/
int rpmdbOpen (const char * prefix, rpmdb * dbp,
int mode, int perms);
/** \ingroup rpmdb
* Initialize database.
* @param prefix path to top of install tree
* @param perms database permissions
* @return 0 on success
*/
int rpmdbInit(const char * prefix, int perms);
/** \ingroup rpmdb
* Verify database components.
* @param prefix path to top of install tree
* @return 0 on success
*/
int rpmdbVerify(const char * prefix);
/**
* Close a single database index.
* @param db rpm database
* @param rpmtag rpm tag
* @return 0 on success
*/
int rpmdbCloseDBI(rpmdb db, rpm_tag_t rpmtag);
/** \ingroup rpmdb
* Close all database indices and free rpmdb.
* @param db rpm database
* @return 0 on success
*/
int rpmdbClose (rpmdb db);
/** \ingroup rpmdb
* Sync all database indices.
* @param db rpm database
* @return 0 on success
*/
int rpmdbSync (rpmdb db);
/** \ingroup rpmdb
* Open all database indices.
* @param db rpm database
* @return 0 on success
*/
int rpmdbOpenAll (rpmdb db);
/** \ingroup rpmdb
* Return number of instances of package in rpm database.
* @param db rpm database
* @param name rpm package name
* @return number of instances
*/
int rpmdbCountPackages(rpmdb db, const char * name);
/** \ingroup rpmdb
* Return header join key for current position of rpm database iterator.
* @param mi rpm database iterator
* @return current header join key
*/
unsigned int rpmdbGetIteratorOffset(rpmdbMatchIterator mi);
/** \ingroup rpmdb
* Return number of elements in rpm database iterator.
* @param mi rpm database iterator
* @return number of elements
*/
int rpmdbGetIteratorCount(rpmdbMatchIterator mi);
/** \ingroup rpmdb
*/
unsigned int rpmdbGetIteratorFileNum(rpmdbMatchIterator mi);
/** \ingroup rpmdb
* Append items to set of package instances to iterate.
* @param mi rpm database iterator
* @param hdrNums array of package instances
* @param nHdrNums number of elements in array
* @return 0 on success, 1 on failure (bad args)
*/
int rpmdbAppendIterator(rpmdbMatchIterator mi,
const int * hdrNums, int nHdrNums);
/** \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 array of package instances
* @param nHdrNums number of elements in array
* @param sorted is the array sorted? (array will be sorted on return)
* @return 0 on success, 1 on failure (bad args)
*/
int rpmdbPruneIterator(rpmdbMatchIterator mi,
int * hdrNums, int nHdrNums, int sorted);
/** \ingroup rpmdb
* Add pattern to iterator selector.
* @param mi rpm database iterator
* @param tag rpm tag
* @param mode type of pattern match
* @param pattern pattern to match
* @return 0 on success
*/
int rpmdbSetIteratorRE(rpmdbMatchIterator mi, rpm_tag_t tag,
rpmMireMode mode, const char * pattern);
/** \ingroup rpmdb
* Prepare iterator for lazy writes.
* @note Must be called before rpmdbNextIterator() with CDB model database.
* @param mi rpm database iterator
* @param rewrite new value of rewrite
* @return previous value
*/
int rpmdbSetIteratorRewrite(rpmdbMatchIterator mi, int rewrite);
/** \ingroup rpmdb
* Modify iterator to mark header for lazy write on release.
* @param mi rpm database iterator
* @param modified new value of modified
* @return previous value
*/
int rpmdbSetIteratorModified(rpmdbMatchIterator mi, int modified);
/** \ingroup rpmdb
* Modify iterator to verify retrieved header blobs.
* @param mi rpm database iterator
* @param ts transaction set
* @param (*hdrchk) headerCheck() vector
* @return 0 always
*/
int rpmdbSetHdrChk(rpmdbMatchIterator mi, rpmts ts,
rpmRC (*hdrchk) (rpmts ts, const void * uh, size_t uc, char ** msg));
/** \ingroup rpmdb
* Return database iterator.
* @param db rpm database
* @param rpmtag rpm tag
* @param keyp key data (NULL for sequential access)
* @param keylen key data length (0 will use strlen(keyp))
* @return NULL on failure
*/
rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpm_tag_t rpmtag,
const void * keyp, size_t keylen);
/** \ingroup rpmdb
* Return next package header from iteration.
* @param mi rpm database iterator
* @return NULL on end of iteration.
*/
Header rpmdbNextIterator(rpmdbMatchIterator mi);
/** \ingroup rpmdb
* Check for and exit on termination signals.
*/
int rpmdbCheckSignals(void);
/** \ingroup rpmdb
* Check rpmdb signal handler for trapped signal and/or requested exit,
* clean up any open iterators and databases on termination condition.
* On non-zero exit any open references to rpmdb are invalid and cannot
* be accessed anymore, calling process should terminate immediately.
* @param terminate 0 to only check for signals, 1 to terminate anyway
* @return 0 to continue, 1 if termination cleanup was done.
*/
int rpmdbCheckTerminate(int terminate);
/** \ingroup rpmdb
* Destroy rpm database iterator.
* @param mi rpm database iterator
* @return NULL always
*/
rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi);
/** \ingroup rpmdb
* Add package header to rpm database and indices.
* @param db rpm database
* @param iid install transaction id (iid = 0 or -1 to skip)
* @param h header
* @param ts (unused) transaction set (or NULL)
* @param (*hdrchk) (unused) headerCheck() vector (or NULL)
* @return 0 on success
*/
int rpmdbAdd(rpmdb db, int iid, Header h, rpmts ts,
rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, char ** msg));
/** \ingroup rpmdb
* Remove package header from rpm database and indices.
* @param db rpm database
* @param rid (unused) remove transaction id (rid = 0 or -1 to skip)
* @param hdrNum package instance number in database
* @param ts (unused) transaction set (or NULL)
* @param (*hdrchk) (unused) headerCheck() vector (or NULL)
* @return 0 on success
*/
int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum,
rpmts ts,
rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, char ** msg));
/** \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
*/
int rpmdbRebuild(const char * prefix, rpmts ts,
rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, char ** msg));
#ifdef __cplusplus
}
#endif
#endif /* H_RPMDB */
|