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_SHA256 32
37 typedef struct _Repokey {
39 Id type; /* REPOKEY_TYPE_xxx */
41 unsigned int storage; /* KEY_STORAGE_xxx */
44 #define KEY_STORAGE_DROPPED 0
45 #define KEY_STORAGE_SOLVABLE 1
46 #define KEY_STORAGE_INCORE 2
47 #define KEY_STORAGE_VERTICAL_OFFSET 3
49 #ifdef LIBSOLV_INTERNAL
53 typedef struct _Repodata {
54 Id repodataid; /* our id */
55 struct _Repo *repo; /* back pointer to repo */
57 #define REPODATA_AVAILABLE 0
58 #define REPODATA_STUB 1
59 #define REPODATA_ERROR 2
60 #define REPODATA_STORE 3
61 #define REPODATA_LOADING 4
63 int state; /* available, stub or error */
65 void (*loadcallback)(struct _Repodata *);
67 int start; /* start of solvables this repodata is valid for */
68 int end; /* last solvable + 1 of this repodata */
70 Repokey *keys; /* keys, first entry is always zero */
71 int nkeys; /* length of keys array */
72 unsigned char keybits[32]; /* keyname hash */
74 Id *schemata; /* schema -> offset into schemadata */
75 int nschemata; /* number of schemata */
76 Id *schemadata; /* schema storage */
78 Stringpool spool; /* local string pool */
79 int localpool; /* is local string pool used */
81 Dirpool dirpool; /* local dir pool */
83 #ifdef LIBSOLV_INTERNAL
84 FILE *fp; /* file pointer of solv file */
85 int error; /* corrupt solv file */
87 unsigned int schemadatalen; /* schema storage size */
88 Id *schematahash; /* unification helper */
90 unsigned char *incoredata; /* in-core data */
91 unsigned int incoredatalen; /* in-core data used */
92 unsigned int incoredatafree; /* free data len */
94 Id mainschema; /* SOLVID_META schema */
95 Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */
97 Id *incoreoffset; /* offset for all entries */
99 Id *verticaloffset; /* offset for all verticals, nkeys elements */
100 Id lastverticaloffset; /* end of verticals */
102 Repopagestore store; /* our page store */
103 Id storestate; /* incremented every time the store might change */
105 unsigned char *vincore; /* internal vertical data */
106 unsigned int vincorelen; /* data size */
108 Id **attrs; /* un-internalized attributes */
109 Id **xattrs; /* anonymous handles */
110 int nxattrs; /* number of handles */
112 unsigned char *attrdata; /* their string data space */
113 unsigned int attrdatalen; /* its len */
114 Id *attriddata; /* their id space */
115 unsigned int attriddatalen; /* its len */
116 unsigned long long *attrnum64data; /* their 64bit num data space */
117 unsigned int attrnum64datalen; /* its len */
119 /* array cache to speed up repodata_add functions*/
124 /* directory cache to speed up repodata_str2dir */
125 struct dircache *dircache;
130 #define SOLVID_META -1
131 #define SOLVID_POS -2
132 #define SOLVID_SUBSCHEMA -3 /* internal! */
136 * management functions
138 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
139 void repodata_freedata(Repodata *data);
141 void repodata_free(Repodata *data);
142 void repodata_empty(Repodata *data, int localpool);
146 * key management functions
148 Id repodata_key2id(Repodata *data, Repokey *key, int create);
150 static inline Repokey *
151 repodata_id2key(Repodata *data, Id keyid)
153 return data->keys + keyid;
157 * schema management functions
159 Id repodata_schema2id(Repodata *data, Id *schema, int create);
160 void repodata_free_schemahash(Repodata *data);
163 repodata_id2schema(Repodata *data, Id schemaid)
165 return data->schemadata + data->schemata[schemaid];
169 * data search and access
172 /* check if there is a chance that the repodata contains data for
173 * the specified keyname */
175 repodata_precheck_keyname(Repodata *data, Id keyname)
177 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
178 return x && (x & (1 << (keyname & 7))) ? 1 : 0;
181 /* check if the repodata contains data for the specified keyname */
183 repodata_has_keyname(Repodata *data, Id keyname)
186 if (!repodata_precheck_keyname(data, keyname))
188 for (i = 1; i < data->nkeys; i++)
189 if (data->keys[i].name == keyname)
194 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
195 * Call <callback> for each match */
196 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct _KeyValue *kv), void *cbdata);
198 /* Make sure the found KeyValue has the "str" field set. Return false
200 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
202 int repodata_filelistfilter_matches(Repodata *data, const char *str);
205 /* lookup functions */
206 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
207 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
208 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
209 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned long long *value);
210 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
211 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
212 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
213 const void *repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp);
217 * data assignment functions
221 * extend the data so that it contains the specified solvables
222 * (no longer needed, as the repodata_set functions autoextend)
224 void repodata_extend(Repodata *data, Id p);
225 void repodata_extend_block(Repodata *data, Id p, int num);
226 void repodata_shrink(Repodata *data, int end);
228 /* internalize freshly set data, so that it is found by the search
229 * functions and written out */
230 void repodata_internalize(Repodata *data);
232 /* create an anonymous handle. useful for substructures like
233 * fixarray/flexarray */
234 Id repodata_new_handle(Repodata *data);
236 /* basic types: void, num, string, Id */
237 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
238 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned long long num);
239 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
240 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
241 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
242 /* create id from string, then set_id */
243 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
245 /* set numeric constant */
246 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
248 /* set Id constant */
249 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
252 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
253 const unsigned char *buf);
254 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
256 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
259 /* directory (for package file list) */
260 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
261 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
262 void repodata_free_dircache(Repodata *data);
266 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
267 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
268 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
269 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
271 void repodata_unset(Repodata *data, Id solvid, Id keyname);
272 void repodata_unset_uninternalized(Repodata *data, Id solvid, Id keyname);
275 merge/swap attributes from one solvable to another
276 works only if the data is not yet internalized
278 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
279 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
280 void repodata_swap_attrs(Repodata *data, Id dest, Id src);
282 Repodata *repodata_create_stubs(Repodata *data);
285 * load all paged data, used to speed up copying in repo_rpmdb
287 void repodata_disable_paging(Repodata *data);
289 /* helper functions */
290 Id repodata_globalize_id(Repodata *data, Id id, int create);
291 Id repodata_localize_id(Repodata *data, Id id, int create);
292 Id repodata_translate_id(Repodata *data, Repodata *fromdata, Id id, int create);
294 Id repodata_str2dir(Repodata *data, const char *dir, int create);
295 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
296 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
297 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
298 void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file);
299 void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg);
300 Id repodata_lookup_id_uninternalized(Repodata *data, Id solvid, Id keyname, Id voidid);
303 unsigned int repodata_memused(Repodata *data);
309 #endif /* LIBSOLV_REPODATA_H */