]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/fuse/fuse_node.h
fusefs: eliminate superfluous FUSE_GETATTR when filesize=0
[FreeBSD/FreeBSD.git] / sys / fs / fuse / fuse_node.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2007-2009 Google Inc. and Amit Singh
5  * All rights reserved.
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  * 
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
16  *   distribution.
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.
20  * 
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.
32  * 
33  * Copyright (C) 2005 Csaba Henk.
34  * All rights reserved.
35  * 
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
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.
44  * 
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
55  * SUCH DAMAGE.
56  *
57  * $FreeBSD$
58  */
59
60 #ifndef _FUSE_NODE_H_
61 #define _FUSE_NODE_H_
62
63 #include <sys/types.h>
64 #include <sys/mutex.h>
65
66 #include "fuse_file.h"
67
68 #define FN_REVOKED           0x00000020
69 #define FN_FLUSHINPROG       0x00000040
70 #define FN_FLUSHWANT         0x00000080
71 #define FN_SIZECHANGE        0x00000100
72 #define FN_DIRECTIO          0x00000200
73
74 #define FUSE_FILESIZE_UNINITIALIZED     -1
75
76 struct fuse_vnode_data {
77         /** self **/
78         uint64_t        nid;
79
80         /** parent **/
81         uint64_t        parent_nid;
82
83         /** I/O **/
84         /* List of file handles for all of the vnode's open file descriptors */
85         LIST_HEAD(, fuse_filehandle)    handles;
86
87         /** flags **/
88         uint32_t        flag;
89
90         /** meta **/
91         /* The monotonic time after which the attr cache is invalid */
92         struct bintime  attr_cache_timeout;
93         struct vattr    cached_attrs;
94         /*
95          * File size according to the kernel, not the daemon.
96          * May differ from cached_attrs.st_size due to write caching.  Unlike
97          * cached_attrs.st_size, filesize never expires.
98          */
99         off_t           filesize;
100         uint64_t        nlookup;
101         enum vtype      vtype;
102 };
103
104 #define VTOFUD(vp) \
105         ((struct fuse_vnode_data *)((vp)->v_data))
106 #define VTOI(vp)    (VTOFUD(vp)->nid)
107 static inline struct vattr*
108 VTOVA(struct vnode *vp)
109 {
110         struct bintime now;
111
112         getbinuptime(&now);
113         if (bintime_cmp(&(VTOFUD(vp)->attr_cache_timeout), &now, >))
114                 return &(VTOFUD(vp)->cached_attrs);
115         else
116                 return NULL;
117 }
118
119 static inline void
120 fuse_vnode_clear_attr_cache(struct vnode *vp)
121 {
122         bintime_clear(&VTOFUD(vp)->attr_cache_timeout);
123 }
124
125 #define VTOILLU(vp) ((uint64_t)(VTOFUD(vp) ? VTOI(vp) : 0))
126
127 #define FUSE_NULL_ID 0
128
129 extern struct vop_vector fuse_fifoops;
130 extern struct vop_vector fuse_vnops;
131
132 static inline void
133 fuse_vnode_setparent(struct vnode *vp, struct vnode *dvp)
134 {
135         if (dvp != NULL && vp->v_type == VDIR) {
136                 MPASS(dvp->v_type == VDIR);
137                 VTOFUD(vp)->parent_nid = VTOI(dvp);
138         }
139 }
140
141 void fuse_vnode_destroy(struct vnode *vp);
142
143 int fuse_vnode_get(struct mount *mp, struct fuse_entry_out *feo,
144     uint64_t nodeid, struct vnode *dvp, struct vnode **vpp,
145     struct componentname *cnp, enum vtype vtyp);
146
147 void fuse_vnode_open(struct vnode *vp, int32_t fuse_open_flags,
148     struct thread *td);
149
150 int fuse_vnode_refreshsize(struct vnode *vp, struct ucred *cred);
151
152 int fuse_vnode_savesize(struct vnode *vp, struct ucred *cred, pid_t pid);
153
154 int fuse_vnode_setsize(struct vnode *vp, struct ucred *cred, off_t newsize);
155
156 #endif /* _FUSE_NODE_H_ */