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