1
0

fcall.h 3.0 KB

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