aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/venti/read.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-07-12 15:23:36 +0000
committerrsc <devnull@localhost>2005-07-12 15:23:36 +0000
commita0d146edd7a7de6236a0d60baafeeb59f8452aae (patch)
treeb55baa526d9f5adfc73246e6ee2fadf455e0b7a2 /src/cmd/venti/read.c
parent88bb285e3d87ec2508840af33f7e0af53ec3c13c (diff)
downloadplan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.tar.gz
plan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.tar.bz2
plan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.zip
return of venti
Diffstat (limited to 'src/cmd/venti/read.c')
-rw-r--r--src/cmd/venti/read.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/cmd/venti/read.c b/src/cmd/venti/read.c
new file mode 100644
index 00000000..3f3441e7
--- /dev/null
+++ b/src/cmd/venti/read.c
@@ -0,0 +1,75 @@
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+#include <libsec.h>
+#include <thread.h>
+
+void
+usage(void)
+{
+ fprint(2, "usage: read [-h host] [-t type] score\n");
+ threadexitsall("usage");
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ int type, n;
+ uchar score[VtScoreSize];
+ uchar *buf;
+ VtConn *z;
+ char *host;
+
+ fmtinstall('F', vtfcallfmt);
+ fmtinstall('V', vtscorefmt);
+
+ host = nil;
+ type = -1;
+ ARGBEGIN{
+ case 'h':
+ host = EARGF(usage());
+ break;
+ case 't':
+ type = atoi(argv[1]);
+ break;
+ default:
+ usage();
+ break;
+ }ARGEND
+
+ if(argc != 1)
+ usage();
+
+ if(vtparsescore(argv[0], nil, score) < 0)
+ sysfatal("could not parse score '%s': %r", argv[0]);
+
+ buf = vtmallocz(VtMaxLumpSize);
+
+ z = vtdial(host);
+ if(z == nil)
+ sysfatal("could not connect to server: %r");
+
+ if(vtconnect(z) < 0)
+ sysfatal("vtconnect: %r");
+
+ if(type == -1){
+ n = -1;
+ for(type=0; type<VtMaxType; type++){
+ n = vtread(z, score, type, buf, VtMaxLumpSize);
+ if(n >= 0){
+ fprint(2, "venti/read%s%s %V %d\n", host ? " -h" : "", host ? host : "",
+ score, type);
+ break;
+ }
+ }
+ }else{
+ type = atoi(argv[1]);
+ n = vtread(z, score, type, buf, VtMaxLumpSize);
+ }
+ vthangup(z);
+ if(n < 0)
+ sysfatal("could not read block: %r");
+ if(write(1, buf, n) != n)
+ sysfatal("write: %r");
+ threadexitsall(0);
+}