Coverage Report

Created: 2026-07-30 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfuse/include/fuse.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_H_
10
#define FUSE_H_
11
12
/** @file
13
 *
14
 * This file defines the library interface of FUSE
15
 *
16
 * IMPORTANT: you should define FUSE_USE_VERSION before including this header.
17
 */
18
19
#include "fuse_common.h"
20
21
#include <fcntl.h>
22
#include <time.h>
23
#include <sys/types.h>
24
#include <sys/stat.h>
25
#include <sys/statvfs.h>
26
#include <sys/uio.h>
27
28
#ifdef __cplusplus
29
extern "C" {
30
#endif
31
32
/* ----------------------------------------------------------- *
33
 * Basic FUSE API                *
34
 * ----------------------------------------------------------- */
35
36
/* Forward declaration */
37
struct statx;
38
39
/** Handle for a FUSE filesystem */
40
struct fuse;
41
42
/**
43
 * Readdir flags, passed to ->readdir()
44
 */
45
enum fuse_readdir_flags {
46
  /**
47
   * "Plus" mode.
48
   *
49
   * The kernel wants to prefill the inode cache during readdir.  The
50
   * filesystem may honour this by filling in the attributes and setting
51
   * FUSE_FILL_DIR_FLAGS for the filler function.  The filesystem may also
52
   * just ignore this flag completely.
53
   */
54
  FUSE_READDIR_DEFAULTS = 0,
55
  FUSE_READDIR_PLUS = (1 << 0)
56
};
57
58
/**
59
 * Readdir flags, passed to fuse_fill_dir_t callback.
60
 */
61
enum fuse_fill_dir_flags {
62
  /**
63
   * "Plus" mode: file attributes are valid
64
   *
65
   * The attributes are used by the kernel to prefill the inode cache
66
   * during a readdir.
67
   *
68
   * It is okay to set FUSE_FILL_DIR_PLUS if FUSE_READDIR_PLUS is not set
69
   * and vice versa.
70
   *
71
   * This does not make libfuse honor the 'st_ino' field. That is
72
   * controlled by the 'use_ino' option instead.
73
   */
74
  FUSE_FILL_DIR_DEFAULTS = 0,
75
  FUSE_FILL_DIR_PLUS = (1 << 1)
76
};
77
78
/** Function to add an entry in a readdir() operation
79
 *
80
 * The *off* parameter can be any non-zero value that enables the
81
 * filesystem to identify the current point in the directory
82
 * stream. It does not need to be the actual physical position. A
83
 * value of zero is reserved to indicate that seeking in directories
84
 * is not supported.
85
 *
86
 * @param buf the buffer passed to the readdir() operation
87
 * @param name the file name of the directory entry
88
 * @param stbuf file attributes, can be NULL
89
 * @param off offset of the next entry or zero
90
 * @param flags fill flags
91
 * @return 1 if buffer is full, zero otherwise
92
 */
93
typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
94
        const struct stat *stbuf, off_t off,
95
        enum fuse_fill_dir_flags flags);
96
/**
97
 * Configuration of the high-level API
98
 *
99
 * This structure is initialized from the arguments passed to
100
 * fuse_new(), and then passed to the file system's init() handler
101
 * which should ensure that the configuration is compatible with the
102
 * file system implementation.
103
 *
104
 * Note: this data structure is ABI sensitive, new options have to be
105
 * appended at the end of the structure
106
 */
