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