satsolver 0.16.3
|
00001 /* 00002 * Copyright (c) 2007, Novell Inc. 00003 * 00004 * This program is licensed under the BSD license, read LICENSE.BSD 00005 * for further information 00006 */ 00007 00008 /* 00009 * repodata.h 00010 * 00011 */ 00012 00013 #ifndef SATSOLVER_REPODATA_H 00014 #define SATSOLVER_REPODATA_H 00015 00016 #include <stdio.h> 00017 00018 #include "pooltypes.h" 00019 #include "pool.h" 00020 #include "dirpool.h" 00021 #include "repopage.h" 00022 00023 #define SIZEOF_MD5 16 00024 #define SIZEOF_SHA1 20 00025 #define SIZEOF_SHA256 32 00026 00027 struct _Repo; 00028 struct _KeyValue; 00029 00030 typedef struct _Repokey { 00031 Id name; 00032 Id type; /* REPOKEY_TYPE_xxx */ 00033 unsigned int size; 00034 unsigned int storage; /* KEY_STORAGE_xxx */ 00035 } Repokey; 00036 00037 #define KEY_STORAGE_DROPPED 0 00038 #define KEY_STORAGE_SOLVABLE 1 00039 #define KEY_STORAGE_INCORE 2 00040 #define KEY_STORAGE_VERTICAL_OFFSET 3 00041 00042 00043 typedef struct _Repodata { 00044 struct _Repo *repo; /* back pointer to repo */ 00045 00046 #define REPODATA_AVAILABLE 0 00047 #define REPODATA_STUB 1 00048 #define REPODATA_ERROR 2 00049 #define REPODATA_STORE 3 00050 #define REPODATA_LOADING 4 00051 00052 int state; /* available, stub or error */ 00053 00054 void (*loadcallback)(struct _Repodata *); 00055 00056 int start; /* start of solvables this repodata is valid for */ 00057 int end; /* last solvable + 1 of this repodata */ 00058 00059 FILE *fp; /* file pointer of solv file */ 00060 int error; /* corrupt solv file */ 00061 00062 Repokey *keys; /* keys, first entry is always zero */ 00063 unsigned int nkeys; /* length of keys array */ 00064 unsigned char keybits[32]; /* keyname hash */ 00065 00066 Id *schemata; /* schema -> offset into schemadata */ 00067 unsigned int nschemata; /* number of schemata */ 00068 Id *schemadata; /* schema storage */ 00069 unsigned int schemadatalen; /* schema storage size */ 00070 Id *schematahash; /* unification helper */ 00071 00072 Stringpool spool; /* local string pool */ 00073 int localpool; /* is local string pool used */ 00074 00075 Dirpool dirpool; /* local dir pool */ 00076 00077 unsigned char *incoredata; /* in-core data */ 00078 unsigned int incoredatalen; /* in-core data used */ 00079 unsigned int incoredatafree; /* free data len */ 00080 00081 Id mainschema; /* SOLVID_META schema */ 00082 Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */ 00083 00084 Id *incoreoffset; /* offset for all entries */ 00085 00086 Id *verticaloffset; /* offset for all verticals, nkeys elements */ 00087 Id lastverticaloffset; /* end of verticals */ 00088 00089 Repopagestore store; /* our page store */ 00090 00091 unsigned char *vincore; /* internal vertical data */ 00092 unsigned int vincorelen; /* data size */ 00093 00094 Id **attrs; /* un-internalized attributes */ 00095 Id **xattrs; /* anonymous handles */ 00096 int nxattrs; /* number of handles */ 00097 00098 unsigned char *attrdata; /* their string data space */ 00099 unsigned int attrdatalen; /* its len */ 00100 Id *attriddata; /* their id space */ 00101 unsigned int attriddatalen; /* its len */ 00102 00103 /* array cache to speed up repodata_add functions*/ 00104 Id lasthandle; 00105 Id lastkey; 00106 Id lastdatalen; 00107 00108 } Repodata; 00109 00110 #define SOLVID_META -1 00111 #define SOLVID_POS -2 00112 #define SOLVID_SUBSCHEMA -3 /* internal! */ 00113 00114 00115 /*----- 00116 * management functions 00117 */ 00118 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool); 00119 void repodata_freedata(Repodata *data); 00120 00121 Repodata *repodata_create(struct _Repo *repo, int localpool); 00122 void repodata_free(Repodata *data); 00123 00124 00125 /* 00126 * key management functions 00127 */ 00128 Id repodata_key2id(Repodata *data, Repokey *key, int create); 00129 static inline Repokey * 00130 repodata_id2key(Repodata *data, Id keyid) 00131 { 00132 return data->keys + keyid; 00133 } 00134 00135 /* 00136 * schema management functions 00137 */ 00138 Id repodata_schema2id(Repodata *data, Id *schema, int create); 00139 static inline Id * 00140 repodata_id2schema(Repodata *data, Id schemaid) 00141 { 00142 return data->schemadata + data->schemata[schemaid]; 00143 } 00144 00145 /* 00146 * data search and access 00147 */ 00148 00149 /* check if there is a chance that the repodata contains data for 00150 * the specified keyname */ 00151 static inline int 00152 repodata_precheck_keyname(Repodata *data, Id keyname) 00153 { 00154 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)]; 00155 return x && (x & (1 << (keyname & 7))) ? 1 : 0; 00156 } 00157 00158 /* check if the repodata contains data for the specified keyname */ 00159 static inline int 00160 repodata_has_keyname(Repodata *data, Id keyname) 00161 { 00162 int i; 00163 if (!repodata_precheck_keyname(data, keyname)) 00164 return 0; 00165 for (i = 1; i < data->nkeys; i++) 00166 if (data->keys[i].name == keyname) 00167 return 1; 00168 return 0; 00169 } 00170 00171 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid> 00172 * Call <callback> for each match */ 00173 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); 00174 00175 /* Make sure the found KeyValue has the "str" field set. Return false 00176 * if not possible */ 00177 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags); 00178 00179 int repodata_filelistfilter_matches(Repodata *data, const char *str); 00180 00181 00182 /* lookup functions */ 00183 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname); 00184 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname); 00185 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned int *value); 00186 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname); 00187 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep); 00188 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q); 00189 00190 00191 /*----- 00192 * data assignment functions 00193 */ 00194 00195 /* 00196 * extend the data so that it contains the specified solvables 00197 * (no longer needed, as the repodata_set functions autoextend) 00198 */ 00199 void repodata_extend(Repodata *data, Id p); 00200 void repodata_extend_block(Repodata *data, Id p, int num); 00201 void repodata_shrink(Repodata *data, int end); 00202 00203 /* internalize freshly set data, so that it is found by the search 00204 * functions and written out */ 00205 void repodata_internalize(Repodata *data); 00206 00207 /* create an anonymous handle. useful for substructures like 00208 * fixarray/flexarray */ 00209 Id repodata_new_handle(Repodata *data); 00210 00211 /* basic types: void, num, string, Id */ 00212 void repodata_set_void(Repodata *data, Id solvid, Id keyname); 00213 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned int num); 00214 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id); 00215 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str); 00216 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len); 00217 /* create id from string, then set_id */ 00218 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str); 00219 00220 /* set numeric constant */ 00221 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant); 00222 00223 /* set Id constant */ 00224 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id); 00225 00226 /* checksum */ 00227 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type, 00228 const unsigned char *buf); 00229 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type, 00230 const char *str); 00231 00232 /* directory (for package file list) */ 00233 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2); 00234 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str); 00235 00236 00237 /* Arrays */ 00238 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id); 00239 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str); 00240 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle); 00241 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle); 00242 00243 void repodata_delete_uninternalized(Repodata *data, Id solvid, Id keyname); 00244 00245 /* 00246 merge attributes from one solvable to another 00247 works only if the data is not yet internalized 00248 */ 00249 void repodata_merge_attrs(Repodata *data, Id dest, Id src); 00250 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite); 00251 00252 void repodata_create_stubs(Repodata *data); 00253 void repodata_join(Repodata *data, Id joinkey); 00254 00255 /* 00256 * load all paged data, used to speed up copying in repo_rpmdb 00257 */ 00258 void repodata_disable_paging(Repodata *data); 00259 00260 /* helper functions */ 00261 Id repodata_globalize_id(Repodata *data, Id id, int create); 00262 Id repodata_str2dir(Repodata *data, const char *dir, int create); 00263 const char *repodata_dir2str(Repodata *data, Id did, const char *suf); 00264 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf); 00265 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file); 00266 00267 #endif /* SATSOLVER_REPODATA_H */