fcall.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #define VERSION9P "9P2000"
  10. #define MAXWELEM 16
  11. typedef
  12. struct Fcall
  13. {
  14. uint8_t type;
  15. uint32_t fid;
  16. uint16_t tag;
  17. union {
  18. struct {
  19. uint32_t msize; /* Tversion, Rversion */
  20. char *version; /* Tversion, Rversion */
  21. };
  22. struct {
  23. uint16_t oldtag; /* Tflush */
  24. };
  25. struct {
  26. char *ename; /* Rerror */
  27. };
  28. struct {
  29. Qid qid; /* Rattach, Ropen, Rcreate */
  30. uint32_t iounit; /* Ropen, Rcreate */
  31. };
  32. struct {
  33. Qid aqid; /* Rauth */
  34. };
  35. struct {
  36. uint32_t afid; /* Tauth, Tattach */
  37. char *uname; /* Tauth, Tattach */
  38. char *aname; /* Tauth, Tattach */
  39. };
  40. struct {
  41. uint32_t perm; /* Tcreate */
  42. char *name; /* Tcreate */
  43. uint8_t mode; /* Tcreate, Topen */
  44. };
  45. struct {
  46. uint32_t newfid; /* Twalk */
  47. uint16_t nwname; /* Twalk */
  48. char *wname[MAXWELEM]; /* Twalk */
  49. };
  50. struct {
  51. uint16_t nwqid; /* Rwalk */
  52. Qid wqid[MAXWELEM]; /* Rwalk */
  53. };
  54. struct {
  55. int64_t offset; /* Tread, Twrite */
  56. uint32_t count; /* Tread, Twrite, Rread */
  57. char *data; /* Twrite, Rread */
  58. };
  59. struct {
  60. uint16_t nstat; /* Twstat, Rstat */
  61. uint8_t *stat; /* Twstat, Rstat */
  62. };
  63. };
  64. } Fcall;
  65. #define GBIT8(p) ((p)[0])
  66. #define GBIT16(p) ((p)[0]|((p)[1]<<8))
  67. #define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
  68. #define GBIT64(p) ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
  69. ((int64_t)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
  70. #define PBIT8(p,v) (p)[0]=(v)
  71. #define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
  72. #define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
  73. #define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
  74. (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
  75. #define BIT8SZ 1
  76. #define BIT16SZ 2
  77. #define BIT32SZ 4
  78. #define BIT64SZ 8
  79. #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
  80. /* STATFIXLEN includes leading 16-bit count */
  81. /* The count, however, excludes itself; total size is BIT16SZ+count */
  82. #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
  83. #define NOTAG (uint16_t)~0U /* Dummy tag */
  84. #define NOFID (uint32_t)~0U /* Dummy fid */
  85. #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
  86. enum
  87. {
  88. Tversion = 100,
  89. Rversion,
  90. Tauth = 102,
  91. Rauth,
  92. Tattach = 104,
  93. Rattach,
  94. Terror = 106, /* illegal */
  95. Rerror,
  96. Tflush = 108,
  97. Rflush,
  98. Twalk = 110,
  99. Rwalk,
  100. Topen = 112,
  101. Ropen,
  102. Tcreate = 114,
  103. Rcreate,
  104. Tread = 116,
  105. Rread,
  106. Twrite = 118,
  107. Rwrite,
  108. Tclunk = 120,
  109. Rclunk,
  110. Tremove = 122,
  111. Rremove,
  112. Tstat = 124,
  113. Rstat,
  114. Twstat = 126,
  115. Rwstat,
  116. Tmax,
  117. };
  118. uint convM2S(uint8_t*, uint, Fcall*);
  119. uint convS2M(Fcall*, uint8_t*, uint);
  120. uint sizeS2M(Fcall*);
  121. int statcheck(uint8_t *abuf, uint nbuf);
  122. uint convM2D(uint8_t*, uint, Dir*, char*);
  123. uint convD2M(Dir*, uint8_t*, uint);
  124. uint sizeD2M(Dir*);
  125. int fcallfmt(Fmt*);
  126. int dirfmt(Fmt*);
  127. int dirmodefmt(Fmt*);
  128. int read9pmsg(int, void*, uint);