9 // XXX What to do here?
10 VtMaxLumpSize = 65535,
18 fprint(2, "usage: readfile [-v] [-h host] score\n");
19 threadexitsall("usage");
23 threadmain(int argc, char *argv[])
26 uchar score[VtScoreSize];
37 fmtinstall('F', vtfcallfmt);
38 fmtinstall('V', vtscorefmt);
46 host = EARGF(usage());
60 if(vtparsescore(argv[0], &type, score) < 0)
61 sysfatal("could not parse score '%s': %r", argv[0]);
62 if(type == nil || strcmp(type, "file") != 0)
63 sysfatal("bad score - not file:...");
65 buf = vtmallocz(VtMaxLumpSize);
69 sysfatal("could not connect to server: %r");
72 sysfatal("vtconnect: %r");
75 n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
77 sysfatal("could not read root %V: %r", score);
79 sysfatal("root block %V is wrong size %d != %d", score, n, VtRootSize);
80 if(vtrootunpack(&root, buf) < 0)
81 sysfatal("unpacking root block %V: %r", score);
82 if(strcmp(root.type, "file") != 0)
83 sysfatal("bad root type %q (not 'file')", root.type);
85 fprint(2, "%V: %q %q %V %d %V\n",
86 score, root.name, root.type,
87 root.score, root.blocksize, root.prev);
89 // ... points at entry block
90 n = vtread(z, root.score, VtDirType, buf, VtMaxLumpSize);
92 sysfatal("could not read entry %V: %r", root.score);
94 sysfatal("dir block %V is wrong size %d != %d", root.score, n, VtEntrySize);
95 if(vtentryunpack(&e, buf, 0) < 0)
96 sysfatal("unpacking dir block %V: %r", root.score);
97 if((e.type&VtTypeBaseMask) != VtDataType)
98 sysfatal("not a single file");
100 // open and read file
101 c = vtcachealloc(z, root.blocksize*32);
103 sysfatal("vtcachealloc: %r");
104 f = vtfileopenroot(c, &e);
106 sysfatal("vtfileopenroot: %r");
108 vtfilelock(f, VtOREAD);
109 while((n = vtfileread(f, buf, VtMaxLumpSize, off)) > 0){