puffs.h revision 1.16 1 /* $NetBSD: puffs.h,v 1.16 2006/12/07 23:15:20 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 /*
46 * megaXXX: these are values from inside _KERNEL
47 * need to work on the translation for ALL the necessary values.
48 */
49 #define PUFFS_VNOVAL (-1)
50 #define PUFFS_ISDOTDOT 0x2000
51 #define PUFFS_IO_APPEND 0x20
52
53 /*
54 * puffs vnode, i.e. puffs_node
55 *
56 * This represents all the relevant fields from struct vnode.
57 * This may some day become struct vnode, but let's keep it separate
58 * for now.
59 *
60 * XXX: this is not finished
61 */
62 struct puffs_node {
63 off_t pn_size;
64 int pn_flag; /* struct vnode flags */
65 void *pn_data; /* private data */
66 enum vtype pn_type;
67 struct vattr pn_va; /* XXX: doesn't belong here*/
68
69 struct puffs_usermount *pn_mnt;
70
71 LIST_ENTRY(puffs_node) pn_entries;
72 };
73
74 /* callbacks for operations */
75 struct puffs_ops {
76 int (*puffs_fs_mount)(struct puffs_usermount *, void **);
77 int (*puffs_fs_unmount)(struct puffs_usermount *, int, pid_t);
78 int (*puffs_fs_statvfs)(struct puffs_usermount *,
79 struct statvfs *, pid_t);
80 int (*puffs_fs_sync)(struct puffs_usermount *, int,
81 const struct puffs_cred *, pid_t);
82
83 int (*puffs_node_lookup)(struct puffs_usermount *,
84 void *, void **, enum vtype *, voff_t *, dev_t *,
85 const struct puffs_cn *);
86 int (*puffs_node_create)(struct puffs_usermount *,
87 void *, void **, const struct puffs_cn *, const struct vattr *);
88 int (*puffs_node_mknod)(struct puffs_usermount *,
89 void *, void **, const struct puffs_cn *, const struct vattr *);
90 int (*puffs_node_open)(struct puffs_usermount *,
91 void *, int, const struct puffs_cred *, pid_t);
92 int (*puffs_node_close)(struct puffs_usermount *,
93 void *, int, const struct puffs_cred *, pid_t);
94 int (*puffs_node_access)(struct puffs_usermount *,
95 void *, int, const struct puffs_cred *, pid_t);
96 int (*puffs_node_getattr)(struct puffs_usermount *,
97 void *, struct vattr *, const struct puffs_cred *, pid_t);
98 int (*puffs_node_setattr)(struct puffs_usermount *,
99 void *, const struct vattr *, const struct puffs_cred *, pid_t);
100 int (*puffs_node_poll)(struct puffs_usermount *,
101 void *, struct puffs_vnreq_poll *);
102 int (*puffs_node_revoke)(struct puffs_usermount *, void *, int);
103 int (*puffs_node_mmap)(struct puffs_usermount *,
104 void *, int, const struct puffs_cred *, pid_t);
105 int (*puffs_node_fsync)(struct puffs_usermount *,
106 void *, const struct puffs_cred *, int, off_t, off_t, pid_t);
107 int (*puffs_node_seek)(struct puffs_usermount *,
108 void *, off_t, off_t, const struct puffs_cred *);
109 int (*puffs_node_remove)(struct puffs_usermount *,
110 void *, void *, const struct puffs_cn *);
111 int (*puffs_node_link)(struct puffs_usermount *,
112 void *, void *, const struct puffs_cn *);
113 int (*puffs_node_rename)(struct puffs_usermount *,
114 void *, void *, const struct puffs_cn *, void *, void *,
115 const struct puffs_cn *);
116 int (*puffs_node_mkdir)(struct puffs_usermount *,
117 void *, void **, const struct puffs_cn *, const struct vattr *);
118 int (*puffs_node_rmdir)(struct puffs_usermount *,
119 void *, void *, const struct puffs_cn *);
120 int (*puffs_node_symlink)(struct puffs_usermount *,
121 void *, void **, const struct puffs_cn *, const struct vattr *,
122 const char *);
123 int (*puffs_node_readdir)(struct puffs_usermount *,
124 void *, struct dirent *, const struct puffs_cred *,
125 off_t *, size_t *);
126 int (*puffs_node_readlink)(struct puffs_usermount *,
127 void *, const struct puffs_cred *, char *, size_t *);
128 int (*puffs_node_reclaim)(struct puffs_usermount *,
129 void *, pid_t);
130 int (*puffs_node_inactive)(struct puffs_usermount *,
131 void *, pid_t, int *);
132 int (*puffs_node_print)(struct puffs_usermount *,
133 void *);
134 int (*puffs_node_pathconf)(struct puffs_usermount *,
135 void *, int, int *);
136 int (*puffs_node_advlock)(struct puffs_usermount *,
137 void *, void *, int, struct flock *, int);
138 int (*puffs_node_getextattr)(struct puffs_usermount *,
139 void *, struct puffs_vnreq_getextattr *);
140 int (*puffs_node_setextattr)(struct puffs_usermount *,
141 void *, struct puffs_vnreq_setextattr *);
142 int (*puffs_node_listextattr)(struct puffs_usermount *,
143 void *, struct puffs_vnreq_listextattr *);
144 int (*puffs_node_read)(struct puffs_usermount *, void *,
145 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
146 int (*puffs_node_write)(struct puffs_usermount *, void *,
147 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
148
149 int (*puffs_node_ioctl1)(struct puffs_usermount *, void *,
150 struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
151 int (*puffs_node_ioctl2)(struct puffs_usermount *, void *,
152 struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
153 int (*puffs_node_fcntl1)(struct puffs_usermount *, void *,
154 struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
155 int (*puffs_node_fcntl2)(struct puffs_usermount *, void *,
156 struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
157 };
158
159 struct puffs_usermount {
160 struct puffs_ops pu_ops;
161
162 int pu_fd;
163 uint32_t pu_flags;
164 size_t pu_maxreqlen;
165
166 struct puffs_node *pu_rootnode;
167 const char * pu_rootpath;
168 fsid_t pu_fsidx;
169 LIST_HEAD(, puffs_node) pu_pnodelst;
170
171 int pu_wcnt;
172 void *pu_privdata;
173 };
174
175 #define PUFFS_FLAG_KERN(a) ((a) & 0x0000ffff)
176 #define PUFFS_FLAG_LIB(a) ((a) & 0xffff0000)
177
178 #define PUFFS_FLAG_OPDUMP 0x80000000 /* dump all operations */
179
180 struct puffs_usermount *puffs_mount(struct puffs_ops *, const char *, int,
181 const char *, uint32_t, size_t);
182 int puffs_mainloop(struct puffs_usermount *, int);
183 int puffs_oneop(struct puffs_usermount *, uint8_t *, size_t);
184 int puffs_getselectable(struct puffs_usermount *);
185 int puffs_setblockingmode(struct puffs_usermount *, int);
186 void puffs_dummyops(struct puffs_ops *);
187
188 /* blocking mode argument */
189 #define PUFFSDEV_BLOCK 0
190 #define PUFFSDEV_NONBLOCK 1
191
192 /* mainloop flags */
193 #define PUFFSLOOP_NODAEMON 0x01
194
195 struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *,
196 enum vtype);
197 void puffs_putpnode(struct puffs_node *);
198 void puffs_setvattr(struct vattr *, const struct vattr *);
199
200 int puffs_fsnop_unmount(struct puffs_usermount *, int, pid_t);
201 int puffs_fsnop_statvfs(struct puffs_usermount *, struct statvfs *, pid_t);
202 int puffs_fsnop_sync(struct puffs_usermount *, int waitfor,
203 const struct puffs_cred *, pid_t);
204
205 #define DENT_DOT 0
206 #define DENT_DOTDOT 1
207 #define DENT_ADJ(a) ((a)-2) /* nth request means dir's n-2th */
208 int puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
209 int puffs_nextdent(struct dirent **, const char *, ino_t,
210 uint8_t, size_t *);
211 int puffs_vtype2dt(enum vtype);
212 enum vtype puffs_mode2vt(mode_t);
213
214
215 /*
216 * Operation credentials
217 */
218
219 /* Credential fetch */
220 int puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
221 int puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
222 int puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
223
224 /* Credential check */
225 int puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
226 int puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
227 /* kernel internal NOCRED */
228 int puffs_cred_iskernel(const struct puffs_cred *pcr);
229 /* kernel internal FSCRED */
230 int puffs_cred_isfs(const struct puffs_cred *pcr);
231 /* root || NOCRED || FSCRED */
232 int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
233
234
235 /*
236 * Requests
237 */
238
239 struct puffs_getreq;
240 struct puffs_putreq;
241
242 struct puffs_getreq *puffs_makegetreq(struct puffs_usermount *,
243 uint8_t *, size_t, int);
244 struct puffs_req *puffs_getreq(struct puffs_getreq *);
245 int puffs_remaininggetreq(struct puffs_getreq *);
246 void puffs_destroygetreq(struct puffs_getreq *);
247
248 struct puffs_putreq *puffs_makeputreq(struct puffs_usermount *);
249 void puffs_putreq(struct puffs_putreq *, struct puffs_req *);
250 int puffs_putputreq(struct puffs_putreq *);
251 void puffs_destroyputreq(struct puffs_putreq *);
252
253
254 #define PUFFSOP_PROTOS(fsname) \
255 int fsname##_fs_mount(struct puffs_usermount *, void **); \
256 int fsname##_fs_unmount(struct puffs_usermount *, int, pid_t); \
257 int fsname##_fs_statvfs(struct puffs_usermount *, \
258 struct statvfs *, pid_t); \
259 int fsname##_fs_sync(struct puffs_usermount *, int, \
260 const struct puffs_cred *cred, pid_t); \
261 \
262 int fsname##_node_lookup(struct puffs_usermount *, \
263 void *, void **, enum vtype *, voff_t *, dev_t *, \
264 const struct puffs_cn *); \
265 int fsname##_node_create(struct puffs_usermount *, \
266 void *, void **, const struct puffs_cn *, \
267 const struct vattr *); \
268 int fsname##_node_mknod(struct puffs_usermount *, \
269 void *, void **, const struct puffs_cn *, \
270 const struct vattr *); \
271 int fsname##_node_open(struct puffs_usermount *, \
272 void *, int, const struct puffs_cred *, pid_t); \
273 int fsname##_node_close(struct puffs_usermount *, \
274 void *, int, const struct puffs_cred *, pid_t); \
275 int fsname##_node_access(struct puffs_usermount *, \
276 void *, int, const struct puffs_cred *, pid_t); \
277 int fsname##_node_getattr(struct puffs_usermount *, \
278 void *, struct vattr *, const struct puffs_cred *, pid_t); \
279 int fsname##_node_setattr(struct puffs_usermount *, \
280 void *, const struct vattr *, const struct puffs_cred *, \
281 pid_t); \
282 int fsname##_node_poll(struct puffs_usermount *, \
283 void *, struct puffs_vnreq_poll *); \
284 int fsname##_node_revoke(struct puffs_usermount *, void *, int);\
285 int fsname##_node_mmap(struct puffs_usermount *, \
286 void *, int, const struct puffs_cred *, pid_t); \
287 int fsname##_node_fsync(struct puffs_usermount *, \
288 void *, const struct puffs_cred *, int, off_t, off_t, \
289 pid_t); \
290 int fsname##_node_seek(struct puffs_usermount *, \
291 void *, off_t, off_t, const struct puffs_cred *); \
292 int fsname##_node_remove(struct puffs_usermount *, \
293 void *, void *, const struct puffs_cn *); \
294 int fsname##_node_link(struct puffs_usermount *, \
295 void *, void *, const struct puffs_cn *); \
296 int fsname##_node_rename(struct puffs_usermount *, \
297 void *, void *, const struct puffs_cn *, void *, void *, \
298 const struct puffs_cn *); \
299 int fsname##_node_mkdir(struct puffs_usermount *, \
300 void *, void **, const struct puffs_cn *, \
301 const struct vattr *); \
302 int fsname##_node_rmdir(struct puffs_usermount *, \
303 void *, void *, const struct puffs_cn *); \
304 int fsname##_node_symlink(struct puffs_usermount *, \
305 void *, void **, const struct puffs_cn *, \
306 const struct vattr *, const char *); \
307 int fsname##_node_readdir(struct puffs_usermount *, \
308 void *, struct dirent *, const struct puffs_cred *, \
309 off_t *, size_t *); \
310 int fsname##_node_readlink(struct puffs_usermount *, \
311 void *, const struct puffs_cred *, char *, size_t *); \
312 int fsname##_node_reclaim(struct puffs_usermount *, \
313 void *, pid_t); \
314 int fsname##_node_inactive(struct puffs_usermount *, \
315 void *, pid_t, int *); \
316 int fsname##_node_print(struct puffs_usermount *, \
317 void *); \
318 int fsname##_node_pathconf(struct puffs_usermount *, \
319 void *, int, int *); \
320 int fsname##_node_advlock(struct puffs_usermount *, \
321 void *, void *, int, struct flock *, int); \
322 int fsname##_node_getextattr(struct puffs_usermount *, \
323 void *, struct puffs_vnreq_getextattr *); \
324 int fsname##_node_setextattr(struct puffs_usermount *, \
325 void *, struct puffs_vnreq_setextattr *); \
326 int fsname##_node_listextattr(struct puffs_usermount *, \
327 void *, struct puffs_vnreq_listextattr *); \
328 int fsname##_node_read(struct puffs_usermount *, void *, \
329 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
330 int fsname##_node_write(struct puffs_usermount *, void *, \
331 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
332
333 #define PUFFSOP_INIT(ops) \
334 memset(ops, 0, sizeof(struct puffs_ops))
335 #define PUFFSOP_SET(ops, fsname, fsornode, opname) \
336 (ops)->puffs_##fsornode##_##opname = fsname##_##fsornode##_##opname
337 #define PUFFSOP_SETFSNOP(ops, opname) \
338 (ops)->puffs_fs_##opname = puffs_fsnop_##opname
339
340 #endif /* _PUFFS_H_ */
341