107
struct fuse_config {
108
  /**
109
   * If `set_gid` is non-zero, the st_gid attribute of each file
110
   * is overwritten with the value of `gid`.
111
   */
112
  int32_t set_gid;
113
  uint32_t gid;
114
115
  /**
116
   * If `set_uid` is non-zero, the st_uid attribute of each file
117
   * is overwritten with the value of `uid`.
118
   */
119
  int32_t set_uid;
120
  uint32_t uid;
121
122
  /**
123
   * If `set_mode` is non-zero, the any permissions bits set in
124
   * `umask` are unset in the st_mode attribute of each file.
125
   */
126
  int32_t set_mode;
127
  uint32_t umask;
128
129
  /**
130
   * The timeout in seconds for which name lookups will be
131
   * cached.
132
   */
133
  double entry_timeout;
134
135
  /**
136
   * The timeout in seconds for which a negative lookup will be
137
   * cached. This means, that if file did not exist (lookup
138
   * returned ENOENT), the lookup will only be redone after the
139
   * timeout, and the file/directory will be assumed to not
140
   * exist until then. A value of zero means that negative
141
   * lookups are not cached.
142
   */
143
  double negative_timeout;
144
145
  /**
146
   * The timeout in seconds for which file/directory attributes
147
   * (as returned by e.g. the `getattr` handler) are cached.
148
   */
149
  double attr_timeout;
150
151
  /**
152
   * Allow requests to be interrupted
153
   */
154
  int32_t intr;
155
156
  /**
157
   * Specify which signal number to send to the filesystem when
158
   * a request is interrupted.  The default is hardcoded to
159
   * USR1.
160
   */
161
  int32_t intr_signal;
162
163
  /**
164
   * Normally, FUSE assigns inodes to paths only for as long as
165
   * the kernel is aware of them. With this option inodes are
166
   * instead remembered for at least this many seconds.  This
167
   * will require more memory, but may be necessary when using
168
   * applications that make use of inode numbers.
169
   *
170
   * A number of -1 means that inodes will be remembered for the
171
   * entire life-time of the file-system process.
172
   */
173
  int32_t remember;
174
175
  /**
176
   * The default behavior is that if an open file is deleted,
177
   * the file is renamed to a hidden file (.fuse_hiddenXXX), and
178
   * only removed when the file is finally released.  This
179
   * relieves the filesystem implementation of having to deal
180
   * with this problem. This option disables the hiding
181
   * behavior, and files are removed immediately in an unlink
182
   * operation (or in a rename operation which overwrites an
183
   * existing file).
184
   *
185
   * It is recommended that you not use the hard_remove
186
   * option. When hard_remove is set, the following libc
187
   * functions fail on unlinked files (returning errno of
188
   * ENOENT): read(2), write(2), fsync(2), close(2), f*xattr(2),
189
   * ftruncate(2), fstat(2), fchmod(2), fchown(2)
190
   */
191
  int32_t hard_remove;
192
193
  /**
194
   * Honor the st_ino field in the functions getattr() and
195
   * fill_dir(). This value is used to fill in the st_ino field
196
   * in the stat(2), lstat(2), fstat(2) functions and the d_ino
197
   * field in the readdir(2) function. The filesystem does not
198
   * have to guarantee uniqueness, however some applications
199
   * rely on this value being unique for the whole filesystem.
200
   *
201
   * Note that this does *not* affect the inode that libfuse
202
   * and the kernel use internally (also called the "nodeid").
203
   */
204
  int32_t use_ino;
205
206
  /**
207
   * If use_ino option is not given, still try to fill in the
208
   * d_ino field in readdir(2). If the name was previously
209
   * looked up, and is still in the cache, the inode number
210
   * found there will be used.  Otherwise it will be set to -1.
211
   * If use_ino option is given, this option is ignored.
212
   */
213
  int32_t readdir_ino;
214
215
  /**
216
   * This option disables the use of page cache (file content cache)
217
   * in the kernel for this filesystem. This has several affects:
218
   *
219
   * 1. Each read(2) or write(2) system call will initiate one
220
   *    or more read or write operations, data will not be
221
   *    cached in the kernel.
222
   *
223
   * 2. The return value of the read() and write() system calls
224
   *    will correspond to the return values of the read and
225
   *    write operations. This is useful for example if the
226
   *    file size is not known in advance (before reading it).
227
   *
228
   * Internally, enabling this option causes fuse to set the
229
   * `direct_io` field of `struct fuse_file_info` - overwriting
230
   * any value that was put there by the file system.
231
   */
232
  int32_t direct_io;
233
234
  /**
235
   * This option disables flushing the cache of the file
236
   * contents on every open(2).  This should only be enabled on
237
   * filesystems where the file data is never changed
238
   * externally (not through the mounted FUSE filesystem).  Thus
239
   * it is not suitable for network filesystems and other
240
   * intermediate filesystems.
241
   *
242
   * NOTE: if this option is not specified (and neither
243
   * direct_io) data is still cached after the open(2), so a
244
   * read(2) system call will not always initiate a read
245
   * operation.
246
   *
247
   * Internally, enabling this option causes fuse to set the
248
   * `keep_cache` field of `struct fuse_file_info` - overwriting
249
   * any value that was put there by the file system.
250
   */
251
  int32_t kernel_cache;
252
253
  /**
254
   * This option is an alternative to `kernel_cache`. Instead of
255
   * unconditionally keeping cached data, the cached data is
256
   * invalidated on open(2) if if the modification time or the
257
   * size of the file has changed since it was last opened.
258
   */
259
  int32_t auto_cache;
260
261
  /*
262
   * The timeout in seconds for which file attributes are cached
263
   * for the purpose of checking if auto_cache should flush the
264
   * file data on open.
265
   */
266
  int32_t ac_attr_timeout_set;
267
  double ac_attr_timeout;
268
269
  /**
270
   * If this option is given the file-system handlers for the
271
   * following operations will not receive path information:
272
   * read, write, flush, release, fallocate, fsync, readdir,
273
   * releasedir, fsyncdir, lock, ioctl and poll.
274
   *
275
   * For the truncate, getattr, chmod, chown and utimens
276
   * operations the path will be provided only if the struct
277
   * fuse_file_info argument is NULL.
278
   */
279
  int32_t nullpath_ok;
280
281
  /**
282
   * These 3 options are used by libfuse internally and
283
   * should not be touched.
284
   */
285
  int32_t show_help;
286
  char *modules;
287
  int32_t debug;
288
289
  /**
290
   * `fmask` and `dmask` function the same way as `umask`, but apply
291
   * to files and directories separately. If non-zero, `fmask` and
292
   * `dmask` take precedence over the `umask` setting.
293
   */
294
  uint32_t fmask;
295
  uint32_t dmask;
296
297
  /**
298
   * By default, fuse waits for all pending writes to complete
299
   * and calls the FLUSH operation on close(2) of every fuse fd.
300
   * With this option, wait and FLUSH are not done for read-only
301
   * fuse fd, similar to the behavior of NFS/SMB clients.
302
   */
303
  int32_t no_rofd_flush;
304
305
  /**
306
   *  Allow parallel direct-io writes to operate on the same file.
307
   *
308
   *  FUSE implementations which do not handle parallel writes on
309
   *  same file/region should NOT enable this option at all as it
310
   *  might lead to data inconsistencies.
311
   *
312
   *  For the FUSE implementations which have their own mechanism
313
   *  of cache/data integrity are beneficiaries of this setting as
314
   *  it now open doors to parallel writes on the same file (without
315
   *  enabling this setting, all direct writes on the same file are
316
   *  serialized, resulting in huge data bandwidth loss).
317
   */
318
  int32_t parallel_direct_writes;
319
320
321
  /**
322
   * Reserved for future use.
323
   */
324
  uint32_t flags;
325
326
  /**
327
   * Reserved for future use.
328
   */
329
  uint64_t reserved[48];
330
};
331
332
333
/**
334
 * The file system operations:
335
 *
336
 * Most of these should work very similarly to the well known UNIX
337
 * file system operations.  A major exception is that instead of
338
 * returning an error in 'errno', the operation should return the
339
 * negated error value (-errno) directly.
340
 *
341
 * All methods are optional, but some are essential for a useful
342
 * filesystem (e.g. getattr).  Open, flush, release, fsync, opendir,
343
 * releasedir, fsyncdir, access, create, truncate, lock, init and
344
 * destroy are special purpose methods, without which a full featured
345
 * filesystem can still be implemented.
346
 *
347
 * In general, all methods are expected to perform any necessary
348
 * permission checking. However, a filesystem may delegate this task
349
 * to the kernel by passing the `default_permissions` mount option to
350
 * `fuse_new()`. In this case, methods will only be called if
351
 * the kernel's permission check has succeeded.
352
 *
353
 * Almost all operations take a path which can be of any length.
354
 */
355
struct fuse_operations {
356
  /** Get file attributes.
357
   *
358
   * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
359
   * ignored. The 'st_ino' field is ignored except if the 'use_ino'
360
   * mount option is given. In that case it is passed to userspace,
361
   * but libfuse and the kernel will still assign a different
362
   * inode for internal use (called the "nodeid").
363
   *
364
   * `fi` will always be NULL if the file is not currently open, but
365
   * may also be NULL if the file is open.
366
   */
367
  int (*getattr) (const char *, struct stat *, struct fuse_file_info *fi);
368
369
  /** Read the target of a symbolic link
370
   *
371
   * The buffer should be filled with a null terminated string.  The
372
   * buffer size argument includes the space for the terminating
373
   * null character.  If the linkname is too long to fit in the
374
   * buffer, it should be truncated.  The return value should be 0
375
   * for success.
376
   */
377
  int (*readlink) (const char *, char *, size_t);
378
379
  /** Create a file node
380
   *
381
   * This is called for creation of all non-directory, non-symlink
382
   * nodes.  If the filesystem defines a create() method, then for
383
   * regular files that will be called instead.
384
   */
385
  int (*mknod) (const char *, mode_t, dev_t);
386
387
  /** Create a directory
388
   *
389
   * Note that the mode argument may not have the type specification
390
   * bits set, i.e. S_ISDIR(mode) can be false.  To obtain the
391
   * correct directory type bits use  mode|S_IFDIR
392
   * */
393
  int (*mkdir) (const char *, mode_t);
394
395
  /** Remove a file */
396
  int (*unlink) (const char *);
397
398
  /** Remove a directory */
399
  int (*rmdir) (const char *);
400
401
  /** Create a symbolic link */
402
  int (*symlink) (const char *, const char *);
403
404
  /** Rename a file
405
   *
406
   * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
407
   * RENAME_NOREPLACE is specified, the filesystem must not
408
   * overwrite *newname* if it exists and return an error
409
   * instead. If `RENAME_EXCHANGE` is specified, the filesystem
410
   * must atomically exchange the two files, i.e. both must
411
   * exist and neither may be deleted.
412
   */
413
  int (*rename) (const char *, const char *, unsigned int flags);
414
415
  /** Create a hard link to a file */
416
  int (*link) (const char *, const char *);
417
418
  /** Change the permission bits of a file
419
   *
420
   * `fi` will always be NULL if the file is not currently open, but
421
   * may also be NULL if the file is open.
422
   */
423
  int (*chmod) (const char *, mode_t, struct fuse_file_info *fi);
424
425
  /** Change the owner and group of a file
426
   *
427
   * `fi` will always be NULL if the file is not currently open, but
428
   * may also be NULL if the file is open.
429
   *
430
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
431
   * expected to reset the setuid and setgid bits.
432
   */
433
  int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info *fi);
