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