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