434
435
  /** Change the size of a file
436
   *
437
   * `fi` will always be NULL if the file is not currently open, but
438
   * may also be NULL if the file is open.
439
   *
440
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
441
   * expected to reset the setuid and setgid bits.
442
   */
443
  int (*truncate) (const char *, off_t, struct fuse_file_info *fi);
444
445
  /** Open a file
446
   *
447
   * Open flags are available in fi->flags. The following rules
448
   * apply.
449
   *
450
   *  - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
451
   *    filtered out / handled by the kernel.
452
   *
453
   *  - Access modes (O_RDONLY, O_WRONLY, O_RDWR, O_EXEC, O_SEARCH)
454
   *    should be used by the filesystem to check if the operation is
455
   *    permitted.  If the ``-o default_permissions`` mount option is
456
   *    given, this check is already done by the kernel before calling
457
   *    open() and may thus be omitted by the filesystem.
458
   *
459
   *  - When writeback caching is enabled, the kernel may send
460
   *    read requests even for files opened with O_WRONLY. The
461
   *    filesystem should be prepared to handle this.
462
   *
463
   *  - When writeback caching is disabled, the filesystem is
464
   *    expected to properly handle the O_APPEND flag and ensure
465
   *    that each write is appending to the end of the file.
466
   *
467
   *  - When writeback caching is enabled, the kernel will
468
   *    handle O_APPEND. However, unless all changes to the file
469
   *    come through the kernel this will not work reliably. The
470
   *    filesystem should thus either ignore the O_APPEND flag
471
   *    (and let the kernel handle it), or return an error
472
   *    (indicating that reliably O_APPEND is not available).
473
   *
474
   * Filesystem may store an arbitrary file handle (pointer,
475
   * index, etc) in fi->fh, and use this in other all other file
476
   * operations (read, write, flush, release, fsync).
477
   *
478
   * Filesystem may also implement stateless file I/O and not store
479
   * anything in fi->fh.
480
   *
481
   * There are also some flags (direct_io, keep_cache) which the
482
   * filesystem may set in fi, to change the way the file is opened.
483
   * See fuse_file_info structure in <fuse_common.h> for more details.
484
   *
485
   * If this request is answered with an error code of ENOSYS
486
   * and FUSE_CAP_NO_OPEN_SUPPORT is set in
487
   * `fuse_conn_info.capable`, this is treated as success and
488
   * future calls to open will also succeed without being sent
489
   * to the filesystem process.
490
   *
491
   */
492
  int (*open) (const char *, struct fuse_file_info *);
493
494
  /** Read data from an open file
495
   *
496
   * Read should return exactly the number of bytes requested except
497
   * on EOF or error, otherwise the rest of the data will be
498
   * substituted with zeroes.  An exception to this is when the
499
   * 'direct_io' mount option is specified, in which case the return
500
   * value of the read system call will reflect the return value of
501
   * this operation.
502
   */
503
  int (*read) (const char *, char *, size_t, off_t,
504
         struct fuse_file_info *);
505
506
  /** Write data to an open file
507
   *
508
   * Write should return exactly the number of bytes requested
509
   * except on error.  An exception to this is when the 'direct_io'
510
   * mount option is specified (see read operation).
511
   *
512
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
513
   * expected to reset the setuid and setgid bits.
514
   */
515
  int (*write) (const char *, const char *, size_t, off_t,
516
          struct fuse_file_info *);
517
518
  /** Get file system statistics
519
   *
520
   * The 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
521
   */
522
  int (*statfs) (const char *, struct statvfs *);
523
524
  /** Possibly flush cached data
525
   *
526
   * BIG NOTE: This is not equivalent to fsync().  It's not a
527
   * request to sync dirty data.
528
   *
529
   * Flush is called on each close() of a file descriptor, as opposed to
530
   * release which is called on the close of the last file descriptor for
531
   * a file.  Under Linux, errors returned by flush() will be passed to
532
   * userspace as errors from close(), so flush() is a good place to write
533
   * back any cached dirty data. However, many applications ignore errors
534
   * on close(), and on non-Linux systems, close() may succeed even if flush()
535
   * returns an error. For these reasons, filesystems should not assume
536
   * that errors returned by flush will ever be noticed or even
537
   * delivered.
538
   *
539
   * NOTE: The flush() method may be called more than once for each
540
   * open().  This happens if more than one file descriptor refers to an
541
   * open file handle, e.g. due to dup(), dup2() or fork() calls.  It is
542
   * not possible to determine if a flush is final, so each flush should
543
   * be treated equally.  Multiple write-flush sequences are relatively
544
   * rare, so this shouldn't be a problem.
545
   *
546
   * Filesystems shouldn't assume that flush will be called at any
547
   * particular point.  It may be called more times than expected, or not
548
   * at all.
549
   *
550
   * [close]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
551
   */
552
  int (*flush) (const char *, struct fuse_file_info *);
553
554
  /** Release an open file
555
   *
556
   * Release is called when there are no more references to an open
557
   * file: all file descriptors are closed and all memory mappings
558
   * are unmapped.
559
   *
560
   * For every open() call there will be exactly one release() call
561
   * with the same flags and file handle.  It is possible to
562
   * have a file opened more than once, in which case only the last
563
   * release will mean, that no more reads/writes will happen on the
564
   * file.  The return value of release is ignored.
565
   */
566
  int (*release) (const char *, struct fuse_file_info *);
567
568
  /** Synchronize file contents
569
   *
570
   * If the datasync parameter is non-zero, then only the user data
571
   * should be flushed, not the meta data.
572
   */
573
  int (*fsync) (const char *, int, struct fuse_file_info *);
574
575
  /** Set extended attributes */
576
  int (*setxattr) (const char *, const char *, const char *, size_t, int);
577
578
  /** Get extended attributes */
579
  int (*getxattr) (const char *, const char *, char *, size_t);
