xref: /netbsd-src/lib/libperfuse/fuse.h (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*  $NetBSD: fuse.h,v 1.5 2011/12/28 17:33:53 manu Exp $ */
2 
3 /*-
4  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions
8  *  are met:
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _FUSE_H
29 #define _FUSE_H
30 
31 #define FUSE_KERNEL_VERSION 7
32 #define FUSE_KERNEL_MINOR_VERSION 12
33 #define FUSE_ROOT_ID 1
34 #define FUSE_UNKNOWN_FH (uint64_t)0
35 
36 #ifndef FUSE_BUFSIZE
37 #define FUSE_MIN_BUFSIZE 0x21000
38 #define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
39 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
40 #endif /* FUSE_BUFSIZE */
41 
42 /* From <linux/limits.h> */
43 #define LINUX_XATTR_NAME_MAX   255
44 #define LINUX_XATTR_SIZE_MAX 65536
45 #define LINUX_XATTR_LIST_MAX 65536
46 
47 struct fuse_attr {
48 	uint64_t	ino;
49 	uint64_t	size;
50 	uint64_t	blocks;
51 	uint64_t	atime;
52 	uint64_t	mtime;
53 	uint64_t	ctime;
54 	uint32_t	atimensec;
55 	uint32_t	mtimensec;
56 	uint32_t	ctimensec;
57 	uint32_t	mode;
58 	uint32_t	nlink;
59 	uint32_t	uid;
60 	uint32_t	gid;
61 	uint32_t	rdev;
62 	uint32_t	blksize;
63 	uint32_t	padding;
64 };
65 
66 struct fuse_kstatfs {
67 	uint64_t	blocks;
68 	uint64_t	bfree;
69 	uint64_t	bavail;
70 	uint64_t	files;
71 	uint64_t	ffree;
72 	uint32_t	bsize;
73 	uint32_t	namelen;
74 	uint32_t	frsize;
75 	uint32_t	padding;
76 	uint32_t	spare[6];
77 };
78 
79 struct fuse_file_lock {
80 	uint64_t	start;
81 	uint64_t	end;
82 	uint32_t	type;
83 	uint32_t	pid;
84 };
85 
86 /*
87  * Various flags
88  */
89 #define FUSE_FATTR_MODE		0x0001
90 #define FUSE_FATTR_UID		0x0002
91 #define FUSE_FATTR_GID		0x0004
92 #define FUSE_FATTR_SIZE		0x0008
93 #define FUSE_FATTR_ATIME	0x0010
94 #define FUSE_FATTR_MTIME	0x0020
95 #define FUSE_FATTR_FH		0x0040
96 #define FUSE_FATTR_ATIME_NOW	0x0080
97 #define FUSE_FATTR_MTIME_NOW	0x0100
98 #define FUSE_FATTR_LOCKOWNER	0x0200
99 
100 #define FUSE_FOPEN_DIRECT_IO	0x0001
101 #define FUSE_FOPEN_KEEP_CACHE	0x0002
102 #define FUSE_FOPEN_NONSEEKABLE	0x0004
103 
104 #define FUSE_ASYNC_READ		0x0001
105 #define FUSE_POSIX_LOCKS	0x0002
106 #define FUSE_FILE_OPS		0x0004
107 #define FUSE_ATOMIC_O_TRUNC	0x0008
108 #define FUSE_EXPORT_SUPPORT	0x0010
109 #define FUSE_BIG_WRITES		0x0020
110 #define FUSE_DONT_MASK		0x0040
111 
112 #define FUSE_CUSE_UNRESTRICTED_IOCTL	0x0001
113 
114 #define FUSE_RELEASE_FLUSH	0x0001
115 
116 #define FUSE_GETATTR_FH		0x0001
117 
118 #define FUSE_LK_FLOCK		0x0001
119 
120 #define FUSE_WRITE_CACHE	0x0001
121 #define FUSE_WRITE_LOCKOWNER	0x0002
122 
123 #define FUSE_READ_LOCKOWNER	0x0002
124 
125 #define FUSE_IOCTL_COMPAT	0x0001
126 #define FUSE_IOCTL_UNRESTRICTED	0x0002
127 #define FUSE_IOCTL_RETRY	0x0004
128 
129 #define FUSE_IOCTL_MAX_IOV	256
130 
131 #define FUSE_POLL_SCHEDULE_NOTIFY 0x0001
132 
133 enum fuse_opcode {
134 	FUSE_LOOKUP	   = 1,
135 	FUSE_FORGET	   = 2,
136 	FUSE_GETATTR	   = 3,
137 	FUSE_SETATTR	   = 4,
138 	FUSE_READLINK	   = 5,
139 	FUSE_SYMLINK	   = 6,
140 	FUSE_MKNOD	   = 8,
141 	FUSE_MKDIR	   = 9,
142 	FUSE_UNLINK	   = 10,
143 	FUSE_RMDIR	   = 11,
144 	FUSE_RENAME	   = 12,
145 	FUSE_LINK	   = 13,
146 	FUSE_OPEN	   = 14,
147 	FUSE_READ	   = 15,
148 	FUSE_WRITE	   = 16,
149 	FUSE_STATFS	   = 17,
150 	FUSE_RELEASE       = 18,
151 	FUSE_FSYNC         = 20,
152 	FUSE_SETXATTR      = 21,
153 	FUSE_GETXATTR      = 22,
154 	FUSE_LISTXATTR     = 23,
155 	FUSE_REMOVEXATTR   = 24,
156 	FUSE_FLUSH         = 25,
157 	FUSE_INIT          = 26,
158 	FUSE_OPENDIR       = 27,
159 	FUSE_READDIR       = 28,
160 	FUSE_RELEASEDIR    = 29,
161 	FUSE_FSYNCDIR      = 30,
162 	FUSE_GETLK         = 31,
163 	FUSE_SETLK         = 32,
164 	FUSE_SETLKW        = 33,
165 	FUSE_ACCESS        = 34,
166 	FUSE_CREATE        = 35,
167 	FUSE_INTERRUPT     = 36,
168 	FUSE_BMAP          = 37,
169 	FUSE_DESTROY       = 38,
170 	FUSE_IOCTL         = 39,
171 	FUSE_POLL          = 40,
172 	FUSE_OPCODE_MAX,
173 
174 	FUSE_CUSE_INIT     = 4096
175 };
176 
177 enum fuse_notify_code {
178 	FUSE_NOTIFY_POLL   = 1,
179 	FUSE_NOTIFY_INVAL_INODE = 2,
180 	FUSE_NOTIFY_INVAL_ENTRY = 3,
181 	FUSE_NOTIFY_CODE_MAX
182 };
183 
184 #define FUSE_MIN_READ_BUFFER 8192
185 
186 #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
187 
188 struct fuse_entry_out {
189 	uint64_t	nodeid;
190 	uint64_t	generation;
191 	uint64_t	entry_valid;
192 	uint64_t	attr_valid;
193 	uint32_t	entry_valid_nsec;
194 	uint32_t	attr_valid_nsec;
195 	struct fuse_attr attr;
196 };
197 
198 struct fuse_forget_in {
199 	uint64_t	nlookup;
200 };
201 
202 struct fuse_getattr_in {
203 	uint32_t	getattr_flags;
204 	uint32_t	dummy;
205 	uint64_t	fh;
206 };
207 
208 #define FUSE_COMPAT_ATTR_OUT_SIZE 96
209 
210 struct fuse_attr_out {
211 	uint64_t	attr_valid;
212 	uint32_t	attr_valid_nsec;
213 	uint32_t	dummy;
214 	struct fuse_attr attr;
215 };
216 
217 #define FUSE_COMPAT_MKNOD_IN_SIZE 8
218 
219 struct fuse_mknod_in {
220 	uint32_t	mode;
221 	uint32_t	rdev;
222 	uint32_t	umask;
223 	uint32_t	padding;
224 };
225 
226 struct fuse_mkdir_in {
227 	uint32_t	mode;
228 	uint32_t	umask;
229 };
230 
231 struct fuse_rename_in {
232 	uint64_t	newdir;
233 };
234 
235 struct fuse_link_in {
236 	uint64_t	oldnodeid;
237 };
238 
239 struct fuse_setattr_in {
240 	uint32_t	valid;
241 	uint32_t	padding;
242 	uint64_t	fh;
243 	uint64_t	size;
244 	uint64_t	lock_owner;
245 	uint64_t	atime;
246 	uint64_t	mtime;
247 	uint64_t	unused2;
248 	uint32_t	atimensec;
249 	uint32_t	mtimensec;
250 	uint32_t	unused3;
251 	uint32_t	mode;
252 	uint32_t	unused4;
253 	uint32_t	uid;
254 	uint32_t	gid;
255 	uint32_t	unused5;
256 };
257 
258 struct fuse_open_in {
259 	uint32_t	flags;
260 	uint32_t	unused;
261 };
262 
263 struct fuse_create_in {
264 	uint32_t	flags;
265 	uint32_t	mode;
266 	uint32_t	umask;
267 	uint32_t	padding;
268 };
269 
270 struct fuse_open_out {
271 	uint64_t	fh;
272 	uint32_t	open_flags; /* FUSE_FOPEN_ */
273 	uint32_t	padding;
274 };
275 
276 struct fuse_release_in {
277 	uint64_t	fh;
278 	uint32_t	flags;
279 	uint32_t	release_flags;
280 	uint64_t	lock_owner;
281 };
282 
283 struct fuse_flush_in {
284 	uint64_t	fh;
285 	uint32_t	unused;
286 	uint32_t	padding;
287 	uint64_t	lock_owner;
288 };
289 
290 struct fuse_read_in {
291 	uint64_t	fh;
292 	uint64_t	offset;
293 	uint32_t	size;
294 	uint32_t	read_flags;
295 	uint64_t	lock_owner;
296 	uint32_t	flags;
297 	uint32_t	padding;
298 };
299 
300 #define FUSE_COMPAT_WRITE_IN_SIZE 24
301 
302 struct fuse_write_in {
303 	uint64_t	fh;
304 	uint64_t	offset;
305 	uint32_t	size;
306 	uint32_t	write_flags;
307 	uint64_t	lock_owner;
308 	uint32_t	flags;
309 	uint32_t	padding;
310 };
311 
312 struct fuse_write_out {
313 	uint32_t	size;
314 	uint32_t	padding;
315 };
316 
317 #define FUSE_COMPAT_STATFS_SIZE 48
318 
319 struct fuse_statfs_out {
320 	struct fuse_kstatfs st;
321 };
322 
323 struct fuse_fsync_in {
324 	uint64_t	fh;
325 	uint32_t	fsync_flags;
326 	uint32_t	padding;
327 };
328 
329 struct fuse_setxattr_in {
330 	uint32_t	size;
331 	uint32_t	flags;
332 };
333 
334 struct fuse_getxattr_in {
335 	uint32_t	size;
336 	uint32_t	padding;
337 };
338 
339 struct fuse_getxattr_out {
340 	uint32_t	size;
341 	uint32_t	padding;
342 };
343 
344 struct fuse_lk_in {
345 	uint64_t	fh;
346 	uint64_t	owner;
347 	struct fuse_file_lock lk;
348 	uint32_t	lk_flags;
349 	uint32_t	padding;
350 };
351 
352 struct fuse_lk_out {
353 	struct fuse_file_lock lk;
354 };
355 
356 struct fuse_access_in {
357 	uint32_t	mask;
358 	uint32_t	padding;
359 };
360 
361 struct fuse_init_in {
362 	uint32_t	major;
363 	uint32_t	minor;
364 	uint32_t	max_readahead;
365 	uint32_t	flags;
366 };
367 
368 struct fuse_init_out {
369 	uint32_t	major;
370 	uint32_t	minor;
371 	uint32_t	max_readahead;
372 	uint32_t	flags;
373 	uint32_t	unused;
374 	uint32_t	max_write;
375 };
376 
377 #define FUSE_CUSE_INIT_INFO_MAX 4096
378 
379 struct fuse_cuse_init_in {
380 	uint32_t	major;
381 	uint32_t	minor;
382 	uint32_t	unused;
383 	uint32_t	flags;
384 };
385 
386 struct fuse_cuse_init_out {
387 	uint32_t	major;
388 	uint32_t	minor;
389 	uint32_t	unused;
390 	uint32_t	flags;
391 	uint32_t	max_read;
392 	uint32_t	max_write;
393 	uint32_t	dev_major;		/* chardev major */
394 	uint32_t	dev_minor;		/* chardev minor */
395 	uint32_t	spare[10];
396 };
397 
398 struct fuse_interrupt_in {
399 	uint64_t	unique;
400 };
401 
402 struct fuse_bmap_in {
403 	uint64_t	block;
404 	uint32_t	blocksize;
405 	uint32_t	padding;
406 };
407 
408 struct fuse_bmap_out {
409 	uint64_t	block;
410 };
411 
412 struct fuse_ioctl_in {
413 	uint64_t	fh;
414 	uint32_t	flags;
415 	uint32_t	cmd;
416 	uint64_t	arg;
417 	uint32_t	in_size;
418 	uint32_t	out_size;
419 };
420 
421 struct fuse_ioctl_out {
422 	int32_t	result;
423 	uint32_t	flags;
424 	uint32_t	in_iovs;
425 	uint32_t	out_iovs;
426 };
427 
428 struct fuse_poll_in {
429 	uint64_t	fh;
430 	uint64_t	kh;
431 	uint32_t	flags;
432 	uint32_t   padding;
433 };
434 
435 struct fuse_poll_out {
436 	uint32_t	revents;
437 	uint32_t	padding;
438 };
439 
440 struct fuse_notify_poll_wakeup_out {
441 	uint64_t	kh;
442 };
443 
444 #if 0 /* Duplicated in perfuse.h to avoid making fuse.h public */
445 /* Send from kernel to proces */
446 struct fuse_in_header {
447 	uint32_t	len;
448 	uint32_t	opcode;
449 	uint64_t	unique;
450 	uint64_t	nodeid;
451 	uint32_t	uid;
452 	uint32_t	gid;
453 	uint32_t	pid;
454 	uint32_t	padding;
455 };
456 
457 struct fuse_in_arg {
458 	uint32_t	size;
459 	const void *value;
460 };
461 
462 struct fuse_in {
463 	struct 		fuse_in_header h;
464 	uint32_t	argpages:1;	/* Req fits in a page? Always 1 */
465 	uint32_t	numargs;
466 	struct fuse_in_arg args[3];	/* args copied to userspace */
467 };
468 
469 
470 /* From process to kernel */
471 struct fuse_out_header {
472 	uint32_t	len;
473 	int32_t	error;
474 	uint64_t	unique;
475 };
476 #endif
477 
478 struct fuse_dirent {
479 	uint64_t	ino;
480 	uint64_t	off;	/* offset of next field from after foh */
481 	uint32_t	namelen;
482 	uint32_t	type;
483 	char name[0];
484 };
485 
486 #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
487 #define FUSE_DIRENT_ALIGN(x) \
488 	(((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
489 #define FUSE_DIRENT_SIZE(d) \
490 	FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
491 
492 struct fuse_notify_inval_inode_out {
493 	uint64_t	ino;
494 	int64_t	off;
495 	int64_t	len;
496 };
497 
498 struct fuse_notify_inval_entry_out {
499 	uint64_t	parent;
500 	uint32_t	namelen;
501 	uint32_t	padding;
502 };
503 
504 #endif /* _FUSE_H */
505