1
0

fcall.h 3.4 KB

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