580
581
  /** List extended attributes */
582
  int (*listxattr) (const char *, char *, size_t);
583
584
  /** Remove extended attributes */
585
  int (*removexattr) (const char *, const char *);
586
587
  /** Open directory
588
   *
589
   * Unless the 'default_permissions' mount option is given,
590
   * this method should check if opendir is permitted for this
591
   * directory. Optionally opendir may also return an arbitrary
592
   * filehandle in the fuse_file_info structure, which will be
593
   * passed to readdir, releasedir and fsyncdir.
594
   */
595
  int (*opendir) (const char *, struct fuse_file_info *);
596
597
  /** Read directory
598
   *
599
   * The filesystem may choose between two modes of operation:
600
   *
601
   * 1) The readdir implementation ignores the offset parameter, and
602
   * passes zero to the filler function's offset.  The filler
603
   * function will not return '1' (unless an error happens), so the
604
   * whole directory is read in a single readdir operation.
605
   *
606
   * 2) The readdir implementation keeps track of the offsets of the
607
   * directory entries.  It uses the offset parameter and always
608
   * passes non-zero offset to the filler function.  When the buffer
609
   * is full (or an error happens) the filler function will return
610
   * '1'.
611
   *
612
   * When FUSE_READDIR_PLUS is not set, only some parameters of the
613
   * fill function (the fuse_fill_dir_t parameter) are actually used:
614
   * The file type (which is part of stat::st_mode) is used. And if
615
   * fuse_config::use_ino is set, the inode (stat::st_ino) is also
616
   * used. The other fields are ignored when FUSE_READDIR_PLUS is not
617
   * set.
618
   */
619
  int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
620
      struct fuse_file_info *, enum fuse_readdir_flags);
621
622
  /** Release directory
623
   *
624
   * If the directory has been removed after the call to opendir, the
625
   * path parameter will be NULL.
626
   */
627
  int (*releasedir) (const char *, struct fuse_file_info *);
628
629
  /** Synchronize directory contents
630
   *
631
   * If the directory has been removed after the call to opendir, the
632
   * path parameter will be NULL.
633
   *
634
   * If the datasync parameter is non-zero, then only the user data
635
   * should be flushed, not the meta data
636
   */
637
  int (*fsyncdir) (const char *, int, struct fuse_file_info *);
638
639
  /**
640
   * Initialize filesystem
641
   *
642
   * The return value will passed in the `private_data` field of
643
   * `struct fuse_context` to all file operations, and as a
644
   * parameter to the destroy() method. It overrides the initial
645
   * value provided to fuse_main() / fuse_new().
646
   */
647
  void *(*init) (struct fuse_conn_info *conn,
648
           struct fuse_config *cfg);
649
650
  /**
651
   * Clean up filesystem
652
   *
653
   * Called on filesystem exit.
654
   */
655
  void (*destroy) (void *private_data);
656
657
  /**
658
   * Check file access permissions
659
   *
660
   * This will be called for the access() system call.  If the
661
   * 'default_permissions' mount option is given, this method is not
662
   * called.
663
   *
664
   * This method is not called under Linux kernel versions 2.4.x
665
   */
666
  int (*access) (const char *, int);
667
668
  /**
669
   * Create and open a file
670
   *
671
   * If the file does not exist, first create it with the specified
672
   * mode, and then open it.
673
   *
674
   * If this method is not implemented or under Linux kernel
675
   * versions earlier than 2.6.15, the mknod() and open() methods
676
   * will be called instead.
677
   */
678
  int (*create) (const char *, mode_t, struct fuse_file_info *);
679
680
  /**
681
   * Perform POSIX file locking operation
682
   *
683
   * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
684
   *
685
   * For the meaning of fields in 'struct flock' see the man page
686
   * for fcntl(2).  The l_whence field will always be set to
687
   * SEEK_SET.
688
   *
689
   * For checking lock ownership, the 'fuse_file_info->owner'
690
   * argument must be used.
691
   *
692
   * For F_GETLK operation, the library will first check currently
693
   * held locks, and if a conflicting lock is found it will return
694
   * information without calling this method.  This ensures, that
695
   * for local locks the l_pid field is correctly filled in.  The
696
   * results may not be accurate in case of race conditions and in
697
   * the presence of hard links, but it's unlikely that an
698
   * application would rely on accurate GETLK results in these
699
   * cases.  If a conflicting lock is not found, this method will be
700
   * called, and the filesystem may fill out l_pid by a meaningful
701
   * value, or it may leave this field zero.
702
   *
703
   * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
704
   * of the process performing the locking operation.
705
   *
706
   * Note: if this method is not implemented, the kernel will still
707
   * allow file locking to work locally.  Hence it is only
708
   * interesting for network filesystems and similar.
709
   */
710
  int (*lock) (const char *, struct fuse_file_info *, int cmd,
711
         struct flock *);
712
713
  /**
714
   * Change the access and modification times of a file with
715
   * nanosecond resolution
716
   *
717
   * This supersedes the old utime() interface.  New applications
718
   * should use this.
719
   *
720
   * `fi` will always be NULL if the file is not currently open, but
721
   * may also be NULL if the file is open.
722
   *
723
   * See the utimensat(2) man page for details.
724
   */
725
   int (*utimens) (const char *, const struct timespec tv[2],
726
       struct fuse_file_info *fi);
727
728
  /**
729
   * Map block index within file to block index within device
730
   *
731
   * Note: This makes sense only for block device backed filesystems
732
   * mounted with the 'blkdev' option
733
   */
734
  int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
735
736
#if FUSE_USE_VERSION < 35
737
  int (*ioctl) (const char *, int cmd, void *arg,
738
          struct fuse_file_info *, unsigned int flags, void *data);
739
#else
740
  /**
741
   * Ioctl
742
   *
743
   * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in
744
   * 64bit environment.  The size and direction of data is
745
   * determined by _IOC_*() decoding of cmd.  For _IOC_NONE,
746
   * data will be NULL, for _IOC_WRITE data is out area, for
747
   * _IOC_READ in area and if both are set in/out area.  In all
748
   * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes.
749
   *
750
   * If flags has FUSE_IOCTL_DIR then the fuse_file_info refers to a
751
   * directory file handle.
752
   *
753
   * Note : the unsigned long request submitted by the application
754
   * is truncated to 32 bits.
755
   */
756
  int (*ioctl) (const char *, unsigned int cmd, void *arg,
757
          struct fuse_file_info *, unsigned int flags, void *data);
758
#endif
759
760
  /**
761
   * Poll for IO readiness events
762
   *
763
   * Note: If ph is non-NULL, the client should notify
764
   * when IO readiness events occur by calling
765
   * fuse_notify_poll() with the specified ph.
766
   *
767
   * Regardless of the number of times poll with a non-NULL ph
768
   * is received, single notification is enough to clear all.
769
   * Notifying more times incurs overhead but doesn't harm
770
   * correctness.
771
   *
772
   * The callee is responsible for destroying ph with
773
   * fuse_pollhandle_destroy() when no longer in use.
774
   */
