[PATCH] FUSE - read-only operations
[linux-2.6/suspend2-2.6.18.git] / fs / fuse / fuse_i.h
blob8d91e1492f9640559af37cc688f85b30aa3c90f3
1 /*
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.
6 See the file COPYING.
7 */
9 #include <linux/fuse.h>
10 #include <linux/fs.h>
11 #include <linux/wait.h>
12 #include <linux/list.h>
13 #include <linux/spinlock.h>
14 #include <linux/mm.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
24 /** FUSE inode */
25 struct fuse_inode {
26 /** Inode data */
27 struct inode inode;
29 /** Unique ID, which identifies the inode between userspace
30 * and kernel */
31 u64 nodeid;
33 /** The request used for sending the FORGET message */
34 struct fuse_req *forget_req;
36 /** Time in jiffies until the file attributes are valid */
37 unsigned long i_time;
40 /** One input argument of a request */
41 struct fuse_in_arg {
42 unsigned size;
43 const void *value;
46 /** The request input */
47 struct fuse_in {
48 /** The request header */
49 struct fuse_in_header h;
51 /** True if the data for the last argument is in req->pages */
52 unsigned argpages:1;
54 /** Number of arguments */
55 unsigned numargs;
57 /** Array of arguments */
58 struct fuse_in_arg args[3];
61 /** One output argument of a request */
62 struct fuse_arg {
63 unsigned size;
64 void *value;
67 /** The request output */
68 struct fuse_out {
69 /** Header returned from userspace */
70 struct fuse_out_header h;
72 /** Last argument is variable length (can be shorter than
73 arg->size) */
74 unsigned argvar:1;
76 /** Last argument is a list of pages to copy data to */
77 unsigned argpages:1;
79 /** Zero partially or not copied pages */
80 unsigned page_zeroing:1;
82 /** Number or arguments */
83 unsigned numargs;
85 /** Array of arguments */
86 struct fuse_arg args[3];
89 struct fuse_req;
90 struct fuse_conn;
92 /**
93 * A request to the client
95 struct fuse_req {
96 /** This can be on either unused_list, pending or processing
97 lists in fuse_conn */
98 struct list_head list;
100 /** refcount */
101 atomic_t count;
103 /** True if the request has reply */
104 unsigned isreply:1;
106 /** The request is preallocated */
107 unsigned preallocated:1;
109 /** The request was interrupted */
110 unsigned interrupted:1;
112 /** Request is sent in the background */
113 unsigned background:1;
115 /** Data is being copied to/from the request */
116 unsigned locked:1;
118 /** Request has been sent to userspace */
119 unsigned sent:1;
121 /** The request is finished */
122 unsigned finished:1;
124 /** The request input */
125 struct fuse_in in;
127 /** The request output */
128 struct fuse_out out;
130 /** Used to wake up the task waiting for completion of request*/
131 wait_queue_head_t waitq;
133 /** Data for asynchronous requests */
134 union {
135 struct fuse_forget_in forget_in;
136 struct fuse_init_in_out init_in_out;
137 } misc;
139 /** page vector */
140 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
142 /** number of pages in vector */
143 unsigned num_pages;
145 /** offset of data on first page */
146 unsigned page_offset;
148 /** Inode used in the request */
149 struct inode *inode;
151 /** Second inode used in the request (or NULL) */
152 struct inode *inode2;
154 /** File used in the request (or NULL) */
155 struct file *file;
159 * A Fuse connection.
161 * This structure is created, when the filesystem is mounted, and is
162 * destroyed, when the client device is closed and the filesystem is
163 * unmounted.
165 struct fuse_conn {
166 /** The superblock of the mounted filesystem */
167 struct super_block *sb;
169 /** The opened client device */
170 struct file *file;
172 /** The user id for this mount */
173 uid_t user_id;
175 /** Readers of the connection are waiting on this */
176 wait_queue_head_t waitq;
178 /** The list of pending requests */
179 struct list_head pending;
181 /** The list of requests being processed */
182 struct list_head processing;
184 /** Controls the maximum number of outstanding requests */
185 struct semaphore outstanding_sem;
187 /** This counts the number of outstanding requests if
188 outstanding_sem would go negative */
189 unsigned outstanding_debt;
191 /** The list of unused requests */
192 struct list_head unused_list;
194 /** The next unique request id */
195 u64 reqctr;
197 /** Connection failed (version mismatch) */
198 unsigned conn_error : 1;
200 /** Backing dev info */
201 struct backing_dev_info bdi;
204 struct fuse_getdir_out_i {
205 int fd;
206 void *file; /* Used by kernel only */
209 static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
211 return (struct fuse_conn **) &sb->s_fs_info;
214 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
216 return *get_fuse_conn_super_p(sb);
219 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
221 return get_fuse_conn_super(inode->i_sb);
224 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
226 return container_of(inode, struct fuse_inode, inode);
229 static inline u64 get_node_id(struct inode *inode)
231 return get_fuse_inode(inode)->nodeid;
234 /** Device operations */
235 extern struct file_operations fuse_dev_operations;
238 * This is the single global spinlock which protects FUSE's structures
240 * The following data is protected by this lock:
242 * - the private_data field of the device file
243 * - the s_fs_info field of the super block
244 * - unused_list, pending, processing lists in fuse_conn
245 * - the unique request ID counter reqctr in fuse_conn
246 * - the sb (super_block) field in fuse_conn
247 * - the file (device file) field in fuse_conn
249 extern spinlock_t fuse_lock;
252 * Get a filled in inode
254 struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
255 int generation, struct fuse_attr *attr, int version);
258 * Send FORGET command
260 void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
261 unsigned long nodeid, int version);
264 * Initialise inode operations on regular files and special files
266 void fuse_init_common(struct inode *inode);
269 * Initialise inode and file operations on a directory
271 void fuse_init_dir(struct inode *inode);
274 * Initialise inode operations on a symlink
276 void fuse_init_symlink(struct inode *inode);
279 * Change attributes of an inode
281 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
284 * Check if the connection can be released, and if yes, then free the
285 * connection structure
287 void fuse_release_conn(struct fuse_conn *fc);
290 * Initialize the client device
292 int fuse_dev_init(void);
295 * Cleanup the client device
297 void fuse_dev_cleanup(void);
300 * Allocate a request
302 struct fuse_req *fuse_request_alloc(void);
305 * Free a request
307 void fuse_request_free(struct fuse_req *req);
310 * Reinitialize a request, the preallocated flag is left unmodified
312 void fuse_reset_request(struct fuse_req *req);
315 * Reserve a preallocated request
317 struct fuse_req *fuse_get_request(struct fuse_conn *fc);
320 * Reserve a preallocated request, only interruptible by SIGKILL
322 struct fuse_req *fuse_get_request_nonint(struct fuse_conn *fc);
325 * Decrement reference count of a request. If count goes to zero put
326 * on unused list (preallocated) or free reqest (not preallocated).
328 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
331 * Send a request (synchronous, interruptible)
333 void request_send(struct fuse_conn *fc, struct fuse_req *req);
336 * Send a request (synchronous, non-interruptible except by SIGKILL)
338 void request_send_nonint(struct fuse_conn *fc, struct fuse_req *req);
341 * Send a request with no reply
343 void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
346 * Send a request in the background
348 void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
351 * Get the attributes of a file
353 int fuse_do_getattr(struct inode *inode);
356 * Invalidate inode attributes
358 void fuse_invalidate_attr(struct inode *inode);
361 * Send the INIT message
363 void fuse_send_init(struct fuse_conn *fc);