mkroot.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <thread.h>
  13. char *host;
  14. void
  15. usage(void)
  16. {
  17. fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
  18. threadexitsall("usage");
  19. }
  20. void
  21. threadmain(int argc, char *argv[])
  22. {
  23. unsigned char score[VtScoreSize];
  24. unsigned char buf[VtRootSize];
  25. VtConn *z;
  26. VtRoot root;
  27. ARGBEGIN{
  28. case 'h':
  29. host = EARGF(usage());
  30. break;
  31. default:
  32. usage();
  33. break;
  34. }ARGEND
  35. if(argc != 5)
  36. usage();
  37. fmtinstall('V', vtscorefmt);
  38. fmtinstall('F', vtfcallfmt);
  39. strecpy(root.name, root.name+sizeof root.name, argv[0]);
  40. strecpy(root.type, root.type+sizeof root.type, argv[1]);
  41. if(vtparsescore(argv[2], nil, root.score) < 0)
  42. sysfatal("bad score '%s'", argv[2]);
  43. root.blocksize = atoi(argv[3]);
  44. if(vtparsescore(argv[4], nil, root.prev) < 0)
  45. sysfatal("bad score '%s'", argv[4]);
  46. vtrootpack(&root, buf);
  47. z = vtdial(host);
  48. if(z == nil)
  49. sysfatal("could not connect to server: %r");
  50. if(vtconnect(z) < 0)
  51. sysfatal("vtconnect: %r");
  52. if(vtwrite(z, score, VtRootType, buf, VtRootSize) < 0)
  53. sysfatal("vtwrite: %r");
  54. if(vtsync(z) < 0)
  55. sysfatal("vtsync: %r");
  56. vthangup(z);
  57. print("%V\n", score);
  58. threadexitsall(0);
  59. }