2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
9 #include <linux/fuse.h>
11 #include <linux/wait.h>
12 #include <linux/list.h>
13 #include <linux/spinlock.h>
15 #include <linux/backing-dev.h>
16 #include <asm/semaphore.h>
18 /** Max number of pages that can be used in a single read request */
19 #define FUSE_MAX_PAGES_PER_REQ 32
21 /** If more requests are outstanding, then the operation will block */
22 #define FUSE_MAX_OUTSTANDING 10
29 /** Unique ID, which identifies the inode between userspace
33 /** Number of lookups on this inode */
36 /** The request used for sending the FORGET message */
37 struct fuse_req *forget_req;
39 /** Time in jiffies until the file attributes are valid */
43 /** One input argument of a request */
49 /** The request input */
51 /** The request header */
52 struct fuse_in_header h;
54 /** True if the data for the last argument is in req->pages */
57 /** Number of arguments */
60 /** Array of arguments */
61 struct fuse_in_arg args[3];
64 /** One output argument of a request */
70 /** The request output */
72 /** Header returned from userspace */
73 struct fuse_out_header h;
75 /** Last argument is variable length (can be shorter than
79 /** Last argument is a list of pages to copy data to */
82 /** Zero partially or not copied pages */
83 unsigned page_zeroing:1;
85 /** Number or arguments */
88 /** Array of arguments */
89 struct fuse_arg args[3];
96 * A request to the client
99 /** This can be on either unused_list, pending or processing
100 lists in fuse_conn */
101 struct list_head list;
106 /** True if the request has reply */
109 /** The request is preallocated */
110 unsigned preallocated:1;
112 /** The request was interrupted */
113 unsigned interrupted:1;
115 /** Request is sent in the background */
116 unsigned background:1;
118 /** Data is being copied to/from the request */
121 /** Request has been sent to userspace */
124 /** The request is finished */
127 /** The request input */
130 /** The request output */
133 /** Used to wake up the task waiting for completion of request*/
134 wait_queue_head_t waitq;
136 /** Data for asynchronous requests */
138 struct fuse_forget_in forget_in;
139 struct fuse_init_in_out init_in_out;
143 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
145 /** number of pages in vector */
148 /** offset of data on first page */
149 unsigned page_offset;
151 /** Inode used in the request */
154 /** Second inode used in the request (or NULL) */
155 struct inode *inode2;
157 /** File used in the request (or NULL) */
164 * This structure is created, when the filesystem is mounted, and is
165 * destroyed, when the client device is closed and the filesystem is
169 /** The superblock of the mounted filesystem */
170 struct super_block *sb;
172 /** The opened client device */
175 /** The user id for this mount */
178 /** Readers of the connection are waiting on this */
179 wait_queue_head_t waitq;
181 /** The list of pending requests */
182 struct list_head pending;
184 /** The list of requests being processed */
185 struct list_head processing;
187 /** Controls the maximum number of outstanding requests */
188 struct semaphore outstanding_sem;
190 /** This counts the number of outstanding requests if
191 outstanding_sem would go negative */
192 unsigned outstanding_debt;
194 /** The list of unused requests */
195 struct list_head unused_list;
197 /** The next unique request id */
200 /** Connection failed (version mismatch) */
201 unsigned conn_error : 1;
203 /** Backing dev info */
204 struct backing_dev_info bdi;
207 struct fuse_getdir_out_i {
209 void *file; /* Used by kernel only */
212 static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
214 return (struct fuse_conn **) &sb->s_fs_info;
217 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
219 return *get_fuse_conn_super_p(sb);
222 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
224 return get_fuse_conn_super(inode->i_sb);
227 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
229 return container_of(inode, struct fuse_inode, inode);
232 static inline u64 get_node_id(struct inode *inode)
234 return get_fuse_inode(inode)->nodeid;
237 /** Device operations */
238 extern struct file_operations fuse_dev_operations;
241 * This is the single global spinlock which protects FUSE's structures
243 * The following data is protected by this lock:
245 * - the private_data field of the device file
246 * - the s_fs_info field of the super block
247 * - unused_list, pending, processing lists in fuse_conn
248 * - the unique request ID counter reqctr in fuse_conn
249 * - the sb (super_block) field in fuse_conn
250 * - the file (device file) field in fuse_conn
252 extern spinlock_t fuse_lock;
255 * Get a filled in inode
257 struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
258 int generation, struct fuse_attr *attr);
261 * Send FORGET command
263 void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
264 unsigned long nodeid, u64 nlookup);
267 * Initialise inode operations on regular files and special files
269 void fuse_init_common(struct inode *inode);
272 * Initialise inode and file operations on a directory
274 void fuse_init_dir(struct inode *inode);
277 * Initialise inode operations on a symlink
279 void fuse_init_symlink(struct inode *inode);
282 * Change attributes of an inode
284 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
287 * Check if the connection can be released, and if yes, then free the
288 * connection structure
290 void fuse_release_conn(struct fuse_conn *fc);
293 * Initialize the client device
295 int fuse_dev_init(void);
298 * Cleanup the client device
300 void fuse_dev_cleanup(void);
305 struct fuse_req *fuse_request_alloc(void);
310 void fuse_request_free(struct fuse_req *req);
313 * Reinitialize a request, the preallocated flag is left unmodified
315 void fuse_reset_request(struct fuse_req *req);
318 * Reserve a preallocated request
320 struct fuse_req *fuse_get_request(struct fuse_conn *fc);
323 * Reserve a preallocated request, only interruptible by SIGKILL
325 struct fuse_req *fuse_get_request_nonint(struct fuse_conn *fc);
328 * Decrement reference count of a request. If count goes to zero put
329 * on unused list (preallocated) or free reqest (not preallocated).
331 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
334 * Send a request (synchronous, interruptible)
336 void request_send(struct fuse_conn *fc, struct fuse_req *req);
339 * Send a request (synchronous, non-interruptible except by SIGKILL)
341 void request_send_nonint(struct fuse_conn *fc, struct fuse_req *req);
344 * Send a request with no reply
346 void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
349 * Send a request in the background
351 void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
354 * Get the attributes of a file
356 int fuse_do_getattr(struct inode *inode);
359 * Invalidate inode attributes
361 void fuse_invalidate_attr(struct inode *inode);
364 * Send the INIT message
366 void fuse_send_init(struct fuse_conn *fc);