Coverage Report

Created: 2026-01-10 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfuse/include/fuse_lowlevel.h
Line
Count
Source
1
/*
2
  FUSE: Filesystem in Userspace
3
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
4
5
  This program can be distributed under the terms of the GNU LGPLv2.
6
  See the file LGPL2.txt.
7
*/
8
9
#ifndef FUSE_LOWLEVEL_H_
10
#define FUSE_LOWLEVEL_H_
11
12
/** @file
13
 *
14
 * Low level API
15
 *
16
 * IMPORTANT: you should define FUSE_USE_VERSION before including this
17
 * header.  To use the newest API define it to 35 (recommended for any
18
 * new application).
19
 */
20
21
#ifndef FUSE_USE_VERSION
22
#error FUSE_USE_VERSION not defined
23
#endif
24
25
#include "fuse_common.h"
26
27
#include <stddef.h>
28
#include <utime.h>
29
#include <fcntl.h>
30
#include <sys/types.h>
31
#include <sys/stat.h>
32
#include <sys/statvfs.h>
33
#include <sys/uio.h>
34
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
39
/* ----------------------------------------------------------- *
40
 * Miscellaneous definitions               *
41
 * ----------------------------------------------------------- */
42
43
/** The node ID of the root inode */
44
#define FUSE_ROOT_ID 1
45
46
/** Inode number type */
47
typedef uint64_t fuse_ino_t;
48
49
/** Request pointer type */
50
typedef struct fuse_req *fuse_req_t;
51
52
/* Forward declaration */
53
struct statx;
54
55
/**
56
 * Session
57
 *
58
 * This provides hooks for processing requests, and exiting
59
 */
60
struct fuse_session;
61
62
/** Directory entry parameters supplied to fuse_reply_entry() */
63
struct fuse_entry_param {
64
  /** Unique inode number
65
   *
66
   * In lookup, zero means negative entry (from version 2.5)
67
   * Returning ENOENT also means negative entry, but by setting zero
68
   * ino the kernel may cache negative entries for entry_timeout
69
   * seconds.
70
   */
71
  fuse_ino_t ino;
72
73
  /** Generation number for this entry.
74
   *
75
   * If the file system will be exported over NFS, the
76
   * ino/generation pairs need to be unique over the file
77
   * system's lifetime (rather than just the mount time). So if
78
   * the file system reuses an inode after it has been deleted,
79
   * it must assign a new, previously unused generation number
80
   * to the inode at the same time.
81
   *
82
   */
83
  uint64_t generation;
84
85
  /** Inode attributes.
86
   *
87
   * Even if attr_timeout == 0, attr must be correct. For example,
88
   * for open(), FUSE uses attr.st_size from lookup() to determine
89
   * how many bytes to request. If this value is not correct,
90
   * incorrect data will be returned.
91
   */
92
  struct stat attr;
93
94
  /** Validity timeout (in seconds) for inode attributes. If
95
      attributes only change as a result of requests that come
96
      through the kernel, this should be set to a very large
97
      value. */
98
  double attr_timeout;
99
100
  /** Validity timeout (in seconds) for the name. If directory
101
      entries are changed/deleted only as a result of requests
102
      that come through the kernel, this should be set to a very
103
      large value. */
104
  double entry_timeout;
105
};
106
107
/**
108
 * Additional context associated with requests.
109
 *
110
 * Note that the reported client uid, gid and pid may be zero in some
111
 * situations. For example, if the FUSE file system is running in a
112
 * PID or user namespace but then accessed from outside the namespace,
113
 * there is no valid uid/pid/gid that could be reported.
114
 */
115
struct fuse_ctx {
116
  /** User ID of the calling process */
117
  uid_t uid;
118
119
  /** Group ID of the calling process */
120
  gid_t gid;
121
122
  /** Thread ID of the calling process */
123
  pid_t pid;
124
125
  /** Umask of the calling process */
126
  mode_t umask;
127
};
128
129
struct fuse_forget_data {
130
  fuse_ino_t ino;
131
  uint64_t nlookup;
132
};
133
134
struct fuse_custom_io {
135
  ssize_t (*writev)(int fd, struct iovec *iov, int count, void *userdata);
136
  ssize_t (*read)(int fd, void *buf, size_t buf_len, void *userdata);
137
  ssize_t (*splice_receive)(int fdin, off_t *offin, int fdout,
138
            off_t *offout, size_t len,
139
              unsigned int flags, void *userdata);
140
  ssize_t (*splice_send)(int fdin, off_t *offin, int fdout,
141
             off_t *offout, size_t len,
142
                 unsigned int flags, void *userdata);
143
  int (*clone_fd)(int master_fd);
144
};
145
146
/**
147
 * Flags for fuse_lowlevel_notify_entry()
148
 * 0 = invalidate entry
149
 * FUSE_LL_EXPIRE_ONLY = expire entry
150
*/
151
enum fuse_notify_entry_flags {
152
  FUSE_LL_INVALIDATE = 0,
153
  FUSE_LL_EXPIRE_ONLY = (1 << 0),
154
};
155
156
/* 'to_set' flags in setattr */
157
#define FUSE_SET_ATTR_MODE  (1 << 0)
158
#define FUSE_SET_ATTR_UID (1 << 1)
159
#define FUSE_SET_ATTR_GID (1 << 2)
160
#define FUSE_SET_ATTR_SIZE  (1 << 3)
161
#define FUSE_SET_ATTR_ATIME (1 << 4)
162
#define FUSE_SET_ATTR_MTIME (1 << 5)
163
#define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
164
#define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
165
#define FUSE_SET_ATTR_FORCE (1 << 9)
166
#define FUSE_SET_ATTR_CTIME (1 << 10)
167
#define FUSE_SET_ATTR_KILL_SUID (1 << 11)
168
#define FUSE_SET_ATTR_KILL_SGID (1 << 12)
169
#define FUSE_SET_ATTR_FILE  (1 << 13)
170
#define FUSE_SET_ATTR_KILL_PRIV (1 << 14)
171
#define FUSE_SET_ATTR_OPEN  (1 << 15)
172
#define FUSE_SET_ATTR_TIMES_SET (1 << 16)
173
#define FUSE_SET_ATTR_TOUCH (1 << 17)
174
175
/* ----------------------------------------------------------- *
176
 * Request methods and replies               *
177
 * ----------------------------------------------------------- */
178
179
/**
180
 * Low level filesystem operations
181
 *
182
 * Most of the methods (with the exception of init and destroy)
183
 * receive a request handle (fuse_req_t) as their first argument.
184
 * This handle must be passed to one of the specified reply functions.
185
 *
186
 * This may be done inside the method invocation, or after the call
187
 * has returned.  The request handle is valid until one of the reply
188
 * functions is called.
189
 *
190
 * Other pointer arguments (name, fuse_file_info, etc) are not valid
191
 * after the call has returned, so if they are needed later, their
192
 * contents have to be copied.
193
 *
194
 * In general, all methods are expected to perform any necessary
195
 * permission checking. However, a filesystem may delegate this task
196
 * to the kernel by passing the `default_permissions` mount option to
197
 * `fuse_session_new()`. In this case, methods will only be called if
198
 * the kernel's permission check has succeeded.
199
 *
200
 * It is generally not really necessary to check the fuse_reply_* return
201
 * values for errors, as any error in sending a reply indicates an
202
 * unrecoverable problem with the kernel fuse connection, which will also
203
 * terminate the session loop anyway.
204
 *
205
 * This data structure is ABI sensitive, on adding new functions these need to
206
 * be appended at the end of the struct
207
 */
208
struct fuse_lowlevel_ops {
209
  /**
210
   * Initialize filesystem
211
   *
212
   * This function is called when libfuse establishes
213
   * communication with the FUSE kernel module. The file system
214
   * should use this module to inspect and/or modify the
215
   * connection parameters provided in the `conn` structure.
216
   *
217
   * Note that some parameters may be overwritten by options
218
   * passed to fuse_session_new() which take precedence over the
219
   * values set in this handler.
220
   *
221
   * There's no reply to this function
222
   *
223
   * @param userdata the user data passed to fuse_session_new()
224
   */
225
  void (*init) (void *userdata, struct fuse_conn_info *conn);
226
227
  /**
228
   * Clean up filesystem.
229
   *
230
   * Called on filesystem exit. When this method is called, the
231
   * connection to the kernel may be gone already, so that eg. calls
232
   * to fuse_lowlevel_notify_* will fail.
233
   *
234
   * There's no reply to this function
235
   *
236
   * @param userdata the user data passed to fuse_session_new()
237
   */
238
  void (*destroy) (void *userdata);
239
240
  /**
241
   * Look up a directory entry by name and get its attributes.
242
   *
243
   * Valid replies:
244
   *   fuse_reply_entry
245
   *   fuse_reply_err
246
   *
247
   * @param req request handle
248
   * @param parent inode number of the parent directory
249
   * @param name the name to look up
250
   */
251
  void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
252
253
  /**
254
   * Forget about an inode
255
   *
256
   * This function is called when the kernel removes an inode
257
   * from its internal caches.
258
   *
259
   * The inode's lookup count increases by one for every call to
260
   * fuse_reply_entry and fuse_reply_create. The nlookup parameter
261
   * indicates by how much the lookup count should be decreased.
262
   *
263
   * Inodes with a non-zero lookup count may receive request from
264
   * the kernel even after calls to unlink, rmdir or (when
265
   * overwriting an existing file) rename. Filesystems must handle
266
   * such requests properly and it is recommended to defer removal
267
   * of the inode until the lookup count reaches zero. Calls to
268
   * unlink, rmdir or rename will be followed closely by forget
269
   * unless the file or directory is open, in which case the
270
   * kernel issues forget only after the release or releasedir
271
   * calls.
272
   *
273
   * Note that if a file system will be exported over NFS the
274
   * inodes lifetime must extend even beyond forget. See the
275
   * generation field in struct fuse_entry_param above.
276
   *
277
   * On unmount the lookup count for all inodes implicitly drops
278
   * to zero. It is not guaranteed that the file system will
279
   * receive corresponding forget messages for the affected
280
   * inodes.
281
   *
282
   * Valid replies:
283
   *   fuse_reply_none
284
   *
285
   * @param req request handle
286
   * @param ino the inode number
287
   * @param nlookup the number of lookups to forget
288
   */
289
  void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
290
291
  /**
292
   * Get file attributes.
293
   *
294
   * If writeback caching is enabled, the kernel may have a
295
   * better idea of a file's length than the FUSE file system
296
   * (eg if there has been a write that extended the file size,
297
   * but that has not yet been passed to the filesystem.
298
   *
299
   * In this case, the st_size value provided by the file system
300
   * will be ignored.
301
   *
302
   * Valid replies:
303
   *   fuse_reply_attr
304
   *   fuse_reply_err
305
   *
306
   * @param req request handle
307
   * @param ino the inode number
308
   * @param fi file information, or NULL
309
   */
310
  void (*getattr) (fuse_req_t req, fuse_ino_t ino,
311
       struct fuse_file_info *fi);
312
313
  /**
314
   * Set file attributes
315
   *
316
   * In the 'attr' argument only members indicated by the 'to_set'
317
   * bitmask contain valid values.  Other members contain undefined
318
   * values.
319
   *
320
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
321
   * expected to reset the setuid and setgid bits if the file
322
   * size or owner is being changed.
323
   *
324
   * This method will not be called to update st_atime or st_ctime implicitly
325
   * (eg. after a read() request), and only be called to implicitly update st_mtime
326
   * if writeback caching is active. It is the filesystem's responsibility to update
327
   * these timestamps when needed, and (if desired) to implement mount options like
328
   * `noatime` or `relatime`.
329
   *
330
   * If the setattr was invoked from the ftruncate() system call
331
   * under Linux kernel versions 2.6.15 or later, the fi->fh will
332
   * contain the value set by the open method or will be undefined
333
   * if the open method didn't set any value.  Otherwise (not
334
   * ftruncate call, or kernel version earlier than 2.6.15) the fi
335
   * parameter will be NULL.
336
   *
337
   * Valid replies:
338
   *   fuse_reply_attr
339
   *   fuse_reply_err
340
   *
341
   * @param req request handle
342
   * @param ino the inode number
343
   * @param attr the attributes
344
   * @param to_set bit mask of attributes which should be set
345
   * @param fi file information, or NULL
346
   */
347
  void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
348
       int to_set, struct fuse_file_info *fi);
