Coverage Report

Created: 2025-10-13 06:52

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