URI:
       troot.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       troot.c (1389B)
       ---
            1 #include <u.h>
            2 #include <libc.h>
            3 #include <venti.h>
            4 #include <libsec.h>
            5 #include <thread.h>
            6 
            7 enum
            8 {
            9         // XXX What to do here?
           10         VtMaxLumpSize = 65535,
           11 };
           12 
           13 void
           14 usage(void)
           15 {
           16         fprint(2, "usage: root [-h host] score\n");
           17         threadexitsall("usage");
           18 }
           19 
           20 void
           21 threadmain(int argc, char *argv[])
           22 {
           23         int i, n;
           24         uchar score[VtScoreSize];
           25         uchar *buf;
           26         VtConn *z;
           27         char *host;
           28         VtRoot root;
           29 
           30         fmtinstall('F', vtfcallfmt);
           31         fmtinstall('V', vtscorefmt);
           32         quotefmtinstall();
           33 
           34         host = nil;
           35         ARGBEGIN{
           36         case 'h':
           37                 host = EARGF(usage());
           38                 break;
           39         default:
           40                 usage();
           41                 break;
           42         }ARGEND
           43 
           44         if(argc == 0)
           45                 usage();
           46 
           47         buf = vtmallocz(VtMaxLumpSize);
           48 
           49         z = vtdial(host);
           50         if(z == nil)
           51                 sysfatal("could not connect to server: %r");
           52 
           53         if(vtconnect(z) < 0)
           54                 sysfatal("vtconnect: %r");
           55 
           56         for(i=0; i<argc; i++){
           57                 if(vtparsescore(argv[i], nil, score) < 0){
           58                         fprint(2, "cannot parse score '%s': %r\n", argv[i]);
           59                         continue;
           60                 }
           61                 n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
           62                 if(n < 0){
           63                         fprint(2, "could not read block %V: %r\n", score);
           64                         continue;
           65                 }
           66                 if(n != VtRootSize){
           67                         fprint(2, "block %V is wrong size %d != 300\n", score, n);
           68                         continue;
           69                 }
           70                 if(vtrootunpack(&root, buf) < 0){
           71                         fprint(2, "unpacking block %V: %r\n", score);
           72                         continue;
           73                 }
           74                 print("%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev);
           75         }
           76         vthangup(z);
           77         threadexitsall(0);
           78 }