devnull.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /* Copyright (c) 2004 Russ Cox */
  10. #include <u.h>
  11. #include <libc.h>
  12. #include <venti.h>
  13. #include <thread.h>
  14. #include <libsec.h>
  15. #ifndef _UNISTD_H_
  16. #pragma varargck type "F" VtFcall*
  17. #pragma varargck type "T" void
  18. #endif
  19. int verbose;
  20. enum
  21. {
  22. STACK = 8192
  23. };
  24. void
  25. usage(void)
  26. {
  27. fprint(2, "usage: venti/devnull [-v] [-a address]\n");
  28. threadexitsall("usage");
  29. }
  30. void
  31. threadmain(int argc, char **argv)
  32. {
  33. VtReq *r;
  34. VtSrv *srv;
  35. char *address;
  36. fmtinstall('V', vtscorefmt);
  37. fmtinstall('F', vtfcallfmt);
  38. address = "tcp!*!venti";
  39. ARGBEGIN{
  40. case 'v':
  41. verbose++;
  42. break;
  43. case 'a':
  44. address = EARGF(usage());
  45. break;
  46. default:
  47. usage();
  48. }ARGEND
  49. srv = vtlisten(address);
  50. if(srv == nil)
  51. sysfatal("vtlisten %s: %r", address);
  52. while((r = vtgetreq(srv)) != nil){
  53. r->rx.msgtype = r->tx.msgtype+1;
  54. if(verbose)
  55. fprint(2, "<- %F\n", &r->tx);
  56. switch(r->tx.msgtype){
  57. case VtTping:
  58. break;
  59. case VtTgoodbye:
  60. break;
  61. case VtTread:
  62. r->rx.error = vtstrdup("no such block");
  63. r->rx.msgtype = VtRerror;
  64. break;
  65. case VtTwrite:
  66. packetsha1(r->tx.data, r->rx.score);
  67. break;
  68. case VtTsync:
  69. break;
  70. }
  71. if(verbose)
  72. fprint(2, "-> %F\n", &r->rx);
  73. vtrespond(r);
  74. }
  75. threadexitsall(nil);
  76. }