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
|
#ifndef H_RPMDB
#define H_RPMDB
/** \file lib/rpmdb.h
* Access RPM indices using Berkeley db[123] interface.
*/
#include <rpmlib.h>
#include "fprint.h"
typedef void DBI_t;
typedef enum { DBI_BTREE, DBI_HASH, DBI_RECNO, DBI_QUEUE, DBI_UNKNOWN } DBI_TYPE;
typedef /*@abstract@*/ struct _dbiIndexRecord * dbiIndexRecord;
typedef /*@abstract@*/ struct _dbiIndex * dbiIndex;
/* this will break if sizeof(int) != 4 */
/**
* A single item from an index database (i.e. the "data returned").
* Note: In rpm-3.0.4 and earlier, this structure was passed by value,
* and was identical to the "data saved" structure below.
*/
struct _dbiIndexRecord {
unsigned int recOffset; /*!< byte offset of header in db */
unsigned int fileNumber; /*!< file array index */
int fpNum; /*!< finger print index */
int dbNum; /*!< database index */
};
/**
* A single item in an index database (i.e. the "data saved").
*/
struct _dbiIR {
unsigned int recOffset; /*!< byte offset of header in db */
unsigned int fileNumber; /*!< file array index */
};
typedef struct _dbiIR * DBIR_t;
/**
* Items retrieved from the index database.
*/
struct _dbiIndexSet {
/*@owned@*/ struct _dbiIndexRecord * recs; /*!< array of records */
int count; /*!< number of records */
};
/**
* Private methods for accessing an index database.
*/
struct _dbiVec {
int dbv_major; /*<! Berkeley db version major */
int dbv_minor; /*<! Berkeley db version minor */
int dbv_patch; /*<! Berkeley db version patch */
/**
* Return handle for an index database.
* @param dbi index database handle
* @return 0 success 1 fail
*/
int (*open) (dbiIndex dbi);
/**
* Close index database.
* @param dbi index database handle
* @param flags
*/
int (*close) (dbiIndex dbi, unsigned int flags);
/**
* Flush pending operations to disk.
* @param dbi index database handle
* @param flags
*/
int (*sync) (dbiIndex dbi, unsigned int flags);
/**
* Return items that match criteria.
* @param dbi index database handle
* @param str search key
* @param set items retrieved from index database
* @return -1 error, 0 success, 1 not found
*/
int (*SearchIndex) (dbiIndex dbi, const void * str, size_t len, dbiIndexSet * set);
/**
* Change/delete items that match criteria.
* @param dbi index database handle
* @param str update key
* @param set items to update in index database
* @return 0 success, 1 not found
*/
int (*UpdateIndex) (dbiIndex dbi, const char * str, dbiIndexSet set);
/**
* Delete item using db->del.
* @param dbi index database handle
* @param keyp key data
* @param keylen key data length
*/
int (*del) (dbiIndex dbi, void * keyp, size_t keylen);
/**
* Retrieve item using db->get.
* @param dbi index database handle
* @param keyp key data
* @param keylen key data length
* @param datap address of data pointer
* @param datalen address of data length
*/
int (*get) (dbiIndex dbi, void * keyp, size_t keylen,
void ** datap, size_t * datalen);
/**
* Save item using db->put.
* @param dbi index database handle
* @param keyp key data
* @param keylen key data length
* @param datap data pointer
* @param datalen data length
*/
int (*put) (dbiIndex dbi, void * keyp, size_t keylen,
void * datap, size_t datalen);
/**
*/
int (*copen) (dbiIndex dbi);
/**
*/
int (*cclose) (dbiIndex dbi);
/**
*/
int (*join) (dbiIndex dbi);
/**
* Retrieve item using dbcursor->c_get.
* @param dbi index database handle
* @param keyp address of key data
* @param keylen address of key data length
* @param datap address of data pointer
* @param datalen address of data length
*/
int (*cget) (dbiIndex dbi, void ** keyp, size_t * keylen,
void ** datap, size_t * datalen);
};
/**
* Describes an index database (implemented on Berkeley db[123] API).
*/
struct _dbiIndex {
const char *dbi_basename; /*<! last component of name */
int dbi_rpmtag; /*<! rpm tag used for index */
DBI_TYPE dbi_type; /*<! type of access */
int dbi_flags; /*<! flags to use on open */
int dbi_perms; /*<! file permission to use on open */
int dbi_major; /*<! Berkeley db version major */
unsigned int dbi_lastoffset; /*<! db0 with falloc.c needs this */
rpmdb dbi_rpmdb;
const char *dbi_file; /*<! name of index database */
void * dbi_db; /*<! Berkeley db[123] handle */
void * dbi_dbenv;
void * dbi_dbinfo;
void * dbi_dbjoin;
void * dbi_dbcursor;
void * dbi_pkgs;
/*@observer@*/ const struct _dbiVec * dbi_vec; /*<! private methods */
};
/* for RPM's internal use only */
#define RPMDB_FLAG_JUSTCHECK (1 << 0)
#define RPMDB_FLAG_MINIMAL (1 << 1)
#ifdef __cplusplus
extern "C" {
#endif
/**
* @param dbp address of rpm database
*/
int openDatabase(const char * prefix, const char * dbpath, /*@out@*/rpmdb *dbp,
int mode, int perms, int flags);
/**
* @param db rpm database
*/
int rpmdbRemove(rpmdb db, unsigned int offset, int tolerant);
/**
* @param db rpm database
*/
int rpmdbAdd(rpmdb db, Header dbentry);
/**
* @param db rpm database
*/
int rpmdbUpdateRecord(rpmdb db, int secOffset, Header secHeader);
/**
*/
void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath);
/**
*/
int rpmdbMoveDatabase(const char * rootdir, const char * olddbpath, const char * newdbpath);
/**
* @param db rpm database
*/
int rpmdbFindFpList(rpmdb db, fingerPrint * fpList, /*@out@*/dbiIndexSet * matchList,
int numItems);
/* XXX only for the benefit of runTransactions() */
int findMatches(rpmdb db, const char * name, const char * version,
const char * release, /*@out@*/ dbiIndexSet * matches);
#ifdef __cplusplus
}
#endif
#endif /* H_RPMDB */
|