root.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <venti.h>
  4. #include <libsec.h>
  5. #include <thread.h>
  6. void
  7. usage(void)
  8. {
  9. fprint(2, "usage: root [-h host] score\n");
  10. threadexitsall("usage");
  11. }
  12. void
  13. threadmain(int argc, char *argv[])
  14. {
  15. int i, n;
  16. uchar score[VtScoreSize];
  17. uchar *buf;
  18. VtConn *z;
  19. char *host;
  20. VtRoot root;
  21. fmtinstall('F', vtfcallfmt);
  22. fmtinstall('V', vtscorefmt);
  23. quotefmtinstall();
  24. host = nil;
  25. ARGBEGIN{
  26. case 'h':
  27. host = EARGF(usage());
  28. break;
  29. default:
  30. usage();
  31. break;
  32. }ARGEND
  33. if(argc == 0)
  34. usage();
  35. buf = vtmallocz(VtMaxLumpSize);
  36. z = vtdial(host);
  37. if(z == nil)
  38. sysfatal("could not connect to server: %r");
  39. if(vtconnect(z) < 0)
  40. sysfatal("vtconnect: %r");
  41. for(i=0; i<argc; i++){
  42. if(vtparsescore(argv[i], nil, score) < 0){
  43. fprint(2, "cannot parse score '%s': %r\n", argv[i]);
  44. continue;
  45. }
  46. n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
  47. if(n < 0){
  48. fprint(2, "could not read block %V: %r\n", score);
  49. continue;
  50. }
  51. if(n != VtRootSize){
  52. fprint(2, "block %V is wrong size %d != 300\n", score, n);
  53. continue;
  54. }
  55. if(vtrootunpack(&root, buf) < 0){
  56. fprint(2, "unpacking block %V: %r\n", score);
  57. continue;
  58. }
  59. print("%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev);
  60. }
  61. vthangup(z);
  62. threadexitsall(0);
  63. }