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