775
  int (*poll) (const char *, struct fuse_file_info *,
776
         struct fuse_pollhandle *ph, unsigned *reventsp);
777
778
  /** Write contents of buffer to an open file
779
   *
780
   * Similar to the write() method, but data is supplied in a
781
   * generic buffer.  Use fuse_buf_copy() to transfer data to
782
   * the destination.
783
   *
784
   * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
785
   * expected to reset the setuid and setgid bits.
786
   */
787
  int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off,
788
        struct fuse_file_info *);
789
790
  /** Store data from an open file in a buffer
791
   *
792
   * Similar to the read() method, but data is stored and
793
   * returned in a generic buffer.
794
   *
795
   * No actual copying of data has to take place, the source
796
   * file descriptor may simply be stored in the buffer for
797
   * later data transfer.
798
   *
799
   * The buffer must be allocated dynamically and stored at the
800
   * location pointed to by bufp.  If the buffer contains memory
801
   * regions, they too must be allocated using malloc().  The
802
   * allocated memory will be freed by the caller.
803
   */
804
  int (*read_buf) (const char *, struct fuse_bufvec **bufp,
805
       size_t size, off_t off, struct fuse_file_info *);
806
  /**
807
   * Perform BSD file locking operation
808
   *
809
   * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN
810
   *
811
   * Nonblocking requests will be indicated by ORing LOCK_NB to
812
   * the above operations
813
   *
814
   * For more information see the flock(2) manual page.
815
   *
816
   * Additionally fi->owner will be set to a value unique to
817
   * this open file.  This same value will be supplied to
818
   * ->release() when the file is released.
819
   *
820
   * Note: if this method is not implemented, the kernel will still
821
   * allow file locking to work locally.  Hence it is only
822
   * interesting for network filesystems and similar.
823
   */
824
  int (*flock) (const char *, struct fuse_file_info *, int op);
825
826
  /**
827
   * Allocates space for an open file
828
   *
829
   * This function ensures that required space is allocated for specified
830
   * file.  If this function returns success then any subsequent write
831
   * request to specified range is guaranteed not to fail because of lack
832
   * of space on the file system media.
833
   */
834
  int (*fallocate) (const char *, int, off_t, off_t,
835
        struct fuse_file_info *);
836
837
  /**
838
   * Copy a range of data from one file to another
839
   *
840
   * Performs an optimized copy between two file descriptors without the
841
   * additional cost of transferring data through the FUSE kernel module
842
   * to user space (glibc) and then back into the FUSE filesystem again.
843
   *
844
   * In case this method is not implemented, applications are expected to
845
   * fall back to a regular file copy.   (Some glibc versions did this
846
   * emulation automatically, but the emulation has been removed from all
847
   * glibc release branches.)
848
   */
849
  ssize_t (*copy_file_range) (const char *path_in,
850
            struct fuse_file_info *fi_in,
851
            off_t offset_in, const char *path_out,
852
            struct fuse_file_info *fi_out,
853
            off_t offset_out, size_t size, int flags);
854
855
  /**
856
   * Find next data or hole after the specified offset
857
   */
858
  off_t (*lseek) (const char *, off_t off, int whence, struct fuse_file_info *);
859
860
  /**
861
   * Get extended file attributes.
862
   *
863
   * fi may be NULL.
864
   *
865
   * If path is NULL, then the AT_EMPTY_PATH bit in flags will be
866
   * already set.
867
   */
868
  int (*statx)(const char *path, int flags, int mask, struct statx *stxbuf,
869
         struct fuse_file_info *fi);
870
871
  /**
872
   * Synchronize the filesystem.
873
   *
874
   * Causes all dirty file data and filesystem metadata to be written to
875
   * underlying persistent storage.
876
   *
877
   * Supported since Linux kernel 6.18, and only on fuseblk file servers.
878
   *
879
   * path contains a path to a file within the filesystem. On Linux, it
880
   * corresponds to the file descriptor given as an argument to the
881
   * syncfs(2) system call. However, as this is considered a
882
   * filesystem-level operation, the path can usually be safely ignored.
883
   *
884
   * On a successful return, expected to provide the same guarantees as
885
   * calling fsync(2) on every file on the filesystem.
886
   */
887
  int (*syncfs)(const char *path);
888
};
889
890
/** Extra context that may be needed by some filesystems
891
 *
892
 * The uid, gid and pid fields are not filled in case of a writepage
893
 * operation.
894
 */
895
struct fuse_context {
896
  /** Pointer to the fuse object */
897
  struct fuse *fuse;
898
899
  /** User ID of the calling process */
900
  uid_t uid;
901
902
  /** Group ID of the calling process */
903
  gid_t gid;
904
905
  /** Process ID of the calling thread */
906
  pid_t pid;
907
908
  /** Private filesystem data */
909
  void *private_data;
910
911
  /** Umask of the calling process */
912
  mode_t umask;
913
};
914
915
/**
916
 * The real main function
917
 *
918
 * Do not call this directly, use fuse_main()
919
 */
920
int fuse_main_real_versioned(int argc, char *argv[],
921
           const struct fuse_operations *op, size_t op_size,
922
           struct libfuse_version *version, void *user_data);
923
static inline int fuse_main_real(int argc, char *argv[],
924
         const struct fuse_operations *op,
925
         size_t op_size, void *user_data)
926
0
{
927
0
  struct libfuse_version version = { .major = FUSE_MAJOR_VERSION,
928
0
             .minor = FUSE_MINOR_VERSION,
929
0
             .hotfix = FUSE_HOTFIX_VERSION,
930
0
             .padding = 0 };
931
0
932
0
  fuse_log(FUSE_LOG_ERR,
933
0
     "%s is a libfuse internal function, please use fuse_main()\n",
934
0
     __func__);
935
0
936
0
  return fuse_main_real_versioned(argc, argv, op, op_size, &version,
937
0
          user_data);
938
0
}
Unexecuted instantiation: fuzz_optparse.c:fuse_main_real
Unexecuted instantiation: fuse_opt.c:fuse_main_real
939
940
/**
941
 * Main function of FUSE.
942
 *
943
 * This is for the lazy.  This is all that has to be called from the
944
 * main() function.
945
 *
946
 * This function does the following:
947
 *   - parses command line options, and handles --help and
948
 *     --version
949
 *   - installs signal handlers for INT, HUP, TERM and PIPE
950
 *   - registers an exit handler to unmount the filesystem on program exit
951
 *   - creates a fuse handle
952
 *   - registers the operations
953
 *   - calls either the single-threaded or the multi-threaded event loop
954
 *
955
 * Most file systems will have to parse some file-system specific
956
 * arguments before calling this function. It is recommended to do
957
 * this with fuse_opt_parse() and a processing function that passes
958
 * through any unknown options (this can also be achieved by just
959
 * passing NULL as the processing function). That way, the remaining
960
 * options can be passed directly to fuse_main().
961
 *
962
 * fuse_main() accepts all options that can be passed to
963
 * fuse_parse_cmdline(), fuse_new(), or fuse_session_new().
964
 *
965
 * Option parsing skips argv[0], which is assumed to contain the
966
 * program name. This element must always be present and is used to
967
 * construct a basic ``usage: `` message for the --help
968
 * output. argv[0] may also be set to the empty string. In this case
969
 * the usage message is suppressed. This can be used by file systems
970
 * to print their own usage line first. See hello.c for an example of
971
 * how to do this.
972
 *
973
 * Note: this is currently implemented as a macro.
974
 *
975
 * The following error codes may be returned from fuse_main():
976
 *   1: Invalid option arguments
977
 *   2: No mount point specified
978
 *   3: FUSE setup failed
979
 *   4: Mounting failed
980
 *   5: Failed to daemonize (detach from session)
981
 *   6: Failed to set up signal handlers
982
 *   7: An error occurred during the life of the file system
983
 *
984
 * @param argc the argument counter passed to the main() function
985
 * @param argv the argument vector passed to the main() function
986
 * @param op the file system operation
987
 * @param private_data Initial value for the `private_data`
988
 *            field of `struct fuse_context`. May be overridden by the
989
 *            `struct fuse_operations.init` handler.
990
 * @return 0 on success, nonzero on failure
991
 *
992
 * Example usage, see hello.c
993
 */