349
350
  /**
351
   * Read symbolic link
352
   *
353
   * Valid replies:
354
   *   fuse_reply_readlink
355
   *   fuse_reply_err
356
   *
357
   * @param req request handle
358
   * @param ino the inode number
359
   */
360
  void (*readlink) (fuse_req_t req, fuse_ino_t ino);
361
362
  /**
363
   * Create file node
364
   *
365
   * Create a regular file, character device, block device, fifo or
366
   * socket node.
367
   *
368
   * Valid replies:
369
   *   fuse_reply_entry
370
   *   fuse_reply_err
371
   *
372
   * @param req request handle
373
   * @param parent inode number of the parent directory
374
   * @param name to create
375
   * @param mode file type and mode with which to create the new file
376
   * @param rdev the device number (only valid if created file is a device)
377
   */
378
  void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
379
           mode_t mode, dev_t rdev);
380
381
  /**
382
   * Create a directory
383
   *
384
   * Valid replies:
385
   *   fuse_reply_entry
386
   *   fuse_reply_err
387
   *
388
   * @param req request handle
389
   * @param parent inode number of the parent directory
390
   * @param name to create
391
   * @param mode with which to create the new file
392
   */
393
  void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
394
           mode_t mode);
395
396
  /**
397
   * Remove a file
398
   *
399
   * If the file's inode's lookup count is non-zero, the file
400
   * system is expected to postpone any removal of the inode
401
   * until the lookup count reaches zero (see description of the
402
   * forget function).
403
   *
404
   * Valid replies:
405
   *   fuse_reply_err
406
   *
407
   * @param req request handle
408
   * @param parent inode number of the parent directory
409
   * @param name to remove
410
   */
411
  void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
412
413
  /**
414
   * Remove a directory
415
   *
416
   * If the directory's inode's lookup count is non-zero, the
417
   * file system is expected to postpone any removal of the
418
   * inode until the lookup count reaches zero (see description
419
   * of the forget function).
420
   *
421
   * Valid replies:
422
   *   fuse_reply_err
423
   *
424
   * @param req request handle
425
   * @param parent inode number of the parent directory
426
   * @param name to remove
427
   */
428
  void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
429
430
  /**
431
   * Create a symbolic link
432
   *
433
   * Valid replies:
434
   *   fuse_reply_entry
435
   *   fuse_reply_err
436
   *
437
   * @param req request handle
438
   * @param link the contents of the symbolic link
439
   * @param parent inode number of the parent directory
440
   * @param name to create
441
   */
442
  void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
443
       const char *name);
444
445
  /** Rename a file
446
   *
447
   * If the target exists it should be atomically replaced. If
448
   * the target's inode's lookup count is non-zero, the file
449
   * system is expected to postpone any removal of the inode
450
   * until the lookup count reaches zero (see description of the
451
   * forget function).
452
   *
453
   * If this request is answered with an error code of ENOSYS, this is
454
   * treated as a permanent failure with error code EINVAL, i.e. all
455
   * future rename requests will fail with EINVAL without being
456
   * send to the filesystem process.
457
   *
458
   * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
459
   * RENAME_NOREPLACE is specified, the filesystem must not
460
   * overwrite *newname* if it exists and return an error
461
   * instead. If `RENAME_EXCHANGE` is specified, the filesystem
462
   * must atomically exchange the two files, i.e. both must
463
   * exist and neither may be deleted.
464
   *
465
   * Valid replies:
466
   *   fuse_reply_err
467
   *
468
   * @param req request handle
469
   * @param parent inode number of the old parent directory
470
   * @param name old name
471
   * @param newparent inode number of the new parent directory
472
   * @param newname new name
473
   */
474
  void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
475
      fuse_ino_t newparent, const char *newname,
476
      unsigned int flags);
477
478
  /**
479
   * Create a hard link
480
   *
481
   * Valid replies:
482
   *   fuse_reply_entry
483
   *   fuse_reply_err
484
   *
485
   * @param req request handle
486
   * @param ino the old inode number
487
   * @param newparent inode number of the new parent directory
488
   * @param newname new name to create
489
   */
490
  void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
491
          const char *newname);
492
493
  /**
494
   * Open a file
495
   *
496
   * Open flags are available in fi->flags. The following rules
497
   * apply.
498
   *
499
   *  - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
500
   *    filtered out / handled by the kernel.
501
   *
502
   *  - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
503
   *    by the filesystem to check if the operation is
504
   *    permitted.  If the ``-o default_permissions`` mount
505
   *    option is given, this check is already done by the
506
   *    kernel before calling open() and may thus be omitted by
507
   *    the filesystem.
508
   *
509
   *  - When writeback caching is enabled, the kernel may send
510
   *    read requests even for files opened with O_WRONLY. The
511
   *    filesystem should be prepared to handle this.
512
   *
513
   *  - When writeback caching is disabled, the filesystem is
514
   *    expected to properly handle the O_APPEND flag and ensure
515
   *    that each write is appending to the end of the file.
516
   *
517
   *  - When writeback caching is enabled, the kernel will
518
   *    handle O_APPEND. However, unless all changes to the file
519
   *    come through the kernel this will not work reliably. The
520
   *    filesystem should thus either ignore the O_APPEND flag
521
   *    (and let the kernel handle it), or return an error
522
   *    (indicating that reliably O_APPEND is not available).
523
   *
524
   * Filesystem may store an arbitrary file handle (pointer,
525
   * index, etc) in fi->fh, and use this in other all other file
526
   * operations (read, write, flush, release, fsync).
527
   *
528
   * Filesystem may also implement stateless file I/O and not store
529
   * anything in fi->fh.
530
   *
531
   * There are also some flags (direct_io, keep_cache) which the
532
   * filesystem may set in fi, to change the way the file is opened.
533
   * See fuse_file_info structure in <fuse_common.h> for more details.
534
   *
535
   * If this request is answered with an error code of ENOSYS
536
   * and FUSE_CAP_NO_OPEN_SUPPORT is set in
537
   * `fuse_conn_info.capable`, this is treated as success and
538
   * future calls to open and release will also succeed without being
539
   * sent to the filesystem process.
540
   *
541
   * To get this behavior without providing an opendir handler, you may
542
   * set FUSE_CAP_NO_OPEN_SUPPORT in `fuse_conn_info.want` on supported
543
   * kernels to automatically get the zero message open().
544
   *
545
   * If this callback is not provided and FUSE_CAP_NO_OPEN_SUPPORT is not
546
   * set in `fuse_conn_info.want` then an empty reply will be sent.
547
   *
548
   * Valid replies:
549
   *   fuse_reply_open
550
   *   fuse_reply_err
551
   *
552
   * @param req request handle
553
   * @param ino the inode number
554
   * @param fi file information
555
   */
556
  void (*open) (fuse_req_t req, fuse_ino_t ino,
557
          struct fuse_file_info *fi);
558
559
  /**
560
   * Read data
561
   *
562
   * Read should send exactly the number of bytes requested except
563
   * on EOF or error, otherwise the rest of the data will be
564
   * substituted with zeroes.  An exception to this is when the file
565
   * has been opened in 'direct_io' mode, in which case the return
566
   * value of the read system call will reflect the return value of
567
   * this operation.
568
   *
569
   * fi->fh will contain the value set by the open method, or will
570
   * be undefined if the open method didn't set any value.
571
   *
572
   * Valid replies:
573
   *   fuse_reply_buf
574
   *   fuse_reply_iov
575
   *   fuse_reply_data
576
   *   fuse_reply_err
577
   *
578
   * @param req request handle
579
   * @param ino the inode number
580
   * @param size number of bytes to read
581
   * @param off offset to read from
582
   * @param fi file information
583
   */
584
  void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
585
          struct fuse_file_info *fi);
586
587
  /**
588
   * Write data
589
   *
590
   * Write should return exactly the number of bytes requested
591
   * except on error.  An exception to this is when the file has
592
   * been opened in 'direct_io' mode, in which case the return value
593
   * of the write system call will reflect the return value of this
594
   * operation.
595
   *
596
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
597
   * expected to reset the setuid and setgid bits.
598
   *
599
   * fi->fh will contain the value set by the open method, or will
600
   * be undefined if the open method didn't set any value.
601
   *
602
   * Valid replies:
603
   *   fuse_reply_write
604
   *   fuse_reply_err
605
   *
606
   * @param req request handle
607
   * @param ino the inode number
608
   * @param buf data to write
609
   * @param size number of bytes to write
610
   * @param off offset to write to
611
   * @param fi file information
612
   */
613
  void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
614
           size_t size, off_t off, struct fuse_file_info *fi);
