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 7 26 27 #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min)) 28 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION) 29 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 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * Information about open files 41 * 42 * Changed in version 2.5 43 */ 44 struct fuse_file_info { 45 /** Open flags. Available in open() and release() */ 46 int flags; 47 48 /** Old file handle, don't use */ 49 unsigned long fh_old; 50 51 /** In case of a write operation indicates if this was caused by a 52 writepage */ 53 int writepage; 54 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; 58 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; 62 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; 67 68 /** Padding. Do not use*/ 69 unsigned int padding : 29; 70 71 /** File handle. May be filled in by filesystem in open(). 72 Available in all other file operations */ 73 uint64_t fh; 74 75 /** Lock owner id. Available in locking operations and flush */ 76 uint64_t lock_owner; 77 }; 78 79 /** 80 * Connection information, passed to the ->init() method 81 * 82 * Some of the elements are read-write, these can be changed to 83 * indicate the value requested by the filesystem. The requested 84 * value must usually be smaller than the indicated value. 85 */ 86 struct fuse_conn_info { 87 /** 88 * Major version of the protocol (read-only) 89 */ 90 unsigned proto_major; 91 92 /** 93 * Minor version of the protocol (read-only) 94 */ 95 unsigned proto_minor; 96 97 /** 98 * Is asynchronous read supported (read-write) 99 */ 100 unsigned async_read; 101 102 /** 103 * Maximum size of the write buffer 104 */ 105 unsigned max_write; 106 107 /** 108 * Maximum readahead 109 */ 110 unsigned max_readahead; 111 112 /** 113 * For future use. 114 */ 115 unsigned reserved[27]; 116 }; 117 118 struct fuse_session; 119 struct fuse_chan; 120 121 /** 122 * Create a FUSE mountpoint 123 * 124 * Returns a control file descriptor suitable for passing to 125 * fuse_new() 126 * 127 * @param mountpoint the mount point path 128 * @param args argument vector 129 * @return the communication channel on success, NULL on failure 130 */ 131 struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args); 132 133 /** 134 * Umount a FUSE mountpoint 135 * 136 * @param mountpoint the mount point path 137 * @param ch the communication channel 138 */ 139 void fuse_unmount(const char *mountpoint, struct fuse_chan *ch); 140 141 /** 142 * Parse common options 143 * 144 * The following options are parsed: 145 * 146 * '-f' foreground 147 * '-d' '-odebug' foreground, but keep the debug option 148 * '-s' single threaded 149 * '-h' '--help' help 150 * '-ho' help without header 151 * '-ofsname=..' file system name, if not present, then set to the program 152 * name 153 * 154 * All parameters may be NULL 155 * 156 * @param args argument vector 157 * @param mountpoint the returned mountpoint, should be freed after use 158 * @param multithreaded set to 1 unless the '-s' option is present 159 * @param foreground set to 1 if one of the relevant options is present 160 * @return 0 on success, -1 on failure 161 */ 162 int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint, 163 int *multithreaded, int *foreground); 164 165 /** 166 * Go into the background 167 * 168 * @param foreground if true, stay in the foreground 169 * @return 0 on success, -1 on failure 170 */ 171 int fuse_daemonize(int foreground); 172 173 /** 174 * Get the version of the library 175 * 176 * @return the version 177 */ 178 int fuse_version(void); 179 180 /* ----------------------------------------------------------- * 181 * Signal handling * 182 * ----------------------------------------------------------- */ 183 184 /** 185 * Exit session on HUP, TERM and INT signals and ignore PIPE signal 186 * 187 * Stores session in a global variable. May only be called once per 188 * process until fuse_remove_signal_handlers() is called. 189 * 190 * @param se the session to exit 191 * @return 0 on success, -1 on failure 192 */ 193 int fuse_set_signal_handlers(struct fuse_session *se); 194 195 /** 196 * Restore default signal handlers 197 * 198 * Resets global session. After this fuse_set_signal_handlers() may 199 * be called again. 200 * 201 * @param se the same session as given in fuse_set_signal_handlers() 202 */ 203 void fuse_remove_signal_handlers(struct fuse_session *se); 204 205 /* ----------------------------------------------------------- * 206 * Compatibility stuff * 207 * ----------------------------------------------------------- */ 208 209 #if FUSE_USE_VERSION < 26 210 # if defined(__FreeBSD__) || defined(__HAIKU__) 211 # if FUSE_USE_VERSION < 25 212 # error On FreeBSD and Haiku API version 25 or greater must be used 213 # endif 214 # endif 215 # include "fuse_common_compat.h" 216 # undef FUSE_MINOR_VERSION 217 # undef fuse_main 218 # define fuse_unmount fuse_unmount_compat22 219 # if FUSE_USE_VERSION == 25 220 # define FUSE_MINOR_VERSION 5 221 # define fuse_mount fuse_mount_compat25 222 # elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22 223 # define FUSE_MINOR_VERSION 4 224 # define fuse_mount fuse_mount_compat22 225 # elif FUSE_USE_VERSION == 21 226 # define FUSE_MINOR_VERSION 1 227 # define fuse_mount fuse_mount_compat22 228 # elif FUSE_USE_VERSION == 11 229 # warning Compatibility with API version 11 is deprecated 230 # undef FUSE_MAJOR_VERSION 231 # define FUSE_MAJOR_VERSION 1 232 # define FUSE_MINOR_VERSION 1 233 # define fuse_mount fuse_mount_compat1 234 # else 235 # error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported 236 # endif 237 #endif 238 239 #ifdef __cplusplus 240 } 241 #endif 242 243 #endif /* _FUSE_COMMON_H_ */ 244