blob: a5dae3371e3bb3431e361871b97dc69ffc842ab8 [file] [log] [blame]
rscf7012582003-11-25 01:40:27 +00001#ifndef _FCALL_H_
2#define _FCALL_H_ 1
rsce97cead2003-12-06 18:05:27 +00003#ifdef __cplusplus
4extern "C" {
rscf7012582003-11-25 01:40:27 +00005#endif
rsc97a5e5f2003-11-23 18:25:35 +00006/*
7#pragma src "/sys/src/libc/9sys"
8#pragma lib "libc.a"
9*/
10
11#define VERSION9P "9P2000"
rsc97a5e5f2003-11-23 18:25:35 +000012#define MAXWELEM 16
13
14typedef
15struct Fcall
16{
17 uchar type;
18 u32int fid;
19 ushort tag;
20 u32int msize; /* Tversion, Rversion */
21 char *version; /* Tversion, Rversion */
22 ushort oldtag; /* Tflush */
23 char *ename; /* Rerror */
24 Qid qid; /* Rattach, Ropen, Rcreate */
25 u32int iounit; /* Ropen, Rcreate */
26 Qid aqid; /* Rauth */
27 u32int afid; /* Tauth, Tattach */
28 char *uname; /* Tauth, Tattach */
29 char *aname; /* Tauth, Tattach */
30 u32int perm; /* Tcreate */
31 char *name; /* Tcreate */
32 uchar mode; /* Tcreate, Topen */
33 u32int newfid; /* Twalk */
34 ushort nwname; /* Twalk */
35 char *wname[MAXWELEM]; /* Twalk */
36 ushort nwqid; /* Rwalk */
rscb7eed2e2005-09-13 01:34:18 +000037 Qid wqid[MAXWELEM]; /* Rwalk */
rsc97a5e5f2003-11-23 18:25:35 +000038 vlong offset; /* Tread, Twrite */
39 u32int count; /* Tread, Twrite, Rread */
40 char *data; /* Twrite, Rread */
41 ushort nstat; /* Twstat, Rstat */
42 uchar *stat; /* Twstat, Rstat */
rsc32f69c32003-12-11 17:48:38 +000043 int unixfd; /* Ropenfd */
rscb7eed2e2005-09-13 01:34:18 +000044
45 /* 9P2000.u extensions */
46 int errornum; /* Rerror */
rscb5c7be22006-03-03 16:34:49 +000047 char *extension; /* Tcreate */
rsc97a5e5f2003-11-23 18:25:35 +000048} Fcall;
49
50
51#define GBIT8(p) ((p)[0])
52#define GBIT16(p) ((p)[0]|((p)[1]<<8))
rsc9a5678a2006-11-04 20:41:42 +000053#define GBIT32(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
rscfc1d5d82006-01-17 01:33:12 +000054#define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
rsc97a5e5f2003-11-23 18:25:35 +000055 ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
56
57#define PBIT8(p,v) (p)[0]=(v)
58#define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
59#define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
60#define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
61 (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
62
63#define BIT8SZ 1
64#define BIT16SZ 2
65#define BIT32SZ 4
66#define BIT64SZ 8
67#define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
68
69/* STATFIXLEN includes leading 16-bit count */
70/* The count, however, excludes itself; total size is BIT16SZ+count */
71#define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
rscb7eed2e2005-09-13 01:34:18 +000072#define STATFIXLENU (STATFIXLEN+BIT16SZ+3*BIT32SZ) /* for 9P2000.u */
rsc97a5e5f2003-11-23 18:25:35 +000073
74#define NOTAG (ushort)~0U /* Dummy tag */
75#define NOFID (u32int)~0U /* Dummy fid */
76#define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
77
78enum
79{
80 Tversion = 100,
81 Rversion,
82 Tauth = 102,
83 Rauth,
84 Tattach = 104,
85 Rattach,
86 Terror = 106, /* illegal */
87 Rerror,
88 Tflush = 108,
89 Rflush,
90 Twalk = 110,
91 Rwalk,
92 Topen = 112,
93 Ropen,
94 Tcreate = 114,
95 Rcreate,
96 Tread = 116,
97 Rread,
98 Twrite = 118,
99 Rwrite,
100 Tclunk = 120,
101 Rclunk,
102 Tremove = 122,
103 Rremove,
104 Tstat = 124,
105 Rstat,
106 Twstat = 126,
107 Rwstat,
108 Tmax,
rsc32f69c32003-12-11 17:48:38 +0000109
110 Topenfd = 98,
rsccbeb0b22006-04-01 19:24:03 +0000111 Ropenfd
rsc97a5e5f2003-11-23 18:25:35 +0000112};
113
114uint convM2S(uchar*, uint, Fcall*);
115uint convS2M(Fcall*, uchar*, uint);
116uint sizeS2M(Fcall*);
117
118int statcheck(uchar *abuf, uint nbuf);
119uint convM2D(uchar*, uint, Dir*, char*);
120uint convD2M(Dir*, uchar*, uint);
121uint sizeD2M(Dir*);
122
rscb7eed2e2005-09-13 01:34:18 +0000123uint convM2Su(uchar*, uint, Fcall*, int);
124uint convS2Mu(Fcall*, uchar*, uint, int);
125uint sizeS2Mu(Fcall*, int);
126
127int statchecku(uchar *abuf, uint nbuf, int);
128uint convM2Du(uchar*, uint, Dir*, char*, int);
129uint convD2Mu(Dir*, uchar*, uint, int);
130uint sizeD2Mu(Dir*, int);
131
rsc97a5e5f2003-11-23 18:25:35 +0000132int fcallfmt(Fmt*);
133int dirfmt(Fmt*);
134int dirmodefmt(Fmt*);
135
136int read9pmsg(int, void*, uint);
137
138/*
139#pragma varargck type "F" Fcall*
140#pragma varargck type "M" ulong
141#pragma varargck type "D" Dir*
142*/
rsce97cead2003-12-06 18:05:27 +0000143
144#ifdef __cplusplus
rscf7012582003-11-25 01:40:27 +0000145}
146#endif
147#endif