Blob


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