1 /*  $NetBSD: fuse.h,v 1.8 2021/09/17 08:13:06 andvar 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 ((size_t)0x21000)
38 #define FUSE_PREF_BUFSIZE ((size_t)(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_NOTIFY_REPLY  = 41,
173           FUSE_BATCH_FORGET  = 42,
174           FUSE_FALLOCATE     = 43,
175           FUSE_OPCODE_MAX,
176 
177           FUSE_CUSE_INIT     = 4096
178 };
179 
180 enum fuse_notify_code {
181           FUSE_NOTIFY_POLL   = 1,
182           FUSE_NOTIFY_INVAL_INODE = 2,
183           FUSE_NOTIFY_INVAL_ENTRY = 3,
184           FUSE_NOTIFY_CODE_MAX
185 };
186 
187 #define FUSE_MIN_READ_BUFFER 8192
188 
189 #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
190 
191 struct fuse_entry_out {
192           uint64_t  nodeid;
193           uint64_t  generation;
194           uint64_t  entry_valid;
195           uint64_t  attr_valid;
196           uint32_t  entry_valid_nsec;
197           uint32_t  attr_valid_nsec;
198           struct fuse_attr attr;
199 };
200 
201 struct fuse_forget_in {
202           uint64_t  nlookup;
203 };
204 
205 struct fuse_getattr_in {
206           uint32_t  getattr_flags;
207           uint32_t  dummy;
208           uint64_t  fh;
209 };
210 
211 #define FUSE_COMPAT_ATTR_OUT_SIZE 96
212 
213 struct fuse_attr_out {
214           uint64_t  attr_valid;
215           uint32_t  attr_valid_nsec;
216           uint32_t  dummy;
217           struct fuse_attr attr;
218 };
219 
220 #define FUSE_COMPAT_MKNOD_IN_SIZE 8
221 
222 struct fuse_mknod_in {
223           uint32_t  mode;
224           uint32_t  rdev;
225           uint32_t  umask;
226           uint32_t  padding;
227 };
228 
229 struct fuse_mkdir_in {
230           uint32_t  mode;
231           uint32_t  umask;
232 };
233 
234 struct fuse_rename_in {
235           uint64_t  newdir;
236 };
237 
238 struct fuse_link_in {
239           uint64_t  oldnodeid;
240 };
241 
242 struct fuse_setattr_in {
243           uint32_t  valid;
244           uint32_t  padding;
245           uint64_t  fh;
246           uint64_t  size;
247           uint64_t  lock_owner;
248           uint64_t  atime;
249           uint64_t  mtime;
250           uint64_t  unused2;
251           uint32_t  atimensec;
252           uint32_t  mtimensec;
253           uint32_t  unused3;
254           uint32_t  mode;
255           uint32_t  unused4;
256           uint32_t  uid;
257           uint32_t  gid;
258           uint32_t  unused5;
259 };
260 
261 struct fuse_open_in {
262           uint32_t  flags;
263           uint32_t  unused;
264 };
265 
266 struct fuse_create_in {
267           uint32_t  flags;
268           uint32_t  mode;
269           uint32_t  umask;
270           uint32_t  padding;
271 };
272 
273 struct fuse_open_out {
274           uint64_t  fh;
275           uint32_t  open_flags; /* FUSE_FOPEN_ */
276           uint32_t  padding;
277 };
278 
279 struct fuse_release_in {
280           uint64_t  fh;
281           uint32_t  flags;
282           uint32_t  release_flags;
283           uint64_t  lock_owner;
284 };
285 
286 struct fuse_flush_in {
287           uint64_t  fh;
288           uint32_t  unused;
289           uint32_t  padding;
290           uint64_t  lock_owner;
291 };
292 
293 struct fuse_read_in {
294           uint64_t  fh;
295           uint64_t  offset;
296           uint32_t  size;
297           uint32_t  read_flags;
298           uint64_t  lock_owner;
299           uint32_t  flags;
300           uint32_t  padding;
301 };
302 
303 #define FUSE_COMPAT_WRITE_IN_SIZE 24
304 
305 struct fuse_write_in {
306           uint64_t  fh;
307           uint64_t  offset;
308           uint32_t  size;
309           uint32_t  write_flags;
310           uint64_t  lock_owner;
311           uint32_t  flags;
312           uint32_t  padding;
313 };
314 
315 struct fuse_write_out {
316           uint32_t  size;
317           uint32_t  padding;
318 };
319 
320 #define FUSE_COMPAT_STATFS_SIZE 48
321 
322 struct fuse_statfs_out {
323           struct fuse_kstatfs st;
324 };
325 
326 struct fuse_fsync_in {
327           uint64_t  fh;
328           uint32_t  fsync_flags;
329           uint32_t  padding;
330 };
331 
332 struct fuse_setxattr_in {
333           uint32_t  size;
334           uint32_t  flags;
335 };
336 
337 struct fuse_getxattr_in {
338           uint32_t  size;
339           uint32_t  padding;
340 };
341 
342 struct fuse_getxattr_out {
343           uint32_t  size;
344           uint32_t  padding;
345 };
346 
347 struct fuse_lk_in {
348           uint64_t  fh;
349           uint64_t  owner;
350           struct fuse_file_lock lk;
351           uint32_t  lk_flags;
352           uint32_t  padding;
353 };
354 
355 struct fuse_lk_out {
356           struct fuse_file_lock lk;
357 };
358 
359 struct fuse_access_in {
360           uint32_t  mask;
361           uint32_t  padding;
362 };
363 
364 struct fuse_init_in {
365           uint32_t  major;
366           uint32_t  minor;
367           uint32_t  max_readahead;
368           uint32_t  flags;
369 };
370 
371 struct fuse_init_out {
372           uint32_t  major;
373           uint32_t  minor;
374           uint32_t  max_readahead;
375           uint32_t  flags;
376           uint32_t  unused;
377           uint32_t  max_write;
378 };
379 
380 #define FUSE_CUSE_INIT_INFO_MAX 4096
381 
382 struct fuse_cuse_init_in {
383           uint32_t  major;
384           uint32_t  minor;
385           uint32_t  unused;
386           uint32_t  flags;
387 };
388 
389 struct fuse_cuse_init_out {
390           uint32_t  major;
391           uint32_t  minor;
392           uint32_t  unused;
393           uint32_t  flags;
394           uint32_t  max_read;
395           uint32_t  max_write;
396           uint32_t  dev_major;                    /* chardev major */
397           uint32_t  dev_minor;                    /* chardev minor */
398           uint32_t  spare[10];
399 };
400 
401 struct fuse_interrupt_in {
402           uint64_t  unique;
403 };
404 
405 struct fuse_bmap_in {
406           uint64_t  block;
407           uint32_t  blocksize;
408           uint32_t  padding;
409 };
410 
411 struct fuse_bmap_out {
412           uint64_t  block;
413 };
414 
415 struct fuse_ioctl_in {
416           uint64_t  fh;
417           uint32_t  flags;
418           uint32_t  cmd;
419           uint64_t  arg;
420           uint32_t  in_size;
421           uint32_t  out_size;
422 };
423 
424 struct fuse_ioctl_out {
425           int32_t   result;
426           uint32_t  flags;
427           uint32_t  in_iovs;
428           uint32_t  out_iovs;
429 };
430 
431 struct fuse_poll_in {
432           uint64_t  fh;
433           uint64_t  kh;
434           uint32_t  flags;
435           uint32_t   padding;
436 };
437 
438 struct fuse_poll_out {
439           uint32_t  revents;
440           uint32_t  padding;
441 };
442 
443 struct fuse_notify_poll_wakeup_out {
444           uint64_t  kh;
445 };
446 
447 struct fuse_fallocate_in {
448           uint64_t  fh;
449           uint64_t  offset;
450           uint64_t  length;
451           uint32_t  mode;
452           uint32_t  padding;
453 };
454 
455 #if 0 /* Duplicated in perfuse.h to avoid making fuse.h public */
456 /* Send from kernel to process */
457 struct fuse_in_header {
458           uint32_t  len;
459           uint32_t  opcode;
460           uint64_t  unique;
461           uint64_t  nodeid;
462           uint32_t  uid;
463           uint32_t  gid;
464           uint32_t  pid;
465           uint32_t  padding;
466 };
467 
468 struct fuse_in_arg {
469           uint32_t  size;
470           const void *value;
471 };
472 
473 struct fuse_in {
474           struct              fuse_in_header h;
475           uint32_t  argpages:1;         /* Req fits in a page? Always 1 */
476           uint32_t  numargs;
477           struct fuse_in_arg args[3];   /* args copied to userspace */
478 };
479 
480 
481 /* From process to kernel */
482 struct fuse_out_header {
483           uint32_t  len;
484           int32_t   error;
485           uint64_t  unique;
486 };
487 #endif
488 
489 struct fuse_dirent {
490           uint64_t  ino;
491           uint64_t  off;      /* offset of next field from after foh */
492           uint32_t  namelen;
493           uint32_t  type;
494           char name[0];
495 };
496 
497 #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
498 #define FUSE_DIRENT_ALIGN(x) \
499           (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
500 #define FUSE_DIRENT_SIZE(d) \
501           FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
502 
503 struct fuse_notify_inval_inode_out {
504           uint64_t  ino;
505           int64_t   off;
506           int64_t   len;
507 };
508 
509 struct fuse_notify_inval_entry_out {
510           uint64_t  parent;
511           uint32_t  namelen;
512           uint32_t  padding;
513 };
514 
515 #endif /* _FUSE_H */
516