17 fprint(2, "usage: writefile [-v] [-h host] < data\n");
18 threadexitsall("usage");
22 threadmain(int argc, char *argv[])
25 uchar score[VtScoreSize];
36 fmtinstall('F', vtfcallfmt);
37 fmtinstall('V', vtscorefmt);
45 host = EARGF(usage());
58 buf = vtmallocz(Blocksize);
62 sysfatal("could not connect to server: %r");
65 sysfatal("vtconnect: %r");
68 c = vtcachealloc(z, Blocksize*32);
70 sysfatal("vtcachealloc: %r");
71 f = vtfilecreateroot(c, Blocksize, Blocksize, VtDataType);
73 sysfatal("vtfilecreateroot: %r");
75 vtfilelock(f, VtOWRITE);
76 while((n = read(0, buf, Blocksize)) > 0){
77 if(vtfilewrite(f, buf, n, off) != n)
78 sysfatal("vtfilewrite: %r");
80 if(vtfileflushbefore(f, off) < 0)
81 sysfatal("vtfileflushbefore: %r");
83 if(vtfileflush(f) < 0)
84 sysfatal("vtfileflush: %r");
85 if(vtfilegetentry(f, &e) < 0)
86 sysfatal("vtfilegetentry: %r");
89 // write directory entry
90 memset(&root, 0, sizeof root);
91 vtentrypack(&e, buf, 0);
92 if(vtwrite(z, root.score, VtDirType, buf, VtEntrySize) < 0)
93 sysfatal("vtwrite dir: %r");
96 strcpy(root.name, "data");
97 strcpy(root.type, "file");
98 root.blocksize = Blocksize;
99 vtrootpack(&root, buf);
100 if(vtwrite(z, score, VtRootType, buf, VtRootSize) < 0)
101 sysfatal("vtwrite root: %r");
103 print("file:%V\n", score);