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