2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef LIBSOLV_REPODATA_H
14 #define LIBSOLV_REPODATA_H
18 #include "pooltypes.h"
22 #ifdef LIBSOLV_INTERNAL
31 #define SIZEOF_SHA1 20
32 #define SIZEOF_SHA224 28
33 #define SIZEOF_SHA256 32
34 #define SIZEOF_SHA384 48
35 #define SIZEOF_SHA512 64
40 typedef struct s_Repokey {
42 Id type; /* REPOKEY_TYPE_xxx */
44 unsigned int storage; /* KEY_STORAGE_xxx */
47 #define KEY_STORAGE_DROPPED 0
48 #define KEY_STORAGE_SOLVABLE 1
49 #define KEY_STORAGE_INCORE 2
50 #define KEY_STORAGE_VERTICAL_OFFSET 3
51 #define KEY_STORAGE_IDARRAYBLOCK 4
53 #ifdef LIBSOLV_INTERNAL
58 #define REPODATA_AVAILABLE 0
59 #define REPODATA_STUB 1
60 #define REPODATA_ERROR 2
61 #define REPODATA_STORE 3
62 #define REPODATA_LOADING 4
64 /* repodata filelist types */
65 /* note that FILELIST_FILTERED means that the data contains a filtered
66 * filelist *AND* that it is authoritative for all included solvables. */
67 #define REPODATA_FILELIST_FILTERED 1
68 #define REPODATA_FILELIST_EXTENSION 2
70 typedef struct s_Repodata {
71 Id repodataid; /* our id */
72 struct s_Repo *repo; /* back pointer to repo */
74 int state; /* available, stub or error */
76 void (*loadcallback)(struct s_Repodata *);
78 int start; /* start of solvables this repodata is valid for */
79 int end; /* last solvable + 1 of this repodata */
81 Repokey *keys; /* keys, first entry is always zero */
82 int nkeys; /* length of keys array */
83 unsigned char keybits[32]; /* keyname hash */
85 Id *schemata; /* schema -> offset into schemadata */
86 int nschemata; /* number of schemata */
87 Id *schemadata; /* schema storage */
89 Stringpool spool; /* local string pool */
90 int localpool; /* is local string pool used */
92 Dirpool dirpool; /* local dir pool */
94 #ifdef LIBSOLV_INTERNAL
95 FILE *fp; /* file pointer of solv file */
96 int error; /* corrupt solv file */
98 int filelisttype; /* type of filelist */
99 Id *filelistfilter; /* filelist filter used */
100 char *filelistfilterdata; /* filelist filter string space */
102 unsigned int schemadatalen; /* schema storage size */
103 Id *schematahash; /* unification helper */
105 unsigned char *incoredata; /* in-core data */
106 unsigned int incoredatalen; /* in-core data used */
107 unsigned int incoredatafree; /* free data len */
109 Id mainschema; /* SOLVID_META schema */
110 Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */
112 Id *incoreoffset; /* offset for all entries */
114 Id *verticaloffset; /* offset for all verticals, nkeys elements */
115 Id lastverticaloffset; /* end of verticals */
117 Repopagestore store; /* our page store */
118 Id storestate; /* incremented every time the store might change */
120 unsigned char *vincore; /* internal vertical data */
121 unsigned int vincorelen; /* data size */
123 Id **attrs; /* un-internalized attributes */
124 Id **xattrs; /* anonymous handles */
125 int nxattrs; /* number of handles */
127 unsigned char *attrdata; /* their string data space */
128 unsigned int attrdatalen; /* its len */
129 Id *attriddata; /* their id space */
130 unsigned int attriddatalen; /* its len */
131 unsigned long long *attrnum64data; /* their 64bit num data space */
132 unsigned int attrnum64datalen; /* its len */
134 /* array cache to speed up repodata_add functions*/
139 /* directory cache to speed up repodata_str2dir */
140 struct dircache *dircache;
145 #define SOLVID_META -1
146 #define SOLVID_POS -2
150 * management functions
152 void repodata_initdata(Repodata *data, struct s_Repo *repo, int localpool);
153 void repodata_freedata(Repodata *data);
155 void repodata_free(Repodata *data);
156 void repodata_empty(Repodata *data, int localpool);
158 void repodata_load(Repodata *data);
161 * key management functions
163 Id repodata_key2id(Repodata *data, Repokey *key, int create);
165 static inline Repokey *
166 repodata_id2key(Repodata *data, Id keyid)
168 return data->keys + keyid;
172 * schema management functions
174 Id repodata_schema2id(Repodata *data, Id *schema, int create);
175 void repodata_free_schemahash(Repodata *data);
178 repodata_id2schema(Repodata *data, Id schemaid)
180 return data->schemadata + data->schemata[schemaid];
184 * data search and access
187 /* check if there is a chance that the repodata contains data for
188 * the specified keyname */
190 repodata_precheck_keyname(Repodata *data, Id keyname)
192 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
193 return x && (x & (1 << (keyname & 7))) ? 1 : 0;
196 /* check if the repodata contains data for the specified keyname */
198 repodata_has_keyname(Repodata *data, Id keyname)
201 if (!repodata_precheck_keyname(data, keyname))
203 for (i = 1; i < data->nkeys; i++)
204 if (data->keys[i].name == keyname)
209 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
210 * Call <callback> for each match */
211 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
212 void repodata_search_keyskip(Repodata *data, Id solvid, Id keyname, int flags, Id *keyskip, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
213 void repodata_search_arrayelement(Repodata *data, Id solvid, Id keyname, int flags, struct s_KeyValue *kv, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
215 /* Make sure the found KeyValue has the "str" field set. Return "str"
216 * if valid, NULL if not possible */
217 const char *repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct s_KeyValue *kv, int flags);
219 /* filelist filter support */
220 void repodata_set_filelisttype(Repodata *data, int filelisttype);
221 int repodata_filelistfilter_matches(Repodata *data, const char *str);
222 void repodata_free_filelistfilter(Repodata *data);
224 /* lookup functions */
225 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
226 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
227 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
228 unsigned long long repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned long long notfound);
229 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
230 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
231 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
232 const void *repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp);
233 unsigned int repodata_lookup_count(Repodata *data, Id solvid, Id keyname); /* internal */
235 /* internal, used in fileprovides code */
236 const unsigned char *repodata_lookup_packed_dirstrarray(Repodata *data, Id solvid, Id keyname);
238 /* internal, fill keyskip array with data */
239 Id *repodata_fill_keyskip(Repodata *data, Id solvid, Id *keyskip);
242 * data assignment functions
246 * extend the data so that it contains the specified solvables
247 * (no longer needed, as the repodata_set functions autoextend)
249 void repodata_extend(Repodata *data, Id p);
250 void repodata_extend_block(Repodata *data, Id p, int num);
251 void repodata_shrink(Repodata *data, int end);
253 /* internalize freshly set data, so that it is found by the search
254 * functions and written out */
255 void repodata_internalize(Repodata *data);
257 /* create an anonymous handle. useful for substructures like
258 * fixarray/flexarray */
259 Id repodata_new_handle(Repodata *data);
261 /* basic types: void, num, string, Id */
262 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
263 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned long long num);
264 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
265 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
266 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
267 /* create id from string, then set_id */
268 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
270 /* set numeric constant */
271 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
273 /* set Id constant */
274 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
277 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
278 const unsigned char *buf);
279 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
281 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
283 /* directory (for package file list) */
284 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
285 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
286 void repodata_free_dircache(Repodata *data);
290 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
291 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
292 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
293 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
296 void repodata_set_kv(Repodata *data, Id solvid, Id keyname, Id keytype, struct s_KeyValue *kv);
297 void repodata_unset(Repodata *data, Id solvid, Id keyname);
298 void repodata_unset_uninternalized(Repodata *data, Id solvid, Id keyname);
301 merge/swap attributes from one solvable to another
302 works only if the data is not yet internalized
304 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
305 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
306 void repodata_swap_attrs(Repodata *data, Id dest, Id src);
308 Repodata *repodata_create_stubs(Repodata *data);
311 * load all paged data, used to speed up copying in repo_rpmdb
313 void repodata_disable_paging(Repodata *data);
315 /* helper functions */
316 Id repodata_globalize_id(Repodata *data, Id id, int create);
317 Id repodata_localize_id(Repodata *data, Id id, int create);
318 Id repodata_translate_id(Repodata *data, Repodata *fromdata, Id id, int create);
319 Id repodata_translate_dir_slow(Repodata *data, Repodata *fromdata, Id dir, int create, Id *cache);
321 Id repodata_str2dir(Repodata *data, const char *dir, int create);
322 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
323 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
324 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
325 void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file);
326 void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg);
328 /* uninternalized data lookup / search */
329 Repokey *repodata_lookup_kv_uninternalized(Repodata *data, Id solvid, Id keyname, struct s_KeyValue *kv);
330 void repodata_search_uninternalized(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
333 unsigned int repodata_memused(Repodata *data);
336 repodata_translate_dir(Repodata *data, Repodata *fromdata, Id dir, int create, Id *cache)
338 if (cache && dir && cache[(dir & 255) * 2] == dir)
339 return cache[(dir & 255) * 2 + 1];
340 return repodata_translate_dir_slow(data, fromdata, dir, create, cache);
344 repodata_create_dirtranscache(Repodata *data)
346 return (Id *)solv_calloc(256, sizeof(Id) * 2);
350 repodata_free_dirtranscache(Id *cache)
352 return (Id *)solv_free(cache);
360 #endif /* LIBSOLV_REPODATA_H */