Blob


1 #ifndef _FCALL_H_
2 #define _FCALL_H_ 1
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 /*
7 #pragma src "/sys/src/libc/9sys"
8 #pragma lib "libc.a"
9 */
11 #define VERSION9P "9P2000"
12 #define MAXWELEM 16
14 typedef
15 struct 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 */
37 Qid wqid[MAXWELEM]; /* Rwalk */
38 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 */
43 int unixfd; /* Ropenfd */
45 /* 9P2000.u extensions */
46 int errornum; /* Rerror */
47 } Fcall;
50 #define GBIT8(p) ((p)[0])
51 #define GBIT16(p) ((p)[0]|((p)[1]<<8))
52 #define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
53 #define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
54 ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
56 #define PBIT8(p,v) (p)[0]=(v)
57 #define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
58 #define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
59 #define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
60 (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
62 #define BIT8SZ 1
63 #define BIT16SZ 2
64 #define BIT32SZ 4
65 #define BIT64SZ 8
66 #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
68 /* STATFIXLEN includes leading 16-bit count */
69 /* The count, however, excludes itself; total size is BIT16SZ+count */
70 #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
71 #define STATFIXLENU (STATFIXLEN+BIT16SZ+3*BIT32SZ) /* for 9P2000.u */
73 #define NOTAG (ushort)~0U /* Dummy tag */
74 #define NOFID (u32int)~0U /* Dummy fid */
75 #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
77 enum
78 {
79 Tversion = 100,
80 Rversion,
81 Tauth = 102,
82 Rauth,
83 Tattach = 104,
84 Rattach,
85 Terror = 106, /* illegal */
86 Rerror,
87 Tflush = 108,
88 Rflush,
89 Twalk = 110,
90 Rwalk,
91 Topen = 112,
92 Ropen,
93 Tcreate = 114,
94 Rcreate,
95 Tread = 116,
96 Rread,
97 Twrite = 118,
98 Rwrite,
99 Tclunk = 120,
100 Rclunk,
101 Tremove = 122,
102 Rremove,
103 Tstat = 124,
104 Rstat,
105 Twstat = 126,
106 Rwstat,
107 Tmax,
109 Topenfd = 98,
110 Ropenfd,
111 };
113 uint convM2S(uchar*, uint, Fcall*);
114 uint convS2M(Fcall*, uchar*, uint);
115 uint sizeS2M(Fcall*);
117 int statcheck(uchar *abuf, uint nbuf);
118 uint convM2D(uchar*, uint, Dir*, char*);
119 uint convD2M(Dir*, uchar*, uint);
120 uint sizeD2M(Dir*);
122 uint convM2Su(uchar*, uint, Fcall*, int);
123 uint convS2Mu(Fcall*, uchar*, uint, int);
124 uint sizeS2Mu(Fcall*, int);
126 int statchecku(uchar *abuf, uint nbuf, int);
127 uint convM2Du(uchar*, uint, Dir*, char*, int);
128 uint convD2Mu(Dir*, uchar*, uint, int);
129 uint sizeD2Mu(Dir*, int);
131 int fcallfmt(Fmt*);
132 int dirfmt(Fmt*);
133 int dirmodefmt(Fmt*);
135 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 */
143 #ifdef __cplusplus
145 #endif
146 #endif