Blame


1 43b99cd9 2007-04-21 devnull #include "stdinc.h"
2 43b99cd9 2007-04-21 devnull #include "dat.h"
3 43b99cd9 2007-04-21 devnull #include "fns.h"
4 43b99cd9 2007-04-21 devnull #include "whack.h"
5 43b99cd9 2007-04-21 devnull
6 43b99cd9 2007-04-21 devnull static int disksummary(HConnect*);
7 43b99cd9 2007-04-21 devnull static int diskarenapart(HConnect*, char*, Part*);
8 43b99cd9 2007-04-21 devnull static int diskbloom(HConnect*, char*, Part*);
9 43b99cd9 2007-04-21 devnull static int diskisect(HConnect*, char*, Part*);
10 43b99cd9 2007-04-21 devnull
11 43b99cd9 2007-04-21 devnull int
12 43b99cd9 2007-04-21 devnull hdisk(HConnect *c)
13 43b99cd9 2007-04-21 devnull {
14 43b99cd9 2007-04-21 devnull char *disk, *type;
15 43b99cd9 2007-04-21 devnull Part *p;
16 43b99cd9 2007-04-21 devnull int ret;
17 fa325e9b 2020-01-10 cross
18 43b99cd9 2007-04-21 devnull if(hsethtml(c) < 0)
19 43b99cd9 2007-04-21 devnull return -1;
20 43b99cd9 2007-04-21 devnull
21 43b99cd9 2007-04-21 devnull disk = hargstr(c, "disk", "");
22 43b99cd9 2007-04-21 devnull if(!disk[0])
23 43b99cd9 2007-04-21 devnull return disksummary(c);
24 43b99cd9 2007-04-21 devnull if((p = initpart(disk, OREAD)) == nil){
25 43b99cd9 2007-04-21 devnull hprint(&c->hout, "open %s: %r", disk);
26 43b99cd9 2007-04-21 devnull return 0;
27 43b99cd9 2007-04-21 devnull }
28 43b99cd9 2007-04-21 devnull
29 43b99cd9 2007-04-21 devnull type = hargstr(c, "type", "");
30 43b99cd9 2007-04-21 devnull switch(type[0]){
31 43b99cd9 2007-04-21 devnull case 'a':
32 43b99cd9 2007-04-21 devnull ret = diskarenapart(c, disk, p);
33 43b99cd9 2007-04-21 devnull break;
34 43b99cd9 2007-04-21 devnull case 'b':
35 43b99cd9 2007-04-21 devnull ret = diskbloom(c, disk, p);
36 43b99cd9 2007-04-21 devnull break;
37 43b99cd9 2007-04-21 devnull case 'i':
38 43b99cd9 2007-04-21 devnull ret = diskisect(c, disk, p);
39 43b99cd9 2007-04-21 devnull break;
40 43b99cd9 2007-04-21 devnull default:
41 43b99cd9 2007-04-21 devnull hprint(&c->hout, "unknown disk type %s", type);
42 43b99cd9 2007-04-21 devnull return 0;
43 43b99cd9 2007-04-21 devnull }
44 43b99cd9 2007-04-21 devnull freepart(p);
45 fa325e9b 2020-01-10 cross return ret;
46 43b99cd9 2007-04-21 devnull }
47 43b99cd9 2007-04-21 devnull
48 43b99cd9 2007-04-21 devnull static int
49 43b99cd9 2007-04-21 devnull disksummary(HConnect *c)
50 43b99cd9 2007-04-21 devnull {
51 43b99cd9 2007-04-21 devnull int i;
52 43b99cd9 2007-04-21 devnull Index *ix;
53 43b99cd9 2007-04-21 devnull Part *p;
54 fa325e9b 2020-01-10 cross
55 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h1>venti disks</h1>\n");
56 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
57 43b99cd9 2007-04-21 devnull ix = mainindex;
58 43b99cd9 2007-04-21 devnull p = nil;
59 43b99cd9 2007-04-21 devnull for(i=0; i<ix->narenas; i++){
60 43b99cd9 2007-04-21 devnull if(ix->arenas[i]->part == p)
61 43b99cd9 2007-04-21 devnull continue;
62 43b99cd9 2007-04-21 devnull p = ix->arenas[i]->part;
63 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<a href=\"/disk?disk=%s&type=a\">%s</a> %s\n", p->name, p->name, ix->arenas[i]->name);
64 43b99cd9 2007-04-21 devnull }
65 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\n");
66 43b99cd9 2007-04-21 devnull p = nil;
67 43b99cd9 2007-04-21 devnull for(i=0; i<ix->nsects; i++){
68 43b99cd9 2007-04-21 devnull if(ix->sects[i]->part == p)
69 43b99cd9 2007-04-21 devnull continue;
70 43b99cd9 2007-04-21 devnull p = ix->sects[i]->part;
71 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<a href=\"/disk?disk=%s&type=i\">%s</a> %s\n", p->name, p->name, ix->sects[i]->name);
72 43b99cd9 2007-04-21 devnull }
73 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\n");
74 43b99cd9 2007-04-21 devnull if(ix->bloom){
75 43b99cd9 2007-04-21 devnull p = ix->bloom->part;
76 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<a href=\"/disk?disk=%s&type=b\">%s</a> %s\n", p->name, p->name, "bloom filter");
77 43b99cd9 2007-04-21 devnull }
78 43b99cd9 2007-04-21 devnull return 0;
79 43b99cd9 2007-04-21 devnull }
80 43b99cd9 2007-04-21 devnull
81 43b99cd9 2007-04-21 devnull static char*
82 43b99cd9 2007-04-21 devnull readap(Part *p, ArenaPart *ap)
83 43b99cd9 2007-04-21 devnull {
84 43b99cd9 2007-04-21 devnull uchar *blk;
85 43b99cd9 2007-04-21 devnull char *table;
86 fa325e9b 2020-01-10 cross
87 43b99cd9 2007-04-21 devnull blk = vtmalloc(8192);
88 43b99cd9 2007-04-21 devnull if(readpart(p, PartBlank, blk, 8192) != 8192)
89 43b99cd9 2007-04-21 devnull return nil;
90 43b99cd9 2007-04-21 devnull if(unpackarenapart(ap, blk) < 0){
91 43b99cd9 2007-04-21 devnull werrstr("corrupt arena part header: %r");
92 43b99cd9 2007-04-21 devnull return nil;
93 43b99cd9 2007-04-21 devnull }
94 43b99cd9 2007-04-21 devnull vtfree(blk);
95 43b99cd9 2007-04-21 devnull ap->tabbase = (PartBlank+HeadSize+ap->blocksize-1)&~(ap->blocksize-1);
96 43b99cd9 2007-04-21 devnull ap->tabsize = ap->arenabase - ap->tabbase;
97 43b99cd9 2007-04-21 devnull table = vtmalloc(ap->tabsize+1);
98 43b99cd9 2007-04-21 devnull if(readpart(p, ap->tabbase, (uchar*)table, ap->tabsize) != ap->tabsize){
99 43b99cd9 2007-04-21 devnull werrstr("reading arena part directory: %r");
100 43b99cd9 2007-04-21 devnull return nil;
101 43b99cd9 2007-04-21 devnull }
102 43b99cd9 2007-04-21 devnull table[ap->tabsize] = 0;
103 43b99cd9 2007-04-21 devnull return table;
104 43b99cd9 2007-04-21 devnull }
105 43b99cd9 2007-04-21 devnull
106 43b99cd9 2007-04-21 devnull static int
107 43b99cd9 2007-04-21 devnull xfindarena(char *table, char *name, vlong *start, vlong *end)
108 43b99cd9 2007-04-21 devnull {
109 43b99cd9 2007-04-21 devnull int i, nline;
110 43b99cd9 2007-04-21 devnull char *p, *q, *f[4], line[256];
111 fa325e9b 2020-01-10 cross
112 43b99cd9 2007-04-21 devnull nline = atoi(table);
113 43b99cd9 2007-04-21 devnull p = strchr(table, '\n');
114 43b99cd9 2007-04-21 devnull if(p)
115 43b99cd9 2007-04-21 devnull p++;
116 43b99cd9 2007-04-21 devnull for(i=0; i<nline; i++){
117 43b99cd9 2007-04-21 devnull if(p == nil)
118 43b99cd9 2007-04-21 devnull break;
119 43b99cd9 2007-04-21 devnull q = strchr(p, '\n');
120 43b99cd9 2007-04-21 devnull if(q)
121 43b99cd9 2007-04-21 devnull *q++ = 0;
122 43b99cd9 2007-04-21 devnull if(strlen(p) >= sizeof line){
123 43b99cd9 2007-04-21 devnull p = q;
124 43b99cd9 2007-04-21 devnull continue;
125 43b99cd9 2007-04-21 devnull }
126 43b99cd9 2007-04-21 devnull strcpy(line, p);
127 43b99cd9 2007-04-21 devnull memset(f, 0, sizeof f);
128 43b99cd9 2007-04-21 devnull if(tokenize(line, f, nelem(f)) < 3){
129 43b99cd9 2007-04-21 devnull p = q;
130 43b99cd9 2007-04-21 devnull continue;
131 43b99cd9 2007-04-21 devnull }
132 43b99cd9 2007-04-21 devnull if(strcmp(f[0], name) == 0){
133 43b99cd9 2007-04-21 devnull *start = strtoull(f[1], 0, 0);
134 43b99cd9 2007-04-21 devnull *end = strtoull(f[2], 0, 0);
135 43b99cd9 2007-04-21 devnull return 0;
136 43b99cd9 2007-04-21 devnull }
137 43b99cd9 2007-04-21 devnull p = q;
138 43b99cd9 2007-04-21 devnull }
139 43b99cd9 2007-04-21 devnull return -1;
140 43b99cd9 2007-04-21 devnull }
141 43b99cd9 2007-04-21 devnull
142 43b99cd9 2007-04-21 devnull static void
143 43b99cd9 2007-04-21 devnull diskarenatable(HConnect *c, char *disk, char *table)
144 43b99cd9 2007-04-21 devnull {
145 43b99cd9 2007-04-21 devnull char *p, *q;
146 43b99cd9 2007-04-21 devnull int i, nline;
147 43b99cd9 2007-04-21 devnull char *f[4], line[256], base[256];
148 43b99cd9 2007-04-21 devnull
149 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>table</h2>\n");
150 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
151 43b99cd9 2007-04-21 devnull nline = atoi(table);
152 43b99cd9 2007-04-21 devnull snprint(base, sizeof base, "/disk?disk=%s&type=a", disk);
153 43b99cd9 2007-04-21 devnull p = strchr(table, '\n');
154 43b99cd9 2007-04-21 devnull if(p)
155 43b99cd9 2007-04-21 devnull p++;
156 43b99cd9 2007-04-21 devnull for(i=0; i<nline; i++){
157 43b99cd9 2007-04-21 devnull if(p == nil){
158 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<b><i>unexpected end of table</i></b>\n");
159 43b99cd9 2007-04-21 devnull break;
160 43b99cd9 2007-04-21 devnull }
161 43b99cd9 2007-04-21 devnull q = strchr(p, '\n');
162 43b99cd9 2007-04-21 devnull if(q)
163 43b99cd9 2007-04-21 devnull *q++ = 0;
164 43b99cd9 2007-04-21 devnull if(strlen(p) >= sizeof line){
165 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%s\n", p);
166 43b99cd9 2007-04-21 devnull p = q;
167 43b99cd9 2007-04-21 devnull continue;
168 43b99cd9 2007-04-21 devnull }
169 43b99cd9 2007-04-21 devnull strcpy(line, p);
170 43b99cd9 2007-04-21 devnull memset(f, 0, sizeof f);
171 43b99cd9 2007-04-21 devnull if(tokenize(line, f, 3) < 3){
172 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%s\n", p);
173 43b99cd9 2007-04-21 devnull p = q;
174 43b99cd9 2007-04-21 devnull continue;
175 43b99cd9 2007-04-21 devnull }
176 43b99cd9 2007-04-21 devnull p = q;
177 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<a href=\"%s&arena=%s\">%s</a> %s %s\n",
178 43b99cd9 2007-04-21 devnull base, f[0], f[0], f[1], f[2]);
179 43b99cd9 2007-04-21 devnull }
180 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre>\n");
181 43b99cd9 2007-04-21 devnull }
182 43b99cd9 2007-04-21 devnull
183 43b99cd9 2007-04-21 devnull static char*
184 43b99cd9 2007-04-21 devnull fmttime(char *buf, ulong time)
185 43b99cd9 2007-04-21 devnull {
186 43b99cd9 2007-04-21 devnull strcpy(buf, ctime(time));
187 43b99cd9 2007-04-21 devnull buf[28] = 0;
188 43b99cd9 2007-04-21 devnull return buf;
189 43b99cd9 2007-04-21 devnull }
190 43b99cd9 2007-04-21 devnull
191 43b99cd9 2007-04-21 devnull
192 43b99cd9 2007-04-21 devnull static int diskarenaclump(HConnect*, Arena*, vlong, char*);
193 43b99cd9 2007-04-21 devnull static int diskarenatoc(HConnect*, Arena*);
194 43b99cd9 2007-04-21 devnull
195 43b99cd9 2007-04-21 devnull static int
196 43b99cd9 2007-04-21 devnull diskarenapart(HConnect *c, char *disk, Part *p)
197 43b99cd9 2007-04-21 devnull {
198 43b99cd9 2007-04-21 devnull char *arenaname;
199 43b99cd9 2007-04-21 devnull ArenaPart ap;
200 43b99cd9 2007-04-21 devnull ArenaHead head;
201 43b99cd9 2007-04-21 devnull Arena arena;
202 43b99cd9 2007-04-21 devnull char *table;
203 43b99cd9 2007-04-21 devnull char *score;
204 43b99cd9 2007-04-21 devnull char *clump;
205 43b99cd9 2007-04-21 devnull uchar *blk;
206 43b99cd9 2007-04-21 devnull vlong start, end, off;
207 43b99cd9 2007-04-21 devnull char tbuf[60];
208 43b99cd9 2007-04-21 devnull
209 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h1>arena partition %s</h1>\n", disk);
210 43b99cd9 2007-04-21 devnull
211 43b99cd9 2007-04-21 devnull if((table = readap(p, &ap)) == nil){
212 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%r\n");
213 43b99cd9 2007-04-21 devnull goto out;
214 43b99cd9 2007-04-21 devnull }
215 fa325e9b 2020-01-10 cross
216 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
217 43b99cd9 2007-04-21 devnull hprint(&c->hout, "version=%d blocksize=%d base=%d\n",
218 43b99cd9 2007-04-21 devnull ap.version, ap.blocksize, ap.arenabase);
219 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre>\n");
220 43b99cd9 2007-04-21 devnull
221 43b99cd9 2007-04-21 devnull arenaname = hargstr(c, "arena", "");
222 43b99cd9 2007-04-21 devnull if(arenaname[0] == 0){
223 43b99cd9 2007-04-21 devnull diskarenatable(c, disk, table);
224 43b99cd9 2007-04-21 devnull goto out;
225 43b99cd9 2007-04-21 devnull }
226 fa325e9b 2020-01-10 cross
227 43b99cd9 2007-04-21 devnull if(xfindarena(table, arenaname, &start, &end) < 0){
228 43b99cd9 2007-04-21 devnull hprint(&c->hout, "no such arena %s\n", arenaname);
229 43b99cd9 2007-04-21 devnull goto out;
230 43b99cd9 2007-04-21 devnull }
231 fa325e9b 2020-01-10 cross
232 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>arena %s</h2>\n", arenaname);
233 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>start=%#llx end=%#llx<pre>\n", start, end);
234 43b99cd9 2007-04-21 devnull if(end < start || end - start < HeadSize){
235 43b99cd9 2007-04-21 devnull hprint(&c->hout, "bad size %#llx\n", end - start);
236 43b99cd9 2007-04-21 devnull goto out;
237 43b99cd9 2007-04-21 devnull }
238 43b99cd9 2007-04-21 devnull
239 43b99cd9 2007-04-21 devnull // read arena header, tail
240 43b99cd9 2007-04-21 devnull blk = vtmalloc(HeadSize);
241 43b99cd9 2007-04-21 devnull if(readpart(p, start, blk, HeadSize) != HeadSize){
242 43b99cd9 2007-04-21 devnull hprint(&c->hout, "reading header: %r\n");
243 43b99cd9 2007-04-21 devnull vtfree(blk);
244 43b99cd9 2007-04-21 devnull goto out;
245 43b99cd9 2007-04-21 devnull }
246 43b99cd9 2007-04-21 devnull if(unpackarenahead(&head, blk) < 0){
247 43b99cd9 2007-04-21 devnull hprint(&c->hout, "corrupt arena header: %r\n");
248 43b99cd9 2007-04-21 devnull // hhex(blk, HeadSize);
249 43b99cd9 2007-04-21 devnull vtfree(blk);
250 43b99cd9 2007-04-21 devnull goto out;
251 43b99cd9 2007-04-21 devnull }
252 43b99cd9 2007-04-21 devnull vtfree(blk);
253 43b99cd9 2007-04-21 devnull
254 43b99cd9 2007-04-21 devnull hprint(&c->hout, "head:\n<pre>\n");
255 43b99cd9 2007-04-21 devnull hprint(&c->hout, "version=%d name=%s blocksize=%d size=%#llx clumpmagic=%#ux\n",
256 fa325e9b 2020-01-10 cross head.version, head.name, head.blocksize, head.size,
257 43b99cd9 2007-04-21 devnull head.clumpmagic);
258 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre><br><br>\n");
259 43b99cd9 2007-04-21 devnull
260 43b99cd9 2007-04-21 devnull if(head.blocksize > MaxIoSize || head.blocksize >= end - start){
261 43b99cd9 2007-04-21 devnull hprint(&c->hout, "corrupt block size %d\n", head.blocksize);
262 43b99cd9 2007-04-21 devnull goto out;
263 43b99cd9 2007-04-21 devnull }
264 43b99cd9 2007-04-21 devnull
265 43b99cd9 2007-04-21 devnull blk = vtmalloc(head.blocksize);
266 43b99cd9 2007-04-21 devnull if(readpart(p, end - head.blocksize, blk, head.blocksize) < 0){
267 43b99cd9 2007-04-21 devnull hprint(&c->hout, "reading tail: %r\n");
268 43b99cd9 2007-04-21 devnull vtfree(blk);
269 43b99cd9 2007-04-21 devnull goto out;
270 43b99cd9 2007-04-21 devnull }
271 43b99cd9 2007-04-21 devnull memset(&arena, 0, sizeof arena);
272 43b99cd9 2007-04-21 devnull arena.part = p;
273 43b99cd9 2007-04-21 devnull arena.blocksize = head.blocksize;
274 43b99cd9 2007-04-21 devnull arena.clumpmax = head.blocksize / ClumpInfoSize;
275 43b99cd9 2007-04-21 devnull arena.base = start + head.blocksize;
276 43b99cd9 2007-04-21 devnull arena.size = end - start - 2 * head.blocksize;
277 43b99cd9 2007-04-21 devnull if(unpackarena(&arena, blk) < 0){
278 43b99cd9 2007-04-21 devnull vtfree(blk);
279 43b99cd9 2007-04-21 devnull goto out;
280 43b99cd9 2007-04-21 devnull }
281 43b99cd9 2007-04-21 devnull scorecp(arena.score, blk+head.blocksize - VtScoreSize);
282 43b99cd9 2007-04-21 devnull
283 43b99cd9 2007-04-21 devnull vtfree(blk);
284 fa325e9b 2020-01-10 cross
285 43b99cd9 2007-04-21 devnull hprint(&c->hout, "tail:\n<pre>\n");
286 43b99cd9 2007-04-21 devnull hprint(&c->hout, "version=%d name=%s\n", arena.version, arena.name);
287 43b99cd9 2007-04-21 devnull hprint(&c->hout, "ctime=%d %s\n", arena.ctime, fmttime(tbuf, arena.ctime));
288 43b99cd9 2007-04-21 devnull hprint(&c->hout, "wtime=%d %s\n", arena.wtime, fmttime(tbuf, arena.wtime));
289 43b99cd9 2007-04-21 devnull hprint(&c->hout, "clumpmagic=%#ux\n", arena.clumpmagic);
290 43b99cd9 2007-04-21 devnull hprint(&c->hout, "score %V\n", arena.score);
291 43b99cd9 2007-04-21 devnull hprint(&c->hout, "diskstats:\n");
292 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n",
293 43b99cd9 2007-04-21 devnull arena.diskstats.clumps, arena.diskstats.cclumps,
294 43b99cd9 2007-04-21 devnull arena.diskstats.used, arena.diskstats.uncsize,
295 43b99cd9 2007-04-21 devnull arena.diskstats.sealed);
296 43b99cd9 2007-04-21 devnull hprint(&c->hout, "memstats:\n");
297 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n",
298 43b99cd9 2007-04-21 devnull arena.memstats.clumps, arena.memstats.cclumps,
299 43b99cd9 2007-04-21 devnull arena.memstats.used, arena.memstats.uncsize,
300 43b99cd9 2007-04-21 devnull arena.memstats.sealed);
301 43b99cd9 2007-04-21 devnull if(arena.clumpmax == 0){
302 43b99cd9 2007-04-21 devnull hprint(&c->hout, "bad clumpmax\n");
303 43b99cd9 2007-04-21 devnull goto out;
304 43b99cd9 2007-04-21 devnull }
305 43b99cd9 2007-04-21 devnull
306 43b99cd9 2007-04-21 devnull score = hargstr(c, "score", "");
307 43b99cd9 2007-04-21 devnull clump = hargstr(c, "clump", "");
308 43b99cd9 2007-04-21 devnull
309 43b99cd9 2007-04-21 devnull if(clump[0]){
310 43b99cd9 2007-04-21 devnull off = strtoull(clump, 0, 0);
311 43b99cd9 2007-04-21 devnull diskarenaclump(c, &arena, off, score[0] ? score : nil);
312 43b99cd9 2007-04-21 devnull }else if(score[0]){
313 43b99cd9 2007-04-21 devnull diskarenaclump(c, &arena, -1, score);
314 43b99cd9 2007-04-21 devnull }else{
315 43b99cd9 2007-04-21 devnull diskarenatoc(c, &arena);
316 43b99cd9 2007-04-21 devnull }
317 43b99cd9 2007-04-21 devnull
318 43b99cd9 2007-04-21 devnull out:
319 43b99cd9 2007-04-21 devnull free(table);
320 43b99cd9 2007-04-21 devnull return 0;
321 43b99cd9 2007-04-21 devnull }
322 43b99cd9 2007-04-21 devnull
323 43b99cd9 2007-04-21 devnull static vlong
324 43b99cd9 2007-04-21 devnull findintoc(HConnect *c, Arena *arena, uchar *score)
325 43b99cd9 2007-04-21 devnull {
326 43b99cd9 2007-04-21 devnull uchar *blk;
327 43b99cd9 2007-04-21 devnull int i;
328 43b99cd9 2007-04-21 devnull vlong off;
329 43b99cd9 2007-04-21 devnull vlong coff;
330 43b99cd9 2007-04-21 devnull ClumpInfo ci;
331 43b99cd9 2007-04-21 devnull
332 43b99cd9 2007-04-21 devnull blk = vtmalloc(arena->blocksize);
333 43b99cd9 2007-04-21 devnull off = arena->base + arena->size;
334 43b99cd9 2007-04-21 devnull coff = 0;
335 43b99cd9 2007-04-21 devnull for(i=0; i<arena->memstats.clumps; i++){
336 43b99cd9 2007-04-21 devnull if(i%arena->clumpmax == 0){
337 43b99cd9 2007-04-21 devnull off -= arena->blocksize;
338 43b99cd9 2007-04-21 devnull if(readpart(arena->part, off, blk, arena->blocksize) != arena->blocksize){
339 43b99cd9 2007-04-21 devnull if(c)
340 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<i>clump info directory at %#llx: %r</i>\n<br>\n",
341 43b99cd9 2007-04-21 devnull off);
342 43b99cd9 2007-04-21 devnull break;
343 43b99cd9 2007-04-21 devnull }
344 43b99cd9 2007-04-21 devnull }
345 43b99cd9 2007-04-21 devnull unpackclumpinfo(&ci, blk+(i%arena->clumpmax)*ClumpInfoSize);
346 43b99cd9 2007-04-21 devnull if(scorecmp(ci.score, score) == 0){
347 43b99cd9 2007-04-21 devnull vtfree(blk);
348 43b99cd9 2007-04-21 devnull return coff;
349 43b99cd9 2007-04-21 devnull }
350 43b99cd9 2007-04-21 devnull coff += ClumpSize + ci.size;
351 43b99cd9 2007-04-21 devnull }
352 43b99cd9 2007-04-21 devnull vtfree(blk);
353 43b99cd9 2007-04-21 devnull return -1;
354 43b99cd9 2007-04-21 devnull }
355 43b99cd9 2007-04-21 devnull
356 43b99cd9 2007-04-21 devnull
357 43b99cd9 2007-04-21 devnull static int
358 43b99cd9 2007-04-21 devnull diskarenatoc(HConnect *c, Arena *arena)
359 43b99cd9 2007-04-21 devnull {
360 43b99cd9 2007-04-21 devnull uchar *blk;
361 43b99cd9 2007-04-21 devnull int i;
362 43b99cd9 2007-04-21 devnull vlong off;
363 43b99cd9 2007-04-21 devnull vlong coff;
364 43b99cd9 2007-04-21 devnull ClumpInfo ci;
365 43b99cd9 2007-04-21 devnull char base[512];
366 43b99cd9 2007-04-21 devnull int cib;
367 43b99cd9 2007-04-21 devnull
368 43b99cd9 2007-04-21 devnull snprint(base, sizeof base, "/disk?disk=%s&type=a&arena=%s",
369 43b99cd9 2007-04-21 devnull arena->part->name, arena->name);
370 43b99cd9 2007-04-21 devnull
371 43b99cd9 2007-04-21 devnull blk = vtmalloc(arena->blocksize);
372 43b99cd9 2007-04-21 devnull off = arena->base + arena->size;
373 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>table of contents</h2>\n");
374 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
375 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%5s %6s %7s %s\n", "type", "size", "uncsize", "score");
376 43b99cd9 2007-04-21 devnull coff = 0;
377 43b99cd9 2007-04-21 devnull cib = hargint(c, "cib", 0);
378 43b99cd9 2007-04-21 devnull
379 43b99cd9 2007-04-21 devnull for(i=0; i<arena->memstats.clumps; i++){
380 43b99cd9 2007-04-21 devnull if(i%arena->clumpmax == 0){
381 43b99cd9 2007-04-21 devnull off -= arena->blocksize;
382 43b99cd9 2007-04-21 devnull if(readpart(arena->part, off, blk, arena->blocksize) != arena->blocksize){
383 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<i>clump info directory at %#llx: %r</i>\n<br>\n",
384 43b99cd9 2007-04-21 devnull off);
385 43b99cd9 2007-04-21 devnull i += arena->clumpmax-1;
386 43b99cd9 2007-04-21 devnull coff = -1;
387 43b99cd9 2007-04-21 devnull continue;
388 43b99cd9 2007-04-21 devnull }
389 43b99cd9 2007-04-21 devnull }
390 43b99cd9 2007-04-21 devnull unpackclumpinfo(&ci, blk+(i%arena->clumpmax)*ClumpInfoSize);
391 43b99cd9 2007-04-21 devnull if(i/arena->clumpmax == cib || i%arena->clumpmax == 0){
392 fa325e9b 2020-01-10 cross hprint(&c->hout, "%5d %6d %7d %V",
393 43b99cd9 2007-04-21 devnull ci.type, ci.size, ci.uncsize, ci.score);
394 43b99cd9 2007-04-21 devnull if(coff >= 0)
395 fa325e9b 2020-01-10 cross hprint(&c->hout, " at <a href=\"%s&clump=%#llx&score=%V\">%#llx</a>",
396 43b99cd9 2007-04-21 devnull base, coff, ci.score, coff);
397 43b99cd9 2007-04-21 devnull if(i/arena->clumpmax != cib)
398 43b99cd9 2007-04-21 devnull hprint(&c->hout, " <font size=-1><a href=\"%s&cib=%d\">more</a></font>", base, i/arena->clumpmax);
399 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\n");
400 43b99cd9 2007-04-21 devnull }
401 43b99cd9 2007-04-21 devnull if(coff >= 0)
402 43b99cd9 2007-04-21 devnull coff += ClumpSize + ci.size;
403 43b99cd9 2007-04-21 devnull }
404 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre>\n");
405 43b99cd9 2007-04-21 devnull return 0;
406 43b99cd9 2007-04-21 devnull }
407 43b99cd9 2007-04-21 devnull
408 43b99cd9 2007-04-21 devnull #define U32GET(p) ((u32int)(((p)[0]<<24)|((p)[1]<<16)|((p)[2]<<8)|(p)[3]))
409 43b99cd9 2007-04-21 devnull static int
410 43b99cd9 2007-04-21 devnull diskarenaclump(HConnect *c, Arena *arena, vlong off, char *scorestr)
411 43b99cd9 2007-04-21 devnull {
412 43b99cd9 2007-04-21 devnull uchar *blk, *blk2;
413 43b99cd9 2007-04-21 devnull Clump cl;
414 43b99cd9 2007-04-21 devnull char err[ERRMAX];
415 43b99cd9 2007-04-21 devnull uchar xscore[VtScoreSize], score[VtScoreSize];
416 43b99cd9 2007-04-21 devnull Unwhack uw;
417 43b99cd9 2007-04-21 devnull int n;
418 fa325e9b 2020-01-10 cross
419 43b99cd9 2007-04-21 devnull if(scorestr){
420 43b99cd9 2007-04-21 devnull if(vtparsescore(scorestr, nil, score) < 0){
421 43b99cd9 2007-04-21 devnull hprint(&c->hout, "bad score %s: %r\n", scorestr);
422 43b99cd9 2007-04-21 devnull return -1;
423 43b99cd9 2007-04-21 devnull }
424 43b99cd9 2007-04-21 devnull if(off < 0){
425 43b99cd9 2007-04-21 devnull off = findintoc(c, arena, score);
426 43b99cd9 2007-04-21 devnull if(off < 0){
427 43b99cd9 2007-04-21 devnull hprint(&c->hout, "score %V not found in arena %s\n", score, arena->name);
428 43b99cd9 2007-04-21 devnull return -1;
429 43b99cd9 2007-04-21 devnull }
430 43b99cd9 2007-04-21 devnull hprint(&c->hout, "score %V at %#llx\n", score, off);
431 43b99cd9 2007-04-21 devnull }
432 43b99cd9 2007-04-21 devnull }else
433 43b99cd9 2007-04-21 devnull memset(score, 0, sizeof score);
434 43b99cd9 2007-04-21 devnull
435 43b99cd9 2007-04-21 devnull if(off < 0){
436 43b99cd9 2007-04-21 devnull hprint(&c->hout, "bad offset %#llx\n", off);
437 43b99cd9 2007-04-21 devnull return -1;
438 43b99cd9 2007-04-21 devnull }
439 fa325e9b 2020-01-10 cross
440 43b99cd9 2007-04-21 devnull off += arena->base;
441 43b99cd9 2007-04-21 devnull
442 43b99cd9 2007-04-21 devnull blk = vtmalloc(ClumpSize + VtMaxLumpSize);
443 43b99cd9 2007-04-21 devnull if(readpart(arena->part, off, blk, ClumpSize + VtMaxLumpSize) != ClumpSize + VtMaxLumpSize){
444 43b99cd9 2007-04-21 devnull hprint(&c->hout, "reading at %#llx: %r\n", off);
445 43b99cd9 2007-04-21 devnull vtfree(blk);
446 43b99cd9 2007-04-21 devnull return -1;
447 43b99cd9 2007-04-21 devnull }
448 43b99cd9 2007-04-21 devnull
449 43b99cd9 2007-04-21 devnull if(unpackclump(&cl, blk, arena->clumpmagic) < 0){
450 43b99cd9 2007-04-21 devnull hprint(&c->hout, "unpackclump: %r\n<br>");
451 43b99cd9 2007-04-21 devnull rerrstr(err, sizeof err);
452 43b99cd9 2007-04-21 devnull if(strstr(err, "magic")){
453 43b99cd9 2007-04-21 devnull hprint(&c->hout, "trying again with magic=%#ux<br>\n", U32GET(blk));
454 43b99cd9 2007-04-21 devnull if(unpackclump(&cl, blk, U32GET(blk)) < 0){
455 43b99cd9 2007-04-21 devnull hprint(&c->hout, "unpackclump: %r\n<br>\n");
456 43b99cd9 2007-04-21 devnull goto error;
457 43b99cd9 2007-04-21 devnull }
458 43b99cd9 2007-04-21 devnull }else
459 43b99cd9 2007-04-21 devnull goto error;
460 43b99cd9 2007-04-21 devnull }
461 43b99cd9 2007-04-21 devnull
462 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>type=%d size=%d uncsize=%d score=%V\n", cl.info.type, cl.info.size, cl.info.uncsize, cl.info.score);
463 43b99cd9 2007-04-21 devnull hprint(&c->hout, "encoding=%d creator=%d time=%d %s</pre>\n", cl.encoding, cl.creator, cl.time, fmttime(err, cl.time));
464 fa325e9b 2020-01-10 cross
465 43b99cd9 2007-04-21 devnull if(cl.info.type == VtCorruptType)
466 43b99cd9 2007-04-21 devnull hprint(&c->hout, "clump is marked corrupt<br>\n");
467 fa325e9b 2020-01-10 cross
468 43b99cd9 2007-04-21 devnull if(cl.info.size >= VtMaxLumpSize){
469 43b99cd9 2007-04-21 devnull hprint(&c->hout, "clump too big\n");
470 43b99cd9 2007-04-21 devnull goto error;
471 43b99cd9 2007-04-21 devnull }
472 fa325e9b 2020-01-10 cross
473 43b99cd9 2007-04-21 devnull switch(cl.encoding){
474 43b99cd9 2007-04-21 devnull case ClumpECompress:
475 43b99cd9 2007-04-21 devnull blk2 = vtmalloc(VtMaxLumpSize);
476 43b99cd9 2007-04-21 devnull unwhackinit(&uw);
477 43b99cd9 2007-04-21 devnull n = unwhack(&uw, blk2, cl.info.uncsize, blk+ClumpSize, cl.info.size);
478 43b99cd9 2007-04-21 devnull if(n < 0){
479 43b99cd9 2007-04-21 devnull hprint(&c->hout, "decompression failed\n");
480 43b99cd9 2007-04-21 devnull vtfree(blk2);
481 43b99cd9 2007-04-21 devnull goto error;
482 43b99cd9 2007-04-21 devnull }
483 43b99cd9 2007-04-21 devnull if(n != cl.info.uncsize){
484 43b99cd9 2007-04-21 devnull hprint(&c->hout, "got wrong amount: %d wanted %d\n", n, cl.info.uncsize);
485 43b99cd9 2007-04-21 devnull // hhex(blk2, n);
486 43b99cd9 2007-04-21 devnull vtfree(blk2);
487 43b99cd9 2007-04-21 devnull goto error;
488 43b99cd9 2007-04-21 devnull }
489 43b99cd9 2007-04-21 devnull scoremem(xscore, blk2, cl.info.uncsize);
490 43b99cd9 2007-04-21 devnull vtfree(blk2);
491 43b99cd9 2007-04-21 devnull break;
492 43b99cd9 2007-04-21 devnull case ClumpENone:
493 43b99cd9 2007-04-21 devnull scoremem(xscore, blk+ClumpSize, cl.info.size);
494 43b99cd9 2007-04-21 devnull break;
495 43b99cd9 2007-04-21 devnull }
496 fa325e9b 2020-01-10 cross
497 43b99cd9 2007-04-21 devnull hprint(&c->hout, "score=%V<br>\n", xscore);
498 43b99cd9 2007-04-21 devnull if(scorestr && scorecmp(score, xscore) != 0)
499 43b99cd9 2007-04-21 devnull hprint(&c->hout, "score does NOT match expected %V\n", score);
500 43b99cd9 2007-04-21 devnull
501 43b99cd9 2007-04-21 devnull vtfree(blk);
502 43b99cd9 2007-04-21 devnull return 0;
503 43b99cd9 2007-04-21 devnull
504 43b99cd9 2007-04-21 devnull error:
505 43b99cd9 2007-04-21 devnull // hhex(blk, ClumpSize + VtMaxLumpSize);
506 43b99cd9 2007-04-21 devnull vtfree(blk);
507 43b99cd9 2007-04-21 devnull return -1;
508 43b99cd9 2007-04-21 devnull }
509 43b99cd9 2007-04-21 devnull
510 43b99cd9 2007-04-21 devnull static int
511 43b99cd9 2007-04-21 devnull diskbloom(HConnect *c, char *disk, Part *p)
512 43b99cd9 2007-04-21 devnull {
513 43b99cd9 2007-04-21 devnull USED(c);
514 43b99cd9 2007-04-21 devnull USED(disk);
515 43b99cd9 2007-04-21 devnull USED(p);
516 43b99cd9 2007-04-21 devnull return 0;
517 43b99cd9 2007-04-21 devnull }
518 43b99cd9 2007-04-21 devnull
519 43b99cd9 2007-04-21 devnull static int
520 43b99cd9 2007-04-21 devnull diskisect(HConnect *c, char *disk, Part *p)
521 43b99cd9 2007-04-21 devnull {
522 43b99cd9 2007-04-21 devnull USED(c);
523 43b99cd9 2007-04-21 devnull USED(disk);
524 43b99cd9 2007-04-21 devnull USED(p);
525 43b99cd9 2007-04-21 devnull return 0;
526 43b99cd9 2007-04-21 devnull }
527 43b99cd9 2007-04-21 devnull
528 43b99cd9 2007-04-21 devnull static void
529 43b99cd9 2007-04-21 devnull debugamap(HConnect *c)
530 43b99cd9 2007-04-21 devnull {
531 43b99cd9 2007-04-21 devnull int i;
532 43b99cd9 2007-04-21 devnull AMap *amap;
533 43b99cd9 2007-04-21 devnull
534 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>arena map</h2>\n");
535 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
536 43b99cd9 2007-04-21 devnull
537 43b99cd9 2007-04-21 devnull amap = mainindex->amap;
538 43b99cd9 2007-04-21 devnull for(i=0; i<mainindex->narenas; i++)
539 fa325e9b 2020-01-10 cross hprint(&c->hout, "%s %#llx %#llx\n",
540 43b99cd9 2007-04-21 devnull amap[i].name, amap[i].start, amap[i].stop);
541 43b99cd9 2007-04-21 devnull }
542 43b99cd9 2007-04-21 devnull
543 43b99cd9 2007-04-21 devnull static void
544 43b99cd9 2007-04-21 devnull debugread(HConnect *c, u8int *score)
545 43b99cd9 2007-04-21 devnull {
546 43b99cd9 2007-04-21 devnull int type;
547 43b99cd9 2007-04-21 devnull Lump *u;
548 43b99cd9 2007-04-21 devnull IAddr ia;
549 43b99cd9 2007-04-21 devnull IEntry ie;
550 7a400ee9 2007-09-25 rsc int i;
551 43b99cd9 2007-04-21 devnull Arena *arena;
552 43b99cd9 2007-04-21 devnull u64int aa;
553 43b99cd9 2007-04-21 devnull ZBlock *zb;
554 43b99cd9 2007-04-21 devnull Clump cl;
555 43b99cd9 2007-04-21 devnull vlong off;
556 43b99cd9 2007-04-21 devnull u8int sc[VtScoreSize];
557 43b99cd9 2007-04-21 devnull
558 43b99cd9 2007-04-21 devnull if(scorecmp(score, zeroscore) == 0){
559 43b99cd9 2007-04-21 devnull hprint(&c->hout, "zero score\n");
560 43b99cd9 2007-04-21 devnull return;
561 43b99cd9 2007-04-21 devnull }
562 fa325e9b 2020-01-10 cross
563 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>index search %V</h2><pre>\n", score);
564 7a400ee9 2007-09-25 rsc if(icachelookup(score, -1, &ia) < 0)
565 43b99cd9 2007-04-21 devnull hprint(&c->hout, " icache: not found\n");
566 43b99cd9 2007-04-21 devnull else
567 43b99cd9 2007-04-21 devnull hprint(&c->hout, " icache: addr=%#llx size=%d type=%d blocks=%d\n",
568 43b99cd9 2007-04-21 devnull ia.addr, ia.size, ia.type, ia.blocks);
569 fa325e9b 2020-01-10 cross
570 43b99cd9 2007-04-21 devnull if(loadientry(mainindex, score, -1, &ie) < 0)
571 43b99cd9 2007-04-21 devnull hprint(&c->hout, " idisk: not found\n");
572 43b99cd9 2007-04-21 devnull else
573 43b99cd9 2007-04-21 devnull hprint(&c->hout, " idisk: addr=%#llx size=%d type=%d blocks=%d\n",
574 43b99cd9 2007-04-21 devnull ie.ia.addr, ie.ia.size, ie.ia.type, ie.ia.blocks);
575 fa325e9b 2020-01-10 cross
576 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre><h2>lookup %V</h2>\n", score);
577 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
578 fa325e9b 2020-01-10 cross
579 43b99cd9 2007-04-21 devnull for(type=0; type < VtMaxType; type++){
580 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%V type %d:", score, type);
581 43b99cd9 2007-04-21 devnull u = lookuplump(score, type);
582 43b99cd9 2007-04-21 devnull if(u->data != nil)
583 43b99cd9 2007-04-21 devnull hprint(&c->hout, " +cache");
584 43b99cd9 2007-04-21 devnull else
585 43b99cd9 2007-04-21 devnull hprint(&c->hout, " -cache");
586 43b99cd9 2007-04-21 devnull putlump(u);
587 fa325e9b 2020-01-10 cross
588 7a400ee9 2007-09-25 rsc if(lookupscore(score, type, &ia) < 0){
589 43b99cd9 2007-04-21 devnull hprint(&c->hout, " -lookup\n");
590 43b99cd9 2007-04-21 devnull continue;
591 43b99cd9 2007-04-21 devnull }
592 7a400ee9 2007-09-25 rsc hprint(&c->hout, "\n lookupscore: addr=%#llx size=%d blocks=%d\n",
593 7a400ee9 2007-09-25 rsc ia.addr, ia.size, ia.blocks);
594 fa325e9b 2020-01-10 cross
595 43b99cd9 2007-04-21 devnull arena = amapitoa(mainindex, ia.addr, &aa);
596 43b99cd9 2007-04-21 devnull if(arena == nil){
597 43b99cd9 2007-04-21 devnull hprint(&c->hout, " amapitoa failed: %r\n");
598 43b99cd9 2007-04-21 devnull continue;
599 43b99cd9 2007-04-21 devnull }
600 43b99cd9 2007-04-21 devnull
601 43b99cd9 2007-04-21 devnull hprint(&c->hout, " amapitoa: aa=%#llx arena="
602 43b99cd9 2007-04-21 devnull "<a href=\"/disk?disk=%s&type=a&arena=%s&score=%V\">%s</a>\n",
603 43b99cd9 2007-04-21 devnull aa, arena->part->name, arena->name, score, arena->name);
604 43b99cd9 2007-04-21 devnull zb = loadclump(arena, aa, ia.blocks, &cl, sc, 1);
605 43b99cd9 2007-04-21 devnull if(zb == nil){
606 43b99cd9 2007-04-21 devnull hprint(&c->hout, " loadclump failed: %r\n");
607 43b99cd9 2007-04-21 devnull continue;
608 43b99cd9 2007-04-21 devnull }
609 fa325e9b 2020-01-10 cross
610 43b99cd9 2007-04-21 devnull hprint(&c->hout, " loadclump: uncsize=%d type=%d score=%V\n",
611 43b99cd9 2007-04-21 devnull cl.info.uncsize, cl.info.type, sc);
612 43b99cd9 2007-04-21 devnull if(ia.size != cl.info.uncsize || ia.type != cl.info.type || scorecmp(score, sc) != 0){
613 43b99cd9 2007-04-21 devnull hprint(&c->hout, " clump info mismatch\n");
614 43b99cd9 2007-04-21 devnull continue;
615 43b99cd9 2007-04-21 devnull }
616 43b99cd9 2007-04-21 devnull }
617 fa325e9b 2020-01-10 cross
618 43b99cd9 2007-04-21 devnull if(hargstr(c, "brute", "")[0] == 'y'){
619 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre>\n");
620 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>brute force arena search %V</h2>\n", score);
621 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
622 fa325e9b 2020-01-10 cross
623 43b99cd9 2007-04-21 devnull for(i=0; i<mainindex->narenas; i++){
624 43b99cd9 2007-04-21 devnull arena = mainindex->arenas[i];
625 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%s...\n", arena->name);
626 43b99cd9 2007-04-21 devnull hflush(&c->hout);
627 43b99cd9 2007-04-21 devnull off = findintoc(nil, arena, score);
628 43b99cd9 2007-04-21 devnull if(off >= 0)
629 43b99cd9 2007-04-21 devnull hprint(&c->hout, "%s %#llx (%#llx)\n", arena->name, off, mainindex->amap[i].start + off);
630 43b99cd9 2007-04-21 devnull }
631 43b99cd9 2007-04-21 devnull }
632 43b99cd9 2007-04-21 devnull
633 43b99cd9 2007-04-21 devnull hprint(&c->hout, "</pre>\n");
634 43b99cd9 2007-04-21 devnull }
635 43b99cd9 2007-04-21 devnull
636 43b99cd9 2007-04-21 devnull static void
637 43b99cd9 2007-04-21 devnull debugmem(HConnect *c)
638 43b99cd9 2007-04-21 devnull {
639 43b99cd9 2007-04-21 devnull Index *ix;
640 fa325e9b 2020-01-10 cross
641 43b99cd9 2007-04-21 devnull ix = mainindex;
642 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h2>memory</h2>\n");
643 fa325e9b 2020-01-10 cross
644 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<pre>\n");
645 43b99cd9 2007-04-21 devnull hprint(&c->hout, "ix=%p\n", ix);
646 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tarenas=%p\n", ix->arenas);
647 43b99cd9 2007-04-21 devnull if(ix->narenas > 0)
648 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tarenas[...] = %p...%p\n", ix->arenas[0], ix->arenas[ix->narenas-1]);
649 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tsmap=%p\n", ix->smap);
650 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tamap=%p\n", ix->amap);
651 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tbloom=%p\n", ix->bloom);
652 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tbloom->data=%p\n", ix->bloom ? ix->bloom->data : nil);
653 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tisects=%p\n", ix->sects);
654 43b99cd9 2007-04-21 devnull if(ix->nsects > 0)
655 43b99cd9 2007-04-21 devnull hprint(&c->hout, "\tsects[...] = %p...%p\n", ix->sects[0], ix->sects[ix->nsects-1]);
656 43b99cd9 2007-04-21 devnull }
657 43b99cd9 2007-04-21 devnull
658 43b99cd9 2007-04-21 devnull int
659 43b99cd9 2007-04-21 devnull hdebug(HConnect *c)
660 43b99cd9 2007-04-21 devnull {
661 43b99cd9 2007-04-21 devnull char *scorestr, *op;
662 43b99cd9 2007-04-21 devnull u8int score[VtScoreSize];
663 fa325e9b 2020-01-10 cross
664 43b99cd9 2007-04-21 devnull if(hsethtml(c) < 0)
665 43b99cd9 2007-04-21 devnull return -1;
666 43b99cd9 2007-04-21 devnull hprint(&c->hout, "<h1>venti debug</h1>\n");
667 43b99cd9 2007-04-21 devnull
668 43b99cd9 2007-04-21 devnull op = hargstr(c, "op", "");
669 43b99cd9 2007-04-21 devnull if(!op[0]){
670 43b99cd9 2007-04-21 devnull hprint(&c->hout, "no op\n");
671 43b99cd9 2007-04-21 devnull return 0;
672 43b99cd9 2007-04-21 devnull }
673 fa325e9b 2020-01-10 cross
674 43b99cd9 2007-04-21 devnull if(strcmp(op, "amap") == 0){
675 43b99cd9 2007-04-21 devnull debugamap(c);
676 43b99cd9 2007-04-21 devnull return 0;
677 43b99cd9 2007-04-21 devnull }
678 43b99cd9 2007-04-21 devnull
679 43b99cd9 2007-04-21 devnull if(strcmp(op, "mem") == 0){
680 43b99cd9 2007-04-21 devnull debugmem(c);
681 43b99cd9 2007-04-21 devnull return 0;
682 43b99cd9 2007-04-21 devnull }
683 43b99cd9 2007-04-21 devnull
684 43b99cd9 2007-04-21 devnull if(strcmp(op, "read") == 0){
685 43b99cd9 2007-04-21 devnull scorestr = hargstr(c, "score", "");
686 43b99cd9 2007-04-21 devnull if(vtparsescore(scorestr, nil, score) < 0){
687 43b99cd9 2007-04-21 devnull hprint(&c->hout, "bad score %s: %r\n", scorestr);
688 43b99cd9 2007-04-21 devnull return 0;
689 43b99cd9 2007-04-21 devnull }
690 43b99cd9 2007-04-21 devnull debugread(c, score);
691 43b99cd9 2007-04-21 devnull return 0;
692 43b99cd9 2007-04-21 devnull }
693 fa325e9b 2020-01-10 cross
694 43b99cd9 2007-04-21 devnull hprint(&c->hout, "unknown op %s", op);
695 43b99cd9 2007-04-21 devnull return 0;
696 43b99cd9 2007-04-21 devnull }