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