]> git.lizzy.rs Git - plan9front.git/blob - sys/include/9p.h
pool: use uintptr for pool size
[plan9front.git] / sys / include / 9p.h
1 #pragma src "/sys/src/lib9p"
2 #pragma lib "lib9p.a"
3
4 /*
5  * Maps from ulongs to void*s.
6  */
7 typedef struct Intmap   Intmap;
8
9 #pragma incomplete Intmap
10
11 Intmap* allocmap(void (*inc)(void*));
12 void            freemap(Intmap*, void (*destroy)(void*));
13 void*   lookupkey(Intmap*, ulong);
14 void*   insertkey(Intmap*, ulong, void*);
15 int             caninsertkey(Intmap*, ulong, void*);
16 void*   deletekey(Intmap*, ulong);
17
18 /*
19  * Fid and Request structures.
20  */
21 typedef struct Fid              Fid;
22 typedef struct Req              Req;
23 typedef struct Fidpool  Fidpool;
24 typedef struct Reqpool  Reqpool;
25 typedef struct File             File;
26 typedef struct Filelist Filelist;
27 typedef struct Tree             Tree;
28 typedef struct Readdir  Readdir;
29 typedef struct Srv Srv;
30 typedef struct Reqqueue Reqqueue;
31 typedef struct Queueelem Queueelem;
32
33 #pragma incomplete Filelist
34 #pragma incomplete Readdir
35
36 struct Queueelem
37 {
38         Queueelem *prev, *next;
39         void (*f)(Req *);
40 };
41
42 struct Reqqueue
43 {
44         QLock;
45         Rendez;
46         Queueelem;
47         int pid, flush;
48         Req *cur;
49 };
50
51 struct Fid
52 {
53         ulong   fid;
54         char            omode;  /* -1 = not open */
55         File*           file;
56         char*   uid;
57         Qid             qid;
58         void*   aux;
59
60 /* below is implementation-specific; don't use */
61         Readdir*        rdir;
62         Ref             ref;
63         Fidpool*        pool;
64         vlong   diroffset;
65         long            dirindex;
66 };
67
68 struct Req
69 {
70         ulong   tag;
71         void*   aux;
72         Fcall           ifcall;
73         Fcall           ofcall;
74         Dir             d;
75         Req*            oldreq;
76         Fid*            fid;
77         Fid*            afid;
78         Fid*            newfid;
79         Srv*            srv;
80         
81         Queueelem qu;
82
83 /* below is implementation-specific; don't use */
84         QLock   lk;
85         Ref             ref;
86         Reqpool*        pool;
87         uchar*  buf;
88         uchar   type;
89         uchar   responded;
90         char*   error;
91         void*   rbuf;
92         Req**   flush;
93         int             nflush;
94 };
95
96 /*
97  * Pools to maintain Fid <-> fid and Req <-> tag maps.
98  */
99
100 struct Fidpool {
101         Intmap  *map;
102         void            (*destroy)(Fid*);
103         Srv             *srv;
104 };
105
106 struct Reqpool {
107         Intmap  *map;
108         void            (*destroy)(Req*);
109         Srv             *srv;
110 };
111
112 Fidpool*        allocfidpool(void (*destroy)(Fid*));
113 void            freefidpool(Fidpool*);
114 Fid*            allocfid(Fidpool*, ulong);
115 Fid*            lookupfid(Fidpool*, ulong);
116 void            closefid(Fid*);
117 Fid*            removefid(Fidpool*, ulong);
118
119 Reqpool*        allocreqpool(void (*destroy)(Req*));
120 void            freereqpool(Reqpool*);
121 Req*            allocreq(Reqpool*, ulong);
122 Req*            lookupreq(Reqpool*, ulong);
123 void            closereq(Req*);
124 Req*            removereq(Reqpool*, ulong);
125
126 typedef int     Dirgen(int, Dir*, void*);
127 void            dirread9p(Req*, Dirgen*, void*);
128
129 /*
130  * File trees.
131  */
132 struct File {
133         Ref;
134         Dir;
135         File *parent;
136         void *aux;
137
138 /* below is implementation-specific; don't use */
139         RWLock;
140         Filelist *filelist;
141         Tree *tree;
142         int nchild;
143         int allocd;
144         int nxchild;
145         Ref readers;
146 };
147
148 struct Tree {
149         File *root;
150         void    (*destroy)(File *file);
151
152 /* below is implementation-specific; don't use */
153         Lock genlock;
154         ulong qidgen;
155         ulong dirqidgen;
156 };
157
158 Tree*   alloctree(char*, char*, ulong, void(*destroy)(File*));
159 void            freetree(Tree*);
160 File*           createfile(File*, char*, char*, ulong, void*);
161 int             removefile(File*);
162 void            closefile(File*);
163 File*           walkfile(File*, char*);
164 Readdir*        opendirfile(File*);
165 long            readdirfile(Readdir*, uchar*, long);
166 void            closedirfile(Readdir*);
167
168 /*
169  * Kernel-style command parser
170  */
171 typedef struct Cmdbuf Cmdbuf;
172 typedef struct Cmdtab Cmdtab;
173 Cmdbuf*         parsecmd(char *a, int n);
174 void            respondcmderror(Req*, Cmdbuf*, char*, ...);
175 Cmdtab* lookupcmd(Cmdbuf*, Cmdtab*, int);
176 #pragma varargck argpos respondcmderr 3
177 struct Cmdbuf
178 {
179         char    *buf;
180         char    **f;
181         int     nf;
182 };
183
184 struct Cmdtab
185 {
186         int     index;  /* used by client to switch on result */
187         char    *cmd;   /* command name */
188         int     narg;   /* expected #args; 0 ==> variadic */
189 };
190
191 /*
192  * File service loop.
193  */
194 struct Srv {
195         Tree*   tree;
196         void            (*destroyfid)(Fid*);
197         void            (*destroyreq)(Req*);
198         void            (*start)(Srv*);
199         void            (*end)(Srv*);
200         void*   aux;
201
202         void            (*attach)(Req*);
203         void            (*auth)(Req*);
204         void            (*open)(Req*);
205         void            (*create)(Req*);
206         void            (*read)(Req*);
207         void            (*write)(Req*);
208         void            (*remove)(Req*);
209         void            (*flush)(Req*);
210         void            (*stat)(Req*);
211         void            (*wstat)(Req*);
212         void            (*walk)(Req*);
213         char*   (*clone)(Fid*, Fid*);
214         char*   (*walk1)(Fid*, char*, Qid*);
215
216         int             infd;
217         int             outfd;
218         int             nopipe;
219         int             srvfd;
220         int             leavefdsopen;   /* magic for acme win */
221         char*   keyspec;
222
223 /* below is implementation-specific; don't use */
224         Fidpool*        fpool;
225         Reqpool*        rpool;
226         uint            msize;
227
228         uchar*  rbuf;
229         QLock   rlock;
230         uchar*  wbuf;
231         QLock   wlock;
232         
233         char*   addr;
234
235         QLock   slock;
236         Ref     sref;
237         Ref     rref;
238 };
239
240 void            srv(Srv*);
241 void            postmountsrv(Srv*, char*, char*, int);
242 void            _postmountsrv(Srv*, char*, char*, int);
243 void            postsharesrv(Srv*, char*, char*, char*);
244 void            _postsharesrv(Srv*, char*, char*, char*);
245 void            listensrv(Srv*, char*);
246 void            _listensrv(Srv*, char*);
247 int             postfd(char*, int);
248 int             sharefd(char*, char*, int);
249 int             chatty9p;
250 void            respond(Req*, char*);
251 void            responderror(Req*);
252 void            threadpostmountsrv(Srv*, char*, char*, int);
253 void            threadpostsharesrv(Srv*, char*, char*, char*);
254 void            threadlistensrv(Srv *s, char *addr);
255
256 /*
257  * Helper.  Assumes user is same as group.
258  */
259 int             hasperm(File*, char*, int);
260
261 void*   emalloc9p(ulong);
262 void*   erealloc9p(void*, ulong);
263 char*   estrdup9p(char*);
264
265 enum {
266         OMASK = 3
267 };
268
269 void            readstr(Req*, char*);
270 void            readbuf(Req*, void*, long);
271 void            walkandclone(Req*, char*(*walk1)(Fid*,char*,void*), 
272                         char*(*clone)(Fid*,Fid*,void*), void*);
273
274 void            auth9p(Req*);
275 void            authread(Req*);
276 void            authwrite(Req*);
277 void            authdestroy(Fid*);
278 int             authattach(Req*);
279
280 extern void (*_forker)(void (*)(void*), void*, int);
281
282 void            srvacquire(Srv *);
283 void            srvrelease(Srv *);
284
285 Reqqueue*       reqqueuecreate(void);
286 void            reqqueuepush(Reqqueue*, Req*, void (*)(Req *));
287 void            reqqueueflush(Reqqueue*, Req*);