fuse_kernel.h revision 253344
1/*-
2 * This file defines the kernel interface of FUSE
3 * Copyright (C) 2001-2007  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 * This -- and only this -- header file may also be distributed under
9 * the terms of the BSD Licence as follows:
10 *
11 * Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $FreeBSD: head/sys/fs/fuse/fuse_kernel.h 253344 2013-07-15 00:05:27Z pfg $
35 */
36
37/*
38 * This file defines the kernel interface of FUSE
39 *
40 * Protocol changelog:
41 *
42 * 7.9:
43 *  - new fuse_getattr_in input argument of GETATTR
44 *  - add lk_flags in fuse_lk_in
45 *  - add lock_owner field to fuse_setattr_in, fuse_read_in and fuse_write_in
46 *  - add blksize field to fuse_attr
47 *  - add file flags field to fuse_read_in and fuse_write_in
48 *
49 * 7.10
50 *  - add nonseekable open flag
51 */
52
53#ifndef _FS_FUSE_FUSE_KERNEL_H_
54#define _FS_FUSE_FUSE_KERNEL_H_
55
56#ifndef linux
57#include <sys/types.h>
58#define __u64 uint64_t
59#define __u32 uint32_t
60#define __s32 int32_t
61#else
62#include <linux/types.h>
63#endif
64
65/** Version number of this interface */
66#define FUSE_KERNEL_VERSION 7
67
68/** Minor version number of this interface */
69#define FUSE_KERNEL_MINOR_VERSION 8
70
71/** The node ID of the root inode */
72#define FUSE_ROOT_ID 1
73
74/* Make sure all structures are padded to 64bit boundary, so 32bit
75   userspace works under 64bit kernels */
76
77struct fuse_attr {
78	__u64	ino;
79	__u64	size;
80	__u64	blocks;
81	__u64	atime;
82	__u64	mtime;
83	__u64	ctime;
84	__u64	crtime;
85	__u32	atimensec;
86	__u32	mtimensec;
87	__u32	ctimensec;
88	__u32	crtimensec;
89	__u32	mode;
90	__u32	nlink;
91	__u32	uid;
92	__u32	gid;
93	__u32	rdev;
94	__u32	blksize;
95};
96
97struct fuse_kstatfs {
98	__u64	blocks;
99	__u64	bfree;
100	__u64	bavail;
101	__u64	files;
102	__u64	ffree;
103	__u32	bsize;
104	__u32	namelen;
105	__u32	frsize;
106	__u32	padding;
107	__u32	spare[6];
108};
109
110struct fuse_file_lock {
111	__u64	start;
112	__u64	end;
113	__u32	type;
114	__u32	pid; /* tgid */
115};
116
117/**
118 * Bitmasks for fuse_setattr_in.valid
119 */
120#define FATTR_MODE	(1 << 0)
121#define FATTR_UID	(1 << 1)
122#define FATTR_GID	(1 << 2)
123#define FATTR_SIZE	(1 << 3)
124#define FATTR_ATIME	(1 << 4)
125#define FATTR_MTIME	(1 << 5)
126#define FATTR_FH	(1 << 6)
127#define FATTR_ATIME_NOW	(1 << 7)
128#define FATTR_MTIME_NOW	(1 << 8)
129#define FATTR_LOCKOWNER	(1 << 9)
130
131/**
132 * Flags returned by the OPEN request
133 *
134 * FOPEN_DIRECT_IO: bypass page cache for this open file
135 * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
136 * FOPEN_NONSEEKABLE: the file is not seekable
137 */
138#define FOPEN_DIRECT_IO		(1 << 0)
139#define FOPEN_KEEP_CACHE	(1 << 1)
140#define FOPEN_NONSEEKABLE	(1 << 2)
141
142/**
143 * INIT request/reply flags
144 *
145 * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
146 */
147#define FUSE_ASYNC_READ		(1 << 0)
148#define FUSE_POSIX_LOCKS	(1 << 1)
149#define FUSE_FILE_OPS		(1 << 2)
150#define FUSE_ATOMIC_O_TRUNC	(1 << 3)
151#define FUSE_EXPORT_SUPPORT	(1 << 4)
152#define FUSE_BIG_WRITES		(1 << 5)
153
154/**
155 * Release flags
156 */
157#define FUSE_RELEASE_FLUSH	(1 << 0)
158
159/**
160 * Getattr flags
161 */
162#define FUSE_GETATTR_FH		(1 << 0)
163
164/**
165 * Lock flags
166 */
167#define FUSE_LK_FLOCK		(1 << 0)
168
169/**
170 * WRITE flags
171 *
172 * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed
173 * FUSE_WRITE_LOCKOWNER: lock_owner field is valid
174 */
175#define FUSE_WRITE_CACHE	(1 << 0)
176#define FUSE_WRITE_LOCKOWNER	(1 << 1)
177
178/**
179 * Read flags
180 */
181#define FUSE_READ_LOCKOWNER	(1 << 1)
182
183enum fuse_opcode {
184	FUSE_LOOKUP	   = 1,
185	FUSE_FORGET	   = 2,  /* no reply */
186	FUSE_GETATTR	   = 3,
187	FUSE_SETATTR	   = 4,
188	FUSE_READLINK	   = 5,
189	FUSE_SYMLINK	   = 6,
190	FUSE_MKNOD	   = 8,
191	FUSE_MKDIR	   = 9,
192	FUSE_UNLINK	   = 10,
193	FUSE_RMDIR	   = 11,
194	FUSE_RENAME	   = 12,
195	FUSE_LINK	   = 13,
196	FUSE_OPEN	   = 14,
197	FUSE_READ	   = 15,
198	FUSE_WRITE	   = 16,
199	FUSE_STATFS	   = 17,
200	FUSE_RELEASE       = 18,
201	FUSE_FSYNC         = 20,
202	FUSE_SETXATTR      = 21,
203	FUSE_GETXATTR      = 22,
204	FUSE_LISTXATTR     = 23,
205	FUSE_REMOVEXATTR   = 24,
206	FUSE_FLUSH         = 25,
207	FUSE_INIT          = 26,
208	FUSE_OPENDIR       = 27,
209	FUSE_READDIR       = 28,
210	FUSE_RELEASEDIR    = 29,
211	FUSE_FSYNCDIR      = 30,
212	FUSE_GETLK         = 31,
213	FUSE_SETLK         = 32,
214	FUSE_SETLKW        = 33,
215	FUSE_ACCESS        = 34,
216	FUSE_CREATE        = 35,
217	FUSE_INTERRUPT     = 36,
218	FUSE_BMAP          = 37,
219	FUSE_DESTROY       = 38,
220};
221
222/* The read buffer is required to be at least 8k, but may be much larger */
223#define FUSE_MIN_READ_BUFFER 8192
224
225#define FUSE_COMPAT_ENTRY_OUT_SIZE 120
226
227struct fuse_entry_out {
228	__u64	nodeid;		/* Inode ID */
229	__u64	generation;	/* Inode generation: nodeid:gen must
230				   be unique for the fs's lifetime */
231	__u64	entry_valid;	/* Cache timeout for the name */
232	__u64	attr_valid;	/* Cache timeout for the attributes */
233	__u32	entry_valid_nsec;
234	__u32	attr_valid_nsec;
235	struct fuse_attr attr;
236};
237
238struct fuse_forget_in {
239	__u64	nlookup;
240};
241
242struct fuse_getattr_in {
243	__u32	getattr_flags;
244	__u32	dummy;
245	__u64	fh;
246};
247
248#define FUSE_COMPAT_ATTR_OUT_SIZE 96
249
250struct fuse_attr_out {
251	__u64	attr_valid;	/* Cache timeout for the attributes */
252	__u32	attr_valid_nsec;
253	__u32	dummy;
254	struct fuse_attr attr;
255};
256
257struct fuse_mknod_in {
258	__u32	mode;
259	__u32	rdev;
260};
261
262struct fuse_mkdir_in {
263	__u32	mode;
264	__u32	padding;
265};
266
267struct fuse_rename_in {
268	__u64	newdir;
269};
270
271struct fuse_link_in {
272	__u64	oldnodeid;
273};
274
275struct fuse_setattr_in {
276	__u32	valid;
277	__u32	padding;
278	__u64	fh;
279	__u64	size;
280	__u64	lock_owner;
281	__u64	atime;
282	__u64	mtime;
283	__u64	unused2;
284	__u32	atimensec;
285	__u32	mtimensec;
286	__u32	unused3;
287	__u32	mode;
288	__u32	unused4;
289	__u32	uid;
290	__u32	gid;
291	__u32	unused5;
292};
293
294struct fuse_open_in {
295	__u32	flags;
296	__u32	mode;
297};
298
299struct fuse_open_out {
300	__u64	fh;
301	__u32	open_flags;
302	__u32	padding;
303};
304
305struct fuse_release_in {
306	__u64	fh;
307	__u32	flags;
308	__u32	release_flags;
309	__u64	lock_owner;
310};
311
312struct fuse_flush_in {
313	__u64	fh;
314	__u32	unused;
315	__u32	padding;
316	__u64	lock_owner;
317};
318
319struct fuse_read_in {
320	__u64	fh;
321	__u64	offset;
322	__u32	size;
323	__u32	read_flags;
324	__u64	lock_owner;
325	__u32	flags;
326	__u32	padding;
327};
328
329#define FUSE_COMPAT_WRITE_IN_SIZE 24
330
331struct fuse_write_in {
332	__u64	fh;
333	__u64	offset;
334	__u32	size;
335	__u32	write_flags;
336	__u64	lock_owner;
337	__u32	flags;
338	__u32	padding;
339};
340
341struct fuse_write_out {
342	__u32	size;
343	__u32	padding;
344};
345
346#define FUSE_COMPAT_STATFS_SIZE 48
347
348struct fuse_statfs_out {
349	struct fuse_kstatfs st;
350};
351
352struct fuse_fsync_in {
353	__u64	fh;
354	__u32	fsync_flags;
355	__u32	padding;
356};
357
358struct fuse_setxattr_in {
359	__u32	size;
360	__u32	flags;
361};
362
363struct fuse_getxattr_in {
364	__u32	size;
365	__u32	padding;
366};
367
368struct fuse_getxattr_out {
369	__u32	size;
370	__u32	padding;
371};
372
373struct fuse_lk_in {
374	__u64	fh;
375	__u64	owner;
376	struct fuse_file_lock lk;
377	__u32	lk_flags;
378	__u32	padding;
379};
380
381struct fuse_lk_out {
382	struct fuse_file_lock lk;
383};
384
385struct fuse_access_in {
386	__u32	mask;
387	__u32	padding;
388};
389
390struct fuse_init_in {
391	__u32	major;
392	__u32	minor;
393	__u32	max_readahead;
394	__u32	flags;
395};
396
397struct fuse_init_out {
398	__u32	major;
399	__u32	minor;
400	__u32	max_readahead;
401	__u32	flags;
402	__u32	unused;
403	__u32	max_write;
404};
405
406struct fuse_interrupt_in {
407	__u64	unique;
408};
409
410struct fuse_bmap_in {
411	__u64	block;
412	__u32	blocksize;
413	__u32	padding;
414};
415
416struct fuse_bmap_out {
417	__u64	block;
418};
419
420struct fuse_in_header {
421	__u32	len;
422	__u32	opcode;
423	__u64	unique;
424	__u64	nodeid;
425	__u32	uid;
426	__u32	gid;
427	__u32	pid;
428	__u32	padding;
429};
430
431struct fuse_out_header {
432	__u32	len;
433	__s32	error;
434	__u64	unique;
435};
436
437struct fuse_dirent {
438	__u64	ino;
439	__u64	off;
440	__u32	namelen;
441	__u32	type;
442	char name[];
443};
444
445#define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
446#define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
447#define FUSE_DIRENT_SIZE(d) \
448	FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
449
450#endif	/* !_FS_FUSE_FUSE_KERNEL_H_ */
451