994
static inline int fuse_main_fn(int argc, char *argv[],
995
             const struct fuse_operations *op,
996
             void *user_data)
997
0
{
998
0
  struct libfuse_version version = {
999
0
    .major  = FUSE_MAJOR_VERSION,
1000
0
    .minor  = FUSE_MINOR_VERSION,
1001
0
    .hotfix = FUSE_HOTFIX_VERSION,
1002
0
    .padding = 0
1003
0
  };
1004
0
1005
0
  return fuse_main_real_versioned(argc, argv, op, sizeof(*(op)), &version,
1006
0
          user_data);
1007
0
}
Unexecuted instantiation: fuzz_optparse.c:fuse_main_fn
Unexecuted instantiation: fuse_opt.c:fuse_main_fn
1008
#define fuse_main(argc, argv, op, user_data) \
1009
  fuse_main_fn(argc, argv, op, user_data)
1010
1011
#if FUSE_MAKE_VERSION(3, 19) <= FUSE_USE_VERSION
1012
struct fuse_service;
1013
int fuse_service_main_real_versioned(struct fuse_service *service,
1014
             struct fuse_args *args,
1015
             const struct fuse_operations *op,
1016
             size_t op_size,
1017
             struct libfuse_version *version,
1018
             void *user_data);
1019
1020
/**
1021
 * Same as fuse_service_main_fn, but takes its information from the mount
1022
 * service context and an fuse_args that has already had fuse_service_append_args
1023
 * applied to it.
1024
 */
1025
static inline int fuse_service_main_fn(struct fuse_service *service,
1026
               struct fuse_args *args,
1027
               const struct fuse_operations *op,
1028
               void *user_data)
1029
0
{
1030
0
  struct libfuse_version version = {
1031
0
    .major  = FUSE_MAJOR_VERSION,
1032
0
    .minor  = FUSE_MINOR_VERSION,
1033
0
    .hotfix = FUSE_HOTFIX_VERSION,
1034
0
    .padding = FUSE_USE_VERSION,
1035
0
  };
1036
0
1037
0
  return fuse_service_main_real_versioned(service, args, op,
1038
0
            sizeof(*(op)), &version,
1039
0
            user_data);
1040
0
}
1041
#define fuse_service_main(s, args, op, user_data) \
1042
  fuse_service_main_fn(s, args, op, user_data)
1043
#endif /* FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 19) */
1044
1045
/* ----------------------------------------------------------- *
1046
 * More detailed API                 *
1047
 * ----------------------------------------------------------- */
1048
1049
/**
1050
 * Print available options (high- and low-level) to stdout.  This is
1051
 * not an exhaustive list, but includes only those options that may be
1052
 * of interest to an end-user of a file system.
1053
 *
1054
 * The function looks at the argument vector only to determine if
1055
 * there are additional modules to be loaded (module=foo option),
1056
 * and attempts to call their help functions as well.
1057
 *
1058
 * @param args the argument vector.
1059
 */
1060
void fuse_lib_help(struct fuse_args *args);
1061
1062
/* Do not call this directly, use fuse_new() instead */
1063
struct fuse *_fuse_new_30(struct fuse_args *args,
1064
        const struct fuse_operations *op, size_t op_size,
1065
        struct libfuse_version *version, void *user_data);
1066
struct fuse *_fuse_new_31(struct fuse_args *args,
1067
        const struct fuse_operations *op, size_t op_size,
1068
        struct libfuse_version *version, void *user_data);
1069
1070
/**
1071
 * Create a new FUSE filesystem.
1072
 *
1073
 * This function accepts most file-system independent mount options
1074
 * (like context, nodev, ro - see mount(8)), as well as the
1075
 * FUSE-specific mount options from mount.fuse(8).
1076
 *
1077
 * If the --help option is specified, the function writes a help text
1078
 * to stdout and returns NULL.
1079
 *
1080
 * Option parsing skips argv[0], which is assumed to contain the
1081
 * program name. This element must always be present and is used to
1082
 * construct a basic ``usage: `` message for the --help output. If
1083
 * argv[0] is set to the empty string, no usage message is included in
1084
 * the --help output.
1085
 *
1086
 * If an unknown option is passed in, an error message is written to
1087
 * stderr and the function returns NULL.
1088
 *
1089
 * @param args argument vector
1090
 * @param op the filesystem operations
1091
 * @param op_size the size of the fuse_operations structure
1092
 * @param private_data Initial value for the `private_data`
1093
 *            field of `struct fuse_context`. May be overridden by the
1094
 *            `struct fuse_operations.init` handler.
1095
 * @return the created FUSE handle
1096
 */
1097
#if FUSE_USE_VERSION == 30
1098
static inline struct fuse *fuse_new_fn(struct fuse_args *args,
1099
               const struct fuse_operations *op,
1100
               size_t op_size, void *user_data)
1101
{
1102
  struct libfuse_version version = {
1103
    .major = FUSE_MAJOR_VERSION,
1104
    .minor = FUSE_MINOR_VERSION,
1105
    .hotfix = FUSE_HOTFIX_VERSION,
1106
    .padding = 0
1107
  };
1108
1109
  return _fuse_new_30(args, op, op_size, &version, user_data);
1110
}
1111
#else /* FUSE_USE_VERSION */
1112
static inline struct fuse *fuse_new_fn(struct fuse_args *args,
1113
               const struct fuse_operations *op,
1114
               size_t op_size, void *user_data)
