2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Read the binary dump of a Repo and create a Repo * from it
14 * Repo *pool_addrepo_solv(Pool *pool, FILE *fp)
26 #include "repo_solv.h"
31 #define INTERESTED_START SOLVABLE_NAME
32 #define INTERESTED_END SOLVABLE_FRESHENS
34 #define SOLV_ERROR_NOT_SOLV 1
35 #define SOLV_ERROR_UNSUPPORTED 2
36 #define SOLV_ERROR_EOF 3
37 #define SOLV_ERROR_ID_RANGE 4
38 #define SOLV_ERROR_OVERFLOW 5
39 #define SOLV_ERROR_CORRUPT 6
41 static Pool *mypool; /* for pool_debug... */
43 /*-----------------------------------------------------------------*/
44 /* .solv read functions */
51 read_u32(Repodata *data)
58 for (i = 0; i < 4; i++)
63 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
64 data->error = SOLV_ERROR_EOF;
78 read_u8(Repodata *data)
87 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
88 data->error = SOLV_ERROR_EOF;
100 read_id(Repodata *data, Id max)
107 for (i = 0; i < 5; i++)
112 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
113 data->error = SOLV_ERROR_EOF;
121 pool_debug(mypool, SAT_ERROR, "read_id: id too large (%u/%u)\n", x, max);
122 data->error = SOLV_ERROR_ID_RANGE;
127 x = (x << 7) ^ c ^ 128;
129 pool_debug(mypool, SAT_ERROR, "read_id: id too long\n");
130 data->error = SOLV_ERROR_CORRUPT;
141 read_rel_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end, Id marker)
154 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
155 data->error = SOLV_ERROR_EOF;
160 x = (x << 7) ^ c ^ 128;
163 x = (x << 6) | (c & 63);
169 pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
170 data->error = SOLV_ERROR_OVERFLOW;
178 *store++ = marker; /* do not map! */
187 pool_debug(mypool, SAT_ERROR, "read_rel_idarray: id too large (%u/%u)\n", x, max);
188 data->error = SOLV_ERROR_ID_RANGE;
195 pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
201 if (x == 0) /* already have trailing zero? */
205 pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
206 data->error = SOLV_ERROR_OVERFLOW;
217 static inline unsigned char *
218 data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, int *error)
221 dp = data_read_id(dp, &x);
224 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
225 *error = SOLV_ERROR_ID_RANGE;
228 *ret = map ? map[x] : x;
233 data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error)
244 x = (x << 7) ^ c ^ 128;
247 x = (x << 6) | (c & 63);
250 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
251 *error = SOLV_ERROR_ID_RANGE;
265 data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error, Id marker)
277 x = (x << 7) ^ c ^ 128;
280 x = (x << 6) | (c & 63);
294 pool_debug(mypool, SAT_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
295 *error = SOLV_ERROR_ID_RANGE;
298 *store++ = map ? map[x] : x;
310 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
322 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
323 data->error = SOLV_ERROR_EOF;
328 x = (x << 7) ^ c ^ 128;
331 x = (x << 6) | (c & 63);
334 pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
335 data->error = SOLV_ERROR_ID_RANGE;
342 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
348 if (x == 0) /* already have trailing zero? */
352 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
353 data->error = SOLV_ERROR_OVERFLOW;
364 read_str(Repodata *data, char **inbuf, unsigned *len)
366 unsigned char *buf = (unsigned char*)*inbuf;
369 buf = sat_malloc(1024);
374 while((c = getc(data->fp)) != 0)
378 pool_debug (mypool, SAT_ERROR, "unexpected EOF\n");
379 data->error = SOLV_ERROR_EOF;
382 /* Plus 1 as we also want to add the 0. */
386 /* Don't realloc on the inbuf, it might be on the stack. */
387 if (buf == (unsigned char*)*inbuf)
389 buf = sat_malloc(*len);
390 memcpy(buf, *inbuf, *len - 256);
393 buf = sat_realloc(buf, *len);
402 skip_item(Repodata *data, unsigned type, unsigned numid, unsigned numrel)
406 case REPOKEY_TYPE_VOID:
407 case REPOKEY_TYPE_CONSTANT:
408 case REPOKEY_TYPE_CONSTANTID:
410 case REPOKEY_TYPE_ID:
411 read_id(data, numid + numrel); /* just check Id */
413 case REPOKEY_TYPE_DIR:
414 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
416 case REPOKEY_TYPE_NUM:
419 case REPOKEY_TYPE_U32:
422 case REPOKEY_TYPE_STR:
423 while (read_u8(data) != 0)
426 case REPOKEY_TYPE_IDARRAY:
427 case REPOKEY_TYPE_REL_IDARRAY:
428 while ((read_u8(data) & 0xc0) != 0)
431 case REPOKEY_TYPE_DIRNUMNUMARRAY:
434 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
436 if (!(read_id(data, 0) & 0x40))
440 case REPOKEY_TYPE_DIRSTRARRAY:
443 Id id = read_id(data, 0);
444 while (read_u8(data) != 0)
451 pool_debug(mypool, SAT_ERROR, "unknown type %d\n", type);
452 data->error = SOLV_ERROR_CORRUPT;
458 key_cmp (const void *pa, const void *pb)
460 Repokey *a = (Repokey *)pa;
461 Repokey *b = (Repokey *)pb;
462 return a->name - b->name;
465 static void repodata_load_solv(Repodata *data);
468 parse_external_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel)
470 Repo *repo = maindata->repo;
476 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof (*data));
477 data = repo->repodata + repo->nrepodata++;
478 memset(data, 0, sizeof(*data));
481 data->state = REPODATA_STUB;
482 data->loadcallback = repodata_load_solv;
484 while ((key = *keyp++) != 0)
487 switch (keys[key].type)
489 case REPOKEY_TYPE_IDARRAY:
490 if (id != REPODATA_KEYS)
492 skip_item(maindata, REPOKEY_TYPE_IDARRAY, numid, numrel);
495 /* read_idarray writes a terminating 0, that's why the + 1 */
496 ida = sat_calloc(keys[key].size + 1, sizeof(Id));
497 ide = read_idarray(maindata, numid, idmap, ida, ida + keys[key].size + 1);
501 pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
502 maindata->error = SOLV_ERROR_CORRUPT;
505 data->nkeys = 1 + (n >> 1);
506 data->keys = sat_malloc2(data->nkeys, sizeof(data->keys[0]));
507 memset(data->keys, 0, sizeof(Repokey));
508 for (i = 1, ide = ida; i < data->nkeys; i++)
510 data->keys[i].name = *ide++;
511 data->keys[i].type = *ide++;
512 data->keys[i].size = 0;
513 data->keys[i].storage = 0;
517 qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
519 case REPOKEY_TYPE_STR:
520 if (id != REPODATA_LOCATION)
521 skip_item(maindata, REPOKEY_TYPE_STR, numid, numrel);
525 unsigned len = sizeof(buf);
526 char *filename = buf;
527 read_str(maindata, &filename, &len);
528 data->location = strdup(filename);
534 skip_item(maindata, keys[key].type, numid, numrel);
541 parse_info_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel)
545 while ((key = *keyp++) != 0)
548 if (id == REPODATA_ADDEDFILEPROVIDES && keys[key].type == REPOKEY_TYPE_REL_IDARRAY)
551 /* + 1 just in case */
552 ida = sat_calloc(keys[key].size + 1, sizeof(Id));
553 read_idarray(maindata, 0, 0, ida, ida + keys[key].size + 1);
554 maindata->addedfileprovides = ida;
563 *ida = idmap ? idmap[old] : old;
567 skip_item(maindata, keys[key].type, numid, numrel);
571 /*-----------------------------------------------------------------*/
575 skip_schema(Repodata *data, Id *keyp, Repokey *keys, unsigned int numid, unsigned int numrel)
578 while ((key = *keyp++) != 0)
579 skip_item(data, keys[key].type, numid, numrel);
582 /*-----------------------------------------------------------------*/
585 incore_add_id(Repodata *data, Id x)
588 /* make sure we have at least 5 bytes free */
589 if (data->incoredatafree < 5)
591 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
592 data->incoredatafree = 1024;
594 dp = data->incoredata + data->incoredatalen;
600 *dp++ = (x >> 28) | 128;
602 *dp++ = (x >> 21) | 128;
603 *dp++ = (x >> 14) | 128;
606 *dp++ = (x >> 7) | 128;
608 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
609 data->incoredatalen = dp - data->incoredata;
613 incore_add_blob(Repodata *data, unsigned char *buf, int len)
615 if (data->incoredatafree < len)
617 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024 + len);
618 data->incoredatafree = 1024 + len;
620 memcpy(data->incoredata + data->incoredatalen, buf, len);
621 data->incoredatafree -= len;
622 data->incoredatalen += len;
626 incore_add_u32(Repodata *data, unsigned int x)
629 /* make sure we have at least 4 bytes free */
630 if (data->incoredatafree < 4)
632 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
633 data->incoredatafree = 1024;
635 dp = data->incoredata + data->incoredatalen;
640 data->incoredatafree -= 4;
641 data->incoredatalen += 4;
646 incore_add_u8(Repodata *data, unsigned int x)
649 /* make sure we have at least 1 byte free */
650 if (data->incoredatafree < 1)
652 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
653 data->incoredatafree = 1024;
655 dp = data->incoredata + data->incoredatalen;
657 data->incoredatafree--;
658 data->incoredatalen++;
664 // ----------------------------------------------
668 * read repo from .solv file
673 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
675 Pool *pool = repo->pool;
677 unsigned int numid, numrel, numdir, numsolv;
678 unsigned int numkeys, numschemata, numinfo;
681 Offset *str; /* map Id -> Offset into string space */
682 char *strsp; /* repo string space */
683 char *sp; /* pointer into string space */
684 Id *idmap; /* map of repo Ids to pool Ids */
686 unsigned int hashmask, h;
692 unsigned int size_idarray;
693 Id *idarraydatap, *idarraydataend;
696 unsigned int solvflags;
697 unsigned int solvversion;
699 Id *schemadata, *schemadatap, *schemadataend;
702 unsigned oldnrepodata;
703 int maxsize, allsize;
704 unsigned char *buf, *dp, *dps;
707 struct _Stringpool *spool;
711 memset(&data, 0, sizeof(data));
718 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
720 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
721 return SOLV_ERROR_NOT_SOLV;
723 solvversion = read_u32(&data);
729 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
730 return SOLV_ERROR_UNSUPPORTED;
733 pool_freeidhashes(pool);
735 numid = read_u32(&data);
736 numrel = read_u32(&data);
737 numdir = read_u32(&data);
738 numsolv = read_u32(&data);
739 numkeys = read_u32(&data);
740 numschemata = read_u32(&data);
741 numinfo = read_u32(&data);
742 solvflags = read_u32(&data);
744 if (numdir && numdir < 2)
746 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
747 return SOLV_ERROR_CORRUPT;
754 pool_debug(pool, SAT_ERROR, "relations are forbidden in a store\n");
755 return SOLV_ERROR_CORRUPT;
757 if (parent->end - parent->start != numsolv)
759 pool_debug(pool, SAT_ERROR, "unequal number of solvables in a store\n");
760 return SOLV_ERROR_CORRUPT;
764 pool_debug(pool, SAT_ERROR, "info blocks are forbidden in a store\n");
765 return SOLV_ERROR_CORRUPT;
769 /******* Part 1: string IDs *****************************************/
771 sizeid = read_u32(&data); /* size of string+Id space */
774 * read strings and Ids
789 spool->stringspace = sat_malloc(7);
790 strcpy(spool->stringspace, "<NULL>");
795 /* alloc string buffer */
796 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
797 /* alloc string offsets (Id -> Offset into string space) */
798 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
800 strsp = spool->stringspace;
801 str = spool->strings; /* array of offsets into strsp, indexed by Id */
803 /* point to _BEHIND_ already allocated string/Id space */
804 strsp += spool->sstrings;
808 * read new repo at end of pool
811 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
813 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
815 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
816 return SOLV_ERROR_EOF;
821 unsigned int pfsize = read_u32(&data);
822 char *prefix = sat_malloc(pfsize);
828 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
830 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
832 return SOLV_ERROR_EOF;
834 for (i = 1; i < numid; i++)
836 int same = (unsigned char)*pp++;
837 size_t len = strlen(pp) + 1;
838 freesp -= same + len;
841 pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
843 return SOLV_ERROR_OVERFLOW;
846 memcpy(dest, old_str, same);
847 memcpy(dest + same, pp, len);
855 pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
856 return SOLV_ERROR_CORRUPT;
859 strsp[sizeid] = 0; /* make string space \0 terminated */
864 /* no shared pool, thus no idmap and no unification */
866 spool->nstrings = numid;
870 /* we need the '' for directories */
871 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
872 return SOLV_ERROR_CORRUPT;
874 for (i = 1; i < spool->nstrings; i++)
876 if (sp >= strsp + sizeid)
878 pool_debug(pool, SAT_ERROR, "not enough strings\n");
879 return SOLV_ERROR_OVERFLOW;
881 str[i] = sp - spool->stringspace;
882 sp += strlen(sp) + 1;
884 spool->sstrings = sp - spool->stringspace;
889 /* alloc id map for name and rel Ids. this maps ids in the solv files
890 * to the ids in our pool */
891 idmap = sat_calloc(numid + numrel, sizeof(Id));
894 * build hashes for all read strings
898 hashmask = mkmask(spool->nstrings + numid);
901 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
902 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
906 * create hashtable with strings already in pool
909 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
910 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
912 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
913 hh = HASHCHAIN_START;
915 h = HASHCHAIN_NEXT(h, hh, hashmask);
920 * run over string space, calculate offsets
922 * build id map (maps solv Id -> pool Id)
925 for (i = 1; i < numid; i++)
927 if (sp >= strsp + sizeid)
931 pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
932 return SOLV_ERROR_OVERFLOW;
934 if (!*sp) /* empty string */
942 h = strhash(sp) & hashmask;
943 hh = HASHCHAIN_START;
949 if (!strcmp(spool->stringspace + spool->strings[id], sp))
950 break; /* existing string */
951 h = HASHCHAIN_NEXT(h, hh, hashmask);
954 /* length == offset to next string */
956 if (id == ID_NULL) /* end of hash chain -> new string */
958 id = spool->nstrings++;
960 str[id] = spool->sstrings; /* save Offset */
961 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
962 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
963 spool->sstrings += l;
965 idmap[i] = id; /* repo relative -> pool relative */
966 sp += l; /* next string */
970 pool_shrink_strings(pool); /* vacuum */
973 /******* Part 2: Relation IDs ***************************************/
983 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
986 hashmask = mkmask(pool->nrels + numrel);
988 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
989 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
992 * prep hash table with already existing RelDeps
995 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
996 for (i = 1; i < pool->nrels; i++)
998 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
999 hh = HASHCHAIN_START;
1001 h = HASHCHAIN_NEXT(h, hh, hashmask);
1006 * read RelDeps from repo
1009 for (i = 0; i < numrel; i++)
1011 name = read_id(&data, i + numid); /* read (repo relative) Ids */
1012 evr = read_id(&data, i + numid);
1013 flags = read_u8(&data);
1014 name = idmap[name]; /* map to (pool relative) Ids */
1016 h = relhash(name, evr, flags) & hashmask;
1017 hh = HASHCHAIN_START;
1021 if (id == ID_NULL) /* end of hash chain */
1023 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
1025 h = HASHCHAIN_NEXT(h, hh, hashmask);
1027 if (id == ID_NULL) /* new RelDep */
1031 ran[id].name = name;
1033 ran[id].flags = flags;
1035 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
1038 pool_shrink_rels(pool); /* vacuum */
1042 /******* Part 3: Dirs ***********************************************/
1045 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
1046 data.dirpool.ndirs = numdir;
1047 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
1048 data.dirpool.dirs[1] = 1; /* dir 1: / */
1049 for (i = 2; i < numdir; i++)
1051 id = read_id(&data, i + numid);
1053 data.dirpool.dirs[i] = -(id - numid);
1055 data.dirpool.dirs[i] = idmap[id];
1057 data.dirpool.dirs[i] = id;
1061 /******* Part 4: Keys ***********************************************/
1063 keys = sat_calloc(numkeys, sizeof(*keys));
1064 /* keys start at 1 */
1065 for (i = 1; i < numkeys; i++)
1067 id = read_id(&data, numid);
1071 id = str2id(pool, stringpool_id2str(spool, id), 1);
1072 type = read_id(&data, numid);
1076 type = str2id(pool, stringpool_id2str(spool, type), 1);
1077 if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_DIRNUMNUMARRAY)
1079 pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
1080 data.error = SOLV_ERROR_UNSUPPORTED;
1081 type = REPOKEY_TYPE_VOID;
1084 keys[i].type = type;
1085 keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
1086 keys[i].storage = read_id(&data, 0);
1087 if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
1088 keys[i].storage = KEY_STORAGE_SOLVABLE;
1089 else if (keys[i].storage == KEY_STORAGE_SOLVABLE)
1090 keys[i].storage = KEY_STORAGE_INCORE;
1091 if (keys[i].type == REPOKEY_TYPE_CONSTANTID)
1094 keys[i].size = idmap[keys[i].size];
1096 keys[i].size = str2id(pool, stringpool_id2str(spool, keys[i].size), 1);
1099 fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
1100 keys[i].size, keys[i].storage);
1104 have_xdata = parent ? 1 : 0;
1105 for (i = 1; i < numkeys; i++)
1106 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1110 data.nkeys = numkeys;
1112 /******* Part 5: Schemata ********************************************/
1114 id = read_id(&data, 0);
1115 schemadata = sat_calloc(id + 1, sizeof(Id));
1116 schemadatap = schemadata + 1;
1117 schemadataend = schemadatap + id;
1118 schemata = sat_calloc(numschemata, sizeof(Id));
1119 for (i = 1; i < numschemata; i++)
1121 schemata[i] = schemadatap - schemadata;
1122 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
1124 Id *sp = schemadata + schemata[i];
1125 fprintf (stderr, "schema %d:", i);
1127 fprintf (stderr, " %d", *sp);
1128 fprintf (stderr, "\n");
1131 data.schemata = schemata;
1132 data.nschemata = numschemata;
1133 data.schemadata = schemadata;
1134 data.schemadatalen = schemadataend - data.schemadata;
1137 /******* Part 6: Info ***********************************************/
1138 oldnrepodata = repo->nrepodata;
1141 id = read_id(&data, 0);
1142 id = read_id(&data, 0);
1144 for (i = 0; i < numinfo; i++)
1146 /* for now we're just interested in data that starts with
1147 * the repodata_external id
1150 id = read_id(&data, numschemata);
1151 keyp = schemadata + schemata[id];
1153 if (keys[key].name == REPODATA_EXTERNAL && keys[key].type == REPOKEY_TYPE_VOID)
1155 /* external data for some ids */
1156 parse_external_repodata(&data, keyp, keys, idmap, numid, numrel);
1158 else if (keys[key].name == REPODATA_INFO)
1160 parse_info_repodata(&data, keyp, keys, idmap, numid, numrel);
1164 skip_schema(&data, keyp, keys, numid, numrel);
1169 /******* Part 7: item data *******************************************/
1171 /* calculate idarray size */
1173 for (i = 1; i < numkeys; i++)
1176 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1177 && id >= INTERESTED_START && id <= INTERESTED_END)
1178 size_idarray += keys[i].size;
1183 maxsize = read_id(&data, 0);
1184 allsize = read_id(&data, 0);
1185 if (maxsize > allsize)
1187 pool_debug(pool, SAT_ERROR, "maxsize %d is greater then allsize %d\n", maxsize, allsize);
1188 data.error = SOLV_ERROR_CORRUPT;
1192 maxsize = allsize = 0;
1194 /* allocate needed space in repo */
1195 /* we add maxsize because it is an upper limit for all idarrays */
1196 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1197 idarraydatap = repo->idarraydata + repo->idarraysize;
1198 repo->idarraysize += size_idarray;
1199 idarraydataend = idarraydatap + size_idarray;
1202 /* read solvables */
1206 s = pool_id2solvable(pool, parent->start);
1208 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1209 /* store start and end of our id block */
1210 data.start = s - pool->solvables;
1211 data.end = data.start + numsolv;
1212 /* In case we have info blocks, make them refer to our part of the
1214 for (i = oldnrepodata; i < repo->nrepodata; i++)
1216 repo->repodata[i].start = data.start;
1217 repo->repodata[i].end = data.end;
1225 /* reserve one byte so that all offsets are not zero */
1226 incore_add_id(&data, 0);
1227 repodata_extend_block(&data, data.start, numsolv);
1231 buf = sat_calloc(maxsize + 4, 1);
1233 for (i = 0; i < numsolv; i++, s++)
1242 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1243 data.error = SOLV_ERROR_EOF;
1247 memmove(buf, dp, left);
1251 if (l && fread(buf + left, l, 1, data.fp) != 1)
1253 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1254 data.error = SOLV_ERROR_EOF;
1261 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1264 data.incoreoffset[i] = data.incoredatalen;
1265 incore_add_id(&data, id);
1267 keyp = schemadata + schemata[id];
1268 while ((key = *keyp++) != 0)
1273 id = keys[key].name;
1275 fprintf(stderr, "solv %d name %d type %d class %d\n", i, id, keys[key].type, keys[key].storage);
1277 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1279 /* copy offset/length into incore */
1281 dp = data_skip(dp, REPOKEY_TYPE_ID);
1282 dp = data_skip(dp, REPOKEY_TYPE_ID);
1283 incore_add_blob(&data, dps, dp - dps);
1286 switch (keys[key].type)
1288 case REPOKEY_TYPE_ID:
1289 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1290 if (id == SOLVABLE_NAME)
1292 else if (id == SOLVABLE_ARCH)
1294 else if (id == SOLVABLE_EVR)
1296 else if (id == SOLVABLE_VENDOR)
1298 else if (keys[key].storage == KEY_STORAGE_INCORE)
1299 incore_add_id(&data, did);
1301 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1304 case REPOKEY_TYPE_U32:
1305 dp = data_read_u32(dp, &h);
1307 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1309 if (id == RPM_RPMDBID)
1312 repo->rpmdbid = sat_calloc(numsolv, sizeof(Id));
1313 repo->rpmdbid[i] = h;
1315 else if (keys[key].storage == KEY_STORAGE_INCORE)
1316 incore_add_u32(&data, h);
1318 case REPOKEY_TYPE_IDARRAY:
1319 case REPOKEY_TYPE_REL_IDARRAY:
1320 if (id < INTERESTED_START || id > INTERESTED_END)
1323 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1324 if (keys[key].storage == KEY_STORAGE_INCORE && idmap)
1326 if (keys[key].storage == KEY_STORAGE_INCORE)
1327 incore_add_blob(&data, dps, dp - dps);
1330 ido = idarraydatap - repo->idarraydata;
1331 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1332 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1333 else if (id == SOLVABLE_REQUIRES)
1334 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1335 else if (id == SOLVABLE_PROVIDES)
1336 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1338 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1339 if (idarraydatap > idarraydataend)
1341 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1342 data.error = SOLV_ERROR_OVERFLOW;
1345 if (id == SOLVABLE_PROVIDES)
1347 else if (id == SOLVABLE_OBSOLETES)
1349 else if (id == SOLVABLE_CONFLICTS)
1351 else if (id == SOLVABLE_REQUIRES)
1353 else if (id == SOLVABLE_RECOMMENDS)
1355 else if (id == SOLVABLE_SUPPLEMENTS)
1356 s->supplements = ido;
1357 else if (id == SOLVABLE_SUGGESTS)
1359 else if (id == SOLVABLE_ENHANCES)
1361 else if (id == SOLVABLE_FRESHENS)
1364 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1365 for (; repo->idarraydata[ido]; ido++)
1366 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1371 dp = data_skip(dp, keys[key].type);
1372 if (keys[key].storage == KEY_STORAGE_INCORE)
1373 incore_add_blob(&data, dps, dp - dps);
1379 /* should shrink idarraydata again */
1386 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1387 data.error = SOLV_ERROR_EOF;
1394 /* free solvables */
1395 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1397 repo->idarraysize -= size_idarray;
1398 /* free incore data */
1399 data.incoredata = sat_free(data.incoredata);
1400 data.incoredatalen = data.incoredatafree = 0;
1403 if (data.incoredatafree)
1405 /* shrink excess size */
1406 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1407 data.incoredatafree = 0;
1410 for (i = 1; i < numkeys; i++)
1411 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1413 if (i < numkeys && !data.error)
1416 unsigned int pagesize;
1418 /* we have vertical data, make it available */
1419 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1420 for (i = 1; i < numkeys; i++)
1421 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1423 data.verticaloffset[i] = fileoffset;
1424 fileoffset += keys[i].size;
1426 data.lastverticaloffset = fileoffset;
1427 pagesize = read_u32(&data);
1428 repodata_read_or_setup_pages(&data, pagesize, fileoffset);
1432 /* no longer needed */
1436 if (parent && !data.error)
1439 sat_free(parent->schemata);
1440 sat_free(parent->schemadata);
1441 sat_free(parent->keys);
1442 sat_free(parent->location);
1445 else if ((data.incoredatalen || data.fp) && !data.error)
1447 /* we got some data, make it available */
1448 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1449 repo->repodata[repo->nrepodata++] = data;
1454 sat_free(data.dirpool.dirs);
1455 sat_free(data.incoreoffset);
1457 sat_free(schemadata);
1467 repo_add_solv(Repo *repo, FILE *fp)
1469 return repo_add_solv_parent(repo, fp, 0);
1473 repodata_load_solv(Repodata *data)
1476 Pool *pool = data->repo->pool;
1477 if (!pool->loadcallback)
1479 data->state = REPODATA_ERROR;
1482 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1485 data->state = REPODATA_ERROR;
1488 if (repo_add_solv_parent(data->repo, fp, data))
1489 data->state = REPODATA_ERROR;
1491 data->state = REPODATA_AVAILABLE;