Coverage Report

Created: 2026-06-10 06:50

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