1115
0
{
1116
0
  struct libfuse_version version = {
1117
0
    .major = FUSE_MAJOR_VERSION,
1118
0
    .minor = FUSE_MINOR_VERSION,
1119
0
    .hotfix = FUSE_HOTFIX_VERSION,
1120
0
    .padding = 0
1121
0
  };
1122
0
1123
0
  return _fuse_new_31(args, op, op_size, &version, user_data);
1124
0
}
Unexecuted instantiation: fuzz_optparse.c:fuse_new_fn
Unexecuted instantiation: fuse_opt.c:fuse_new_fn
1125
#endif
1126
#define fuse_new(args, op, size, data) fuse_new_fn(args, op, size, data)
1127
1128
/**
1129
 * Mount a FUSE file system.
1130
 *
1131
 * @param mountpoint the mount point path
1132
 * @param f the FUSE handle
1133
 *
1134
 * @return 0 on success, -1 on failure.
1135
 **/
1136
int fuse_mount(const struct fuse *f, const char *mountpoint);
1137
1138
/**
1139
 * Unmount a FUSE file system.
1140
 *
1141
 * See fuse_session_unmount() for additional information.
1142
 *
1143
 * @param f the FUSE handle
1144
 **/
1145
void fuse_unmount(const struct fuse *f);
1146
1147
/**
1148
 * Destroy the FUSE handle.
1149
 *
1150
 * NOTE: This function does not unmount the filesystem.  If this is
1151
 * needed, call fuse_unmount() before calling this function.
1152
 *
1153
 * @param f the FUSE handle
1154
 */
1155
void fuse_destroy(struct fuse *f);
1156
1157
/**
1158
 * FUSE event loop.
1159
 *
1160
 * Requests from the kernel are processed, and the appropriate
1161
 * operations are called.
1162
 *
1163
 * For a description of the return value and the conditions when the
1164
 * event loop exits, refer to the documentation of
1165
 * fuse_session_loop().
1166
 *
1167
 * @param f the FUSE handle
1168
 * @return see fuse_session_loop()
1169
 *
1170
 * See also: fuse_loop_mt()
1171
 */
1172
int fuse_loop(struct fuse *f);
1173
1174
/**
1175
 * Flag session as terminated
1176
 *
1177
 * This function will cause any running event loops to exit on
1178
 * the next opportunity.
1179
 *
1180
 * @param f the FUSE handle
1181
 */
1182
void fuse_exit(struct fuse *f);
1183
1184
#if FUSE_USE_VERSION < 32
1185
int fuse_loop_mt_31(struct fuse *f, int clone_fd);
1186
#define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd)
1187
#elif FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
1188
int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config *config);
1189
#define fuse_loop_mt(f, config) fuse_loop_mt_32(f, config)
1190
#else
1191
/**
1192
 * FUSE event loop with multiple threads
1193
 *
1194
 * Requests from the kernel are processed, and the appropriate
1195
 * operations are called.  Request are processed in parallel by
1196
 * distributing them between multiple threads.
1197
 *
1198
 * For a description of the return value and the conditions when the
1199
 * event loop exits, refer to the documentation of
1200
 * fuse_session_loop().
1201
 *
1202
 * Note: using fuse_loop() instead of fuse_loop_mt() means you are running in
1203
 * single-threaded mode, and that you will not have to worry about reentrancy,
1204
 * though you will have to worry about recursive lookups. In single-threaded
1205
 * mode, FUSE will wait for one callback to return before calling another.
1206
 *
1207
 * Enabling multiple threads, by using fuse_loop_mt(), will cause FUSE to make
1208
 * multiple simultaneous calls into the various callback functions given by your
1209
 * fuse_operations record.
1210
 *
1211
 * If you are using multiple threads, you can enjoy all the parallel execution
1212
 * and interactive response benefits of threads, and you get to enjoy all the
1213
 * benefits of race conditions and locking bugs, too. Ensure that any code used
1214
 * in the callback function of fuse_operations is also thread-safe.
1215
 *
1216
 * @param f the FUSE handle
1217
 * @param config loop configuration, may be NULL and defaults will be used then
1218
 * @return see fuse_session_loop()
1219
 *
1220
 * See also: fuse_loop()
1221
 */
1222
#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
1223
int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config);
1224
#else
1225
#define fuse_loop_mt(f, config) fuse_loop_mt_312(f, config)
1226
#endif /* LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS */
1227
#endif
1228
1229
1230
/**
1231
 * Get the current context
1232
 *
1233
 * The context is only valid for the duration of a filesystem
1234
 * operation, and thus must not be stored and used later.
1235
 *
1236
 * @return the context
1237
 */
1238
struct fuse_context *fuse_get_context(void);
1239
1240
/**
1241
 * Get the current supplementary group IDs for the current request
1242
 *
1243
 * Similar to the getgroups(2) system call, except the return value is
1244
 * always the total number of group IDs, even if it is larger than the
1245
 * specified size.
1246
 *
1247
 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1248
 * the group list to userspace, hence this function needs to parse
1249
 * "/proc/$TID/task/$TID/status" to get the group IDs.
1250
 *
1251
 * This feature may not be supported on all operating systems.  In
1252
 * such a case this function will return -ENOSYS.
1253
 *
1254
 * @param size size of given array
1255
 * @param list array of group IDs to be filled in
1256
 * @return the total number of supplementary group IDs or -errno on failure
1257
 */
1258
int fuse_getgroups(int size, gid_t list[]);
1259
1260
/**
1261
 * Check if the current request has already been interrupted
1262
 *
1263
 * @return 1 if the request has been interrupted, 0 otherwise
1264
 */
1265
int fuse_interrupted(void);
1266
1267
/**
1268
 * Invalidates cache for the given path.
1269
 *
1270
 * This calls fuse_lowlevel_notify_inval_inode internally.
1271
 *
1272
 * @return 0 on successful invalidation, negative error value otherwise.
1273
 *         This routine may return -ENOENT to indicate that there was
1274
 *         no entry to be invalidated, e.g., because the path has not
1275
 *         been seen before or has been forgotten; this should not be
1276
 *         considered to be an error.
1277
 */
1278
int fuse_invalidate_path(struct fuse *f, const char *path);
1279
1280
/**
1281
 * Start the cleanup thread when using option "remember".
1282
 *
1283
 * This is done automatically by fuse_loop_mt()
1284
 * @param fuse struct fuse pointer for fuse instance
1285
 * @return 0 on success and -1 on error
1286
 */
1287
int fuse_start_cleanup_thread(struct fuse *fuse);
1288
1289
/**
1290
 * Stop the cleanup thread when using option "remember".
1291
 *
1292
 * This is done automatically by fuse_loop_mt()
1293
 * @param fuse struct fuse pointer for fuse instance
1294
 */
1295
void fuse_stop_cleanup_thread(struct fuse *fuse);
1296
1297
/**
1298
 * Iterate over cache removing stale entries
1299
 * use in conjunction with "-oremember"
1300
 *
1301
 * NOTE: This is already done for the standard sessions
1302
 *
1303
 * @param fuse struct fuse pointer for fuse instance
1304
 * @return the number of seconds until the next cleanup
1305
 */
