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