puffs.h revision 1.14 1 1.14 pooka /* $NetBSD: puffs.h,v 1.14 2006/12/07 10:53:21 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.1 pooka * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
5 1.1 pooka *
6 1.1 pooka * Development of this software was supported by the
7 1.1 pooka * Google Summer of Code program and the Ulla Tuominen Foundation.
8 1.1 pooka * The Google SoC project was mentored by Bill Studenmund.
9 1.1 pooka *
10 1.1 pooka * Redistribution and use in source and binary forms, with or without
11 1.1 pooka * modification, are permitted provided that the following conditions
12 1.1 pooka * are met:
13 1.1 pooka * 1. Redistributions of source code must retain the above copyright
14 1.1 pooka * notice, this list of conditions and the following disclaimer.
15 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pooka * notice, this list of conditions and the following disclaimer in the
17 1.1 pooka * documentation and/or other materials provided with the distribution.
18 1.1 pooka * 3. The name of the company nor the name of the author may be used to
19 1.1 pooka * endorse or promote products derived from this software without specific
20 1.1 pooka * prior written permission.
21 1.1 pooka *
22 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 1.1 pooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 1.1 pooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 1.1 pooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 1.1 pooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 pooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 pooka * SUCH DAMAGE.
33 1.1 pooka */
34 1.1 pooka
35 1.14 pooka #ifndef _PUFFS_H_
36 1.14 pooka #define _PUFFS_H_
37 1.1 pooka
38 1.1 pooka #include <sys/param.h>
39 1.1 pooka #include <sys/mount.h>
40 1.1 pooka #include <sys/statvfs.h>
41 1.1 pooka #include <sys/vnode.h>
42 1.1 pooka
43 1.1 pooka #include <fs/puffs/puffs_msgif.h>
44 1.1 pooka
45 1.1 pooka /*
46 1.1 pooka * megaXXX: these are values from inside _KERNEL
47 1.1 pooka * need to work on the translation for ALL the necessary values.
48 1.1 pooka */
49 1.1 pooka #define PUFFS_VNOVAL (-1)
50 1.1 pooka #define PUFFS_ISDOTDOT 0x2000
51 1.1 pooka #define PUFFS_IO_APPEND 0x20
52 1.1 pooka
53 1.1 pooka /*
54 1.1 pooka * puffs vnode, i.e. puffs_node
55 1.1 pooka *
56 1.1 pooka * This represents all the relevant fields from struct vnode.
57 1.1 pooka * This may some day become struct vnode, but let's keep it separate
58 1.1 pooka * for now.
59 1.1 pooka *
60 1.1 pooka * XXX: this is not finished
61 1.1 pooka */
62 1.1 pooka struct puffs_node {
63 1.1 pooka off_t pn_size;
64 1.1 pooka int pn_flag; /* struct vnode flags */
65 1.1 pooka void *pn_data; /* private data */
66 1.1 pooka enum vtype pn_type;
67 1.3 pooka struct vattr pn_va; /* XXX: doesn't belong here*/
68 1.1 pooka
69 1.1 pooka struct puffs_usermount *pn_mnt;
70 1.1 pooka
71 1.1 pooka LIST_ENTRY(puffs_node) pn_entries;
72 1.1 pooka };
73 1.1 pooka
74 1.1 pooka /* callbacks for operations */
75 1.14 pooka struct puffs_ops {
76 1.14 pooka int (*puffs_fs_mount)(struct puffs_usermount *, void **);
77 1.14 pooka int (*puffs_fs_unmount)(struct puffs_usermount *, int, pid_t);
78 1.14 pooka int (*puffs_fs_statvfs)(struct puffs_usermount *,
79 1.1 pooka struct statvfs *, pid_t);
80 1.14 pooka int (*puffs_fs_sync)(struct puffs_usermount *, int,
81 1.1 pooka const struct puffs_cred *, pid_t);
82 1.1 pooka
83 1.14 pooka int (*puffs_node_lookup)(struct puffs_usermount *,
84 1.4 pooka void *, void **, enum vtype *, voff_t *, dev_t *,
85 1.3 pooka const struct puffs_cn *);
86 1.14 pooka int (*puffs_node_create)(struct puffs_usermount *,
87 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
88 1.14 pooka int (*puffs_node_mknod)(struct puffs_usermount *,
89 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
90 1.14 pooka int (*puffs_node_open)(struct puffs_usermount *,
91 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
92 1.14 pooka int (*puffs_node_close)(struct puffs_usermount *,
93 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
94 1.14 pooka int (*puffs_node_access)(struct puffs_usermount *,
95 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
96 1.14 pooka int (*puffs_node_getattr)(struct puffs_usermount *,
97 1.1 pooka void *, struct vattr *, const struct puffs_cred *, pid_t);
98 1.14 pooka int (*puffs_node_setattr)(struct puffs_usermount *,
99 1.1 pooka void *, const struct vattr *, const struct puffs_cred *, pid_t);
100 1.14 pooka int (*puffs_node_poll)(struct puffs_usermount *,
101 1.1 pooka void *, struct puffs_vnreq_poll *);
102 1.14 pooka int (*puffs_node_revoke)(struct puffs_usermount *, void *, int);
103 1.14 pooka int (*puffs_node_mmap)(struct puffs_usermount *,
104 1.1 pooka void *, struct puffs_vnreq_mmap *);
105 1.14 pooka int (*puffs_node_fsync)(struct puffs_usermount *,
106 1.1 pooka void *, const struct puffs_cred *, int, off_t, off_t, pid_t);
107 1.14 pooka int (*puffs_node_seek)(struct puffs_usermount *,
108 1.1 pooka void *, off_t, off_t, const struct puffs_cred *);
109 1.14 pooka int (*puffs_node_remove)(struct puffs_usermount *,
110 1.1 pooka void *, void *, const struct puffs_cn *);
111 1.14 pooka int (*puffs_node_link)(struct puffs_usermount *,
112 1.1 pooka void *, void *, const struct puffs_cn *);
113 1.14 pooka int (*puffs_node_rename)(struct puffs_usermount *,
114 1.1 pooka void *, void *, const struct puffs_cn *, void *, void *,
115 1.1 pooka const struct puffs_cn *);
116 1.14 pooka int (*puffs_node_mkdir)(struct puffs_usermount *,
117 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
118 1.14 pooka int (*puffs_node_rmdir)(struct puffs_usermount *,
119 1.1 pooka void *, void *, const struct puffs_cn *);
120 1.14 pooka int (*puffs_node_symlink)(struct puffs_usermount *,
121 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *,
122 1.1 pooka const char *);
123 1.14 pooka int (*puffs_node_readdir)(struct puffs_usermount *,
124 1.1 pooka void *, struct dirent *, const struct puffs_cred *,
125 1.1 pooka off_t *, size_t *);
126 1.14 pooka int (*puffs_node_readlink)(struct puffs_usermount *,
127 1.1 pooka void *, const struct puffs_cred *, char *, size_t *);
128 1.14 pooka int (*puffs_node_reclaim)(struct puffs_usermount *,
129 1.1 pooka void *, pid_t);
130 1.14 pooka int (*puffs_node_inactive)(struct puffs_usermount *,
131 1.2 pooka void *, pid_t, int *);
132 1.14 pooka int (*puffs_node_print)(struct puffs_usermount *,
133 1.1 pooka void *);
134 1.14 pooka int (*puffs_node_pathconf)(struct puffs_usermount *,
135 1.1 pooka void *, int, int *);
136 1.14 pooka int (*puffs_node_advlock)(struct puffs_usermount *,
137 1.1 pooka void *, void *, int, struct flock *, int);
138 1.14 pooka int (*puffs_node_getextattr)(struct puffs_usermount *,
139 1.1 pooka void *, struct puffs_vnreq_getextattr *);
140 1.14 pooka int (*puffs_node_setextattr)(struct puffs_usermount *,
141 1.1 pooka void *, struct puffs_vnreq_setextattr *);
142 1.14 pooka int (*puffs_node_listextattr)(struct puffs_usermount *,
143 1.1 pooka void *, struct puffs_vnreq_listextattr *);
144 1.14 pooka int (*puffs_node_read)(struct puffs_usermount *, void *,
145 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
146 1.14 pooka int (*puffs_node_write)(struct puffs_usermount *, void *,
147 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
148 1.1 pooka
149 1.14 pooka int (*puffs_node_ioctl1)(struct puffs_usermount *, void *,
150 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
151 1.14 pooka int (*puffs_node_ioctl2)(struct puffs_usermount *, void *,
152 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
153 1.14 pooka int (*puffs_node_fcntl1)(struct puffs_usermount *, void *,
154 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
155 1.14 pooka int (*puffs_node_fcntl2)(struct puffs_usermount *, void *,
156 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
157 1.1 pooka };
158 1.1 pooka
159 1.1 pooka struct puffs_usermount {
160 1.14 pooka struct puffs_ops pu_ops;
161 1.1 pooka
162 1.1 pooka int pu_fd;
163 1.1 pooka uint32_t pu_flags;
164 1.1 pooka size_t pu_maxreqlen;
165 1.1 pooka
166 1.1 pooka struct puffs_node *pu_rootnode;
167 1.1 pooka const char * pu_rootpath;
168 1.5 pooka fsid_t pu_fsidx;
169 1.1 pooka LIST_HEAD(, puffs_node) pu_pnodelst;
170 1.1 pooka
171 1.1 pooka int pu_wcnt;
172 1.1 pooka void *pu_privdata;
173 1.1 pooka };
174 1.1 pooka
175 1.13 pooka #define PUFFS_FLAG_KERN(a) ((a) & 0x0000ffff)
176 1.13 pooka #define PUFFS_FLAG_LIB(a) ((a) & 0xffff0000)
177 1.12 pooka
178 1.13 pooka #define PUFFS_FLAG_OPDUMP 0x80000000 /* dump all operations */
179 1.1 pooka
180 1.14 pooka struct puffs_usermount *puffs_mount(struct puffs_ops *, const char *, int,
181 1.14 pooka const char *, uint32_t, size_t);
182 1.12 pooka int puffs_mainloop(struct puffs_usermount *, int);
183 1.1 pooka int puffs_oneop(struct puffs_usermount *, uint8_t *, size_t);
184 1.1 pooka int puffs_getselectable(struct puffs_usermount *);
185 1.1 pooka int puffs_setblockingmode(struct puffs_usermount *, int);
186 1.14 pooka void puffs_dummyops(struct puffs_ops *);
187 1.1 pooka
188 1.12 pooka /* blocking mode argument */
189 1.5 pooka #define PUFFSDEV_BLOCK 0
190 1.5 pooka #define PUFFSDEV_NONBLOCK 1
191 1.5 pooka
192 1.12 pooka /* mainloop flags */
193 1.12 pooka #define PUFFSLOOP_NODAEMON 0x01
194 1.12 pooka
195 1.1 pooka struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *,
196 1.1 pooka enum vtype);
197 1.1 pooka void puffs_putpnode(struct puffs_node *);
198 1.1 pooka void puffs_setvattr(struct vattr *, const struct vattr *);
199 1.1 pooka
200 1.14 pooka int puffs_fsnop_unmount(struct puffs_usermount *, int, pid_t);
201 1.14 pooka int puffs_fsnop_statvfs(struct puffs_usermount *, struct statvfs *, pid_t);
202 1.14 pooka int puffs_fsnop_sync(struct puffs_usermount *, int waitfor,
203 1.7 pooka const struct puffs_cred *, pid_t);
204 1.6 pooka
205 1.1 pooka #define DENT_DOT 0
206 1.1 pooka #define DENT_DOTDOT 1
207 1.1 pooka #define DENT_ADJ(a) ((a)-2) /* nth request means dir's n-2th */
208 1.1 pooka int puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
209 1.1 pooka int puffs_nextdent(struct dirent **, const char *, ino_t,
210 1.1 pooka uint8_t, size_t *);
211 1.1 pooka int puffs_vtype2dt(enum vtype);
212 1.10 pooka enum vtype puffs_mode2vt(mode_t);
213 1.1 pooka
214 1.1 pooka
215 1.1 pooka /*
216 1.1 pooka * Operation credentials
217 1.1 pooka */
218 1.1 pooka
219 1.1 pooka /* Credential fetch */
220 1.1 pooka int puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
221 1.1 pooka int puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
222 1.1 pooka int puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
223 1.1 pooka
224 1.1 pooka /* Credential check */
225 1.1 pooka int puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
226 1.1 pooka int puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
227 1.1 pooka /* kernel internal NOCRED */
228 1.1 pooka int puffs_cred_iskernel(const struct puffs_cred *pcr);
229 1.1 pooka /* kernel internal FSCRED */
230 1.1 pooka int puffs_cred_isfs(const struct puffs_cred *pcr);
231 1.1 pooka /* root || NOCRED || FSCRED */
232 1.1 pooka int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
233 1.1 pooka
234 1.1 pooka
235 1.14 pooka #define PUFFSOP_PROTOS(fsname) \
236 1.14 pooka int fsname##_fs_mount(struct puffs_usermount *, void **); \
237 1.14 pooka int fsname##_fs_unmount(struct puffs_usermount *, int, pid_t); \
238 1.14 pooka int fsname##_fs_statvfs(struct puffs_usermount *, \
239 1.1 pooka struct statvfs *, pid_t); \
240 1.14 pooka int fsname##_fs_sync(struct puffs_usermount *, int, \
241 1.14 pooka const struct puffs_cred *cred, pid_t); \
242 1.14 pooka \
243 1.14 pooka int fsname##_node_lookup(struct puffs_usermount *, \
244 1.4 pooka void *, void **, enum vtype *, voff_t *, dev_t *, \
245 1.3 pooka const struct puffs_cn *); \
246 1.14 pooka int fsname##_node_create(struct puffs_usermount *, \
247 1.1 pooka void *, void **, const struct puffs_cn *, \
248 1.1 pooka const struct vattr *); \
249 1.14 pooka int fsname##_node_mknod(struct puffs_usermount *, \
250 1.1 pooka void *, void **, const struct puffs_cn *, \
251 1.1 pooka const struct vattr *); \
252 1.14 pooka int fsname##_node_open(struct puffs_usermount *, \
253 1.1 pooka void *, int, const struct puffs_cred *, pid_t); \
254 1.14 pooka int fsname##_node_close(struct puffs_usermount *, \
255 1.11 pooka void *, int, const struct puffs_cred *, pid_t); \
256 1.14 pooka int fsname##_node_access(struct puffs_usermount *, \
257 1.11 pooka void *, int, const struct puffs_cred *, pid_t); \
258 1.14 pooka int fsname##_node_getattr(struct puffs_usermount *, \
259 1.1 pooka void *, struct vattr *, const struct puffs_cred *, pid_t); \
260 1.14 pooka int fsname##_node_setattr(struct puffs_usermount *, \
261 1.1 pooka void *, const struct vattr *, const struct puffs_cred *, \
262 1.1 pooka pid_t); \
263 1.14 pooka int fsname##_node_poll(struct puffs_usermount *, \
264 1.1 pooka void *, struct puffs_vnreq_poll *); \
265 1.14 pooka int fsname##_node_revoke(struct puffs_usermount *, void *, int);\
266 1.14 pooka int fsname##_node_mmap(struct puffs_usermount *, \
267 1.1 pooka void *, struct puffs_vnreq_mmap *); \
268 1.14 pooka int fsname##_node_fsync(struct puffs_usermount *, \
269 1.1 pooka void *, const struct puffs_cred *, int, off_t, off_t, \
270 1.1 pooka pid_t); \
271 1.14 pooka int fsname##_node_seek(struct puffs_usermount *, \
272 1.1 pooka void *, off_t, off_t, const struct puffs_cred *); \
273 1.14 pooka int fsname##_node_remove(struct puffs_usermount *, \
274 1.1 pooka void *, void *, const struct puffs_cn *); \
275 1.14 pooka int fsname##_node_link(struct puffs_usermount *, \
276 1.1 pooka void *, void *, const struct puffs_cn *); \
277 1.14 pooka int fsname##_node_rename(struct puffs_usermount *, \
278 1.1 pooka void *, void *, const struct puffs_cn *, void *, void *, \
279 1.1 pooka const struct puffs_cn *); \
280 1.14 pooka int fsname##_node_mkdir(struct puffs_usermount *, \
281 1.1 pooka void *, void **, const struct puffs_cn *, \
282 1.1 pooka const struct vattr *); \
283 1.14 pooka int fsname##_node_rmdir(struct puffs_usermount *, \
284 1.1 pooka void *, void *, const struct puffs_cn *); \
285 1.14 pooka int fsname##_node_symlink(struct puffs_usermount *, \
286 1.1 pooka void *, void **, const struct puffs_cn *, \
287 1.1 pooka const struct vattr *, const char *); \
288 1.14 pooka int fsname##_node_readdir(struct puffs_usermount *, \
289 1.1 pooka void *, struct dirent *, const struct puffs_cred *, \
290 1.1 pooka off_t *, size_t *); \
291 1.14 pooka int fsname##_node_readlink(struct puffs_usermount *, \
292 1.1 pooka void *, const struct puffs_cred *, char *, size_t *); \
293 1.14 pooka int fsname##_node_reclaim(struct puffs_usermount *, \
294 1.1 pooka void *, pid_t); \
295 1.14 pooka int fsname##_node_inactive(struct puffs_usermount *, \
296 1.2 pooka void *, pid_t, int *); \
297 1.14 pooka int fsname##_node_print(struct puffs_usermount *, \
298 1.1 pooka void *); \
299 1.14 pooka int fsname##_node_pathconf(struct puffs_usermount *, \
300 1.1 pooka void *, int, int *); \
301 1.14 pooka int fsname##_node_advlock(struct puffs_usermount *, \
302 1.1 pooka void *, void *, int, struct flock *, int); \
303 1.14 pooka int fsname##_node_getextattr(struct puffs_usermount *, \
304 1.1 pooka void *, struct puffs_vnreq_getextattr *); \
305 1.14 pooka int fsname##_node_setextattr(struct puffs_usermount *, \
306 1.1 pooka void *, struct puffs_vnreq_setextattr *); \
307 1.14 pooka int fsname##_node_listextattr(struct puffs_usermount *, \
308 1.1 pooka void *, struct puffs_vnreq_listextattr *); \
309 1.14 pooka int fsname##_node_read(struct puffs_usermount *, void *, \
310 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
311 1.14 pooka int fsname##_node_write(struct puffs_usermount *, void *, \
312 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
313 1.1 pooka
314 1.14 pooka #define PUFFSOP_INIT(ops) \
315 1.14 pooka memset(ops, 0, sizeof(struct puffs_ops))
316 1.14 pooka #define PUFFSOP_SET(ops, fsname, fsornode, opname) \
317 1.14 pooka (ops)->puffs_##fsornode##_##opname = fsname##_##fsornode##_##opname
318 1.14 pooka #define PUFFSOP_SETFSNOP(ops, opname) \
319 1.14 pooka (ops)->puffs_fs_##opname = puffs_fsnop_##opname
320 1.14 pooka
321 1.14 pooka #endif /* _PUFFS_H_ */
322