2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2007-2009 Google Inc. and Amit Singh
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (C) 2005 Csaba Henk.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 #ifndef _FUSE_INTERNAL_H_
61 #define _FUSE_INTERNAL_H_
63 #include <sys/types.h>
66 #include <sys/vnode.h>
69 #include "fuse_node.h"
72 vfs_isrdonly(struct mount *mp)
74 return ((mp->mnt_flag & MNT_RDONLY) != 0 ? 1 : 0);
77 static __inline struct mount *
78 vnode_mount(struct vnode *vp)
84 vnode_mountedhere(struct vnode *vp)
86 return (vp->v_mountedhere != NULL ? 1 : 0);
89 static __inline enum vtype
90 vnode_vtype(struct vnode *vp)
96 vnode_isvroot(struct vnode *vp)
98 return ((vp->v_vflag & VV_ROOT) != 0 ? 1 : 0);
102 vnode_isreg(struct vnode *vp)
104 return (vp->v_type == VREG ? 1 : 0);
108 vnode_isdir(struct vnode *vp)
110 return (vp->v_type == VDIR ? 1 : 0);
114 vnode_islnk(struct vnode *vp)
116 return (vp->v_type == VLNK ? 1 : 0);
119 static __inline ssize_t
120 uio_resid(struct uio *uio)
122 return (uio->uio_resid);
125 static __inline off_t
126 uio_offset(struct uio *uio)
128 return (uio->uio_offset);
132 uio_setoffset(struct uio *uio, off_t offset)
134 uio->uio_offset = offset;
138 uio_setresid(struct uio *uio, ssize_t resid)
140 uio->uio_resid = resid;
147 fuse_isdeadfs(struct vnode *vp)
149 struct fuse_data *data = fuse_get_mpdata(vnode_mount(vp));
151 return (data->dataflags & FSESS_DEAD);
156 fuse_iosize(struct vnode *vp)
158 return vp->v_mount->mnt_stat.f_iosize;
163 #define FVP_ACCESS_NOOP 0x01
165 #define FACCESS_VA_VALID 0x01
166 #define FACCESS_DO_ACCESS 0x02
167 #define FACCESS_STICKY 0x04
168 #define FACCESS_CHOWN 0x08
169 #define FACCESS_NOCHECKSPY 0x10
170 #define FACCESS_SETGID 0x12
172 #define FACCESS_XQUERIES FACCESS_STICKY | FACCESS_CHOWN | FACCESS_SETGID
174 struct fuse_access_param {
181 fuse_match_cred(struct ucred *basecred, struct ucred *usercred)
183 if (basecred->cr_uid == usercred->cr_uid &&
184 basecred->cr_uid == usercred->cr_ruid &&
185 basecred->cr_uid == usercred->cr_svuid &&
186 basecred->cr_groups[0] == usercred->cr_groups[0] &&
187 basecred->cr_groups[0] == usercred->cr_rgid &&
188 basecred->cr_groups[0] == usercred->cr_svgid)
195 fuse_internal_access(struct vnode *vp,
197 struct fuse_access_param *facp,
205 fuse_internal_attr_fat2vat(struct mount *mp,
206 struct fuse_attr *fat,
209 DEBUGX(FUSE_DEBUG_INTERNAL,
210 "node #%ju, mode 0%o\n", (uintmax_t)fat->ino, fat->mode);
214 vap->va_fsid = mp->mnt_stat.f_fsid.val[0];
215 vap->va_fileid = fat->ino;
216 vap->va_mode = fat->mode & ~S_IFMT;
217 vap->va_nlink = fat->nlink;
218 vap->va_uid = fat->uid;
219 vap->va_gid = fat->gid;
220 vap->va_rdev = fat->rdev;
221 vap->va_size = fat->size;
222 vap->va_atime.tv_sec = fat->atime; /* XXX on some platforms cast from 64 bits to 32 */
223 vap->va_atime.tv_nsec = fat->atimensec;
224 vap->va_mtime.tv_sec = fat->mtime;
225 vap->va_mtime.tv_nsec = fat->mtimensec;
226 vap->va_ctime.tv_sec = fat->ctime;
227 vap->va_ctime.tv_nsec = fat->ctimensec;
228 vap->va_blocksize = PAGE_SIZE;
229 vap->va_type = IFTOVT(fat->mode);
231 #if (S_BLKSIZE == 512)
232 /* Optimize this case */
233 vap->va_bytes = fat->blocks << 9;
235 vap->va_bytes = fat->blocks * S_BLKSIZE;
242 #define cache_attrs(vp, fuse_out) \
243 fuse_internal_attr_fat2vat(vnode_mount(vp), &(fuse_out)->attr, \
249 fuse_internal_fsync(struct vnode *vp,
252 struct fuse_filehandle *fufh);
255 fuse_internal_fsync_callback(struct fuse_ticket *tick, struct uio *uio);
259 struct pseudo_dirent {
264 fuse_internal_readdir(struct vnode *vp,
266 struct fuse_filehandle *fufh,
267 struct fuse_iov *cookediov);
270 fuse_internal_readdir_processdata(struct uio *uio,
279 fuse_internal_remove(struct vnode *dvp,
281 struct componentname *cnp,
282 enum fuse_opcode op);
287 fuse_internal_rename(struct vnode *fdvp,
288 struct componentname *fcnp,
290 struct componentname *tcnp);
294 fuse_internal_vnode_disappear(struct vnode *vp);
298 /* entity creation */
302 fuse_internal_checkentry(struct fuse_entry_out *feo, enum vtype vtyp)
304 DEBUGX(FUSE_DEBUG_INTERNAL,
305 "feo=%p, vtype=%d\n", feo, vtyp);
307 if (vtyp != IFTOVT(feo->attr.mode)) {
308 DEBUGX(FUSE_DEBUG_INTERNAL,
309 "EINVAL -- %x != %x\n", vtyp, IFTOVT(feo->attr.mode));
313 if (feo->nodeid == FUSE_NULL_ID) {
314 DEBUGX(FUSE_DEBUG_INTERNAL,
315 "EINVAL -- feo->nodeid is NULL\n");
319 if (feo->nodeid == FUSE_ROOT_ID) {
320 DEBUGX(FUSE_DEBUG_INTERNAL,
321 "EINVAL -- feo->nodeid is FUSE_ROOT_ID\n");
329 fuse_internal_newentry(struct vnode *dvp,
331 struct componentname *cnp,
338 fuse_internal_newentry_makerequest(struct mount *mp,
340 struct componentname *cnp,
344 struct fuse_dispatcher *fdip);
347 fuse_internal_newentry_core(struct vnode *dvp,
349 struct componentname *cnp,
351 struct fuse_dispatcher *fdip);
353 /* entity destruction */
356 fuse_internal_forget_callback(struct fuse_ticket *tick, struct uio *uio);
359 fuse_internal_forget_send(struct mount *mp,
365 /* fuse start/stop */
367 int fuse_internal_init_callback(struct fuse_ticket *tick, struct uio *uio);
368 void fuse_internal_send_init(struct fuse_data *data, struct thread *td);
370 #endif /* _FUSE_INTERNAL_H_ */