puffs.h revision 1.18 1 /* $NetBSD: puffs.h,v 1.18 2007/01/02 15:53:05 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the company nor the name of the author may be used to
19 * endorse or promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #ifndef _PUFFS_H_
36 #define _PUFFS_H_
37
38 #include <sys/param.h>
39 #include <sys/mount.h>
40 #include <sys/statvfs.h>
41 #include <sys/vnode.h>
42
43 #include <fs/puffs/puffs_msgif.h>
44
45 #include <string.h>
46
47 /* forwards */
48 struct puffs_cc;
49
50 struct puffs_getreq;
51 struct puffs_putreq;
52
53 /* XXX: might disappear from here */
54 struct puffs_node {
55 off_t pn_size;
56 int pn_flag;
57 struct vattr pn_va;
58
59 void *pn_data; /* private data */
60
61 char *pn_path; /* PUFFS_FLAG_BUILDPATH */
62 size_t pn_plen;
63
64 struct puffs_usermount *pn_mnt;
65
66 LIST_ENTRY(puffs_node) pn_entries;
67 };
68
69
70 struct puffs_usermount;
71
72 /*
73 * megaXXX: these are values from inside _KERNEL
74 * need to work on the translation for ALL the necessary values.
75 */
76 #define PUFFS_VNOVAL (-1)
77 #define PUFFS_ISDOTDOT 0x2000
78 #define PUFFS_IO_APPEND 0x20
79
80 /*
81 * Magic constants
82 */
83 #define PUFFS_CC_STACKSIZE_DEFAULT (16*1024)
84
85 struct puffs_cn {
86 struct puffs_kcn *pcn_pkcnp; /* kernel input */
87
88 /* XXX: this will be a more complex object some day */
89 char *pcn_fullpath; /* if PUFFS_FLAG_BUILDPATH */
90 size_t pcn_fullplen;
91 };
92 #define pcn_nameiop pcn_pkcnp->pkcn_nameiop
93 #define pcn_flags pcn_pkcnp->pkcn_flags
94 #define pcn_pid pcn_pkcnp->pkcn_pid
95 #define pcn_cred pcn_pkcnp->pkcn_cred
96 #define pcn_name pcn_pkcnp->pkcn_name
97 #define pcn_namelen pcn_pkcnp->pkcn_namelen
98
99 /* callbacks for operations */
100 struct puffs_ops {
101 /*
102 * XXX: mount does not currently allow for sleeping and therefore
103 * cannot call any of the other backends with need cc context.
104 * I hope to change this in the future after some restructuring.
105 */
106 int (*puffs_fs_mount)(struct puffs_usermount *, void **,
107 struct statvfs *);
108
109 int (*puffs_fs_unmount)(struct puffs_cc *, int, pid_t);
110 int (*puffs_fs_statvfs)(struct puffs_cc *,
111 struct statvfs *, pid_t);
112 int (*puffs_fs_sync)(struct puffs_cc *, int,
113 const struct puffs_cred *, pid_t);
114
115 int (*puffs_node_lookup)(struct puffs_cc *,
116 void *, void **, enum vtype *, voff_t *, dev_t *,
117 const struct puffs_cn *);
118 int (*puffs_node_create)(struct puffs_cc *,
119 void *, void **, const struct puffs_cn *, const struct vattr *);
120 int (*puffs_node_mknod)(struct puffs_cc *,
121 void *, void **, const struct puffs_cn *, const struct vattr *);
122 int (*puffs_node_open)(struct puffs_cc *,
123 void *, int, const struct puffs_cred *, pid_t);
124 int (*puffs_node_close)(struct puffs_cc *,
125 void *, int, const struct puffs_cred *, pid_t);
126 int (*puffs_node_access)(struct puffs_cc *,
127 void *, int, const struct puffs_cred *, pid_t);
128 int (*puffs_node_getattr)(struct puffs_cc *,
129 void *, struct vattr *, const struct puffs_cred *, pid_t);
130 int (*puffs_node_setattr)(struct puffs_cc *,
131 void *, const struct vattr *, const struct puffs_cred *, pid_t);
132 int (*puffs_node_poll)(struct puffs_cc *,
133 void *, struct puffs_vnreq_poll *);
134 int (*puffs_node_revoke)(struct puffs_cc *, void *, int);
135 int (*puffs_node_mmap)(struct puffs_cc *,
136 void *, int, const struct puffs_cred *, pid_t);
137 int (*puffs_node_fsync)(struct puffs_cc *,
138 void *, const struct puffs_cred *, int, off_t, off_t, pid_t);
139 int (*puffs_node_seek)(struct puffs_cc *,
140 void *, off_t, off_t, const struct puffs_cred *);
141 int (*puffs_node_remove)(struct puffs_cc *,
142 void *, void *, const struct puffs_cn *);
143 int (*puffs_node_link)(struct puffs_cc *,
144 void *, void *, const struct puffs_cn *);
145 int (*puffs_node_rename)(struct puffs_cc *,
146 void *, void *, const struct puffs_cn *, void *, void *,
147 const struct puffs_cn *);
148 int (*puffs_node_mkdir)(struct puffs_cc *,
149 void *, void **, const struct puffs_cn *, const struct vattr *);
150 int (*puffs_node_rmdir)(struct puffs_cc *,
151 void *, void *, const struct puffs_cn *);
152 int (*puffs_node_symlink)(struct puffs_cc *,
153 void *, void **, const struct puffs_cn *, const struct vattr *,
154 const char *);
155 int (*puffs_node_readdir)(struct puffs_cc *,
156 void *, struct dirent *, const struct puffs_cred *,
157 off_t *, size_t *);
158 int (*puffs_node_readlink)(struct puffs_cc *,
159 void *, const struct puffs_cred *, char *, size_t *);
160 int (*puffs_node_reclaim)(struct puffs_cc *,
161 void *, pid_t);
162 int (*puffs_node_inactive)(struct puffs_cc *,
163 void *, pid_t, int *);
164 int (*puffs_node_print)(struct puffs_cc *,
165 void *);
166 int (*puffs_node_pathconf)(struct puffs_cc *,
167 void *, int, int *);
168 int (*puffs_node_advlock)(struct puffs_cc *,
169 void *, void *, int, struct flock *, int);
170 int (*puffs_node_getextattr)(struct puffs_cc *,
171 void *, struct puffs_vnreq_getextattr *);
172 int (*puffs_node_setextattr)(struct puffs_cc *,
173 void *, struct puffs_vnreq_setextattr *);
174 int (*puffs_node_listextattr)(struct puffs_cc *,
175 void *, struct puffs_vnreq_listextattr *);
176 int (*puffs_node_read)(struct puffs_cc *, void *,
177 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
178 int (*puffs_node_write)(struct puffs_cc *, void *,
179 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
180 };
181
182 struct puffs_usermount {
183 struct puffs_ops pu_ops;
184
185 int pu_fd;
186 uint32_t pu_flags;
187 size_t pu_maxreqlen;
188 size_t pu_cc_stacksize;
189
190 int pu_state;
191
192 struct puffs_node *pu_pn_root;
193
194 fsid_t pu_fsidx;
195 LIST_HEAD(, puffs_node) pu_pnodelst;
196
197 int pu_wcnt;
198 void *pu_privdata;
199 };
200
201 enum {
202 PUFFS_STATE_MOUNTING, PUFFS_STATE_RUNNING,
203 PUFFS_STATE_UNMOUNTING, PUFFS_STATE_UNMOUNTED
204 };
205
206 #define PUFFS_FLAG_KERN(a) ((a) & 0x0000ffff)
207 #define PUFFS_FLAG_LIB(a) ((a) & 0xffff0000)
208
209 #define PUFFS_FLAG_OPDUMP 0x80000000 /* dump all operations */
210 #define PUFFS_FLAG_BUILDPATH 0x40000000 /* node paths in pnode */
211
212 /* blocking mode argument */
213 #define PUFFSDEV_BLOCK 0
214 #define PUFFSDEV_NONBLOCK 1
215
216 /* mainloop flags */
217 #define PUFFSLOOP_NODAEMON 0x01
218
219 int puffs_fsnop_unmount(struct puffs_cc *, int, pid_t);
220 int puffs_fsnop_statvfs(struct puffs_cc *, struct statvfs *, pid_t);
221 int puffs_fsnop_sync(struct puffs_cc *, int waitfor,
222 const struct puffs_cred *, pid_t);
223
224 #define DENT_DOT 0
225 #define DENT_DOTDOT 1
226 #define DENT_ADJ(a) ((a)-2) /* nth request means dir's n-2th */
227 int puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
228 int puffs_nextdent(struct dirent **, const char *, ino_t,
229 uint8_t, size_t *);
230 int puffs_vtype2dt(enum vtype);
231 enum vtype puffs_mode2vt(mode_t);
232
233
234 /*
235 * Operation credentials
236 */
237
238 /* Credential fetch */
239 int puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
240 int puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
241 int puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
242
243 /* Credential check */
244 int puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
245 int puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
246 /* kernel internal NOCRED */
247 int puffs_cred_iskernel(const struct puffs_cred *pcr);
248 /* kernel internal FSCRED */
249 int puffs_cred_isfs(const struct puffs_cred *pcr);
250 /* root || NOCRED || FSCRED */
251 int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
252
253
254 /*
255 * protos
256 */
257
258 #define PUFFSOP_PROTOS(fsname) \
259 int fsname##_fs_mount(struct puffs_usermount *, void **, \
260 struct statvfs *); \
261 int fsname##_fs_unmount(struct puffs_cc *, int, pid_t); \
262 int fsname##_fs_statvfs(struct puffs_cc *, \
263 struct statvfs *, pid_t); \
264 int fsname##_fs_sync(struct puffs_cc *, int, \
265 const struct puffs_cred *cred, pid_t); \
266 \
267 int fsname##_node_lookup(struct puffs_cc *, \
268 void *, void **, enum vtype *, voff_t *, dev_t *, \
269 const struct puffs_cn *); \
270 int fsname##_node_create(struct puffs_cc *, \
271 void *, void **, const struct puffs_cn *, \
272 const struct vattr *); \
273 int fsname##_node_mknod(struct puffs_cc *, \
274 void *, void **, const struct puffs_cn *, \
275 const struct vattr *); \
276 int fsname##_node_open(struct puffs_cc *, \
277 void *, int, const struct puffs_cred *, pid_t); \
278 int fsname##_node_close(struct puffs_cc *, \
279 void *, int, const struct puffs_cred *, pid_t); \
280 int fsname##_node_access(struct puffs_cc *, \
281 void *, int, const struct puffs_cred *, pid_t); \
282 int fsname##_node_getattr(struct puffs_cc *, \
283 void *, struct vattr *, const struct puffs_cred *, pid_t); \
284 int fsname##_node_setattr(struct puffs_cc *, \
285 void *, const struct vattr *, const struct puffs_cred *, \
286 pid_t); \
287 int fsname##_node_poll(struct puffs_cc *, \
288 void *, struct puffs_vnreq_poll *); \
289 int fsname##_node_revoke(struct puffs_cc *, void *, int); \
290 int fsname##_node_mmap(struct puffs_cc *, \
291 void *, int, const struct puffs_cred *, pid_t); \
292 int fsname##_node_fsync(struct puffs_cc *, \
293 void *, const struct puffs_cred *, int, off_t, off_t, \
294 pid_t); \
295 int fsname##_node_seek(struct puffs_cc *, \
296 void *, off_t, off_t, const struct puffs_cred *); \
297 int fsname##_node_remove(struct puffs_cc *, \
298 void *, void *, const struct puffs_cn *); \
299 int fsname##_node_link(struct puffs_cc *, \
300 void *, void *, const struct puffs_cn *); \
301 int fsname##_node_rename(struct puffs_cc *, \
302 void *, void *, const struct puffs_cn *, void *, void *, \
303 const struct puffs_cn *); \
304 int fsname##_node_mkdir(struct puffs_cc *, \
305 void *, void **, const struct puffs_cn *, \
306 const struct vattr *); \
307 int fsname##_node_rmdir(struct puffs_cc *, \
308 void *, void *, const struct puffs_cn *); \
309 int fsname##_node_symlink(struct puffs_cc *, \
310 void *, void **, const struct puffs_cn *, \
311 const struct vattr *, const char *); \
312 int fsname##_node_readdir(struct puffs_cc *, \
313 void *, struct dirent *, const struct puffs_cred *, \
314 off_t *, size_t *); \
315 int fsname##_node_readlink(struct puffs_cc *, \
316 void *, const struct puffs_cred *, char *, size_t *); \
317 int fsname##_node_reclaim(struct puffs_cc *, \
318 void *, pid_t); \
319 int fsname##_node_inactive(struct puffs_cc *, \
320 void *, pid_t, int *); \
321 int fsname##_node_print(struct puffs_cc *, \
322 void *); \
323 int fsname##_node_pathconf(struct puffs_cc *, \
324 void *, int, int *); \
325 int fsname##_node_advlock(struct puffs_cc *, \
326 void *, void *, int, struct flock *, int); \
327 int fsname##_node_getextattr(struct puffs_cc *, \
328 void *, struct puffs_vnreq_getextattr *); \
329 int fsname##_node_setextattr(struct puffs_cc *, \
330 void *, struct puffs_vnreq_setextattr *); \
331 int fsname##_node_listextattr(struct puffs_cc *, \
332 void *, struct puffs_vnreq_listextattr *); \
333 int fsname##_node_read(struct puffs_cc *, void *, \
334 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
335 int fsname##_node_write(struct puffs_cc *, void *, \
336 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
337
338 #define PUFFSOP_INIT(ops) \
339 ops = malloc(sizeof(struct puffs_ops)); \
340 memset(ops, 0, sizeof(struct puffs_ops))
341 #define PUFFSOP_SET(ops, fsname, fsornode, opname) \
342 (ops)->puffs_##fsornode##_##opname = fsname##_##fsornode##_##opname
343 #define PUFFSOP_SETFSNOP(ops, opname) \
344 (ops)->puffs_fs_##opname = puffs_fsnop_##opname
345
346 #define PUFFS_DEVEL_LIBVERSION 0
347 #define puffs_mount(a,b,c,d,e,f,g) \
348 _puffs_mount(PUFFS_DEVEL_LIBVERSION,a,b,c,d,e,f,g)
349
350 __BEGIN_DECLS
351
352 struct puffs_usermount *_puffs_mount(int, struct puffs_ops *, const char *, int,
353 const char *, void *, uint32_t, size_t);
354 int puffs_mainloop(struct puffs_usermount *, int);
355
356
357 int puffs_getselectable(struct puffs_usermount *);
358 int puffs_setblockingmode(struct puffs_usermount *, int);
359 int puffs_getstate(struct puffs_usermount *);
360 int puffs_setrootpath(struct puffs_usermount *, const char *);
361 void puffs_setstacksize(struct puffs_usermount *, size_t);
362
363 struct puffs_node * puffs_pn_new(struct puffs_usermount *, void *);
364 void puffs_pn_put(struct puffs_node *);
365 struct vattr *puffs_pn_getvattrp(struct puffs_node *);
366 void puffs_setvattr(struct vattr *, const struct vattr *);
367 void puffs_vattr_null(struct vattr *);
368
369 /*
370 * Requests
371 */
372
373 struct puffs_getreq *puffs_makegetreq(struct puffs_usermount *,
374 size_t, int);
375 int puffs_loadgetreq(struct puffs_getreq *);
376 struct puffs_req *puffs_getreq(struct puffs_getreq *);
377 int puffs_remaininggetreq(struct puffs_getreq *);
378 void puffs_setmaxgetreq(struct puffs_getreq *, int);
379 void puffs_destroygetreq(struct puffs_getreq *);
380
381 struct puffs_putreq *puffs_makeputreq(struct puffs_usermount *);
382 void puffs_putreq(struct puffs_putreq *, struct puffs_req *);
383 void puffs_putreq_cc(struct puffs_putreq *,struct puffs_cc*);
384 int puffs_putputreq(struct puffs_putreq *);
385 void puffs_resetputreq(struct puffs_putreq *);
386 void puffs_destroyputreq(struct puffs_putreq *);
387
388 /*
389 * Call Context interfaces relevant for user.
390 */
391
392 void puffs_cc_yield(struct puffs_cc *);
393 void puffs_cc_continue(struct puffs_cc *);
394
395 void *puffs_cc_getpriv(struct puffs_cc *);
396 void puffs_cc_setpriv(struct puffs_cc *, void *, int);
397
398 struct puffs_usermount *puffs_cc_getusermount(struct puffs_cc *);
399
400 /*
401 * Execute or continue a request
402 */
403
404 int puffs_handlereqs(struct puffs_usermount *, struct puffs_getreq *,
405 struct puffs_putreq *, int);
406
407 int puffs_dopreq(struct puffs_usermount *, struct puffs_putreq *,
408 struct puffs_req *);
409 int puffs_docc(struct puffs_putreq *, struct puffs_cc *);
410
411 __END_DECLS
412
413 #endif /* _PUFFS_H_ */
414