1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4
5 void
Bpass(Biobuf * bin,Biobuf * bout,int n)6 Bpass(Biobuf *bin, Biobuf *bout, int n)
7 {
8 char buf[8192];
9 int m;
10
11 while(n > 0) {
12 m = sizeof buf;
13 if(m > n)
14 m = n;
15 m = Bread(bin, buf, m);
16 if(m <= 0) {
17 fprint(2, "corrupt archive\n");
18 exits("notdone");
19 }
20 Bwrite(bout, buf, m);
21 n -= m;
22 }
23 assert(n == 0);
24 }
25
26 void
main(int argc,char ** argv)27 main(int argc, char **argv)
28 {
29 char *p, *f[10];
30 Biobuf bin, bout;
31 int nf;
32 ulong d, size;
33
34 if(argc != 2) {
35 fprint(2, "usage: cat mkfs-archive | touchfs date (in seconds)\n");
36 exits("usage");
37 }
38
39 d = strtoul(argv[1], 0, 0);
40
41 quotefmtinstall();
42 Binit(&bin, 0, OREAD);
43 Binit(&bout, 1, OWRITE);
44
45 while(p = Brdline(&bin, '\n')) {
46 p[Blinelen(&bin)-1] = '\0';
47 if(strcmp(p, "end of archive") == 0) {
48 Bprint(&bout, "end of archive\n");
49 exits(0);
50 }
51
52 nf = tokenize(p, f, nelem(f));
53 if(nf != 6) {
54 fprint(2, "corrupt archive\n");
55 exits("notdone");
56 }
57
58 Bprint(&bout, "%q %q %q %q %lud %q\n",
59 f[0], f[1], f[2], f[3], d, f[5]);
60
61 size = strtoul(f[5], 0, 0);
62 Bpass(&bin, &bout, size);
63 }
64 fprint(2, "premature end of archive\n");
65 exits("notdone");
66 }
67