* Fix stack alignment for clone()
[fuse.git] / include / fuse_common.h
blobc263f6f1fba1fda933ff83f330a8e19df33c1702
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB.
7 */
9 /** @file */
11 #if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_)
12 #error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
13 #endif
15 #ifndef _FUSE_COMMON_H_
16 #define _FUSE_COMMON_H_
18 #include "fuse_opt.h"
19 #include <stdint.h>
21 /** Major version of FUSE library interface */
22 #define FUSE_MAJOR_VERSION 2
24 /** Minor version of FUSE library interface */
25 #define FUSE_MINOR_VERSION 8
27 #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
28 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
30 /* This interface uses 64 bit off_t */
31 #if _FILE_OFFSET_BITS != 64
32 #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
33 #endif
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 /**
40 * Information about open files
42 * Changed in version 2.5
44 struct fuse_file_info {
45 /** Open flags. Available in open() and release() */
46 int flags;
48 /** Old file handle, don't use */
49 unsigned long fh_old;
51 /** In case of a write operation indicates if this was caused by a
52 writepage */
53 int writepage;
55 /** Can be filled in by open, to use direct I/O on this file.
56 Introduced in version 2.4 */
57 unsigned int direct_io : 1;
59 /** Can be filled in by open, to indicate, that cached file data
60 need not be invalidated. Introduced in version 2.4 */
61 unsigned int keep_cache : 1;
63 /** Indicates a flush operation. Set in flush operation, also
64 maybe set in highlevel lock operation and lowlevel release
65 operation. Introduced in version 2.6 */
66 unsigned int flush : 1;
68 /** Can be filled in by open, to indicate that the file is not
69 seekable. Introduced in version 2.8 */
70 unsigned int nonseekable : 1;
72 /** Padding. Do not use*/
73 unsigned int padding : 28;
75 /** File handle. May be filled in by filesystem in open().
76 Available in all other file operations */
77 uint64_t fh;
79 /** Lock owner id. Available in locking operations and flush */
80 uint64_t lock_owner;
83 /**
84 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want'
86 * FUSE_CAP_ASYNC_READ: filesystem supports asynchronous read requests
87 * FUSE_CAP_POSIX_LOCKS: filesystem supports "remote" locking
88 * FUSE_CAP_ATOMIC_O_TRUNC: filesystem handles the O_TRUNC open flag
89 * FUSE_CAP_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
90 * FUSE_CAP_BIG_WRITES: filesystem can handle write size larger than 4kB
91 * FUSE_CAP_DONT_MASK: don't apply umask to file mode on create operations
93 #define FUSE_CAP_ASYNC_READ (1 << 0)
94 #define FUSE_CAP_POSIX_LOCKS (1 << 1)
95 #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
96 #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
97 #define FUSE_CAP_BIG_WRITES (1 << 5)
98 #define FUSE_CAP_DONT_MASK (1 << 6)
101 * Ioctl flags
103 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
104 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
105 * FUSE_IOCTL_RETRY: retry with new iovecs
107 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
109 #define FUSE_IOCTL_COMPAT (1 << 0)
110 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
111 #define FUSE_IOCTL_RETRY (1 << 2)
113 #define FUSE_IOCTL_MAX_IOV 256
116 * Connection information, passed to the ->init() method
118 * Some of the elements are read-write, these can be changed to
119 * indicate the value requested by the filesystem. The requested
120 * value must usually be smaller than the indicated value.
122 struct fuse_conn_info {
124 * Major version of the protocol (read-only)
126 unsigned proto_major;
129 * Minor version of the protocol (read-only)
131 unsigned proto_minor;
134 * Is asynchronous read supported (read-write)
136 unsigned async_read;
139 * Maximum size of the write buffer
141 unsigned max_write;
144 * Maximum readahead
146 unsigned max_readahead;
149 * Capability flags, that the kernel supports
151 unsigned capable;
154 * Capability flags, that the filesystem wants to enable
156 unsigned want;
159 * For future use.
161 unsigned reserved[25];
164 struct fuse_session;
165 struct fuse_chan;
166 struct fuse_pollhandle;
169 * Create a FUSE mountpoint
171 * Returns a control file descriptor suitable for passing to
172 * fuse_new()
174 * @param mountpoint the mount point path
175 * @param args argument vector
176 * @return the communication channel on success, NULL on failure
178 struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args);
181 * Umount a FUSE mountpoint
183 * @param mountpoint the mount point path
184 * @param ch the communication channel
186 void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
189 * Parse common options
191 * The following options are parsed:
193 * '-f' foreground
194 * '-d' '-odebug' foreground, but keep the debug option
195 * '-s' single threaded
196 * '-h' '--help' help
197 * '-ho' help without header
198 * '-ofsname=..' file system name, if not present, then set to the program
199 * name
201 * All parameters may be NULL
203 * @param args argument vector
204 * @param mountpoint the returned mountpoint, should be freed after use
205 * @param multithreaded set to 1 unless the '-s' option is present
206 * @param foreground set to 1 if one of the relevant options is present
207 * @return 0 on success, -1 on failure
209 int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
210 int *multithreaded, int *foreground);
213 * Go into the background
215 * @param foreground if true, stay in the foreground
216 * @return 0 on success, -1 on failure
218 int fuse_daemonize(int foreground);
221 * Get the version of the library
223 * @return the version
225 int fuse_version(void);
228 * Destroy poll handle
230 * @param ph the poll handle
232 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
234 /* ----------------------------------------------------------- *
235 * Signal handling *
236 * ----------------------------------------------------------- */
239 * Exit session on HUP, TERM and INT signals and ignore PIPE signal
241 * Stores session in a global variable. May only be called once per
242 * process until fuse_remove_signal_handlers() is called.
244 * @param se the session to exit
245 * @return 0 on success, -1 on failure
247 int fuse_set_signal_handlers(struct fuse_session *se);
250 * Restore default signal handlers
252 * Resets global session. After this fuse_set_signal_handlers() may
253 * be called again.
255 * @param se the same session as given in fuse_set_signal_handlers()
257 void fuse_remove_signal_handlers(struct fuse_session *se);
259 /* ----------------------------------------------------------- *
260 * Compatibility stuff *
261 * ----------------------------------------------------------- */
263 #if FUSE_USE_VERSION < 26
264 # ifdef __FreeBSD__
265 # if FUSE_USE_VERSION < 25
266 # error On FreeBSD API version 25 or greater must be used
267 # endif
268 # endif
269 # include "fuse_common_compat.h"
270 # undef FUSE_MINOR_VERSION
271 # undef fuse_main
272 # define fuse_unmount fuse_unmount_compat22
273 # if FUSE_USE_VERSION == 25
274 # define FUSE_MINOR_VERSION 5
275 # define fuse_mount fuse_mount_compat25
276 # elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
277 # define FUSE_MINOR_VERSION 4
278 # define fuse_mount fuse_mount_compat22
279 # elif FUSE_USE_VERSION == 21
280 # define FUSE_MINOR_VERSION 1
281 # define fuse_mount fuse_mount_compat22
282 # elif FUSE_USE_VERSION == 11
283 # warning Compatibility with API version 11 is deprecated
284 # undef FUSE_MAJOR_VERSION
285 # define FUSE_MAJOR_VERSION 1
286 # define FUSE_MINOR_VERSION 1
287 # define fuse_mount fuse_mount_compat1
288 # else
289 # error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
290 # endif
291 #endif
293 #ifdef __cplusplus
295 #endif
297 #endif /* _FUSE_COMMON_H_ */