615
616
  /**
617
   * Flush method
618
   *
619
   * This is called on each close() of the opened file.
620
   *
621
   * Since file descriptors can be duplicated (dup, dup2, fork), for
622
   * one open call there may be many flush calls.
623
   *
624
   * Filesystems shouldn't assume that flush will always be called
625
   * after some writes, or that if will be called at all.
626
   *
627
   * fi->fh will contain the value set by the open method, or will
628
   * be undefined if the open method didn't set any value.
629
   *
630
   * NOTE: the name of the method is misleading, since (unlike
631
   * fsync) the filesystem is not forced to flush pending writes.
632
   * One reason to flush data is if the filesystem wants to return
633
   * write errors during close.  However, such use is non-portable
634
   * because POSIX does not require [close] to wait for delayed I/O to
635
   * complete.
636
   *
637
   * If the filesystem supports file locking operations (setlk,
638
   * getlk) it should remove all locks belonging to 'fi->owner'.
639
   *
640
   * If this request is answered with an error code of ENOSYS,
641
   * this is treated as success and future calls to flush() will
642
   * succeed automatically without being send to the filesystem
643
   * process.
644
   *
645
   * Valid replies:
646
   *   fuse_reply_err
647
   *
648
   * @param req request handle
649
   * @param ino the inode number
650
   * @param fi file information
651
   *
652
   * [close]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
653
   */
654
  void (*flush) (fuse_req_t req, fuse_ino_t ino,
655
           struct fuse_file_info *fi);
656
657
  /**
658
   * Release an open file
659
   *
660
   * Release is called when there are no more references to an open
661
   * file: all file descriptors are closed and all memory mappings
662
   * are unmapped.
663
   *
664
   * For every open call there will be exactly one release call (unless
665
   * the filesystem is force-unmounted).
666
   *
667
   * The filesystem may reply with an error, but error values are
668
   * not returned to close() or munmap() which triggered the
669
   * release.
670
   *
671
   * fi->fh will contain the value set by the open method, or will
672
   * be undefined if the open method didn't set any value.
673
   * fi->flags will contain the same flags as for open.
674
   *
675
   * Valid replies:
676
   *   fuse_reply_err
677
   *
678
   * @param req request handle
679
   * @param ino the inode number
680
   * @param fi file information
681
   */
682
  void (*release) (fuse_req_t req, fuse_ino_t ino,
683
       struct fuse_file_info *fi);
684
685
  /**
686
   * Synchronize file contents
687
   *
688
   * If the datasync parameter is non-zero, then only the user data
689
   * should be flushed, not the meta data.
690
   *
691
   * If this request is answered with an error code of ENOSYS,
692
   * this is treated as success and future calls to fsync() will
693
   * succeed automatically without being send to the filesystem
694
   * process.
695
   *
696
   * Valid replies:
697
   *   fuse_reply_err
698
   *
699
   * @param req request handle
700
   * @param ino the inode number
701
   * @param datasync flag indicating if only data should be flushed
702
   * @param fi file information
703
   */
704
  void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
705
           struct fuse_file_info *fi);
706
707
  /**
708
   * Open a directory
709
   *
710
   * Filesystem may store an arbitrary file handle (pointer, index,
711
   * etc) in fi->fh, and use this in other all other directory
712
   * stream operations (readdir, releasedir, fsyncdir).
713
   *
714
   * If this request is answered with an error code of ENOSYS and
715
   * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
716
   * this is treated as success and future calls to opendir and
717
   * releasedir will also succeed without being sent to the filesystem
718
   * process. In addition, the kernel will cache readdir results
719
   * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
720
   *
721
   * To get this behavior without providing an opendir handler, you may
722
   * set FUSE_CAP_NO_OPENDIR_SUPPORT in `fuse_conn_info.want` on supported
723
   * kernels to automatically get the zero message opendir().
724
   *
725
   * If this callback is not provided and FUSE_CAP_NO_OPENDIR_SUPPORT is
726
   * not set in `fuse_conn_info.want` then an empty reply will be sent.
727
   *
728
   * Valid replies:
729
   *   fuse_reply_open
730
   *   fuse_reply_err
731
   *
732
   * @param req request handle
733
   * @param ino the inode number
734
   * @param fi file information
735
   */
736
  void (*opendir) (fuse_req_t req, fuse_ino_t ino,
737
       struct fuse_file_info *fi);
738
739
  /**
740
   * Read directory
741
   *
742
   * Send a buffer filled using fuse_add_direntry(), with size not
743
   * exceeding the requested size.  Send an empty buffer on end of
744
   * stream.
745
   *
746
   * fi->fh will contain the value set by the opendir method, or
747
   * will be undefined if the opendir method didn't set any value.
748
   *
749
   * Returning a directory entry from readdir() does not affect
750
   * its lookup count.
751
   *
752
   * If off_t is non-zero, then it will correspond to one of the off_t
753
   * values that was previously returned by readdir() for the same
754
   * directory handle. In this case, readdir() should skip over entries
755
   * coming before the position defined by the off_t value. If entries
756
   * are added or removed while the directory handle is open, the filesystem
757
   * may still include the entries that have been removed, and may not
758
   * report the entries that have been created. However, addition or
759
   * removal of entries must never cause readdir() to skip over unrelated
760
   * entries or to report them more than once. This means
761
   * that off_t can not be a simple index that enumerates the entries
762
   * that have been returned but must contain sufficient information to
763
   * uniquely determine the next directory entry to return even when the
764
   * set of entries is changing.
765
   *
766
   * The function does not have to report the '.' and '..'
767
   * entries, but is allowed to do so. Note that, if readdir does
768
   * not return '.' or '..', they will not be implicitly returned,
769
   * and this behavior is observable by the caller.
770
   *
771
   * Valid replies:
772
   *   fuse_reply_buf
773
   *   fuse_reply_data
774
   *   fuse_reply_err
775
   *
776
   * @param req request handle
777
   * @param ino the inode number
778
   * @param size maximum number of bytes to send
779
   * @param off offset to continue reading the directory stream
780
   * @param fi file information
781
   */
782
  void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
783
       struct fuse_file_info *fi);
784
785
  /**
786
   * Release an open directory
787
   *
788
   * For every opendir call there will be exactly one releasedir
789
   * call (unless the filesystem is force-unmounted).
790
   *
791
   * fi->fh will contain the value set by the opendir method, or
792
   * will be undefined if the opendir method didn't set any value.
793
   *
794
   * Valid replies:
795
   *   fuse_reply_err
796
   *
797
   * @param req request handle
798
   * @param ino the inode number
799
   * @param fi file information
800
   */
801
  void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
802
          struct fuse_file_info *fi);
803
804
  /**
805
   * Synchronize directory contents
806
   *
807
   * If the datasync parameter is non-zero, then only the directory
808
   * contents should be flushed, not the meta data.
809
   *
810
   * fi->fh will contain the value set by the opendir method, or
811
   * will be undefined if the opendir method didn't set any value.
812
   *
813
   * If this request is answered with an error code of ENOSYS,
814
   * this is treated as success and future calls to fsyncdir() will
815
   * succeed automatically without being send to the filesystem
816
   * process.
817
   *
818
   * Valid replies:
819
   *   fuse_reply_err
820
   *
821
   * @param req request handle
822
   * @param ino the inode number
823
   * @param datasync flag indicating if only data should be flushed
824
   * @param fi file information
825
   */
826
  void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
827
        struct fuse_file_info *fi);
828
829
  /**
830
   * Get file system statistics
831
   *
832
   * Valid replies:
833
   *   fuse_reply_statfs
834
   *   fuse_reply_err
835
   *
836
   * @param req request handle
837
   * @param ino the inode number, zero means "undefined"
838
   */
839
  void (*statfs) (fuse_req_t req, fuse_ino_t ino);
840
841
  /**
842
   * Set an extended attribute
843
   *
844
   * If this request is answered with an error code of ENOSYS, this is
845
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
846
   * future setxattr() requests will fail with EOPNOTSUPP without being
847
   * send to the filesystem process.
848
   *
849
   * Valid replies:
850
   *   fuse_reply_err
851
   */
852
  void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
853
        const char *value, size_t size, int flags);
854
855
  /**
856
   * Get an extended attribute
857
   *
858
   * If size is zero, the size of the value should be sent with
859
   * fuse_reply_xattr.
860
   *
861
   * If the size is non-zero, and the value fits in the buffer, the
862
   * value should be sent with fuse_reply_buf.
863
   *
864
   * If the size is too small for the value, the ERANGE error should
865
   * be sent.
866
   *
867
   * If this request is answered with an error code of ENOSYS, this is
868
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
869
   * future getxattr() requests will fail with EOPNOTSUPP without being
870
   * send to the filesystem process.
871
   *
872
   * Valid replies:
873
   *   fuse_reply_buf
874
   *   fuse_reply_data
875
   *   fuse_reply_xattr
876
   *   fuse_reply_err
877
   *
878
   * @param req request handle
879
   * @param ino the inode number
880
   * @param name of the extended attribute
881
   * @param size maximum size of the value to send
882
   */
883
  void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
884
        size_t size);
885
886
  /**
887
   * List extended attribute names
888
   *
889
   * If size is zero, the total size of the attribute list should be
890
   * sent with fuse_reply_xattr.
891
   *
892
   * If the size is non-zero, and the null character separated
893
   * attribute list fits in the buffer, the list should be sent with
894
   * fuse_reply_buf.
895
   *
896
   * If the size is too small for the list, the ERANGE error should
897
   * be sent.
898
   *
899
   * If this request is answered with an error code of ENOSYS, this is
900
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
901
   * future listxattr() requests will fail with EOPNOTSUPP without being
902
   * send to the filesystem process.
903
   *
904
   * Valid replies:
905
   *   fuse_reply_buf
906
   *   fuse_reply_data
907
   *   fuse_reply_xattr
908
   *   fuse_reply_err
909
   *
910
   * @param req request handle
911
   * @param ino the inode number
912
   * @param size maximum size of the list to send
913
   */
914
  void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
915
916
  /**
917
   * Remove an extended attribute
918
   *
919
   * If this request is answered with an error code of ENOSYS, this is
920
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
921
   * future removexattr() requests will fail with EOPNOTSUPP without being
922
   * send to the filesystem process.
923
   *
924
   * Valid replies:
925
   *   fuse_reply_err
926
   *
927
   * @param req request handle
928
   * @param ino the inode number
929
   * @param name of the extended attribute
930
   */
931
  void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
932
933
  /**
934
   * Check file access permissions
935
   *
936
   * This will be called for the access() and chdir() system
937
   * calls.  If the 'default_permissions' mount option is given,
938
   * this method is not called.
939
   *
940
   * This method is not called under Linux kernel versions 2.4.x
941
   *
942
   * If this request is answered with an error code of ENOSYS, this is
943
   * treated as a permanent success, i.e. this and all future access()
944
   * requests will succeed without being send to the filesystem process.
945
   *
946
   * Valid replies:
947
   *   fuse_reply_err
948
   *
949
   * @param req request handle
950
   * @param ino the inode number
951
   * @param mask requested access mode
952
   */
