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