Merge branch 'fix' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa-linux-2.6
[pandora-kernel.git] / include / linux / fuse.h
1 /*
2     FUSE: Filesystem in Userspace
3     Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
4
5     This program can be distributed under the terms of the GNU GPL.
6     See the file COPYING.
7 */
8
9 /*
10  * This file defines the kernel interface of FUSE
11  *
12  * Protocol changelog:
13  *
14  * 7.9:
15  *  - new fuse_getattr_in input argument of GETATTR
16  *  - add lk_flags in fuse_lk_in
17  *  - add lock_owner field to fuse_setattr_in, fuse_read_in and fuse_write_in
18  *  - add blksize field to fuse_attr
19  *  - add file flags field to fuse_read_in and fuse_write_in
20  *
21  * 7.10
22  *  - add nonseekable open flag
23  *
24  * 7.11
25  *  - add IOCTL message
26  *  - add unsolicited notification support
27  *  - add POLL message and NOTIFY_POLL notification
28  *
29  * 7.12
30  *  - add umask flag to input argument of open, mknod and mkdir
31  *  - add notification messages for invalidation of inodes and
32  *    directory entries
33  *
34  * 7.13
35  *  - make max number of background requests and congestion threshold
36  *    tunables
37  *
38  * 7.14
39  *  - add splice support to fuse device
40  */
41
42 #ifndef _LINUX_FUSE_H
43 #define _LINUX_FUSE_H
44
45 #include <linux/types.h>
46
47 /*
48  * Version negotiation:
49  *
50  * Both the kernel and userspace send the version they support in the
51  * INIT request and reply respectively.
52  *
53  * If the major versions match then both shall use the smallest
54  * of the two minor versions for communication.
55  *
56  * If the kernel supports a larger major version, then userspace shall
57  * reply with the major version it supports, ignore the rest of the
58  * INIT message and expect a new INIT message from the kernel with a
59  * matching major version.
60  *
61  * If the library supports a larger major version, then it shall fall
62  * back to the major protocol version sent by the kernel for
63  * communication and reply with that major version (and an arbitrary
64  * supported minor version).
65  */
66
67 /** Version number of this interface */
68 #define FUSE_KERNEL_VERSION 7
69
70 /** Minor version number of this interface */
71 #define FUSE_KERNEL_MINOR_VERSION 14
72
73 /** The node ID of the root inode */
74 #define FUSE_ROOT_ID 1
75
76 /* Make sure all structures are padded to 64bit boundary, so 32bit
77    userspace works under 64bit kernels */
78
79 struct fuse_attr {
80         __u64   ino;
81         __u64   size;
82         __u64   blocks;
83         __u64   atime;
84         __u64   mtime;
85         __u64   ctime;
86         __u32   atimensec;
87         __u32   mtimensec;
88         __u32   ctimensec;
89         __u32   mode;
90         __u32   nlink;
91         __u32   uid;
92         __u32   gid;
93         __u32   rdev;
94         __u32   blksize;
95         __u32   padding;
96 };
97
98 struct fuse_kstatfs {
99         __u64   blocks;
100         __u64   bfree;
101         __u64   bavail;
102         __u64   files;
103         __u64   ffree;
104         __u32   bsize;
105         __u32   namelen;
106         __u32   frsize;
107         __u32   padding;
108         __u32   spare[6];
109 };
110
111 struct fuse_file_lock {
112         __u64   start;
113         __u64   end;
114         __u32   type;
115         __u32   pid; /* tgid */
116 };
117
118 /**
119  * Bitmasks for fuse_setattr_in.valid
120  */
121 #define FATTR_MODE      (1 << 0)
122 #define FATTR_UID       (1 << 1)
123 #define FATTR_GID       (1 << 2)
124 #define FATTR_SIZE      (1 << 3)
125 #define FATTR_ATIME     (1 << 4)
126 #define FATTR_MTIME     (1 << 5)
127 #define FATTR_FH        (1 << 6)
128 #define FATTR_ATIME_NOW (1 << 7)
129 #define FATTR_MTIME_NOW (1 << 8)
130 #define FATTR_LOCKOWNER (1 << 9)
131
132 /**
133  * Flags returned by the OPEN request
134  *
135  * FOPEN_DIRECT_IO: bypass page cache for this open file
136  * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
137  * FOPEN_NONSEEKABLE: the file is not seekable
138  */
139 #define FOPEN_DIRECT_IO         (1 << 0)
140 #define FOPEN_KEEP_CACHE        (1 << 1)
141 #define FOPEN_NONSEEKABLE       (1 << 2)
142
143 /**
144  * INIT request/reply flags
145  *
146  * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
147  * FUSE_DONT_MASK: don't apply umask to file mode on create operations
148  */
149 #define FUSE_ASYNC_READ         (1 << 0)
150 #define FUSE_POSIX_LOCKS        (1 << 1)
151 #define FUSE_FILE_OPS           (1 << 2)
152 #define FUSE_ATOMIC_O_TRUNC     (1 << 3)
153 #define FUSE_EXPORT_SUPPORT     (1 << 4)
154 #define FUSE_BIG_WRITES         (1 << 5)
155 #define FUSE_DONT_MASK          (1 << 6)
156
157 /**
158  * CUSE INIT request/reply flags
159  *
160  * CUSE_UNRESTRICTED_IOCTL:  use unrestricted ioctl
161  */
162 #define CUSE_UNRESTRICTED_IOCTL (1 << 0)
163
164 /**
165  * Release flags
166  */
167 #define FUSE_RELEASE_FLUSH      (1 << 0)
168
169 /**
170  * Getattr flags
171  */
172 #define FUSE_GETATTR_FH         (1 << 0)
173
174 /**
175  * Lock flags
176  */
177 #define FUSE_LK_FLOCK           (1 << 0)
178
179 /**
180  * WRITE flags
181  *
182  * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed
183  * FUSE_WRITE_LOCKOWNER: lock_owner field is valid
184  */
185 #define FUSE_WRITE_CACHE        (1 << 0)
186 #define FUSE_WRITE_LOCKOWNER    (1 << 1)
187
188 /**
189  * Read flags
190  */
191 #define FUSE_READ_LOCKOWNER     (1 << 1)
192
193 /**
194  * Ioctl flags
195  *
196  * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
197  * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
198  * FUSE_IOCTL_RETRY: retry with new iovecs
199  *
200  * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
201  */
202 #define FUSE_IOCTL_COMPAT       (1 << 0)
203 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
204 #define FUSE_IOCTL_RETRY        (1 << 2)
205
206 #define FUSE_IOCTL_MAX_IOV      256
207
208 /**
209  * Poll flags
210  *
211  * FUSE_POLL_SCHEDULE_NOTIFY: request poll notify
212  */
213 #define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
214
215 enum fuse_opcode {
216         FUSE_LOOKUP        = 1,
217         FUSE_FORGET        = 2,  /* no reply */
218         FUSE_GETATTR       = 3,
219         FUSE_SETATTR       = 4,
220         FUSE_READLINK      = 5,
221         FUSE_SYMLINK       = 6,
222         FUSE_MKNOD         = 8,
223         FUSE_MKDIR         = 9,
224         FUSE_UNLINK        = 10,
225         FUSE_RMDIR         = 11,
226         FUSE_RENAME        = 12,
227         FUSE_LINK          = 13,
228         FUSE_OPEN          = 14,
229         FUSE_READ          = 15,
230         FUSE_WRITE         = 16,
231         FUSE_STATFS        = 17,
232         FUSE_RELEASE       = 18,
233         FUSE_FSYNC         = 20,
234         FUSE_SETXATTR      = 21,
235         FUSE_GETXATTR      = 22,
236         FUSE_LISTXATTR     = 23,
237         FUSE_REMOVEXATTR   = 24,
238         FUSE_FLUSH         = 25,
239         FUSE_INIT          = 26,
240         FUSE_OPENDIR       = 27,
241         FUSE_READDIR       = 28,
242         FUSE_RELEASEDIR    = 29,
243         FUSE_FSYNCDIR      = 30,
244         FUSE_GETLK         = 31,
245         FUSE_SETLK         = 32,
246         FUSE_SETLKW        = 33,
247         FUSE_ACCESS        = 34,
248         FUSE_CREATE        = 35,
249         FUSE_INTERRUPT     = 36,
250         FUSE_BMAP          = 37,
251         FUSE_DESTROY       = 38,
252         FUSE_IOCTL         = 39,
253         FUSE_POLL          = 40,
254
255         /* CUSE specific operations */
256         CUSE_INIT          = 4096,
257 };
258
259 enum fuse_notify_code {
260         FUSE_NOTIFY_POLL   = 1,
261         FUSE_NOTIFY_INVAL_INODE = 2,
262         FUSE_NOTIFY_INVAL_ENTRY = 3,
263         FUSE_NOTIFY_CODE_MAX,
264 };
265
266 /* The read buffer is required to be at least 8k, but may be much larger */
267 #define FUSE_MIN_READ_BUFFER 8192
268
269 #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
270
271 struct fuse_entry_out {
272         __u64   nodeid;         /* Inode ID */
273         __u64   generation;     /* Inode generation: nodeid:gen must
274                                    be unique for the fs's lifetime */
275         __u64   entry_valid;    /* Cache timeout for the name */
276         __u64   attr_valid;     /* Cache timeout for the attributes */
277         __u32   entry_valid_nsec;
278         __u32   attr_valid_nsec;
279         struct fuse_attr attr;
280 };
281
282 struct fuse_forget_in {
283         __u64   nlookup;
284 };
285
286 struct fuse_getattr_in {
287         __u32   getattr_flags;
288         __u32   dummy;
289         __u64   fh;
290 };
291
292 #define FUSE_COMPAT_ATTR_OUT_SIZE 96
293
294 struct fuse_attr_out {
295         __u64   attr_valid;     /* Cache timeout for the attributes */
296         __u32   attr_valid_nsec;
297         __u32   dummy;
298         struct fuse_attr attr;
299 };
300
301 #define FUSE_COMPAT_MKNOD_IN_SIZE 8
302
303 struct fuse_mknod_in {
304         __u32   mode;
305         __u32   rdev;
306         __u32   umask;
307         __u32   padding;
308 };
309
310 struct fuse_mkdir_in {
311         __u32   mode;
312         __u32   umask;
313 };
314
315 struct fuse_rename_in {
316         __u64   newdir;
317 };
318
319 struct fuse_link_in {
320         __u64   oldnodeid;
321 };
322
323 struct fuse_setattr_in {
324         __u32   valid;
325         __u32   padding;
326         __u64   fh;
327         __u64   size;
328         __u64   lock_owner;
329         __u64   atime;
330         __u64   mtime;
331         __u64   unused2;
332         __u32   atimensec;
333         __u32   mtimensec;
334         __u32   unused3;
335         __u32   mode;
336         __u32   unused4;
337         __u32   uid;
338         __u32   gid;
339         __u32   unused5;
340 };
341
342 struct fuse_open_in {
343         __u32   flags;
344         __u32   unused;
345 };
346
347 struct fuse_create_in {
348         __u32   flags;
349         __u32   mode;
350         __u32   umask;
351         __u32   padding;
352 };
353
354 struct fuse_open_out {
355         __u64   fh;
356         __u32   open_flags;
357         __u32   padding;
358 };
359
360 struct fuse_release_in {
361         __u64   fh;
362         __u32   flags;
363         __u32   release_flags;
364         __u64   lock_owner;
365 };
366
367 struct fuse_flush_in {
368         __u64   fh;
369         __u32   unused;
370         __u32   padding;
371         __u64   lock_owner;
372 };
373
374 struct fuse_read_in {
375         __u64   fh;
376         __u64   offset;
377         __u32   size;
378         __u32   read_flags;
379         __u64   lock_owner;
380         __u32   flags;
381         __u32   padding;
382 };
383
384 #define FUSE_COMPAT_WRITE_IN_SIZE 24
385
386 struct fuse_write_in {
387         __u64   fh;
388         __u64   offset;
389         __u32   size;
390         __u32   write_flags;
391         __u64   lock_owner;
392         __u32   flags;
393         __u32   padding;
394 };
395
396 struct fuse_write_out {
397         __u32   size;
398         __u32   padding;
399 };
400
401 #define FUSE_COMPAT_STATFS_SIZE 48
402
403 struct fuse_statfs_out {
404         struct fuse_kstatfs st;
405 };
406
407 struct fuse_fsync_in {
408         __u64   fh;
409         __u32   fsync_flags;
410         __u32   padding;
411 };
412
413 struct fuse_setxattr_in {
414         __u32   size;
415         __u32   flags;
416 };
417
418 struct fuse_getxattr_in {
419         __u32   size;
420         __u32   padding;
421 };
422
423 struct fuse_getxattr_out {
424         __u32   size;
425         __u32   padding;
426 };
427
428 struct fuse_lk_in {
429         __u64   fh;
430         __u64   owner;
431         struct fuse_file_lock lk;
432         __u32   lk_flags;
433         __u32   padding;
434 };
435
436 struct fuse_lk_out {
437         struct fuse_file_lock lk;
438 };
439
440 struct fuse_access_in {
441         __u32   mask;
442         __u32   padding;
443 };
444
445 struct fuse_init_in {
446         __u32   major;
447         __u32   minor;
448         __u32   max_readahead;
449         __u32   flags;
450 };
451
452 struct fuse_init_out {
453         __u32   major;
454         __u32   minor;
455         __u32   max_readahead;
456         __u32   flags;
457         __u16   max_background;
458         __u16   congestion_threshold;
459         __u32   max_write;
460 };
461
462 #define CUSE_INIT_INFO_MAX 4096
463
464 struct cuse_init_in {
465         __u32   major;
466         __u32   minor;
467         __u32   unused;
468         __u32   flags;
469 };
470
471 struct cuse_init_out {
472         __u32   major;
473         __u32   minor;
474         __u32   unused;
475         __u32   flags;
476         __u32   max_read;
477         __u32   max_write;
478         __u32   dev_major;              /* chardev major */
479         __u32   dev_minor;              /* chardev minor */
480         __u32   spare[10];
481 };
482
483 struct fuse_interrupt_in {
484         __u64   unique;
485 };
486
487 struct fuse_bmap_in {
488         __u64   block;
489         __u32   blocksize;
490         __u32   padding;
491 };
492
493 struct fuse_bmap_out {
494         __u64   block;
495 };
496
497 struct fuse_ioctl_in {
498         __u64   fh;
499         __u32   flags;
500         __u32   cmd;
501         __u64   arg;
502         __u32   in_size;
503         __u32   out_size;
504 };
505
506 struct fuse_ioctl_out {
507         __s32   result;
508         __u32   flags;
509         __u32   in_iovs;
510         __u32   out_iovs;
511 };
512
513 struct fuse_poll_in {
514         __u64   fh;
515         __u64   kh;
516         __u32   flags;
517         __u32   padding;
518 };
519
520 struct fuse_poll_out {
521         __u32   revents;
522         __u32   padding;
523 };
524
525 struct fuse_notify_poll_wakeup_out {
526         __u64   kh;
527 };
528
529 struct fuse_in_header {
530         __u32   len;
531         __u32   opcode;
532         __u64   unique;
533         __u64   nodeid;
534         __u32   uid;
535         __u32   gid;
536         __u32   pid;
537         __u32   padding;
538 };
539
540 struct fuse_out_header {
541         __u32   len;
542         __s32   error;
543         __u64   unique;
544 };
545
546 struct fuse_dirent {
547         __u64   ino;
548         __u64   off;
549         __u32   namelen;
550         __u32   type;
551         char name[0];
552 };
553
554 #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
555 #define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
556 #define FUSE_DIRENT_SIZE(d) \
557         FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
558
559 struct fuse_notify_inval_inode_out {
560         __u64   ino;
561         __s64   off;
562         __s64   len;
563 };
564
565 struct fuse_notify_inval_entry_out {
566         __u64   parent;
567         __u32   namelen;
568         __u32   padding;
569 };
570
571 #endif /* _LINUX_FUSE_H */