953
  void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
954
955
  /**
956
   * Create and open a file
957
   *
958
   * If the file does not exist, first create it with the specified
959
   * mode, and then open it.
960
   *
961
   * See the description of the open handler for more
962
   * information.
963
   *
964
   * If this method is not implemented or under Linux kernel
965
   * versions earlier than 2.6.15, the mknod() and open() methods
966
   * will be called instead.
967
   *
968
   * If this request is answered with an error code of ENOSYS, the handler
969
   * is treated as not implemented (i.e., for this and future requests the
970
   * mknod() and open() handlers will be called instead).
971
   *
972
   * Valid replies:
973
   *   fuse_reply_create
974
   *   fuse_reply_err
975
   *
976
   * @param req request handle
977
   * @param parent inode number of the parent directory
978
   * @param name to create
979
   * @param mode file type and mode with which to create the new file
980
   * @param fi file information
981
   */
982
  void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
983
      mode_t mode, struct fuse_file_info *fi);
984
985
  /**
986
   * Test for a POSIX file lock
987
   *
988
   * Valid replies:
989
   *   fuse_reply_lock
990
   *   fuse_reply_err
991
   *
992
   * @param req request handle
993
   * @param ino the inode number
994
   * @param fi file information
995
   * @param lock the region/type to test
996
   */
997
  void (*getlk) (fuse_req_t req, fuse_ino_t ino,
998
           struct fuse_file_info *fi, struct flock *lock);
999
1000
  /**
1001
   * Acquire, modify or release a POSIX file lock
1002
   *
1003
   * For POSIX threads (NPTL) there's a 1-1 relation between pid and
1004
   * owner, but otherwise this is not always the case.  For checking
1005
   * lock ownership, 'fi->owner' must be used.  The l_pid field in
1006
   * 'struct flock' should only be used to fill in this field in
1007
   * getlk().
1008
   *
1009
   * Note: if the locking methods are not implemented, the kernel
1010
   * will still allow file locking to work locally.  Hence these are
1011
   * only interesting for network filesystems and similar.
1012
   *
1013
   * Valid replies:
1014
   *   fuse_reply_err
1015
   *
1016
   * @param req request handle
1017
   * @param ino the inode number
1018
   * @param fi file information
1019
   * @param lock the region/type to set
1020
   * @param sleep locking operation may sleep
1021
   */
1022
  void (*setlk) (fuse_req_t req, fuse_ino_t ino,
1023
           struct fuse_file_info *fi,
1024
           struct flock *lock, int sleep);
1025
1026
  /**
1027
   * Map block index within file to block index within device
1028
   *
1029
   * Note: This makes sense only for block device backed filesystems
1030
   * mounted with the 'blkdev' option
1031
   *
1032
   * If this request is answered with an error code of ENOSYS, this is
1033
   * treated as a permanent failure, i.e. all future bmap() requests will
1034
   * fail with the same error code without being send to the filesystem
1035
   * process.
1036
   *
1037
   * Valid replies:
1038
   *   fuse_reply_bmap
1039
   *   fuse_reply_err
1040
   *
1041
   * @param req request handle
1042
   * @param ino the inode number
1043
   * @param blocksize unit of block index
1044
   * @param idx block index within file
1045
   */
1046
  void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
1047
          uint64_t idx);
1048
1049
#if FUSE_USE_VERSION < 35
1050
  void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd,
1051
           void *arg, struct fuse_file_info *fi, unsigned flags,
1052
           const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1053
#else
1054
  /**
1055
   * Ioctl
1056
   *
1057
   * Note: For unrestricted ioctls (not allowed for FUSE
1058
   * servers), data in and out areas can be discovered by giving
1059
   * iovs and setting FUSE_IOCTL_RETRY in *flags*.  For
1060
   * restricted ioctls, kernel prepares in/out data area
1061
   * according to the information encoded in cmd.
1062
   *
1063
   * Valid replies:
1064
   *   fuse_reply_ioctl_retry
1065
   *   fuse_reply_ioctl
1066
   *   fuse_reply_ioctl_iov
1067
   *   fuse_reply_err
1068
   *
1069
   * @param req request handle
1070
   * @param ino the inode number
1071
   * @param cmd ioctl command
1072
   * @param arg ioctl argument
1073
   * @param fi file information
1074
   * @param flags for FUSE_IOCTL_* flags
1075
   * @param in_buf data fetched from the caller
1076
   * @param in_bufsz number of fetched bytes
1077
   * @param out_bufsz maximum size of output data
1078
   *
1079
   * Note : the unsigned long request submitted by the application
1080
   * is truncated to 32 bits.
1081
   */
1082
  void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned int cmd,
1083
           void *arg, struct fuse_file_info *fi, unsigned flags,
1084
           const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1085
#endif
1086
1087
  /**
1088
   * Poll for IO readiness
1089
   *
1090
   * The client should immediately respond with fuse_reply_poll(),
1091
   * setting revents appropriately according to which events are ready.
1092
   *
1093
   * Additionally, if ph is non-NULL, the client must retain it and
1094
   * notify when all future IO readiness events occur by calling
1095
   * fuse_lowlevel_notify_poll() with the specified ph.
1096
   *
1097
   * Regardless of the number of times poll with a non-NULL ph is
1098
   * received, a single notify_poll is enough to service all. (Notifying
1099
   * more times incurs overhead but doesn't harm correctness.) Any
1100
   * additional received handles can be immediately destroyed.
1101
   *
1102
   * The callee is responsible for destroying ph with
1103
   * fuse_pollhandle_destroy() when no longer in use.
1104
   *
1105
   * If this request is answered with an error code of ENOSYS, this is
1106
   * treated as success (with a kernel-defined default poll-mask) and
1107
   * future calls to poll() will succeed the same way without being send
1108
   * to the filesystem process.
1109
   *
1110
   * Valid replies:
1111
   *   fuse_reply_poll
1112
   *   fuse_reply_err
1113
   *
1114
   * @param req request handle
1115
   * @param ino the inode number
1116
   * @param fi file information
1117
   * @param ph poll handle to be used for notification
1118
   */
1119
  void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1120
          struct fuse_pollhandle *ph);
1121
1122
  /**
1123
   * Write data made available in a buffer
1124
   *
1125
   * This is a more generic version of the ->write() method.  If
1126
   * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1127
   * kernel supports splicing from the fuse device, then the
1128
   * data will be made available in pipe for supporting zero
1129
   * copy data transfer.
1130
   *
1131
   * buf->count is guaranteed to be one (and thus buf->idx is
1132
   * always zero). The write_buf handler must ensure that
1133
   * bufv->off is correctly updated (reflecting the number of
1134
   * bytes read from bufv->buf[0]).
1135
   *
1136
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1137
   * expected to reset the setuid and setgid bits.
1138
   *
1139
   * Valid replies:
1140
   *   fuse_reply_write
1141
   *   fuse_reply_err
1142
   *
1143
   * @param req request handle
1144
   * @param ino the inode number
1145
   * @param bufv buffer containing the data
1146
   * @param off offset to write to
1147
   * @param fi file information
1148
   */
1149
  void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
1150
         struct fuse_bufvec *bufv, off_t off,
1151
         struct fuse_file_info *fi);
1152
1153
  /**
1154
   * Callback function for the retrieve request
1155
   *
1156
   * Valid replies:
1157
   *  fuse_reply_none
1158
   *
1159
   * @param req request handle
1160
   * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
1161
   * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
1162
   * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
1163
   * @param bufv the buffer containing the returned data
1164
   */
1165
  void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
1166
        off_t offset, struct fuse_bufvec *bufv);
1167
1168
  /**
1169
   * Forget about multiple inodes
1170
   *
1171
   * See description of the forget function for more
1172
   * information.
1173
   *
1174
   * Valid replies:
1175
   *   fuse_reply_none
1176
   *
1177
   * @param req request handle
1178
   */
1179
  void (*forget_multi) (fuse_req_t req, size_t count,
1180
            struct fuse_forget_data *forgets);
1181
1182
  /**
1183
   * Acquire, modify or release a BSD file lock
1184
   *
1185
   * Note: if the locking methods are not implemented, the kernel
1186
   * will still allow file locking to work locally.  Hence these are
1187
   * only interesting for network filesystems and similar.
1188
   *
1189
   * Valid replies:
1190
   *   fuse_reply_err
1191
   *
1192
   * @param req request handle
1193
   * @param ino the inode number
1194
   * @param fi file information
1195
   * @param op the locking operation, see flock(2)
1196
   */
1197
  void (*flock) (fuse_req_t req, fuse_ino_t ino,
1198
           struct fuse_file_info *fi, int op);
1199
1200
  /**
1201
   * Allocate requested space. If this function returns success then
1202
   * subsequent writes to the specified range shall not fail due to the lack
1203
   * of free space on the file system storage media.
1204
   *
1205
   * If this request is answered with an error code of ENOSYS, this is
1206
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1207
   * future fallocate() requests will fail with EOPNOTSUPP without being
1208
   * send to the filesystem process.
1209
   *
1210
   * Valid replies:
1211
   *   fuse_reply_err
1212
   *
1213
   * @param req request handle
1214
   * @param ino the inode number
1215
   * @param offset starting point for allocated region
1216
   * @param length size of allocated region
1217
   * @param mode determines the operation to be performed on the given range,
1218
   *             see fallocate(2)
1219
   */
1220
  void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1221
           off_t offset, off_t length, struct fuse_file_info *fi);
1222
1223
  /**
1224
   * Read directory with attributes
1225
   *
1226
   * Send a buffer filled using fuse_add_direntry_plus(), with size not
1227
   * exceeding the requested size.  Send an empty buffer on end of
1228
   * stream.
1229
   *
1230
   * fi->fh will contain the value set by the opendir method, or
1231
   * will be undefined if the opendir method didn't set any value.
1232
   *
1233
   * In contrast to readdir() (which does not affect the lookup counts),
1234
   * the lookup count of every entry returned by readdirplus(), except "."
1235
   * and "..", is incremented by one.
1236
   *
1237
   * Valid replies:
1238
   *   fuse_reply_buf
1239
   *   fuse_reply_data
1240
   *   fuse_reply_err
1241
   *
1242
   * @param req request handle
1243
   * @param ino the inode number
1244
   * @param size maximum number of bytes to send
1245
   * @param off offset to continue reading the directory stream
1246
   * @param fi file information
1247
   */
1248
  void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1249
       struct fuse_file_info *fi);
