Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/fuse.h> |
| 10 | #include <linux/fs.h> |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 11 | #include <linux/mount.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 12 | #include <linux/wait.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/backing-dev.h> |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 18 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 19 | /** Max number of pages that can be used in a single read request */ |
| 20 | #define FUSE_MAX_PAGES_PER_REQ 32 |
| 21 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 22 | /** Maximum number of outstanding background requests */ |
Miklos Szeredi | f92b99b | 2007-10-16 23:30:59 -0700 | [diff] [blame] | 23 | #define FUSE_MAX_BACKGROUND 12 |
| 24 | |
| 25 | /** Congestion starts at 75% of maximum */ |
| 26 | #define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100) |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 27 | |
Miklos Szeredi | 1d3d752 | 2006-01-06 00:19:40 -0800 | [diff] [blame] | 28 | /** It could be as large as PATH_MAX, but would that have any uses? */ |
| 29 | #define FUSE_NAME_MAX 1024 |
| 30 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 31 | /** Number of dentries for each connection in the control filesystem */ |
| 32 | #define FUSE_CTL_NUM_DENTRIES 3 |
| 33 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 34 | /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem |
| 35 | module will check permissions based on the file mode. Otherwise no |
| 36 | permission checking is done in the kernel */ |
| 37 | #define FUSE_DEFAULT_PERMISSIONS (1 << 0) |
| 38 | |
| 39 | /** If the FUSE_ALLOW_OTHER flag is given, then not only the user |
| 40 | doing the mount will be allowed to access the filesystem */ |
| 41 | #define FUSE_ALLOW_OTHER (1 << 1) |
| 42 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 43 | /** List of active connections */ |
| 44 | extern struct list_head fuse_conn_list; |
| 45 | |
| 46 | /** Global mutex protecting fuse_conn_list and the control filesystem */ |
| 47 | extern struct mutex fuse_mutex; |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 48 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 49 | /** FUSE inode */ |
| 50 | struct fuse_inode { |
| 51 | /** Inode data */ |
| 52 | struct inode inode; |
| 53 | |
| 54 | /** Unique ID, which identifies the inode between userspace |
| 55 | * and kernel */ |
| 56 | u64 nodeid; |
| 57 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 58 | /** Number of lookups on this inode */ |
| 59 | u64 nlookup; |
| 60 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 61 | /** The request used for sending the FORGET message */ |
| 62 | struct fuse_req *forget_req; |
| 63 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 64 | /** Time in jiffies until the file attributes are valid */ |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 65 | u64 i_time; |
Miklos Szeredi | ebc14c4 | 2007-10-16 23:31:03 -0700 | [diff] [blame] | 66 | |
| 67 | /** The sticky bit in inode->i_mode may have been removed, so |
| 68 | preserve the original mode */ |
| 69 | mode_t orig_i_mode; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 72 | /** FUSE specific file data */ |
| 73 | struct fuse_file { |
| 74 | /** Request reserved for flush and release */ |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 75 | struct fuse_req *reserved_req; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 76 | |
| 77 | /** File handle used by userspace */ |
| 78 | u64 fh; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 79 | |
| 80 | /** Refcount */ |
| 81 | atomic_t count; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 84 | /** One input argument of a request */ |
| 85 | struct fuse_in_arg { |
| 86 | unsigned size; |
| 87 | const void *value; |
| 88 | }; |
| 89 | |
| 90 | /** The request input */ |
| 91 | struct fuse_in { |
| 92 | /** The request header */ |
| 93 | struct fuse_in_header h; |
| 94 | |
| 95 | /** True if the data for the last argument is in req->pages */ |
| 96 | unsigned argpages:1; |
| 97 | |
| 98 | /** Number of arguments */ |
| 99 | unsigned numargs; |
| 100 | |
| 101 | /** Array of arguments */ |
| 102 | struct fuse_in_arg args[3]; |
| 103 | }; |
| 104 | |
| 105 | /** One output argument of a request */ |
| 106 | struct fuse_arg { |
| 107 | unsigned size; |
| 108 | void *value; |
| 109 | }; |
| 110 | |
| 111 | /** The request output */ |
| 112 | struct fuse_out { |
| 113 | /** Header returned from userspace */ |
| 114 | struct fuse_out_header h; |
| 115 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 116 | /* |
| 117 | * The following bitfields are not changed during the request |
| 118 | * processing |
| 119 | */ |
| 120 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 121 | /** Last argument is variable length (can be shorter than |
| 122 | arg->size) */ |
| 123 | unsigned argvar:1; |
| 124 | |
| 125 | /** Last argument is a list of pages to copy data to */ |
| 126 | unsigned argpages:1; |
| 127 | |
| 128 | /** Zero partially or not copied pages */ |
| 129 | unsigned page_zeroing:1; |
| 130 | |
| 131 | /** Number or arguments */ |
| 132 | unsigned numargs; |
| 133 | |
| 134 | /** Array of arguments */ |
| 135 | struct fuse_arg args[3]; |
| 136 | }; |
| 137 | |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 138 | /** The request state */ |
| 139 | enum fuse_req_state { |
| 140 | FUSE_REQ_INIT = 0, |
| 141 | FUSE_REQ_PENDING, |
| 142 | FUSE_REQ_READING, |
| 143 | FUSE_REQ_SENT, |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 144 | FUSE_REQ_WRITING, |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 145 | FUSE_REQ_FINISHED |
| 146 | }; |
| 147 | |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 148 | struct fuse_conn; |
| 149 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 150 | /** |
| 151 | * A request to the client |
| 152 | */ |
| 153 | struct fuse_req { |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 154 | /** This can be on either pending processing or io lists in |
| 155 | fuse_conn */ |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 156 | struct list_head list; |
| 157 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 158 | /** Entry on the interrupts list */ |
| 159 | struct list_head intr_entry; |
| 160 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 161 | /** refcount */ |
| 162 | atomic_t count; |
| 163 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 164 | /** Unique ID for the interrupt request */ |
| 165 | u64 intr_unique; |
| 166 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 167 | /* |
| 168 | * The following bitfields are either set once before the |
| 169 | * request is queued or setting/clearing them is protected by |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 170 | * fuse_conn->lock |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 171 | */ |
| 172 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 173 | /** True if the request has reply */ |
| 174 | unsigned isreply:1; |
| 175 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 176 | /** Force sending of the request even if interrupted */ |
| 177 | unsigned force:1; |
| 178 | |
Miklos Szeredi | f9a2842 | 2006-06-25 05:48:53 -0700 | [diff] [blame] | 179 | /** The request was aborted */ |
| 180 | unsigned aborted:1; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 181 | |
| 182 | /** Request is sent in the background */ |
| 183 | unsigned background:1; |
| 184 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 185 | /** The request has been interrupted */ |
| 186 | unsigned interrupted:1; |
| 187 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 188 | /** Data is being copied to/from the request */ |
| 189 | unsigned locked:1; |
| 190 | |
Miklos Szeredi | 9bc5ddd | 2006-04-11 21:16:09 +0200 | [diff] [blame] | 191 | /** Request is counted as "waiting" */ |
| 192 | unsigned waiting:1; |
| 193 | |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 194 | /** State of the request */ |
| 195 | enum fuse_req_state state; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 196 | |
| 197 | /** The request input */ |
| 198 | struct fuse_in in; |
| 199 | |
| 200 | /** The request output */ |
| 201 | struct fuse_out out; |
| 202 | |
| 203 | /** Used to wake up the task waiting for completion of request*/ |
| 204 | wait_queue_head_t waitq; |
| 205 | |
| 206 | /** Data for asynchronous requests */ |
| 207 | union { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 208 | struct fuse_forget_in forget_in; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 209 | struct fuse_release_in release_in; |
Miklos Szeredi | 3ec870d | 2006-01-06 00:19:41 -0800 | [diff] [blame] | 210 | struct fuse_init_in init_in; |
| 211 | struct fuse_init_out init_out; |
Miklos Szeredi | 361b1eb | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 212 | struct fuse_read_in read_in; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 213 | struct fuse_lk_in lk_in; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 214 | } misc; |
| 215 | |
| 216 | /** page vector */ |
| 217 | struct page *pages[FUSE_MAX_PAGES_PER_REQ]; |
| 218 | |
| 219 | /** number of pages in vector */ |
| 220 | unsigned num_pages; |
| 221 | |
| 222 | /** offset of data on first page */ |
| 223 | unsigned page_offset; |
| 224 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 225 | /** File used in the request (or NULL) */ |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 226 | struct fuse_file *ff; |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 227 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 228 | /** vfsmount used in release */ |
| 229 | struct vfsmount *vfsmount; |
| 230 | |
| 231 | /** dentry used in release */ |
| 232 | struct dentry *dentry; |
| 233 | |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 234 | /** Request completion callback */ |
| 235 | void (*end)(struct fuse_conn *, struct fuse_req *); |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 236 | |
| 237 | /** Request is stolen from fuse_file->reserved_req */ |
| 238 | struct file *stolen_file; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 241 | /** |
| 242 | * A Fuse connection. |
| 243 | * |
| 244 | * This structure is created, when the filesystem is mounted, and is |
| 245 | * destroyed, when the client device is closed and the filesystem is |
| 246 | * unmounted. |
| 247 | */ |
| 248 | struct fuse_conn { |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 249 | /** Lock protecting accessess to members of this structure */ |
| 250 | spinlock_t lock; |
| 251 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 252 | /** Mutex protecting against directory alias creation */ |
| 253 | struct mutex inst_mutex; |
| 254 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 255 | /** Refcount */ |
| 256 | atomic_t count; |
| 257 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 258 | /** The user id for this mount */ |
| 259 | uid_t user_id; |
| 260 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 261 | /** The group id for this mount */ |
| 262 | gid_t group_id; |
| 263 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 264 | /** The fuse mount flags for this mount */ |
| 265 | unsigned flags; |
| 266 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 267 | /** Maximum read size */ |
| 268 | unsigned max_read; |
| 269 | |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 270 | /** Maximum write size */ |
| 271 | unsigned max_write; |
| 272 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 273 | /** Readers of the connection are waiting on this */ |
| 274 | wait_queue_head_t waitq; |
| 275 | |
| 276 | /** The list of pending requests */ |
| 277 | struct list_head pending; |
| 278 | |
| 279 | /** The list of requests being processed */ |
| 280 | struct list_head processing; |
| 281 | |
Miklos Szeredi | d77a1d5 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 282 | /** The list of requests under I/O */ |
| 283 | struct list_head io; |
| 284 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 285 | /** Number of requests currently in the background */ |
| 286 | unsigned num_background; |
| 287 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 288 | /** Pending interrupts */ |
| 289 | struct list_head interrupts; |
| 290 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 291 | /** Flag indicating if connection is blocked. This will be |
| 292 | the case before the INIT reply is received, and if there |
| 293 | are too many outstading backgrounds requests */ |
| 294 | int blocked; |
| 295 | |
| 296 | /** waitq for blocked connection */ |
| 297 | wait_queue_head_t blocked_waitq; |
| 298 | |
Miklos Szeredi | de5e3de | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 299 | /** waitq for reserved requests */ |
| 300 | wait_queue_head_t reserved_req_waitq; |
| 301 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 302 | /** The next unique request id */ |
| 303 | u64 reqctr; |
| 304 | |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 305 | /** Connection established, cleared on umount, connection |
| 306 | abort and device release */ |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 307 | unsigned connected; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 308 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 309 | /** Connection failed (version mismatch). Cannot race with |
| 310 | setting other bitfields since it is only set once in INIT |
| 311 | reply, before any other request, and never cleared */ |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 312 | unsigned conn_error : 1; |
| 313 | |
Miklos Szeredi | 0ec7ca4 | 2006-12-06 20:35:52 -0800 | [diff] [blame] | 314 | /** Connection successful. Only set in INIT */ |
| 315 | unsigned conn_init : 1; |
| 316 | |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 317 | /** Do readpages asynchronously? Only set in INIT */ |
| 318 | unsigned async_read : 1; |
| 319 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 320 | /* |
| 321 | * The following bitfields are only for optimization purposes |
| 322 | * and hence races in setting them will not cause malfunction |
| 323 | */ |
| 324 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 325 | /** Is fsync not implemented by fs? */ |
| 326 | unsigned no_fsync : 1; |
| 327 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 328 | /** Is fsyncdir not implemented by fs? */ |
| 329 | unsigned no_fsyncdir : 1; |
| 330 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 331 | /** Is flush not implemented by fs? */ |
| 332 | unsigned no_flush : 1; |
| 333 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 334 | /** Is setxattr not implemented by fs? */ |
| 335 | unsigned no_setxattr : 1; |
| 336 | |
| 337 | /** Is getxattr not implemented by fs? */ |
| 338 | unsigned no_getxattr : 1; |
| 339 | |
| 340 | /** Is listxattr not implemented by fs? */ |
| 341 | unsigned no_listxattr : 1; |
| 342 | |
| 343 | /** Is removexattr not implemented by fs? */ |
| 344 | unsigned no_removexattr : 1; |
| 345 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 346 | /** Are file locking primitives not implemented by fs? */ |
| 347 | unsigned no_lock : 1; |
| 348 | |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 349 | /** Is access not implemented by fs? */ |
| 350 | unsigned no_access : 1; |
| 351 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 352 | /** Is create not implemented by fs? */ |
| 353 | unsigned no_create : 1; |
| 354 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 355 | /** Is interrupt not implemented by fs? */ |
| 356 | unsigned no_interrupt : 1; |
| 357 | |
Miklos Szeredi | b2d2272 | 2006-12-06 20:35:51 -0800 | [diff] [blame] | 358 | /** Is bmap not implemented by fs? */ |
| 359 | unsigned no_bmap : 1; |
| 360 | |
Miklos Szeredi | 0cd5b88 | 2006-01-16 22:14:38 -0800 | [diff] [blame] | 361 | /** The number of requests waiting for completion */ |
| 362 | atomic_t num_waiting; |
| 363 | |
Miklos Szeredi | 45714d6 | 2006-01-06 00:19:36 -0800 | [diff] [blame] | 364 | /** Negotiated minor version */ |
| 365 | unsigned minor; |
| 366 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 367 | /** Backing dev info */ |
| 368 | struct backing_dev_info bdi; |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 369 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 370 | /** Entry on the fuse_conn_list */ |
| 371 | struct list_head entry; |
| 372 | |
| 373 | /** Unique ID */ |
| 374 | u64 id; |
| 375 | |
| 376 | /** Dentries in the control filesystem */ |
| 377 | struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; |
| 378 | |
| 379 | /** number of dentries used in the above array */ |
| 380 | int ctl_ndents; |
Jeff Dike | 385a17b | 2006-04-10 22:54:52 -0700 | [diff] [blame] | 381 | |
| 382 | /** O_ASYNC requests */ |
| 383 | struct fasync_struct *fasync; |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 384 | |
| 385 | /** Key for lock owner ID scrambling */ |
| 386 | u32 scramble_key[4]; |
Miklos Szeredi | 0ec7ca4 | 2006-12-06 20:35:52 -0800 | [diff] [blame] | 387 | |
| 388 | /** Reserved request for the DESTROY message */ |
| 389 | struct fuse_req *destroy_req; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 390 | }; |
| 391 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 392 | static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) |
| 393 | { |
Miklos Szeredi | 6383bda | 2006-01-16 22:14:29 -0800 | [diff] [blame] | 394 | return sb->s_fs_info; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static inline struct fuse_conn *get_fuse_conn(struct inode *inode) |
| 398 | { |
| 399 | return get_fuse_conn_super(inode->i_sb); |
| 400 | } |
| 401 | |
| 402 | static inline struct fuse_inode *get_fuse_inode(struct inode *inode) |
| 403 | { |
| 404 | return container_of(inode, struct fuse_inode, inode); |
| 405 | } |
| 406 | |
| 407 | static inline u64 get_node_id(struct inode *inode) |
| 408 | { |
| 409 | return get_fuse_inode(inode)->nodeid; |
| 410 | } |
| 411 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 412 | /** Device operations */ |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 413 | extern const struct file_operations fuse_dev_operations; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 414 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 415 | /** |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 416 | * Get a filled in inode |
| 417 | */ |
| 418 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 419 | int generation, struct fuse_attr *attr); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 420 | |
| 421 | /** |
| 422 | * Send FORGET command |
| 423 | */ |
| 424 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 425 | unsigned long nodeid, u64 nlookup); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 426 | |
| 427 | /** |
Miklos Szeredi | 361b1eb | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 428 | * Initialize READ or READDIR request |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 429 | */ |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 430 | void fuse_read_fill(struct fuse_req *req, struct fuse_file *ff, |
Miklos Szeredi | 361b1eb | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 431 | struct inode *inode, loff_t pos, size_t count, int opcode); |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 432 | |
| 433 | /** |
| 434 | * Send OPEN or OPENDIR request |
| 435 | */ |
| 436 | int fuse_open_common(struct inode *inode, struct file *file, int isdir); |
| 437 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 438 | struct fuse_file *fuse_file_alloc(void); |
| 439 | void fuse_file_free(struct fuse_file *ff); |
| 440 | void fuse_finish_open(struct inode *inode, struct file *file, |
| 441 | struct fuse_file *ff, struct fuse_open_out *outarg); |
| 442 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 443 | /** Fill in ff->reserved_req with a RELEASE request */ |
| 444 | void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode); |
| 445 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 446 | /** |
| 447 | * Send RELEASE or RELEASEDIR request |
| 448 | */ |
| 449 | int fuse_release_common(struct inode *inode, struct file *file, int isdir); |
| 450 | |
| 451 | /** |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 452 | * Send FSYNC or FSYNCDIR request |
| 453 | */ |
| 454 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, |
| 455 | int isdir); |
| 456 | |
| 457 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 458 | * Initialize file operations on a regular file |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 459 | */ |
| 460 | void fuse_init_file_inode(struct inode *inode); |
| 461 | |
| 462 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 463 | * Initialize inode operations on regular files and special files |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 464 | */ |
| 465 | void fuse_init_common(struct inode *inode); |
| 466 | |
| 467 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 468 | * Initialize inode and file operations on a directory |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 469 | */ |
| 470 | void fuse_init_dir(struct inode *inode); |
| 471 | |
| 472 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 473 | * Initialize inode operations on a symlink |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 474 | */ |
| 475 | void fuse_init_symlink(struct inode *inode); |
| 476 | |
| 477 | /** |
| 478 | * Change attributes of an inode |
| 479 | */ |
| 480 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr); |
| 481 | |
| 482 | /** |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 483 | * Initialize the client device |
| 484 | */ |
| 485 | int fuse_dev_init(void); |
| 486 | |
| 487 | /** |
| 488 | * Cleanup the client device |
| 489 | */ |
| 490 | void fuse_dev_cleanup(void); |
| 491 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 492 | int fuse_ctl_init(void); |
| 493 | void fuse_ctl_cleanup(void); |
| 494 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 495 | /** |
| 496 | * Allocate a request |
| 497 | */ |
| 498 | struct fuse_req *fuse_request_alloc(void); |
| 499 | |
| 500 | /** |
| 501 | * Free a request |
| 502 | */ |
| 503 | void fuse_request_free(struct fuse_req *req); |
| 504 | |
| 505 | /** |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 506 | * Get a request, may fail with -ENOMEM |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 507 | */ |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 508 | struct fuse_req *fuse_get_req(struct fuse_conn *fc); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 509 | |
| 510 | /** |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 511 | * Gets a requests for a file operation, always succeeds |
| 512 | */ |
| 513 | struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file); |
| 514 | |
| 515 | /** |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 516 | * Decrement reference count of a request. If count goes to zero free |
| 517 | * the request. |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 518 | */ |
| 519 | void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); |
| 520 | |
| 521 | /** |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 522 | * Send a request (synchronous) |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 523 | */ |
| 524 | void request_send(struct fuse_conn *fc, struct fuse_req *req); |
| 525 | |
| 526 | /** |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 527 | * Send a request with no reply |
| 528 | */ |
| 529 | void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req); |
| 530 | |
| 531 | /** |
| 532 | * Send a request in the background |
| 533 | */ |
| 534 | void request_send_background(struct fuse_conn *fc, struct fuse_req *req); |
| 535 | |
Miklos Szeredi | 5a5fb1e | 2006-04-26 10:48:55 +0200 | [diff] [blame] | 536 | /* Abort all requests */ |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 537 | void fuse_abort_conn(struct fuse_conn *fc); |
| 538 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 539 | /** |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 540 | * Invalidate inode attributes |
| 541 | */ |
| 542 | void fuse_invalidate_attr(struct inode *inode); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * Acquire reference to fuse_conn |
| 546 | */ |
| 547 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); |
| 548 | |
| 549 | /** |
| 550 | * Release reference to fuse_conn |
| 551 | */ |
| 552 | void fuse_conn_put(struct fuse_conn *fc); |
| 553 | |
| 554 | /** |
| 555 | * Add connection to control filesystem |
| 556 | */ |
| 557 | int fuse_ctl_add_conn(struct fuse_conn *fc); |
| 558 | |
| 559 | /** |
| 560 | * Remove connection from control filesystem |
| 561 | */ |
| 562 | void fuse_ctl_remove_conn(struct fuse_conn *fc); |
Timo Savola | a5bfffa | 2007-04-08 16:04:00 -0700 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Is file type valid? |
| 566 | */ |
| 567 | int fuse_valid_type(int m); |