1306
int fuse_clean_cache(struct fuse *fuse);
1307
1308
/*
1309
 * Stacking API
1310
 */
1311
1312
/**
1313
 * Fuse filesystem object
1314
 *
1315
 * This is opaque object represents a filesystem layer
1316
 */
1317
struct fuse_fs;
1318
1319
/*
1320
 * These functions call the relevant filesystem operation, and return
1321
 * the result.
1322
 *
1323
 * If the operation is not defined, they return -ENOSYS, with the
1324
 * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
1325
 * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
1326
 */
1327
1328
int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf,
1329
        struct fuse_file_info *fi);
1330
int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
1331
       const char *newpath, unsigned int flags);
1332
int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
1333
int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
1334
int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
1335
        const char *path);
1336
int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
1337
int fuse_fs_release(struct fuse_fs *fs,  const char *path,
1338
        struct fuse_file_info *fi);
1339
int fuse_fs_open(struct fuse_fs *fs, const char *path,
1340
     struct fuse_file_info *fi);
1341
int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
1342
     off_t off, struct fuse_file_info *fi);
1343
int fuse_fs_read_buf(struct fuse_fs *fs, const char *path,
1344
         struct fuse_bufvec **bufp, size_t size, off_t off,
1345
         struct fuse_file_info *fi);
1346
int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
1347
      size_t size, off_t off, struct fuse_file_info *fi);
1348
int fuse_fs_write_buf(struct fuse_fs *fs, const char *path,
1349
          struct fuse_bufvec *buf, off_t off,
1350
          struct fuse_file_info *fi);
1351
int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
1352
      struct fuse_file_info *fi);
1353
int fuse_fs_flush(struct fuse_fs *fs, const char *path,
1354
      struct fuse_file_info *fi);
1355
int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
1356
int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
1357
        struct fuse_file_info *fi);
1358
int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
1359
        fuse_fill_dir_t filler, off_t off,
1360
        struct fuse_file_info *fi, enum fuse_readdir_flags flags);
1361
int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
1362
         struct fuse_file_info *fi);
1363
int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
1364
           struct fuse_file_info *fi);
1365
int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
1366
       struct fuse_file_info *fi);
1367
int fuse_fs_lock(struct fuse_fs *fs, const char *path,
1368
     struct fuse_file_info *fi, int cmd, struct flock *lock);
1369
int fuse_fs_flock(struct fuse_fs *fs, const char *path,
1370
      struct fuse_file_info *fi, int op);
1371
int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode,
1372
      struct fuse_file_info *fi);
1373
int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid,
1374
      struct fuse_file_info *fi);
1375
int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size,
1376
         struct fuse_file_info *fi);
1377
int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
1378
        const struct timespec tv[2], struct fuse_file_info *fi);
1379
int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
1380
int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
1381
         size_t len);
1382
int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
1383
      dev_t rdev);
1384
int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
1385
int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
1386
         const char *value, size_t size, int flags);
1387
int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
1388
         char *value, size_t size);
1389
int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
1390
          size_t size);
1391
int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
1392
      const char *name);
1393
int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
1394
     uint64_t *idx);
1395
#if FUSE_USE_VERSION < 35
1396
int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd,
1397
      void *arg, struct fuse_file_info *fi, unsigned int flags,
1398
      void *data);
1399
#else
1400
int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, unsigned int cmd,
1401
      void *arg, struct fuse_file_info *fi, unsigned int flags,
1402
      void *data);
1403
#endif
1404
int fuse_fs_poll(struct fuse_fs *fs, const char *path,
1405
     struct fuse_file_info *fi, struct fuse_pollhandle *ph,
1406
     unsigned *reventsp);
1407
int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode,
1408
     off_t offset, off_t length, struct fuse_file_info *fi);
1409
ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, const char *path_in,
1410
        struct fuse_file_info *fi_in, off_t off_in,
1411
        const char *path_out,
1412
        struct fuse_file_info *fi_out, off_t off_out,
1413
        size_t len, int flags);
1414
off_t fuse_fs_lseek(struct fuse_fs *fs, const char *path, off_t off, int whence,
1415
        struct fuse_file_info *fi);
1416
int fuse_fs_statx(struct fuse_fs *fs, const char *path, int flags, int mask,
1417
      struct statx *stxbuf, struct fuse_file_info *fi);
1418
int fuse_fs_syncfs(struct fuse_fs *fs, const char *path);
1419
void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
1420
    struct fuse_config *cfg);
1421
void fuse_fs_destroy(struct fuse_fs *fs);
1422
1423
int fuse_notify_poll(struct fuse_pollhandle *ph);
1424
1425
/**
1426
 * Create a new fuse filesystem object
1427
 *
1428
 * This is usually called from the factory of a fuse module to create
1429
 * a new instance of a filesystem.
1430
 *
1431
 * @param op the filesystem operations
1432
 * @param op_size the size of the fuse_operations structure
1433
 * @param private_data Initial value for the `private_data`
1434
 *            field of `struct fuse_context`. May be overridden by the
1435
 *            `struct fuse_operations.init` handler.
1436
 * @return a new filesystem object
1437
 */
1438
struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
1439
          void *private_data);
1440
1441
/**
1442
 * Factory for creating filesystem objects
1443
 *
1444
 * The function may use and remove options from 'args' that belong
1445
 * to this module.
1446
 *
1447
 * For now the 'fs' vector always contains exactly one filesystem.
1448
 * This is the filesystem which will be below the newly created
1449
 * filesystem in the stack.
1450
 *
1451
 * @param args the command line arguments
1452
 * @param fs NULL terminated filesystem object vector
1453
 * @return the new filesystem object
1454
 */
1455
typedef struct fuse_fs *(*fuse_module_factory_t)(struct fuse_args *args,
1456
             struct fuse_fs *fs[]);
1457
/**
1458
 * Register filesystem module
1459
 *
1460
 * If the "-omodules=*name*_:..." option is present, filesystem
1461
 * objects are created and pushed onto the stack with the *factory_*
1462
 * function.
1463
 *
1464
 * @param name_ the name of this filesystem module
1465
 * @param factory_ the factory function for this filesystem module
1466
 */
1467
#define FUSE_REGISTER_MODULE(name_, factory_) \
1468
  fuse_module_factory_t fuse_module_ ## name_ ## _factory = factory_
1469
1470
/** Get session from fuse object */
1471
struct fuse_session *fuse_get_session(const struct fuse *f);
1472
1473
/**
1474
 * Open a FUSE file descriptor and set up the mount for the given
1475
 * mountpoint and flags.
1476
 *
1477
 * @param mountpoint reference to the mount in the file system
1478
 * @param options mount options
1479
 * @return the FUSE file descriptor or -1 upon error
1480
 */
1481
int fuse_open_channel(const char *mountpoint, const char *options);
1482
1483
#ifdef __cplusplus
1484
}
1485
#endif
1486
1487
#endif /* FUSE_H_ */