Coverage Report

Created: 2025-07-11 06:23

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