devnull.c 1.5 KB

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