7 static Packet *readilump(Lump *u, IAddr *ia, u8int *score, int rac);
10 readlump(u8int *score, int type, u32int size)
21 u = lookuplump(score, type);
23 n = packetsize(u->data);
25 seterr(EOk, "read too small: asked for %d need at least %d", size, n);
30 p = packetdup(u->data, 0, n);
36 if(lookupscore(score, type, &ia, &rac) < 0){
37 //ZZZ place to check for someone trying to guess scores
38 seterr(EOk, "no block with that score exists");
44 seterr(EOk, "read too small 1: asked for %d need at least %d", size, ia.size);
50 p = readilump(u, &ia, score, rac);
57 * save away a lump, and return it's score.
58 * doesn't store duplicates, but checks that the data is really the same.
61 writelump(Packet *p, u8int *score, int type, u32int creator)
72 u = lookuplump(score, type);
75 if(packetcmp(p, u->data) != 0){
76 seterr(EStrange, "score collision");
85 return queuewrite(u, p, creator);
87 ok = writeqlump(u, p, creator);
94 writeqlump(Lump *u, Packet *p, int creator)
102 if(lookupscore(u->score, u->type, &ia, &rac) == 0){
105 * assume it was corrupted data and store the block again
107 old = readilump(u, &ia, u->score, rac);
110 if(packetcmp(p, old) != 0){
111 seterr(EStrange, "score collision");
119 logerr(EAdmin, "writelump: read %V failed, rewriting: %r\n", u->score);
122 flat = packet2zblock(p, packetsize(p));
123 ok = storeclump(mainindex, flat, u->score, u->type, creator, &ia);
126 ok = insertscore(u->score, &ia, 1);
136 readahead(u64int a, Arena *arena, u64int aa, int n)
138 u8int buf[ClumpSize];
143 if (aa >= arena->used)
145 if(readarena(arena, aa, buf, ClumpSize) < ClumpSize)
147 if(unpackclump(&cl, buf) < 0)
150 ia.type = cl.info.type;
151 ia.size = cl.info.uncsize;
152 ia.blocks = (cl.info.size + ClumpSize + (1 << ABlockLog) - 1) >> ABlockLog;
153 insertscore(cl.info.score, &ia, 0);
154 a += ClumpSize + cl.info.size;
155 aa += ClumpSize + cl.info.size;
161 readilump(Lump *u, IAddr *ia, u8int *score, int rac)
168 u8int sc[VtScoreSize];
170 arena = amapitoa(mainindex, ia->addr, &aa);
174 zb = loadclump(arena, aa, ia->blocks, &cl, sc, paranoid);
178 if(ia->size != cl.info.uncsize){
179 seterr(EInconsist, "index and clump size mismatch");
183 if(ia->type != cl.info.type){
184 seterr(EInconsist, "index and clump type mismatch");
188 if(scorecmp(score, sc) != 0){
189 seterr(ECrash, "score mismatch");
195 a = ia->addr + ClumpSize + cl.info.size;
196 aa += ClumpSize + cl.info.size;
197 readahead(a, arena, aa, 20);
200 p = zblock2packet(zb, cl.info.uncsize);
202 pp = packetdup(p, 0, packetsize(p));