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