1250
1251
  /**
1252
   * Copy a range of data from one file to another
1253
   *
1254
   * Performs an optimized copy between two file descriptors without the
1255
   * additional cost of transferring data through the FUSE kernel module
1256
   * to user space (glibc) and then back into the FUSE filesystem again.
1257
   *
1258
   * In case this method is not implemented, glibc falls back to reading
1259
   * data from the source and writing to the destination. Effectively
1260
   * doing an inefficient copy of the data.
1261
   *
1262
   * If this request is answered with an error code of ENOSYS, this is
1263
   * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1264
   * future copy_file_range() requests will fail with EOPNOTSUPP without
1265
   * being send to the filesystem process.
1266
   *
1267
   * Valid replies:
1268
   *   fuse_reply_write
1269
   *   fuse_reply_err
1270
   *
1271
   * @param req request handle
1272
   * @param ino_in the inode number or the source file
1273
   * @param off_in starting point from were the data should be read
1274
   * @param fi_in file information of the source file
1275
   * @param ino_out the inode number or the destination file
1276
   * @param off_out starting point where the data should be written
1277
   * @param fi_out file information of the destination file
1278
   * @param len maximum size of the data to copy
1279
   * @param flags passed along with the copy_file_range() syscall
1280
   */
1281
  void (*copy_file_range) (fuse_req_t req, fuse_ino_t ino_in,
1282
         off_t off_in, struct fuse_file_info *fi_in,
1283
         fuse_ino_t ino_out, off_t off_out,
1284
         struct fuse_file_info *fi_out, size_t len,
1285
         int flags);
1286
1287
  /**
1288
   * Find next data or hole after the specified offset
1289
   *
1290
   * If this request is answered with an error code of ENOSYS, this is
1291
   * treated as a permanent failure, i.e. all future lseek() requests will
1292
   * fail with the same error code without being send to the filesystem
1293
   * process.
1294
   *
1295
   * Valid replies:
1296
   *   fuse_reply_lseek
1297
   *   fuse_reply_err
1298
   *
1299
   * @param req request handle
1300
   * @param ino the inode number
1301
   * @param off offset to start search from
1302
   * @param whence either SEEK_DATA or SEEK_HOLE
1303
   * @param fi file information
1304
   */
1305
  void (*lseek) (fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1306
           struct fuse_file_info *fi);
1307
1308
  /**
1309
   * Create a tempfile
1310
   *
1311
   * Tempfile means an anonymous file. It can be made into a normal file later
1312
   * by using linkat or such.
1313
   *
1314
   * If this is answered with an error ENOSYS this is treated by the kernel as
1315
   * a permanent failure and it will disable the feature and not ask again.
1316
   *
1317
   * Valid replies:
1318
   *   fuse_reply_create
1319
   *   fuse_reply_err
1320
   *
1321
   * @param req request handle
1322
   * @param parent inode number of the parent directory
1323
   * @param mode file type and mode with which to create the new file
1324
   * @param fi file information
1325
   */
1326
  void (*tmpfile) (fuse_req_t req, fuse_ino_t parent,
1327
      mode_t mode, struct fuse_file_info *fi);
1328
1329
  /**
1330
   * Get extended file attributes.
1331
   *
1332
   * Valid replies:
1333
   *   fuse_reply_statx
1334
   *   fuse_reply_err
1335
   *
1336
   * @param req request handle
1337
   * @param ino the inode number
1338
   * @param flags bitmask of requested flags
1339
   * @param mask bitmask of requested fields
1340
   * @param fi file information (may be NULL)
1341
   */
1342
  void (*statx)(fuse_req_t req, fuse_ino_t ino, int flags, int mask,
1343
          struct fuse_file_info *fi);
1344
};
1345
1346
/**
1347
 * Reply with an error code or success.
1348
 *
1349
 * Possible requests:
1350
 *   all except forget, forget_multi, retrieve_reply
1351
 *
1352
 * Wherever possible, error codes should be chosen from the list of
1353
 * documented error conditions in the corresponding system calls
1354
 * manpage.
1355
 *
1356
 * An error code of ENOSYS is sometimes treated specially. This is
1357
 * indicated in the documentation of the affected handler functions.
1358
 *
1359
 * The following requests may be answered with a zero error code:
1360
 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1361
 * removexattr, setlk.
1362
 *
1363
 * @param req request handle
1364
 * @param err the positive error value, or zero for success
1365
 * @return zero for success, -errno for failure to send reply
1366
 */
1367
int fuse_reply_err(fuse_req_t req, int err);
1368
1369
/**
1370
 * Don't send reply
1371
 *
1372
 * Possible requests:
1373
 *   forget
1374
 *   forget_multi
1375
 *   retrieve_reply
1376
 *
1377
 * @param req request handle
1378
 */
1379
void fuse_reply_none(fuse_req_t req);
1380
1381
/**
1382
 * Reply with a directory entry
1383
 *
1384
 * Possible requests:
1385
 *   lookup, mknod, mkdir, symlink, link
1386
 *
1387
 * Side effects:
1388
 *   increments the lookup count on success
1389
 *
1390
 * @param req request handle
1391
 * @param e the entry parameters
1392
 * @return zero for success, -errno for failure to send reply
1393
 */
1394
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1395
1396
/**
1397
 * Reply with a directory entry and open parameters
1398
 *
1399
 * currently the following members of 'fi' are used:
1400
 *   fh, direct_io, keep_cache, cache_readdir, nonseekable, noflush,
1401
 *   parallel_direct_writes
1402
 *
1403
 * Possible requests:
1404
 *   create
1405
 *
1406
 * Side effects:
1407
 *   increments the lookup count on success
1408
 *
1409
 * @param req request handle
1410
 * @param e the entry parameters
1411
 * @param fi file information
1412
 * @return zero for success, -errno for failure to send reply
1413
 */
1414
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1415
          const struct fuse_file_info *fi);
1416
1417
/**
1418
 * Reply with attributes
1419
 *
1420
 * Possible requests:
1421
 *   getattr, setattr
1422
 *
1423
 * @param req request handle
1424
 * @param attr the attributes
1425
 * @param attr_timeout  validity timeout (in seconds) for the attributes
1426
 * @return zero for success, -errno for failure to send reply
1427
 */
1428
int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1429
        double attr_timeout);
1430
1431
/**
1432
 * Reply with the contents of a symbolic link
1433
 *
1434
 * Possible requests:
1435
 *   readlink
1436
 *
1437
 * @param req request handle
1438
 * @param link symbolic link contents
1439
 * @return zero for success, -errno for failure to send reply
1440
 */
1441
int fuse_reply_readlink(fuse_req_t req, const char *link);
1442
1443
/**
1444
 * Setup passthrough backing file for open reply
1445
 *
1446
 * Currently there should be only one backing id per node / backing file.
1447
 *
1448
 * Possible requests:
1449
 *   open, opendir, create
1450
 *
1451
 * @param req request handle
1452
 * @param fd backing file descriptor
1453
 * @return positive backing id for success, 0 for failure
1454
 */
1455
int fuse_passthrough_open(fuse_req_t req, int fd);
1456
int fuse_passthrough_close(fuse_req_t req, int backing_id);
1457
1458
/**
1459
 * Reply with open parameters
1460
 *
1461
 * currently the following members of 'fi' are used:
1462
 *   fh, direct_io, keep_cache, cache_readdir, nonseekable, noflush,
1463
 *   parallel_direct_writes,
1464
 *
1465
 * Possible requests:
1466
 *   open, opendir
1467
 *
1468
 * @param req request handle
1469
 * @param fi file information
1470
 * @return zero for success, -errno for failure to send reply
1471
 */
1472
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1473
1474
/**
1475
 * Reply with number of bytes written
1476
 *
1477
 * Possible requests:
1478
 *   write
1479
 *
1480
 * @param req request handle
1481
 * @param count the number of bytes written
1482
 * @return zero for success, -errno for failure to send reply
1483
 */
1484
int fuse_reply_write(fuse_req_t req, size_t count);
1485
1486
/**
1487
 * Reply with data
1488
 *
1489
 * Possible requests:
1490
 *   read, readdir, getxattr, listxattr
1491
 *
1492
 * @param req request handle
1493
 * @param buf buffer containing data
1494
 * @param size the size of data in bytes
1495
 * @return zero for success, -errno for failure to send reply
1496
 */
1497
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1498
1499
/**
1500
 * Reply with data copied/moved from buffer(s)
1501
 *
1502
 * Zero copy data transfer ("splicing") will be used under
1503
 * the following circumstances:
1504
 *
1505
 * 1. FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.want, and
1506
 * 2. the kernel supports splicing from the fuse device
1507
 *    (FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.capable), and
1508
 * 3. *flags* does not contain FUSE_BUF_NO_SPLICE
1509
 * 4. The amount of data that is provided in file-descriptor backed
1510
 *    buffers (i.e., buffers for which bufv[n].flags == FUSE_BUF_FD)
1511
 *    is at least twice the page size.
1512
 *
1513
 * In order for SPLICE_F_MOVE to be used, the following additional
1514
 * conditions have to be fulfilled:
1515
 *
1516
 * 1. FUSE_CAP_SPLICE_MOVE is set in fuse_conn_info.want, and
1517
 * 2. the kernel supports it (i.e, FUSE_CAP_SPLICE_MOVE is set in
1518
      fuse_conn_info.capable), and
1519
 * 3. *flags* contains FUSE_BUF_SPLICE_MOVE
1520
 *
1521
 * Note that, if splice is used, the data is actually spliced twice:
1522
 * once into a temporary pipe (to prepend header data), and then again
1523
 * into the kernel. If some of the provided buffers are memory-backed,
1524
 * the data in them is copied in step one and spliced in step two.
1525
 *
1526
 * The FUSE_BUF_SPLICE_FORCE_SPLICE and FUSE_BUF_SPLICE_NONBLOCK flags
1527
 * are silently ignored.
1528
 *
1529
 * Possible requests:
1530
 *   read, readdir, getxattr, listxattr
1531
 *
1532
 * Side effects:
1533
 *   when used to return data from a readdirplus() (but not readdir())
1534
 *   call, increments the lookup count of each returned entry by one
1535
 *   on success.
1536
 *
1537
 * @param req request handle
1538
 * @param bufv buffer vector
1539
 * @param flags flags controlling the copy
1540
 * @return zero for success, -errno for failure to send reply
1541
 */
1542
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1543
        enum fuse_buf_copy_flags flags);
1544
1545
/**
1546
 * Reply with data vector
1547
 *
1548
 * Possible requests:
1549
 *   read, readdir, getxattr, listxattr
1550
 *
1551
 * @param req request handle
1552
 * @param iov the vector containing the data
1553
 * @param count the size of vector
1554
 * @return zero for success, -errno for failure to send reply
1555
 */
1556
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1557
1558
/**
1559
 * Reply with filesystem statistics
1560
 *
1561
 * Possible requests:
1562
 *   statfs
1563
 *
1564
 * @param req request handle
1565
 * @param stbuf filesystem statistics
1566
 * @return zero for success, -errno for failure to send reply
1567
 */
