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