9P2000.h 4.0 KB

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