1568
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1569
1570
/**
1571
 * Reply with needed buffer size
1572
 *
1573
 * Possible requests:
1574
 *   getxattr, listxattr
1575
 *
1576
 * @param req request handle
1577
 * @param count the buffer size needed in bytes
1578
 * @return zero for success, -errno for failure to send reply
1579
 */
1580
int fuse_reply_xattr(fuse_req_t req, size_t count);
1581
1582
/**
1583
 * Reply with file lock information
1584
 *
1585
 * Possible requests:
1586
 *   getlk
1587
 *
1588
 * @param req request handle
1589
 * @param lock the lock information
1590
 * @return zero for success, -errno for failure to send reply
1591
 */
1592
int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1593
1594
/**
1595
 * Reply with block index
1596
 *
1597
 * Possible requests:
1598
 *   bmap
1599
 *
1600
 * @param req request handle
1601
 * @param idx block index within device
1602
 * @return zero for success, -errno for failure to send reply
1603
 */
1604
int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1605
1606
/* ----------------------------------------------------------- *
1607
 * Filling a buffer in readdir               *
1608
 * ----------------------------------------------------------- */
1609
1610
/**
1611
 * Add a directory entry to the buffer
1612
 *
1613
 * Buffer needs to be large enough to hold the entry.  If it's not,
1614
 * then the entry is not filled in but the size of the entry is still
1615
 * returned.  The caller can check this by comparing the bufsize
1616
 * parameter with the returned entry size.  If the entry size is
1617
 * larger than the buffer size, the operation failed.
1618
 *
1619
 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1620
 * st_mode field are used.  The other fields are ignored.
1621
 *
1622
 * *off* should be any non-zero value that the filesystem can use to
1623
 * identify the current point in the directory stream. It does not
1624
 * need to be the actual physical position. A value of zero is
1625
 * reserved to mean "from the beginning", and should therefore never
1626
 * be used (the first call to fuse_add_direntry should be passed the
1627
 * offset of the second directory entry).
1628
 *
1629
 * @param req request handle
1630
 * @param buf the point where the new entry will be added to the buffer
1631
 * @param bufsize remaining size of the buffer
1632
 * @param name the name of the entry
1633
 * @param stbuf the file attributes
1634
 * @param off the offset of the next entry
1635
 * @return the space needed for the entry
1636
 */
1637
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1638
       const char *name, const struct stat *stbuf,
1639
       off_t off);
1640
1641
/**
1642
 * Add a directory entry to the buffer with the attributes
1643
 *
1644
 * See documentation of `fuse_add_direntry()` for more details.
1645
 *
1646
 * @param req request handle
1647
 * @param buf the point where the new entry will be added to the buffer
1648
 * @param bufsize remaining size of the buffer
1649
 * @param name the name of the entry
1650
 * @param e the directory entry
1651
 * @param off the offset of the next entry
1652
 * @return the space needed for the entry
1653
 */
1654
size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1655
            const char *name,
1656
            const struct fuse_entry_param *e, off_t off);
1657
1658
/**
1659
 * Reply to ask for data fetch and output buffer preparation.  ioctl
1660
 * will be retried with the specified input data fetched and output
1661
 * buffer prepared.
1662
 *
1663
 * Possible requests:
1664
 *   ioctl
1665
 *
1666
 * @param req request handle
1667
 * @param in_iov iovec specifying data to fetch from the caller
1668
 * @param in_count number of entries in in_iov
1669
 * @param out_iov iovec specifying addresses to write output to
1670
 * @param out_count number of entries in out_iov
1671
 * @return zero for success, -errno for failure to send reply
1672
 */
1673
int fuse_reply_ioctl_retry(fuse_req_t req,
1674
         const struct iovec *in_iov, size_t in_count,
1675
         const struct iovec *out_iov, size_t out_count);
1676
1677
/**
1678
 * Reply to finish ioctl
1679
 *
1680
 * Possible requests:
1681
 *   ioctl
1682
 *
1683
 * @param req request handle
1684
 * @param result result to be passed to the caller
1685
 * @param buf buffer containing output data
1686
 * @param size length of output data
1687
 */
1688
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1689
1690
/**
1691
 * Reply to finish ioctl with iov buffer
1692
 *
1693
 * Possible requests:
1694
 *   ioctl
1695
 *
1696
 * @param req request handle
1697
 * @param result result to be passed to the caller
1698
 * @param iov the vector containing the data
1699
 * @param count the size of vector
1700
 */
1701
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1702
       int count);
1703
1704
/**
1705
 * Reply with poll result event mask
1706
 *
1707
 * @param req request handle
1708
 * @param revents poll result event mask
1709
 */
1710
int fuse_reply_poll(fuse_req_t req, unsigned revents);
1711
1712
/**
1713
 * Reply with offset
1714
 *
1715
 * Possible requests:
1716
 *   lseek
1717
 *
1718
 * @param req request handle
1719
 * @param off offset of next data or hole
1720
 * @return zero for success, -errno for failure to send reply
1721
 */
1722
int fuse_reply_lseek(fuse_req_t req, off_t off);
1723
1724
/**
1725
 * Reply with extended file attributes.
1726
 *
1727
 * Possible requests:
1728
 *   statx
1729
 *
1730
 * @param req request handle
1731
 * @param flags statx flags
1732
 * @param statx the attributes
1733
 * @param attr_timeout  validity timeout (in seconds) for the attributes
1734
 * @return zero for success, -errno for failure to send reply
1735
 */
1736
int fuse_reply_statx(fuse_req_t req, int flags, struct statx *statx, double attr_timeout);
1737
1738
/* ----------------------------------------------------------- *
1739
 * Notification                  *
1740
 * ----------------------------------------------------------- */
1741
1742
/**
1743
 * Notify IO readiness event
1744
 *
1745
 * For more information, please read comment for poll operation.
1746
 *
1747
 * @param ph poll handle to notify IO readiness event for
1748
 */
1749
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1750
1751
/**
1752
 * Notify to invalidate cache for an inode.
1753
 *
1754
 * Added in FUSE protocol version 7.12. If the kernel does not support
1755
 * this (or a newer) version, the function will return -ENOSYS and do
1756
 * nothing.
1757
 *
1758
 * If the filesystem has writeback caching enabled, invalidating an
1759
 * inode will first trigger a writeback of all dirty pages. The call
1760
 * will block until all writeback requests have completed and the
1761
 * inode has been invalidated. It will, however, not wait for
1762
 * completion of pending writeback requests that have been issued
1763
 * before.
1764
 *
1765
 * If there are no dirty pages, this function will never block.
1766
 *
1767
 * @param se the session object
1768
 * @param ino the inode number
1769
 * @param off the offset in the inode where to start invalidating
1770
 *            or negative to invalidate attributes only
1771
 * @param len the amount of cache to invalidate or 0 for all
1772
 * @return zero for success, -errno for failure
1773
 */
1774
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1775
             off_t off, off_t len);
1776
1777
/**
1778
 * Notify to increment the epoch for the current
1779
 *
1780
 * Each fuse connection has an 'epoch', which is initialized during INIT.
1781
 * Caching will then be validated against the epoch value: if the current epoch
1782
 * is higher than an object being revalidated, the object is invalid.
1783
 *
1784
 * This function simply increment the current epoch value.
1785
 *
1786
 * @param se the session object
1787
 * @return zero for success, -errno for failure
1788
 */
1789
int fuse_lowlevel_notify_increment_epoch(struct fuse_session *se);
1790
1791
/**
1792
 * Notify to invalidate parent attributes and the dentry matching parent/name
1793
 *
1794
 * To avoid a deadlock this function must not be called in the
1795
 * execution path of a related filesystem operation or within any code
1796
 * that could hold a lock that could be needed to execute such an
1797
 * operation. As of kernel 4.18, a "related operation" is a lookup(),
1798
 * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1799
 * request for the parent, and a setattr(), unlink(), rmdir(),
1800
 * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1801
 * request for the inode itself.
1802
 *
1803
 * When called correctly, this function will never block.
1804
 *
1805
 * Added in FUSE protocol version 7.12. If the kernel does not support
1806
 * this (or a newer) version, the function will return -ENOSYS and do
1807
 * nothing.
1808
 *
1809
 * @param se the session object
1810
 * @param parent inode number
1811
 * @param name file name
1812
 * @param namelen strlen() of file name
1813
 * @return zero for success, -errno for failure
1814
 */
1815
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1816
             const char *name, size_t namelen);
1817
1818
/**
1819
 * Notify to expire parent attributes and the dentry matching parent/name
1820
 *
1821
 * Same restrictions apply as for fuse_lowlevel_notify_inval_entry()
1822
 *
1823
 * Compared to invalidating an entry, expiring the entry results not in a
1824
 * forceful removal of that entry from kernel cache but instead the next access
1825
 * to it forces a lookup from the filesystem.
1826
 *
1827
 * This makes a difference for overmounted dentries, where plain invalidation
1828
 * would detach all submounts before dropping the dentry from the cache.
1829
 * If only expiry is set on the dentry, then any overmounts are left alone and
1830
 * until ->d_revalidate() is called.
1831
 *
1832
 * Note: ->d_revalidate() is not called for the case of following a submount,
1833
 * so invalidation will only be triggered for the non-overmounted case.
1834
 * The dentry could also be mounted in a different mount instance, in which case
1835
 * any submounts will still be detached.
1836
 *
1837
 * Added in FUSE protocol version 7.38. If the kernel does not support
1838
 * this (or a newer) version, the function will return -ENOSYS and do nothing.
1839
 *
1840
 * @param se the session object
1841
 * @param parent inode number
1842
 * @param name file name
1843
 * @param namelen strlen() of file name
1844
 * @return zero for success, -errno for failure, -enosys if no kernel support
1845
*/
1846
int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent,
1847
                                      const char *name, size_t namelen);
1848
1849
/**
1850
 * This function behaves like fuse_lowlevel_notify_inval_entry() with
1851
 * the following additional effect (at least as of Linux kernel 4.8):
1852
 *
1853
 * If the provided *child* inode matches the inode that is currently
1854
 * associated with the cached dentry, and if there are any inotify
1855
 * watches registered for the dentry, then the watchers are informed
1856
 * that the dentry has been deleted.
1857
 *
1858
 * To avoid a deadlock this function must not be called while
1859
 * executing a related filesystem operation or while holding a lock
1860
 * that could be needed to execute such an operation (see the
1861
 * description of fuse_lowlevel_notify_inval_entry() for more
1862
 * details).
1863
 *
1864
 * When called correctly, this function will never block.
1865
 *
1866
 * Added in FUSE protocol version 7.18. If the kernel does not support
1867
 * this (or a newer) version, the function will return -ENOSYS and do
1868
 * nothing.
1869
 *
1870
 * @param se the session object
1871
 * @param parent inode number
1872
 * @param child inode number
1873
 * @param name file name
1874
 * @param namelen strlen() of file name
1875
 * @return zero for success, -errno for failure
1876
 */
