fcall.h 2.6 KB

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