/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2007-2009 Google Inc. and Amit Singh4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are8* met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* * Redistributions in binary form must reproduce the above13* copyright notice, this list of conditions and the following disclaimer14* in the documentation and/or other materials provided with the15* distribution.16* * Neither the name of Google Inc. nor the names of its17* contributors may be used to endorse or promote products derived from18* this software without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*32* Copyright (C) 2005 Csaba Henk.33* All rights reserved.34*35* Copyright (c) 2019 The FreeBSD Foundation36*37* Portions of this software were developed by BFF Storage Systems, LLC under38* sponsorship from the FreeBSD Foundation.39*40* Redistribution and use in source and binary forms, with or without41* modification, are permitted provided that the following conditions42* are met:43* 1. Redistributions of source code must retain the above copyright44* notice, this list of conditions and the following disclaimer.45* 2. Redistributions in binary form must reproduce the above copyright46* notice, this list of conditions and the following disclaimer in the47* documentation and/or other materials provided with the distribution.48*49* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND50* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE51* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE52* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE53* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL54* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS55* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)56* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT57* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY58* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF59* SUCH DAMAGE.60*/6162#ifndef _FUSE_NODE_H_63#define _FUSE_NODE_H_6465#include <sys/fnv_hash.h>66#include <sys/types.h>67#include <sys/mutex.h>68#include <sys/buf.h>6970#include "fuse_file.h"7172#define FN_REVOKED 0x0000002073#define FN_FLUSHINPROG 0x0000004074#define FN_FLUSHWANT 0x0000008075/*76* Indicates that the file's size is dirty; the kernel has changed it but not77* yet send the change to the daemon. When this bit is set, the78* cache_attrs.va_size field does not time out.79*/80#define FN_SIZECHANGE 0x0000010081#define FN_DIRECTIO 0x0000020082/* Indicates that parent_nid is valid */83#define FN_PARENT_NID 0x000004008485/*86* Indicates that the file's cached timestamps are dirty. They will be flushed87* during the next SETATTR or WRITE. Until then, the cached fields will not88* time out.89*/90#define FN_MTIMECHANGE 0x0000080091#define FN_CTIMECHANGE 0x0000100092#define FN_ATIMECHANGE 0x000020009394struct fuse_vnode_data {95/** self **/96uint64_t nid;97uint64_t generation;9899/** parent **/100uint64_t parent_nid;101102/** I/O **/103/* List of file handles for all of the vnode's open file descriptors */104LIST_HEAD(, fuse_filehandle) handles;105106/** flags **/107uint32_t flag;108109/** meta **/110/* The monotonic time after which the attr cache is invalid */111struct bintime attr_cache_timeout;112/*113* Monotonic time after which the entry is invalid. Used for lookups114* by nodeid instead of pathname.115*/116struct bintime entry_cache_timeout;117/*118* Monotonic time of the last FUSE operation that modified the file119* size. Used to avoid races between mutator ops like VOP_SETATTR and120* unlocked accessor ops like VOP_LOOKUP.121*/122struct timespec last_local_modify;123struct vattr cached_attrs;124uint64_t nlookup;125__enum_uint8(vtype) vtype;126struct vn_clusterw clusterw;127};128129/*130* This overlays the fid structure (see mount.h). Mostly the same as the types131* used by UFS and ext2.132*/133struct fuse_fid {134uint16_t len; /* Length of structure. */135uint16_t pad; /* Force 32-bit alignment. */136uint32_t gen; /* Generation number. */137uint64_t nid; /* FUSE node id. */138};139140#define VTOFUD(vp) \141((struct fuse_vnode_data *)((vp)->v_data))142#define VTOI(vp) (VTOFUD(vp)->nid)143static inline bool144fuse_vnode_attr_cache_valid(struct vnode *vp)145{146struct bintime now;147148getbinuptime(&now);149return (bintime_cmp(&(VTOFUD(vp)->attr_cache_timeout), &now, >));150}151152static inline struct vattr*153VTOVA(struct vnode *vp)154{155if (fuse_vnode_attr_cache_valid(vp))156return &(VTOFUD(vp)->cached_attrs);157else158return NULL;159}160161static inline void162fuse_vnode_clear_attr_cache(struct vnode *vp)163{164bintime_clear(&VTOFUD(vp)->attr_cache_timeout);165}166167static uint32_t inline168fuse_vnode_hash(uint64_t id)169{170return (fnv_32_buf(&id, sizeof(id), FNV1_32_INIT));171}172173#define VTOILLU(vp) ((uint64_t)(VTOFUD(vp) ? VTOI(vp) : 0))174175#define FUSE_NULL_ID 0176177extern struct vop_vector fuse_fifoops;178extern struct vop_vector fuse_vnops;179180int fuse_vnode_cmp(struct vnode *vp, void *nidp);181182static inline void183fuse_vnode_setparent(struct vnode *vp, struct vnode *dvp)184{185if (dvp != NULL && vp->v_type == VDIR) {186MPASS(dvp->v_type == VDIR);187VTOFUD(vp)->parent_nid = VTOI(dvp);188VTOFUD(vp)->flag |= FN_PARENT_NID;189} else {190VTOFUD(vp)->flag &= ~FN_PARENT_NID;191}192}193194int fuse_vnode_size(struct vnode *vp, off_t *filesize, struct ucred *cred,195struct thread *td);196197void fuse_vnode_destroy(struct vnode *vp);198199int fuse_vnode_get(struct mount *mp, struct fuse_entry_out *feo,200uint64_t nodeid, struct vnode *dvp, struct vnode **vpp,201struct componentname *cnp, __enum_uint8(vtype) vtyp);202203void fuse_vnode_open(struct vnode *vp, int32_t fuse_open_flags,204struct thread *td);205206int fuse_vnode_savesize(struct vnode *vp, struct ucred *cred, pid_t pid);207208int fuse_vnode_setsize(struct vnode *vp, off_t newsize, bool from_server);209210void fuse_vnode_undirty_cached_timestamps(struct vnode *vp, bool atime);211212void fuse_vnode_update(struct vnode *vp, int flags);213214void fuse_node_init(void);215void fuse_node_destroy(void);216#endif /* _FUSE_NODE_H_ */217218219