xref: /freebsd/sys/fs/fuse/fuse_node.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 /*
2  * Copyright (c) 2007-2009 Google Inc. and Amit Singh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  *   copyright notice, this list of conditions and the following disclaimer
13  *   in the documentation and/or other materials provided with the
14  *   distribution.
15  * * Neither the name of Google Inc. nor the names of its
16  *   contributors may be used to endorse or promote products derived from
17  *   this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Copyright (C) 2005 Csaba Henk.
32  * All rights reserved.
33  *
34  * Redistribution and use in source and binary forms, with or without
35  * modification, are permitted provided that the following conditions
36  * are met:
37  * 1. Redistributions of source code must retain the above copyright
38  *    notice, this list of conditions and the following disclaimer.
39  * 2. Redistributions in binary form must reproduce the above copyright
40  *    notice, this list of conditions and the following disclaimer in the
41  *    documentation and/or other materials provided with the distribution.
42  *
43  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
47  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  *
55  * $FreeBSD$
56  */
57 
58 #ifndef _FUSE_NODE_H_
59 #define _FUSE_NODE_H_
60 
61 #include <sys/types.h>
62 #include <sys/mutex.h>
63 
64 #include "fuse_file.h"
65 
66 #define FN_REVOKED           0x00000020
67 #define FN_FLUSHINPROG       0x00000040
68 #define FN_FLUSHWANT         0x00000080
69 #define FN_SIZECHANGE        0x00000100
70 #define FN_DIRECTIO          0x00000200
71 
72 struct fuse_vnode_data {
73     /** self **/
74     uint64_t   nid;
75 
76     /** parent **/
77     /* XXXIP very likely to be stale, it's not updated in rename() */
78     uint64_t   parent_nid;
79 
80     /** I/O **/
81     struct     fuse_filehandle fufh[FUFH_MAXTYPE];
82 
83     /** flags **/
84     uint32_t   flag;
85 
86     /** meta **/
87     struct vattr      cached_attrs;
88     off_t             filesize;
89     uint64_t          nlookup;
90     enum vtype        vtype;
91 };
92 
93 #define VTOFUD(vp) \
94     ((struct fuse_vnode_data *)((vp)->v_data))
95 #define VTOI(vp)    (VTOFUD(vp)->nid)
96 #define VTOVA(vp)   (&(VTOFUD(vp)->cached_attrs))
97 #define VTOILLU(vp) ((uint64_t)(VTOFUD(vp) ? VTOI(vp) : 0))
98 
99 #define FUSE_NULL_ID 0
100 
101 extern struct vop_vector fuse_vnops;
102 
103 static __inline void
104 fuse_vnode_setparent(struct vnode *vp, struct vnode *dvp)
105 {
106     if (dvp != NULL && vp->v_type == VDIR) {
107         MPASS(dvp->v_type == VDIR);
108         VTOFUD(vp)->parent_nid = VTOI(dvp);
109     }
110 }
111 
112 void fuse_vnode_destroy(struct vnode *vp);
113 
114 int fuse_vnode_get(struct mount         *mp,
115                    uint64_t              nodeid,
116                    struct vnode         *dvp,
117                    struct vnode        **vpp,
118                    struct componentname *cnp,
119                    enum vtype            vtyp);
120 
121 void fuse_vnode_open(struct vnode *vp,
122                      int32_t fuse_open_flags,
123                      struct thread *td);
124 
125 void fuse_vnode_refreshsize(struct vnode *vp, struct ucred *cred);
126 
127 int fuse_vnode_savesize(struct vnode *vp, struct ucred *cred);
128 
129 int fuse_vnode_setsize(struct vnode *vp, struct ucred *cred, off_t newsize);
130 
131 #endif /* _FUSE_NODE_H_ */
132