puffs.h revision 1.4 1 1.4 pooka /* $NetBSD: puffs.h,v 1.4 2006/11/07 22:10:53 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.1 pooka #ifndef _PUFFS_USER_H_
36 1.1 pooka #define _PUFFS_USER_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.1 pooka struct puffs_vfsops {
76 1.1 pooka int (*puffs_start)(struct puffs_usermount *,
77 1.1 pooka struct puffs_vfsreq_start *);
78 1.1 pooka int (*puffs_unmount)(struct puffs_usermount *, int, pid_t);
79 1.1 pooka int (*puffs_statvfs)(struct puffs_usermount *,
80 1.1 pooka struct statvfs *, pid_t);
81 1.1 pooka int (*puffs_sync)(struct puffs_usermount *, int,
82 1.1 pooka const struct puffs_cred *, pid_t);
83 1.1 pooka };
84 1.1 pooka
85 1.1 pooka struct puffs_vnops {
86 1.1 pooka int (*puffs_lookup)(struct puffs_usermount *,
87 1.4 pooka void *, void **, enum vtype *, voff_t *, dev_t *,
88 1.3 pooka const struct puffs_cn *);
89 1.1 pooka int (*puffs_create)(struct puffs_usermount *,
90 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
91 1.1 pooka int (*puffs_mknod)(struct puffs_usermount *,
92 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
93 1.1 pooka int (*puffs_open)(struct puffs_usermount *,
94 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
95 1.1 pooka int (*puffs_close)(struct puffs_usermount *,
96 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
97 1.1 pooka int (*puffs_access)(struct puffs_usermount *,
98 1.1 pooka void *, int, const struct puffs_cred *, pid_t);
99 1.1 pooka int (*puffs_getattr)(struct puffs_usermount *,
100 1.1 pooka void *, struct vattr *, const struct puffs_cred *, pid_t);
101 1.1 pooka int (*puffs_setattr)(struct puffs_usermount *,
102 1.1 pooka void *, const struct vattr *, const struct puffs_cred *, pid_t);
103 1.1 pooka int (*puffs_poll)(struct puffs_usermount *,
104 1.1 pooka void *, struct puffs_vnreq_poll *);
105 1.1 pooka int (*puffs_revoke)(struct puffs_usermount *, void *, int);
106 1.1 pooka int (*puffs_mmap)(struct puffs_usermount *,
107 1.1 pooka void *, struct puffs_vnreq_mmap *);
108 1.1 pooka int (*puffs_fsync)(struct puffs_usermount *,
109 1.1 pooka void *, const struct puffs_cred *, int, off_t, off_t, pid_t);
110 1.1 pooka int (*puffs_seek)(struct puffs_usermount *,
111 1.1 pooka void *, off_t, off_t, const struct puffs_cred *);
112 1.1 pooka int (*puffs_remove)(struct puffs_usermount *,
113 1.1 pooka void *, void *, const struct puffs_cn *);
114 1.1 pooka int (*puffs_link)(struct puffs_usermount *,
115 1.1 pooka void *, void *, const struct puffs_cn *);
116 1.1 pooka int (*puffs_rename)(struct puffs_usermount *,
117 1.1 pooka void *, void *, const struct puffs_cn *, void *, void *,
118 1.1 pooka const struct puffs_cn *);
119 1.1 pooka int (*puffs_mkdir)(struct puffs_usermount *,
120 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *);
121 1.1 pooka int (*puffs_rmdir)(struct puffs_usermount *,
122 1.1 pooka void *, void *, const struct puffs_cn *);
123 1.1 pooka int (*puffs_symlink)(struct puffs_usermount *,
124 1.1 pooka void *, void **, const struct puffs_cn *, const struct vattr *,
125 1.1 pooka const char *);
126 1.1 pooka int (*puffs_readdir)(struct puffs_usermount *,
127 1.1 pooka void *, struct dirent *, const struct puffs_cred *,
128 1.1 pooka off_t *, size_t *);
129 1.1 pooka int (*puffs_readlink)(struct puffs_usermount *,
130 1.1 pooka void *, const struct puffs_cred *, char *, size_t *);
131 1.1 pooka int (*puffs_reclaim)(struct puffs_usermount *,
132 1.1 pooka void *, pid_t);
133 1.2 pooka int (*puffs_inactive)(struct puffs_usermount *,
134 1.2 pooka void *, pid_t, int *);
135 1.1 pooka int (*puffs_print)(struct puffs_usermount *,
136 1.1 pooka void *);
137 1.1 pooka int (*puffs_pathconf)(struct puffs_usermount *,
138 1.1 pooka void *, int, int *);
139 1.1 pooka int (*puffs_advlock)(struct puffs_usermount *,
140 1.1 pooka void *, void *, int, struct flock *, int);
141 1.1 pooka int (*puffs_getpages)(struct puffs_usermount *,
142 1.1 pooka void *, struct puffs_vnreq_getpages *);
143 1.1 pooka int (*puffs_putpages)(struct puffs_usermount *,
144 1.1 pooka void *, struct puffs_vnreq_putpages *);
145 1.1 pooka int (*puffs_getextattr)(struct puffs_usermount *,
146 1.1 pooka void *, struct puffs_vnreq_getextattr *);
147 1.1 pooka int (*puffs_setextattr)(struct puffs_usermount *,
148 1.1 pooka void *, struct puffs_vnreq_setextattr *);
149 1.1 pooka int (*puffs_listextattr)(struct puffs_usermount *,
150 1.1 pooka void *, struct puffs_vnreq_listextattr *);
151 1.1 pooka int (*puffs_read)(struct puffs_usermount *, void *,
152 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
153 1.1 pooka int (*puffs_write)(struct puffs_usermount *, void *,
154 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
155 1.1 pooka
156 1.1 pooka int (*puffs_ioctl1)(struct puffs_usermount *, void *,
157 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
158 1.1 pooka int (*puffs_ioctl2)(struct puffs_usermount *, void *,
159 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
160 1.1 pooka int (*puffs_fcntl1)(struct puffs_usermount *, void *,
161 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
162 1.1 pooka int (*puffs_fcntl2)(struct puffs_usermount *, void *,
163 1.1 pooka struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
164 1.1 pooka };
165 1.1 pooka
166 1.1 pooka struct puffs_usermount {
167 1.1 pooka struct puffs_vfsops pu_pvfs;
168 1.1 pooka struct puffs_vnops pu_pvn;
169 1.1 pooka
170 1.1 pooka int pu_fd;
171 1.1 pooka uint32_t pu_flags;
172 1.1 pooka size_t pu_maxreqlen;
173 1.1 pooka
174 1.1 pooka struct puffs_node *pu_rootnode;
175 1.1 pooka const char * pu_rootpath;
176 1.1 pooka LIST_HEAD(, puffs_node) pu_pnodelst;
177 1.1 pooka
178 1.1 pooka int pu_wcnt;
179 1.1 pooka void *pu_privdata;
180 1.1 pooka };
181 1.1 pooka
182 1.1 pooka #define PUFFSFLAG_OPDUMP 0x01 /* dump all operations */
183 1.1 pooka
184 1.1 pooka struct puffs_usermount *puffs_mount(struct puffs_vfsops *, struct puffs_vnops *,
185 1.1 pooka const char *, int, const char *,
186 1.1 pooka uint32_t, size_t);
187 1.1 pooka int puffs_mainloop(struct puffs_usermount *);
188 1.1 pooka int puffs_oneop(struct puffs_usermount *, uint8_t *, size_t);
189 1.1 pooka int puffs_getselectable(struct puffs_usermount *);
190 1.1 pooka int puffs_setblockingmode(struct puffs_usermount *, int);
191 1.1 pooka void puffs_dummyops(struct puffs_vnops *);
192 1.1 pooka
193 1.1 pooka struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *,
194 1.1 pooka enum vtype);
195 1.1 pooka void puffs_putpnode(struct puffs_node *);
196 1.1 pooka void puffs_setvattr(struct vattr *, const struct vattr *);
197 1.1 pooka
198 1.1 pooka #define DENT_DOT 0
199 1.1 pooka #define DENT_DOTDOT 1
200 1.1 pooka #define DENT_ADJ(a) ((a)-2) /* nth request means dir's n-2th */
201 1.1 pooka int puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
202 1.1 pooka int puffs_nextdent(struct dirent **, const char *, ino_t,
203 1.1 pooka uint8_t, size_t *);
204 1.1 pooka int puffs_vtype2dt(enum vtype);
205 1.1 pooka
206 1.1 pooka
207 1.1 pooka /*
208 1.1 pooka * Operation credentials
209 1.1 pooka */
210 1.1 pooka
211 1.1 pooka /* Credential fetch */
212 1.1 pooka int puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
213 1.1 pooka int puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
214 1.1 pooka int puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
215 1.1 pooka
216 1.1 pooka /* Credential check */
217 1.1 pooka int puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
218 1.1 pooka int puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
219 1.1 pooka /* kernel internal NOCRED */
220 1.1 pooka int puffs_cred_iskernel(const struct puffs_cred *pcr);
221 1.1 pooka /* kernel internal FSCRED */
222 1.1 pooka int puffs_cred_isfs(const struct puffs_cred *pcr);
223 1.1 pooka /* root || NOCRED || FSCRED */
224 1.1 pooka int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
225 1.1 pooka
226 1.1 pooka
227 1.1 pooka #define PUFFSVFS_PROTOS(fsname) \
228 1.1 pooka int fsname##_start(struct puffs_usermount *, \
229 1.1 pooka struct puffs_vfsreq_start *); \
230 1.1 pooka int fsname##_unmount(struct puffs_usermount *, int, pid_t); \
231 1.1 pooka int fsname##_statvfs(struct puffs_usermount *, \
232 1.1 pooka struct statvfs *, pid_t); \
233 1.1 pooka int fsname##_sync(struct puffs_usermount *, int, \
234 1.1 pooka const struct puffs_cred *cred, pid_t);
235 1.1 pooka
236 1.1 pooka #define PUFFSVN_PROTOS(fsname) \
237 1.1 pooka int fsname##_lookup(struct puffs_usermount *, \
238 1.4 pooka void *, void **, enum vtype *, voff_t *, dev_t *, \
239 1.3 pooka const struct puffs_cn *); \
240 1.1 pooka int fsname##_create(struct puffs_usermount *, \
241 1.1 pooka void *, void **, const struct puffs_cn *, \
242 1.1 pooka const struct vattr *); \
243 1.1 pooka int fsname##_mknod(struct puffs_usermount *, \
244 1.1 pooka void *, void **, const struct puffs_cn *, \
245 1.1 pooka const struct vattr *); \
246 1.1 pooka int fsname##_open(struct puffs_usermount *, \
247 1.1 pooka void *, int, const struct puffs_cred *, pid_t); \
248 1.1 pooka int fsname##_close(struct puffs_usermount *, \
249 1.1 pooka void *, int, struct puffs_cred *, pid_t); \
250 1.1 pooka int fsname##_access(struct puffs_usermount *, \
251 1.1 pooka void *, int, struct puffs_cred *, pid_t); \
252 1.1 pooka int fsname##_getattr(struct puffs_usermount *, \
253 1.1 pooka void *, struct vattr *, const struct puffs_cred *, pid_t); \
254 1.1 pooka int fsname##_setattr(struct puffs_usermount *, \
255 1.1 pooka void *, const struct vattr *, const struct puffs_cred *, \
256 1.1 pooka pid_t); \
257 1.1 pooka int fsname##_poll(struct puffs_usermount *, \
258 1.1 pooka void *, struct puffs_vnreq_poll *); \
259 1.1 pooka int fsname##_revoke(struct puffs_usermount *, void *, int); \
260 1.1 pooka int fsname##_mmap(struct puffs_usermount *, \
261 1.1 pooka void *, struct puffs_vnreq_mmap *); \
262 1.1 pooka int fsname##_fsync(struct puffs_usermount *, \
263 1.1 pooka void *, const struct puffs_cred *, int, off_t, off_t, \
264 1.1 pooka pid_t); \
265 1.1 pooka int fsname##_seek(struct puffs_usermount *, \
266 1.1 pooka void *, off_t, off_t, const struct puffs_cred *); \
267 1.1 pooka int fsname##_remove(struct puffs_usermount *, \
268 1.1 pooka void *, void *, const struct puffs_cn *); \
269 1.1 pooka int fsname##_link(struct puffs_usermount *, \
270 1.1 pooka void *, void *, const struct puffs_cn *); \
271 1.1 pooka int fsname##_rename(struct puffs_usermount *, \
272 1.1 pooka void *, void *, const struct puffs_cn *, void *, void *, \
273 1.1 pooka const struct puffs_cn *); \
274 1.1 pooka int fsname##_mkdir(struct puffs_usermount *, \
275 1.1 pooka void *, void **, const struct puffs_cn *, \
276 1.1 pooka const struct vattr *); \
277 1.1 pooka int fsname##_rmdir(struct puffs_usermount *, \
278 1.1 pooka void *, void *, const struct puffs_cn *); \
279 1.1 pooka int fsname##_symlink(struct puffs_usermount *, \
280 1.1 pooka void *, void **, const struct puffs_cn *, \
281 1.1 pooka const struct vattr *, const char *); \
282 1.1 pooka int fsname##_readdir(struct puffs_usermount *, \
283 1.1 pooka void *, struct dirent *, const struct puffs_cred *, \
284 1.1 pooka off_t *, size_t *); \
285 1.1 pooka int fsname##_readlink(struct puffs_usermount *, \
286 1.1 pooka void *, const struct puffs_cred *, char *, size_t *); \
287 1.1 pooka int fsname##_reclaim(struct puffs_usermount *, \
288 1.1 pooka void *, pid_t); \
289 1.2 pooka int fsname##_inactive(struct puffs_usermount *, \
290 1.2 pooka void *, pid_t, int *); \
291 1.1 pooka int fsname##_print(struct puffs_usermount *, \
292 1.1 pooka void *); \
293 1.1 pooka int fsname##_pathconf(struct puffs_usermount *, \
294 1.1 pooka void *, int, int *); \
295 1.1 pooka int fsname##_advlock(struct puffs_usermount *, \
296 1.1 pooka void *, void *, int, struct flock *, int); \
297 1.1 pooka int fsname##_getpages(struct puffs_usermount *, \
298 1.1 pooka void *, struct puffs_vnreq_getpages *); \
299 1.1 pooka int fsname##_putpages(struct puffs_usermount *, \
300 1.1 pooka void *, struct puffs_vnreq_putpages *); \
301 1.1 pooka int fsname##_getextattr(struct puffs_usermount *, \
302 1.1 pooka void *, struct puffs_vnreq_getextattr *); \
303 1.1 pooka int fsname##_setextattr(struct puffs_usermount *, \
304 1.1 pooka void *, struct puffs_vnreq_setextattr *); \
305 1.1 pooka int fsname##_listextattr(struct puffs_usermount *, \
306 1.1 pooka void *, struct puffs_vnreq_listextattr *); \
307 1.1 pooka int fsname##_read(struct puffs_usermount *, void *, \
308 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
309 1.1 pooka int fsname##_write(struct puffs_usermount *, void *, \
310 1.1 pooka uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
311 1.1 pooka
312 1.1 pooka #endif /* _PUFFS_USER_H_ */
313