xref: /freebsd/sys/fs/fuse/fuse.h (revision 0957b409)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2007-2009 Google Inc.
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 #include "fuse_kernel.h"
61 
62 #define FUSE_DEFAULT_DAEMON_TIMEOUT                60     /* s */
63 #define FUSE_MIN_DAEMON_TIMEOUT                    0      /* s */
64 #define FUSE_MAX_DAEMON_TIMEOUT                    600    /* s */
65 
66 #ifndef FUSE_FREEBSD_VERSION
67 #define	FUSE_FREEBSD_VERSION	"0.4.4"
68 #endif
69 
70 /* Mapping versions to features */
71 
72 #define FUSE_KERNELABI_GEQ(maj, min)	\
73 (FUSE_KERNEL_VERSION > (maj) || (FUSE_KERNEL_VERSION == (maj) && FUSE_KERNEL_MINOR_VERSION >= (min)))
74 
75 /*
76  * Appearance of new FUSE operations is not always in par with version
77  * numbering... At least, 7.3 is a sufficient condition for having
78  * FUSE_{ACCESS,CREATE}.
79  */
80 #if FUSE_KERNELABI_GEQ(7, 3)
81 #ifndef FUSE_HAS_ACCESS
82 #define FUSE_HAS_ACCESS 1
83 #endif
84 #ifndef FUSE_HAS_CREATE
85 #define FUSE_HAS_CREATE 1
86 #endif
87 #else /* FUSE_KERNELABI_GEQ(7, 3) */
88 #ifndef FUSE_HAS_ACCESS
89 #define FUSE_HAS_ACCESS 0
90 #endif
91 #ifndef FUSE_HAS_CREATE
92 #define FUSE_HAS_CREATE 0
93 #endif
94 #endif
95 
96 #if FUSE_KERNELABI_GEQ(7, 7)
97 #ifndef FUSE_HAS_GETLK
98 #define FUSE_HAS_GETLK 1
99 #endif
100 #ifndef FUSE_HAS_SETLK
101 #define FUSE_HAS_SETLK 1
102 #endif
103 #ifndef FUSE_HAS_SETLKW
104 #define FUSE_HAS_SETLKW 1
105 #endif
106 #ifndef FUSE_HAS_INTERRUPT
107 #define FUSE_HAS_INTERRUPT 1
108 #endif
109 #else /* FUSE_KERNELABI_GEQ(7, 7) */
110 #ifndef FUSE_HAS_GETLK
111 #define FUSE_HAS_GETLK 0
112 #endif
113 #ifndef FUSE_HAS_SETLK
114 #define FUSE_HAS_SETLK 0
115 #endif
116 #ifndef FUSE_HAS_SETLKW
117 #define FUSE_HAS_SETLKW 0
118 #endif
119 #ifndef FUSE_HAS_INTERRUPT
120 #define FUSE_HAS_INTERRUPT 0
121 #endif
122 #endif
123 
124 #if FUSE_KERNELABI_GEQ(7, 8)
125 #ifndef FUSE_HAS_FLUSH_RELEASE
126 #define FUSE_HAS_FLUSH_RELEASE 1
127 /*
128  * "DESTROY" came in the middle of the 7.8 era,
129  * so this is not completely exact...
130  */
131 #ifndef FUSE_HAS_DESTROY
132 #define FUSE_HAS_DESTROY 1
133 #endif
134 #endif
135 #else /* FUSE_KERNELABI_GEQ(7, 8) */
136 #ifndef FUSE_HAS_FLUSH_RELEASE
137 #define FUSE_HAS_FLUSH_RELEASE 0
138 #ifndef FUSE_HAS_DESTROY
139 #define FUSE_HAS_DESTROY 0
140 #endif
141 #endif
142 #endif
143 
144 /* misc */
145 
146 SYSCTL_DECL(_vfs_fuse);
147 
148 /* Fuse locking */
149 
150 extern struct mtx fuse_mtx;
151 #define FUSE_LOCK() fuse_lck_mtx_lock(fuse_mtx)
152 #define FUSE_UNLOCK() fuse_lck_mtx_unlock(fuse_mtx)
153 
154 #define RECTIFY_TDCR(td, cred)			\
155 do {						\
156 	if (! (td))				\
157 		(td) = curthread;		\
158 	if (! (cred))				\
159 		(cred) = (td)->td_ucred;	\
160 } while (0)
161 
162 /* Debug related stuff */
163 
164 #ifndef FUSE_DEBUG_DEVICE
165 #define FUSE_DEBUG_DEVICE               0
166 #endif
167 
168 #ifndef FUSE_DEBUG_FILE
169 #define FUSE_DEBUG_FILE                 0
170 #endif
171 
172 #ifndef FUSE_DEBUG_INTERNAL
173 #define FUSE_DEBUG_INTERNAL             0
174 #endif
175 
176 #ifndef FUSE_DEBUG_IO
177 #define FUSE_DEBUG_IO                   0
178 #endif
179 
180 #ifndef FUSE_DEBUG_IPC
181 #define FUSE_DEBUG_IPC                  0
182 #endif
183 
184 #ifndef FUSE_DEBUG_LOCK
185 #define FUSE_DEBUG_LOCK                 0
186 #endif
187 
188 #ifndef FUSE_DEBUG_VFSOPS
189 #define FUSE_DEBUG_VFSOPS               0
190 #endif
191 
192 #ifndef FUSE_DEBUG_VNOPS
193 #define FUSE_DEBUG_VNOPS                0
194 #endif
195 
196 #ifndef FUSE_TRACE
197 #define FUSE_TRACE                      0
198 #endif
199 
200 #define DEBUGX(cond, fmt, ...) do {					\
201 	if (((cond))) {							\
202 		printf("%s: " fmt, __func__, ## __VA_ARGS__);		\
203 	}								\
204 } while (0)
205 
206 #define fuse_lck_mtx_lock(mtx) do {						\
207 	DEBUGX(FUSE_DEBUG_LOCK, "0:   lock(%s): %s@%d by %d\n",			\
208 	    __STRING(mtx), __func__, __LINE__, curthread->td_proc->p_pid);	\
209 	mtx_lock(&(mtx));							\
210 	DEBUGX(FUSE_DEBUG_LOCK, "1:   lock(%s): %s@%d by %d\n",			\
211 	    __STRING(mtx), __func__, __LINE__, curthread->td_proc->p_pid);	\
212 } while (0)
213 
214 #define fuse_lck_mtx_unlock(mtx) do {						\
215 	DEBUGX(FUSE_DEBUG_LOCK, "0: unlock(%s): %s@%d by %d\n",			\
216 	    __STRING(mtx), __func__, __LINE__, curthread->td_proc->p_pid);	\
217 	mtx_unlock(&(mtx));							\
218 	DEBUGX(FUSE_DEBUG_LOCK, "1: unlock(%s): %s@%d by %d\n",			\
219 	    __STRING(mtx), __func__, __LINE__, curthread->td_proc->p_pid);	\
220 } while (0)
221 
222 void fuse_ipc_init(void);
223 void fuse_ipc_destroy(void);
224 
225 int fuse_device_init(void);
226 void fuse_device_destroy(void);
227