fcall.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. u8 type;
  15. u32 fid;
  16. u16 tag;
  17. union {
  18. struct {
  19. u32 msize; /* Tversion, Rversion */
  20. char *version; /* Tversion, Rversion */
  21. };
  22. struct {
  23. u16 oldtag; /* Tflush */
  24. };
  25. struct {
  26. char *ename; /* Rerror */
  27. };
  28. struct {
  29. u32 errno; /* Rlerror */
  30. };
  31. struct {
  32. Qid qid; /* Rattach, Ropen, Rcreate */
  33. u32 iounit; /* Ropen, Rcreate */
  34. };
  35. struct {
  36. Qid aqid; /* Rauth */
  37. };
  38. struct {
  39. u32 afid; /* Tauth, Tattach */
  40. char *uname; /* Tauth, Tattach */
  41. char *aname; /* Tauth, Tattach */
  42. };
  43. struct {
  44. u32 perm; /* Tcreate */
  45. char *name; /* Tcreate */
  46. u8 mode; /* Tcreate, Topen */
  47. };
  48. struct {
  49. u32 newfid; /* Twalk */
  50. u16 nwname; /* Twalk */
  51. char *wname[MAXWELEM]; /* Twalk */
  52. };
  53. struct {
  54. u16 nwqid; /* Rwalk */
  55. Qid wqid[MAXWELEM]; /* Rwalk */
  56. };
  57. struct {
  58. i64 offset; /* Tread, Twrite */
  59. u32 count; /* Tread, Twrite, Rread */
  60. char *data; /* Twrite, Rread */
  61. };
  62. struct {
  63. u16 nstat; /* Twstat, Rstat */
  64. u8 *stat; /* Twstat, Rstat */
  65. };
  66. };
  67. } Fcall;
  68. #define GBIT8(p) ((p)[0])
  69. #define GBIT16(p) ((p)[0]|((p)[1]<<8))
  70. #define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
  71. #define GBIT64(p) ((u32)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
  72. ((i64)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
  73. #define PBIT8(p,v) (p)[0]=(v)
  74. #define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
  75. #define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
  76. #define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
  77. (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
  78. #define BIT8SZ 1
  79. #define BIT16SZ 2
  80. #define BIT32SZ 4
  81. #define BIT64SZ 8
  82. #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
  83. /* STATFIXLEN includes leading 16-bit count */
  84. /* The count, however, excludes itself; total size is BIT16SZ+count */
  85. #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
  86. #define NOTAG (u16)~0U /* Dummy tag */
  87. #define NOFID (u32)~0U /* Dummy fid */
  88. #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
  89. // 9P2000.L, for some reason, lets callers closely tune what comes from a gettattr.
  90. // This *may* be because HPC file systems make getting at some types of metadata
  91. // expensive. Or it may be a pointless over-optimization; we suspect the latter.
  92. // Just ask for it all. Bandwidth is free.
  93. #define P9_GETATTR_MODE 0x00000001ULL
  94. #define P9_GETATTR_NLINK 0x00000002ULL
  95. #define P9_GETATTR_UID 0x00000004ULL
  96. #define P9_GETATTR_GID 0x00000008ULL
  97. #define P9_GETATTR_RDEV 0x00000010ULL
  98. #define P9_GETATTR_ATIME 0x00000020ULL
  99. #define P9_GETATTR_MTIME 0x00000040ULL
  100. #define P9_GETATTR_CTIME 0x00000080ULL
  101. #define P9_GETATTR_INO 0x00000100ULL
  102. #define P9_GETATTR_SIZE 0x00000200ULL
  103. #define P9_GETATTR_BLOCKS 0x00000400ULL
  104. #define P9_GETATTR_BTIME 0x00000800ULL
  105. #define P9_GETATTR_GEN 0x00001000ULL
  106. #define P9_GETATTR_DATA_VERSION 0x00002000ULL
  107. #define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */
  108. #define P9_GETATTR_ALL 0x00003fffULL /* Mask for All fields above */
  109. enum
  110. {
  111. Tversion = 100,
  112. Rversion,
  113. Tauth = 102,
  114. Rauth,
  115. Tattach = 104,
  116. Rattach,
  117. Terror = 106, /* illegal */
  118. Rerror,
  119. Tflush = 108,
  120. Rflush,
  121. Twalk = 110,
  122. Rwalk,
  123. Topen = 112,
  124. Ropen,
  125. Tcreate = 114,
  126. Rcreate,
  127. Tread = 116,
  128. Rread,
  129. Twrite = 118,
  130. Rwrite,
  131. Tclunk = 120,
  132. Rclunk,
  133. Tremove = 122,
  134. Rremove,
  135. Tstat = 124,
  136. Rstat,
  137. Twstat = 126,
  138. Rwstat,
  139. Tmax,
  140. DotLOffset = 100,
  141. Tlattach = Tattach - DotLOffset,
  142. Rlattach,
  143. Tlopen = Topen - DotLOffset,
  144. Rlopen,
  145. Tlcreate = Tcreate - DotLOffset,
  146. Rlcreate,
  147. Tlerror = Terror - DotLOffset,
  148. Rlerror,
  149. Tgetattr = Tstat - DotLOffset,
  150. Rgetattr,
  151. Treaddir = 40,
  152. Rreaddir
  153. };
  154. u32 convM2S(u8*, u32, Fcall*);
  155. u32 convS2M(Fcall*, u8*, u32);
  156. u32 sizeS2M(Fcall*);
  157. int statcheck(u8 *abuf, u32 nbuf);
  158. u32 convM2D(u8*, u32, Dir*, char*);
  159. u32 convLM2D(u8*, u32, Dir*);
  160. u32 convD2M(Dir*, u8*, u32);
  161. u32 sizeD2M(Dir*);
  162. int fcallfmt(Fmt*);
  163. int dirfmt(Fmt*);
  164. int dirmodefmt(Fmt*);
  165. int read9pmsg(int, void*, u32);