1877
int fuse_lowlevel_notify_delete(struct fuse_session *se,
1878
        fuse_ino_t parent, fuse_ino_t child,
1879
        const char *name, size_t namelen);
1880
1881
/**
1882
 * Store data to the kernel buffers
1883
 *
1884
 * Synchronously store data in the kernel buffers belonging to the
1885
 * given inode.  The stored data is marked up-to-date (no read will be
1886
 * performed against it, unless it's invalidated or evicted from the
1887
 * cache).
1888
 *
1889
 * If the stored data overflows the current file size, then the size
1890
 * is extended, similarly to a write(2) on the filesystem.
1891
 *
1892
 * If this function returns an error, then the store wasn't fully
1893
 * completed, but it may have been partially completed.
1894
 *
1895
 * Added in FUSE protocol version 7.15. If the kernel does not support
1896
 * this (or a newer) version, the function will return -ENOSYS and do
1897
 * nothing.
1898
 *
1899
 * @param se the session object
1900
 * @param ino the inode number
1901
 * @param offset the starting offset into the file to store to
1902
 * @param bufv buffer vector
1903
 * @param flags flags controlling the copy
1904
 * @return zero for success, -errno for failure
1905
 */
1906
int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1907
             off_t offset, struct fuse_bufvec *bufv,
1908
             enum fuse_buf_copy_flags flags);
1909
/**
1910
 * Retrieve data from the kernel buffers
1911
 *
1912
 * Retrieve data in the kernel buffers belonging to the given inode.
1913
 * If successful then the retrieve_reply() method will be called with
1914
 * the returned data.
1915
 *
1916
 * Only present pages are returned in the retrieve reply.  Retrieving
1917
 * stops when it finds a non-present page and only data prior to that
1918
 * is returned.
1919
 *
1920
 * If this function returns an error, then the retrieve will not be
1921
 * completed and no reply will be sent.
1922
 *
1923
 * This function doesn't change the dirty state of pages in the kernel
1924
 * buffer.  For dirty pages the write() method will be called
1925
 * regardless of having been retrieved previously.
1926
 *
1927
 * Added in FUSE protocol version 7.15. If the kernel does not support
1928
 * this (or a newer) version, the function will return -ENOSYS and do
1929
 * nothing.
1930
 *
1931
 * @param se the session object
1932
 * @param ino the inode number
1933
 * @param size the number of bytes to retrieve
1934
 * @param offset the starting offset into the file to retrieve from
1935
 * @param cookie user data to supply to the reply callback
1936
 * @return zero for success, -errno for failure
1937
 */
1938
int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1939
          size_t size, off_t offset, void *cookie);
1940
1941
1942
/* ----------------------------------------------------------- *
1943
 * Utility functions                 *
1944
 * ----------------------------------------------------------- */
1945
1946
/**
1947
 * Get the userdata from the request
1948
 *
1949
 * @param req request handle
1950
 * @return the user data passed to fuse_session_new()
1951
 */
1952
void *fuse_req_userdata(fuse_req_t req);
1953
1954
/**
1955
 * Get the context from the request
1956
 *
1957
 * The pointer returned by this function will only be valid for the
1958
 * request's lifetime
1959
 *
1960
 * @param req request handle
1961
 * @return the context structure
1962
 */
1963
const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1964
1965
/**
1966
 * Get the current supplementary group IDs for the specified request
1967
 *
1968
 * Similar to the getgroups(2) system call, except the return value is
1969
 * always the total number of group IDs, even if it is larger than the
1970
 * specified size.
1971
 *
1972
 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1973
 * the group list to userspace, hence this function needs to parse
1974
 * "/proc/$TID/task/$TID/status" to get the group IDs.
1975
 *
1976
 * This feature may not be supported on all operating systems.  In
1977
 * such a case this function will return -ENOSYS.
1978
 *
1979
 * @param req request handle
1980
 * @param size size of given array
1981
 * @param list array of group IDs to be filled in
1982
 * @return the total number of supplementary group IDs or -errno on failure
1983
 */
1984
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1985
1986
/**
1987
 * Callback function for an interrupt
1988
 *
1989
 * @param req interrupted request
1990
 * @param data user data
1991
 */
1992
typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1993
1994
/**
1995
 * Register/unregister callback for an interrupt
1996
 *
1997
 * If an interrupt has already happened, then the callback function is
1998
 * called from within this function, hence it's not possible for
1999
 * interrupts to be lost.
2000
 *
2001
 * @param req request handle
2002
 * @param func the callback function or NULL for unregister
2003
 * @param data user data passed to the callback function
2004
 */
2005
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
2006
           void *data);
2007
2008
/**
2009
 * Check if a request has already been interrupted
2010
 *
2011
 * @param req request handle
2012
 * @return 1 if the request has been interrupted, 0 otherwise
2013
 */
2014
int fuse_req_interrupted(fuse_req_t req);
2015
2016
2017
/* ----------------------------------------------------------- *
2018
 * Inquiry functions                                           *
2019
 * ----------------------------------------------------------- */
2020
2021
/**
2022
 * Print low-level version information to stdout.
2023
 */
2024
void fuse_lowlevel_version(void);
2025
2026
/**
2027
 * Print available low-level options to stdout. This is not an
2028
 * exhaustive list, but includes only those options that may be of
2029
 * interest to an end-user of a file system.
2030
 */
2031
void fuse_lowlevel_help(void);
2032
2033
/**
2034
 * Print available options for `fuse_parse_cmdline()`.
2035
 */
2036
void fuse_cmdline_help(void);
2037
2038
/* ----------------------------------------------------------- *
2039
 * Filesystem setup & teardown                                 *
2040
 * ----------------------------------------------------------- */
2041
2042
/**
2043
 * Note: Any addition to this struct needs to create a compatibility symbol
2044
 *       for fuse_parse_cmdline(). For ABI compatibility reasons it is also
2045
 *       not possible to remove struct members.
2046
 */
2047
struct fuse_cmdline_opts {
2048
  int singlethread;
2049
  int foreground;
2050
  int debug;
2051
  int nodefault_subtype;
2052
  char *mountpoint;
2053
  int show_version;
2054
  int show_help;
2055
  int clone_fd;
2056
  unsigned int max_idle_threads; /* discouraged, due to thread
2057
                                  * destruct overhead */
2058
2059
  /* Added in libfuse-3.12 */
2060
  unsigned int max_threads;
2061
};
2062
2063
/**
2064
 * Utility function to parse common options for simple file systems
2065
 * using the low-level API. A help text that describes the available
2066
 * options can be printed with `fuse_cmdline_help`. A single
2067
 * non-option argument is treated as the mountpoint. Multiple
2068
 * non-option arguments will result in an error.
2069
 *
2070
 * If neither -o subtype= or -o fsname= options are given, a new
2071
 * subtype option will be added and set to the basename of the program
2072
 * (the fsname will remain unset, and then defaults to "fuse").
2073
 *
2074
 * Known options will be removed from *args*, unknown options will
2075
 * remain.
2076
 *
2077
 * @param args argument vector (input+output)
2078
 * @param opts output argument for parsed options
2079
 * @return 0 on success, -1 on failure
2080
 */
2081
#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
2082
int fuse_parse_cmdline(struct fuse_args *args,
2083
           struct fuse_cmdline_opts *opts);
2084
#else
2085
#if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
2086
int fuse_parse_cmdline_30(struct fuse_args *args,
2087
         struct fuse_cmdline_opts *opts);
2088
#define fuse_parse_cmdline(args, opts) fuse_parse_cmdline_30(args, opts)
2089
#else
2090
int fuse_parse_cmdline_312(struct fuse_args *args,
2091
         struct fuse_cmdline_opts *opts);
2092
#define fuse_parse_cmdline(args, opts) fuse_parse_cmdline_312(args, opts)
2093
#endif
2094
#endif
2095
2096
/* Do not call this directly, use fuse_session_new() instead */
2097
struct fuse_session *
2098
fuse_session_new_versioned(struct fuse_args *args,
2099
         const struct fuse_lowlevel_ops *op, size_t op_size,
2100
         struct libfuse_version *version, void *userdata);
2101
2102
/**
2103
 * Create a low level session.
2104
 *
2105
 * Returns a session structure suitable for passing to
2106
 * fuse_session_mount() and fuse_session_loop().
2107
 *
2108
 * This function accepts most file-system independent mount options
2109
 * (like context, nodev, ro - see mount(8)), as well as the general
2110
 * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
2111
 * -o default_permissions, but not ``-o use_ino``).  Instead of `-o
2112
 * debug`, debugging may also enabled with `-d` or `--debug`.
2113
 *
2114
 * If not all options are known, an error message is written to stderr
2115
 * and the function returns NULL.
2116
 *
2117
 * To create a no-op session just for mounting pass op as NULL.
2118
 *
2119
 * Option parsing skips argv[0], which is assumed to contain the
2120
 * program name. To prevent accidentally passing an option in
2121
 * argv[0], this element must always be present (even if no options
2122
 * are specified). It may be set to the empty string ('\0') if no
2123
 * reasonable value can be provided.
2124
 *
2125
 * @param args argument vector
2126
 * @param op the (low-level) filesystem operations
2127
 * @param op_size sizeof(struct fuse_lowlevel_ops)
2128
 * @param version the libfuse version a file system server was compiled against
2129
 * @param userdata user data
2130
 * @return the fuse session on success, NULL on failure
2131
 **/
2132
static inline struct fuse_session *
2133
fuse_session_new_fn(struct fuse_args *args, const struct fuse_lowlevel_ops *op,
2134
        size_t op_size, void *userdata)
2135
0
{
2136
0
  struct libfuse_version version = {
2137
0
    .major = FUSE_MAJOR_VERSION,
2138
0
    .minor = FUSE_MINOR_VERSION,
2139
0
    .hotfix = FUSE_HOTFIX_VERSION,
2140
0
    .padding = 0
2141
0
  };
2142
0
2143
0
  return fuse_session_new_versioned(args, op, op_size, &version,
2144
0
            userdata);
2145
0
}
2146
#define fuse_session_new(args, op, op_size, userdata) \
2147
  fuse_session_new_fn(args, op, op_size, userdata)
2148
2149
/*
2150
 * This should mostly not be called directly, but instead the
2151
 * fuse_session_custom_io() should be used.
2152
 */
