root.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <venti.h>
  12. #include <libsec.h>
  13. #include <thread.h>
  14. void
  15. usage(void)
  16. {
  17. fprint(2, "usage: root [-h host] score\n");
  18. threadexitsall("usage");
  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. fmtinstall('F', vtfcallfmt);
  30. fmtinstall('V', vtscorefmt);
  31. quotefmtinstall();
  32. host = nil;
  33. ARGBEGIN{
  34. case 'h':
  35. host = EARGF(usage());
  36. break;
  37. default:
  38. usage();
  39. break;
  40. }ARGEND
  41. if(argc == 0)
  42. usage();
  43. buf = vtmallocz(VtMaxLumpSize);
  44. z = vtdial(host);
  45. if(z == nil)
  46. sysfatal("could not connect to server: %r");
  47. if(vtconnect(z) < 0)
  48. sysfatal("vtconnect: %r");
  49. for(i=0; i<argc; i++){
  50. if(vtparsescore(argv[i], nil, score) < 0){
  51. fprint(2, "cannot parse score '%s': %r\n", argv[i]);
  52. continue;
  53. }
  54. n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
  55. if(n < 0){
  56. fprint(2, "could not read block %V: %r\n", score);
  57. continue;
  58. }
  59. if(n != VtRootSize){
  60. fprint(2, "block %V is wrong size %d != 300\n", score, n);
  61. continue;
  62. }
  63. if(vtrootunpack(&root, buf) < 0){
  64. fprint(2, "unpacking block %V: %r\n", score);
  65. continue;
  66. }
  67. print("%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev);
  68. }
  69. vthangup(z);
  70. threadexitsall(0);
  71. }