fuse: refresh stale attributes in fuse_permission()
[linux-2.6/linux-loongson.git] / fs / fuse / fuse_i.h
blobe0555d68b4a7741d35d51200c7d9273d4fd67293
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 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/mount.h>
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>
17 #include <linux/mutex.h>
19 /** Max number of pages that can be used in a single read request */
20 #define FUSE_MAX_PAGES_PER_REQ 32
22 /** Maximum number of outstanding background requests */
23 #define FUSE_MAX_BACKGROUND 12
25 /** Congestion starts at 75% of maximum */
26 #define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100)
28 /** It could be as large as PATH_MAX, but would that have any uses? */
29 #define FUSE_NAME_MAX 1024
31 /** Number of dentries for each connection in the control filesystem */
32 #define FUSE_CTL_NUM_DENTRIES 3
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)
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)
43 /** List of active connections */
44 extern struct list_head fuse_conn_list;
46 /** Global mutex protecting fuse_conn_list and the control filesystem */
47 extern struct mutex fuse_mutex;
49 /** FUSE inode */
50 struct fuse_inode {
51 /** Inode data */
52 struct inode inode;
54 /** Unique ID, which identifies the inode between userspace
55 * and kernel */
56 u64 nodeid;
58 /** Number of lookups on this inode */
59 u64 nlookup;
61 /** The request used for sending the FORGET message */
62 struct fuse_req *forget_req;
64 /** Time in jiffies until the file attributes are valid */
65 u64 i_time;
68 /** FUSE specific file data */
69 struct fuse_file {
70 /** Request reserved for flush and release */
71 struct fuse_req *reserved_req;
73 /** File handle used by userspace */
74 u64 fh;
76 /** Refcount */
77 atomic_t count;
80 /** One input argument of a request */
81 struct fuse_in_arg {
82 unsigned size;
83 const void *value;
86 /** The request input */
87 struct fuse_in {
88 /** The request header */
89 struct fuse_in_header h;
91 /** True if the data for the last argument is in req->pages */
92 unsigned argpages:1;
94 /** Number of arguments */
95 unsigned numargs;
97 /** Array of arguments */
98 struct fuse_in_arg args[3];
101 /** One output argument of a request */
102 struct fuse_arg {
103 unsigned size;
104 void *value;
107 /** The request output */
108 struct fuse_out {
109 /** Header returned from userspace */
110 struct fuse_out_header h;
113 * The following bitfields are not changed during the request
114 * processing
117 /** Last argument is variable length (can be shorter than
118 arg->size) */
119 unsigned argvar:1;
121 /** Last argument is a list of pages to copy data to */
122 unsigned argpages:1;
124 /** Zero partially or not copied pages */
125 unsigned page_zeroing:1;
127 /** Number or arguments */
128 unsigned numargs;
130 /** Array of arguments */
131 struct fuse_arg args[3];
134 /** The request state */
135 enum fuse_req_state {
136 FUSE_REQ_INIT = 0,
137 FUSE_REQ_PENDING,
138 FUSE_REQ_READING,
139 FUSE_REQ_SENT,
140 FUSE_REQ_WRITING,
141 FUSE_REQ_FINISHED
144 struct fuse_conn;
147 * A request to the client
149 struct fuse_req {
150 /** This can be on either pending processing or io lists in
151 fuse_conn */
152 struct list_head list;
154 /** Entry on the interrupts list */
155 struct list_head intr_entry;
157 /** refcount */
158 atomic_t count;
160 /** Unique ID for the interrupt request */
161 u64 intr_unique;
164 * The following bitfields are either set once before the
165 * request is queued or setting/clearing them is protected by
166 * fuse_conn->lock
169 /** True if the request has reply */
170 unsigned isreply:1;
172 /** Force sending of the request even if interrupted */
173 unsigned force:1;
175 /** The request was aborted */
176 unsigned aborted:1;
178 /** Request is sent in the background */
179 unsigned background:1;
181 /** The request has been interrupted */
182 unsigned interrupted:1;
184 /** Data is being copied to/from the request */
185 unsigned locked:1;
187 /** Request is counted as "waiting" */
188 unsigned waiting:1;
190 /** State of the request */
191 enum fuse_req_state state;
193 /** The request input */
194 struct fuse_in in;
196 /** The request output */
197 struct fuse_out out;
199 /** Used to wake up the task waiting for completion of request*/
200 wait_queue_head_t waitq;
202 /** Data for asynchronous requests */
203 union {
204 struct fuse_forget_in forget_in;
205 struct fuse_release_in release_in;
206 struct fuse_init_in init_in;
207 struct fuse_init_out init_out;
208 struct fuse_read_in read_in;
209 struct fuse_lk_in lk_in;
210 } misc;
212 /** page vector */
213 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
215 /** number of pages in vector */
216 unsigned num_pages;
218 /** offset of data on first page */
219 unsigned page_offset;
221 /** File used in the request (or NULL) */
222 struct fuse_file *ff;
224 /** vfsmount used in release */
225 struct vfsmount *vfsmount;
227 /** dentry used in release */
228 struct dentry *dentry;
230 /** Request completion callback */
231 void (*end)(struct fuse_conn *, struct fuse_req *);
233 /** Request is stolen from fuse_file->reserved_req */
234 struct file *stolen_file;
238 * A Fuse connection.
240 * This structure is created, when the filesystem is mounted, and is
241 * destroyed, when the client device is closed and the filesystem is
242 * unmounted.
244 struct fuse_conn {
245 /** Lock protecting accessess to members of this structure */
246 spinlock_t lock;
248 /** Mutex protecting against directory alias creation */
249 struct mutex inst_mutex;
251 /** Refcount */
252 atomic_t count;
254 /** The user id for this mount */
255 uid_t user_id;
257 /** The group id for this mount */
258 gid_t group_id;
260 /** The fuse mount flags for this mount */
261 unsigned flags;
263 /** Maximum read size */
264 unsigned max_read;
266 /** Maximum write size */
267 unsigned max_write;
269 /** Readers of the connection are waiting on this */
270 wait_queue_head_t waitq;
272 /** The list of pending requests */
273 struct list_head pending;
275 /** The list of requests being processed */
276 struct list_head processing;
278 /** The list of requests under I/O */
279 struct list_head io;
281 /** Number of requests currently in the background */
282 unsigned num_background;
284 /** Pending interrupts */
285 struct list_head interrupts;
287 /** Flag indicating if connection is blocked. This will be
288 the case before the INIT reply is received, and if there
289 are too many outstading backgrounds requests */
290 int blocked;
292 /** waitq for blocked connection */
293 wait_queue_head_t blocked_waitq;
295 /** waitq for reserved requests */
296 wait_queue_head_t reserved_req_waitq;
298 /** The next unique request id */
299 u64 reqctr;
301 /** Connection established, cleared on umount, connection
302 abort and device release */
303 unsigned connected;
305 /** Connection failed (version mismatch). Cannot race with
306 setting other bitfields since it is only set once in INIT
307 reply, before any other request, and never cleared */
308 unsigned conn_error : 1;
310 /** Connection successful. Only set in INIT */
311 unsigned conn_init : 1;
313 /** Do readpages asynchronously? Only set in INIT */
314 unsigned async_read : 1;
317 * The following bitfields are only for optimization purposes
318 * and hence races in setting them will not cause malfunction
321 /** Is fsync not implemented by fs? */
322 unsigned no_fsync : 1;
324 /** Is fsyncdir not implemented by fs? */
325 unsigned no_fsyncdir : 1;
327 /** Is flush not implemented by fs? */
328 unsigned no_flush : 1;
330 /** Is setxattr not implemented by fs? */
331 unsigned no_setxattr : 1;
333 /** Is getxattr not implemented by fs? */
334 unsigned no_getxattr : 1;
336 /** Is listxattr not implemented by fs? */
337 unsigned no_listxattr : 1;
339 /** Is removexattr not implemented by fs? */
340 unsigned no_removexattr : 1;
342 /** Are file locking primitives not implemented by fs? */
343 unsigned no_lock : 1;
345 /** Is access not implemented by fs? */
346 unsigned no_access : 1;
348 /** Is create not implemented by fs? */
349 unsigned no_create : 1;
351 /** Is interrupt not implemented by fs? */
352 unsigned no_interrupt : 1;
354 /** Is bmap not implemented by fs? */
355 unsigned no_bmap : 1;
357 /** The number of requests waiting for completion */
358 atomic_t num_waiting;
360 /** Negotiated minor version */
361 unsigned minor;
363 /** Backing dev info */
364 struct backing_dev_info bdi;
366 /** Entry on the fuse_conn_list */
367 struct list_head entry;
369 /** Unique ID */
370 u64 id;
372 /** Dentries in the control filesystem */
373 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
375 /** number of dentries used in the above array */
376 int ctl_ndents;
378 /** O_ASYNC requests */
379 struct fasync_struct *fasync;
381 /** Key for lock owner ID scrambling */
382 u32 scramble_key[4];
384 /** Reserved request for the DESTROY message */
385 struct fuse_req *destroy_req;
388 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
390 return sb->s_fs_info;
393 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
395 return get_fuse_conn_super(inode->i_sb);
398 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
400 return container_of(inode, struct fuse_inode, inode);
403 static inline u64 get_node_id(struct inode *inode)
405 return get_fuse_inode(inode)->nodeid;
408 /** Device operations */
409 extern const struct file_operations fuse_dev_operations;
412 * Get a filled in inode
414 struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
415 int generation, struct fuse_attr *attr);
418 * Send FORGET command
420 void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
421 unsigned long nodeid, u64 nlookup);
424 * Initialize READ or READDIR request
426 void fuse_read_fill(struct fuse_req *req, struct fuse_file *ff,
427 struct inode *inode, loff_t pos, size_t count, int opcode);
430 * Send OPEN or OPENDIR request
432 int fuse_open_common(struct inode *inode, struct file *file, int isdir);
434 struct fuse_file *fuse_file_alloc(void);
435 void fuse_file_free(struct fuse_file *ff);
436 void fuse_finish_open(struct inode *inode, struct file *file,
437 struct fuse_file *ff, struct fuse_open_out *outarg);
439 /** Fill in ff->reserved_req with a RELEASE request */
440 void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode);
443 * Send RELEASE or RELEASEDIR request
445 int fuse_release_common(struct inode *inode, struct file *file, int isdir);
448 * Send FSYNC or FSYNCDIR request
450 int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
451 int isdir);
454 * Initialize file operations on a regular file
456 void fuse_init_file_inode(struct inode *inode);
459 * Initialize inode operations on regular files and special files
461 void fuse_init_common(struct inode *inode);
464 * Initialize inode and file operations on a directory
466 void fuse_init_dir(struct inode *inode);
469 * Initialize inode operations on a symlink
471 void fuse_init_symlink(struct inode *inode);
474 * Change attributes of an inode
476 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
479 * Initialize the client device
481 int fuse_dev_init(void);
484 * Cleanup the client device
486 void fuse_dev_cleanup(void);
488 int fuse_ctl_init(void);
489 void fuse_ctl_cleanup(void);
492 * Allocate a request
494 struct fuse_req *fuse_request_alloc(void);
497 * Free a request
499 void fuse_request_free(struct fuse_req *req);
502 * Get a request, may fail with -ENOMEM
504 struct fuse_req *fuse_get_req(struct fuse_conn *fc);
507 * Gets a requests for a file operation, always succeeds
509 struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file);
512 * Decrement reference count of a request. If count goes to zero free
513 * the request.
515 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
518 * Send a request (synchronous)
520 void request_send(struct fuse_conn *fc, struct fuse_req *req);
523 * Send a request with no reply
525 void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
528 * Send a request in the background
530 void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
532 /* Abort all requests */
533 void fuse_abort_conn(struct fuse_conn *fc);
536 * Invalidate inode attributes
538 void fuse_invalidate_attr(struct inode *inode);
541 * Acquire reference to fuse_conn
543 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
546 * Release reference to fuse_conn
548 void fuse_conn_put(struct fuse_conn *fc);
551 * Add connection to control filesystem
553 int fuse_ctl_add_conn(struct fuse_conn *fc);
556 * Remove connection from control filesystem
558 void fuse_ctl_remove_conn(struct fuse_conn *fc);
561 * Is file type valid?
563 int fuse_valid_type(int m);