2153
int fuse_session_custom_io_317(struct fuse_session *se,
2154
      const struct fuse_custom_io *io, size_t op_size, int fd);
2155
2156
/**
2157
 * Set a file descriptor for the session.
2158
 *
2159
 * This function can be used if you want to have a custom communication
2160
 * interface instead of using a mountpoint. In practice, this means that instead
2161
 * of calling fuse_session_mount() and fuse_session_unmount(), one could call
2162
 * fuse_session_custom_io() where fuse_session_mount() would have otherwise been
2163
 * called.
2164
 *
2165
 * In `io`, implementations for read and writev MUST be provided. Otherwise -1
2166
 * will be returned and `fd` will not be used. Implementations for `splice_send`
2167
 * and `splice_receive` are optional. If they are not provided splice will not
2168
 * be used for send or receive respectively.
2169
 *
2170
 * The provided file descriptor `fd` will be closed when fuse_session_destroy()
2171
 * is called.
2172
 *
2173
 * @param se session object
2174
 * @param io Custom io to use when retrieving/sending requests/responses
2175
 * @param fd file descriptor for the session
2176
 *
2177
 * @return 0  on success
2178
 * @return -EINVAL if `io`, `io->read` or `ìo->writev` are NULL
2179
 * @return -EBADF  if `fd` was smaller than 0
2180
 * @return -errno  if failed to allocate memory to store `io`
2181
 *
2182
 **/
2183
#if FUSE_MAKE_VERSION(3, 17) <= FUSE_USE_VERSION
2184
static inline int fuse_session_custom_io(struct fuse_session *se,
2185
          const struct fuse_custom_io *io, size_t op_size, int fd)
2186
0
{
2187
0
  return fuse_session_custom_io_317(se, io, op_size, fd);
2188
0
}
2189
#else
2190
static inline int fuse_session_custom_io(struct fuse_session *se,
2191
          const struct fuse_custom_io *io, int fd)
2192
{
2193
  return fuse_session_custom_io_317(se, io,
2194
        offsetof(struct fuse_custom_io, clone_fd), fd);
2195
}
2196
#endif
2197
2198
/**
2199
 * Mount a FUSE file system.
2200
 *
2201
 * @param mountpoint the mount point path
2202
 * @param se session object
2203
 *
2204
 * @return 0 on success, -1 on failure.
2205
 **/
2206
int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
2207
2208
/**
2209
 * Enter a single threaded, blocking event loop.
2210
 *
2211
 * When the event loop terminates because the connection to the FUSE
2212
 * kernel module has been closed, this function returns zero. This
2213
 * happens when the filesystem is unmounted regularly (by the
2214
 * filesystem owner or root running the umount(8) or fusermount(1)
2215
 * command), or if connection is explicitly severed by writing ``1``
2216
 * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
2217
 * way to distinguish between these two conditions is to check if the
2218
 * filesystem is still mounted after the session loop returns.
2219
 *
2220
 * When some error occurs during request processing, the function
2221
 * returns a negated errno(3) value.
2222
 *
2223
 * If the loop has been terminated because of a signal handler
2224
 * installed by fuse_set_signal_handlers(), this function returns the
2225
 * (positive) signal value that triggered the exit.
2226
 *
2227
 * @param se the session
2228
 * @return 0, -errno, or a signal value
2229
 */
2230
int fuse_session_loop(struct fuse_session *se);
2231
2232
#if FUSE_USE_VERSION < 32
2233
  int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
2234
  #define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
2235
#elif FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
2236
  int fuse_session_loop_mt_32(struct fuse_session *se, struct fuse_loop_config *config);
2237
  #define fuse_session_loop_mt(se, config) fuse_session_loop_mt_32(se, config)
2238
#else
2239
  #if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
2240
    /**
2241
     * Enter a multi-threaded event loop.
2242
     *
2243
     * For a description of the return value and the conditions when the
2244
     * event loop exits, refer to the documentation of
2245
     * fuse_session_loop().
2246
     *
2247
     * @param se the session
2248
     * @param config session loop configuration
2249
     * @return see fuse_session_loop()
2250
     */
2251
    int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
2252
  #else
2253
    int fuse_session_loop_mt_312(struct fuse_session *se, struct fuse_loop_config *config);
2254
    #define fuse_session_loop_mt(se, config) fuse_session_loop_mt_312(se, config)
2255
  #endif
2256
#endif
2257
2258
/**
2259
 * Flag a session as terminated.
2260
 *
2261
 * This will cause any running event loops to terminate on the next opportunity. If this function is
2262
 * called by a thread that is not a FUSE worker thread, the next
2263
 * opportunity will be when FUSE a request is received (which may be far in the future if the
2264
 * filesystem is not currently being used by any clients). One way to avoid this delay is to
2265
 * afterwards sent a signal to the main thread (if fuse_set_signal_handlers() is used, SIGPIPE
2266
 * will cause the main thread to wake-up but otherwise be ignored).
2267
 *
2268
 * @param se the session
2269
 */
2270
void fuse_session_exit(struct fuse_session *se);
2271
2272
/**
2273
 * Reset the terminated flag of a session
2274
 *
2275
 * @param se the session
2276
 */
2277
void fuse_session_reset(struct fuse_session *se);
2278
2279
/**
2280
 * Query the terminated flag of a session
2281
 *
2282
 * @param se the session
2283
 * @return 1 if exited, 0 if not exited
2284
 */
2285
int fuse_session_exited(struct fuse_session *se);
2286
2287
/**
2288
 * Ensure that file system is unmounted.
2289
 *
2290
 * In regular operation, the file system is typically unmounted by the
2291
 * user calling umount(8) or fusermount(1), which then terminates the
2292
 * FUSE session loop. However, the session loop may also terminate as
2293
 * a result of an explicit call to fuse_session_exit() (e.g. by a
2294
 * signal handler installed by fuse_set_signal_handler()). In this
2295
 * case the filesystem remains mounted, but any attempt to access it
2296
 * will block (while the filesystem process is still running) or give
2297
 * an ESHUTDOWN error (after the filesystem process has terminated).
2298
 *
2299
 * If the communication channel with the FUSE kernel module is still
2300
 * open (i.e., if the session loop was terminated by an explicit call
2301
 * to fuse_session_exit()), this function will close it and unmount
2302
 * the filesystem. If the communication channel has been closed by the
2303
 * kernel, this method will do (almost) nothing.
2304
 *
2305
 * NOTE: The above semantics mean that if the connection to the kernel
2306
 * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
2307
 * this method will *not* unmount the filesystem.
2308
 *
2309
 * @param se the session
2310
 */
2311
void fuse_session_unmount(struct fuse_session *se);
2312
2313
/**
2314
 * Destroy a session
2315
 *
2316
 * @param se the session
2317
 */
2318
void fuse_session_destroy(struct fuse_session *se);
2319
2320
/**
2321
 * Callback type for timeout thread.
2322
 *
2323
 * @param data user-provided context
2324
 */
2325
typedef void (*fuse_timeout_cb)(void *data);
2326
2327
/**
2328
 * Start a timeout thread that polls on the session file descriptor to detect
2329
 * kernel (fuse-client) connection abort (POLLERR). If POLLERR is detected, it
2330
 * will call fuse_session_exit() to terminate the session and will also restart
2331
 * poll with the specified timeout. If the thread is not stopped within this
2332
 * timeout, the callback is invoked (or exit(1) if cb is NULL). This is useful
2333
 * to handle 'umount -f' and '/sys/fs/fuse/connections/NNN/abort'.
2334
 *
2335
 * @param se the session
2336
 * @param timeout_sec timeout in seconds for polling
2337
 * @param cb callback to invoke on timeout, or NULL to call exit(1)
2338
 * @param cb_data user-provided context for callback
2339
 * @return data pointer on success, NULL on failure
2340
 */
2341
void *fuse_session_start_teardown_watchdog(struct fuse_session *se,
2342
             int timeout_sec, fuse_timeout_cb cb,
2343
             void *cb_data);
2344
2345
/**
2346
 * Stop the timeout thread.
2347
 *
2348
 * @param data pointer returned by fuse_start_timeout_thread()
2349
 */
2350
void fuse_session_stop_teardown_watchdog(void *data);
2351
2352
/* ----------------------------------------------------------- *
2353
 * Custom event loop support                                   *
2354
 * ----------------------------------------------------------- */
2355
2356
/**
2357
 * Return file descriptor for communication with kernel.
2358
 *
2359
 * The file selector can be used to integrate FUSE with a custom event
2360
 * loop. Whenever data is available for reading on the provided fd,
2361
 * the event loop should call `fuse_session_receive_buf` followed by
2362
 * `fuse_session_process_buf` to process the request.
2363
 *
2364
 * The returned file descriptor is valid until `fuse_session_unmount`
2365
 * is called.
2366
 *
2367
 * @param se the session
2368
 * @return a file descriptor
2369
 */
2370
int fuse_session_fd(struct fuse_session *se);
2371
2372
/**
2373
 * Process a raw request supplied in a generic buffer
2374
 *
2375
 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
2376
 *
2377
 * @param se the session
2378
 * @param buf the fuse_buf containing the request
2379
 */
2380
void fuse_session_process_buf(struct fuse_session *se,
2381
            const struct fuse_buf *buf);
2382
2383
/**
2384
 * Read a raw request from the kernel into the supplied buffer.
2385
 *
2386
 * Depending on file system options, system capabilities, and request
2387
 * size the request is either read into a memory buffer or spliced
2388
 * into a temporary pipe.
2389
 *
2390
 * @param se the session
2391
 * @param buf the fuse_buf to store the request in
2392
 * @return the actual size of the raw request, or -errno on error
2393
 */
2394
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
2395
2396
/**
2397
 * Check if the request is submitted through fuse-io-uring
2398
 */
2399
bool fuse_req_is_uring(fuse_req_t req);
2400
2401
/**
2402
 * Get the payload of a request
2403
 * (for requests submitted through fuse-io-uring only)
2404
 *
2405
 * This is useful for a file system that wants to write data directly
2406
 * to the request buffer. With io-uring the req is the buffer owner
2407
 * and the file system can write directly to the buffer and avoid
2408
 * extra copying. For example useful for network file systems.
2409
 *
2410
 * @param req the request
2411
 * @param payload pointer to the payload
2412
 * @param payload_sz size of the payload
2413
 * @param mr  memory registration handle, currently unused
2414
 * @return 0 on success, -errno on failure
2415
 */
2416
int fuse_req_get_payload(fuse_req_t req, char **payload, size_t *payload_sz,
2417
       void **mr);
2418
2419
#ifdef __cplusplus
2420
}
2421
#endif
2422
2423
#endif /* FUSE_LOWLEVEL_H_ */