libfuse
fuse_common.h
Go to the documentation of this file.
1/* FUSE: Filesystem in Userspace
2 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
3
4 This program can be distributed under the terms of the GNU LGPLv2.
5 See the file COPYING.LIB.
6*/
7
10#include <stdbool.h>
11#if !defined(FUSE_H_) && !defined(FUSE_LOWLEVEL_H_)
12#error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
13#endif
14
15#ifndef FUSE_COMMON_H_
16#define FUSE_COMMON_H_
17
18#ifdef HAVE_LIBFUSE_PRIVATE_CONFIG_H
19#include "fuse_config.h"
20#endif
21
22#include "libfuse_config.h"
23
24#include "fuse_opt.h"
25#include "fuse_log.h"
26#include <stdint.h>
27#include <sys/types.h>
28#include <assert.h>
29
30#define FUSE_MAKE_VERSION(maj, min) ((maj) * 100 + (min))
31#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
50struct fuse_file_info {
52 int32_t flags;
53
60 uint32_t writepage : 1;
61
63 uint32_t direct_io : 1;
64
69 uint32_t keep_cache : 1;
70
74 uint32_t flush : 1;
75
78 uint32_t nonseekable : 1;
79
80 /* Indicates that flock locks for this file should be
81 released. If set, lock_owner shall contain a valid value.
82 May only be set in ->release(). */
83 uint32_t flock_release : 1;
84
89 uint32_t cache_readdir : 1;
90
93 uint32_t noflush : 1;
94
97 uint32_t parallel_direct_writes : 1;
98
100 uint32_t padding : 23;
101 uint32_t padding2 : 32;
102 uint32_t padding3 : 32;
103
107 uint64_t fh;
108
110 uint64_t lock_owner;
111
114 uint32_t poll_events;
115
119 int32_t backing_id;
120
122 uint64_t compat_flags;
123
124 uint64_t reserved[2];
125};
126
137#if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
138struct fuse_loop_config_v1; /* forward declaration */
139struct fuse_loop_config {
140#else
141struct fuse_loop_config_v1 {
142#endif
147 int clone_fd;
148
159 unsigned int max_idle_threads;
160};
161
162
163/**************************************************************************
164 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
165 **************************************************************************/
166
177#define FUSE_CAP_ASYNC_READ (1 << 0)
178
185#define FUSE_CAP_POSIX_LOCKS (1 << 1)
186
194#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
195
206#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
207
214#define FUSE_CAP_DONT_MASK (1 << 6)
215
222#define FUSE_CAP_SPLICE_WRITE (1 << 7)
223
230#define FUSE_CAP_SPLICE_MOVE (1 << 8)
231
239#define FUSE_CAP_SPLICE_READ (1 << 9)
240
252#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
253
259#define FUSE_CAP_IOCTL_DIR (1 << 11)
260
281#define FUSE_CAP_AUTO_INVAL_DATA (1 << 12)
282
289#define FUSE_CAP_READDIRPLUS (1 << 13)
290
317#define FUSE_CAP_READDIRPLUS_AUTO (1 << 14)
318
328#define FUSE_CAP_ASYNC_DIO (1 << 15)
329
337#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
338
352#define FUSE_CAP_NO_OPEN_SUPPORT (1 << 17)
353
360#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
361
379#define FUSE_CAP_POSIX_ACL (1 << 19)
380
388#define FUSE_CAP_HANDLE_KILLPRIV (1 << 20)
389
405#define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 21)
406
418#define FUSE_CAP_CACHE_SYMLINKS (1 << 23)
419
433#define FUSE_CAP_NO_OPENDIR_SUPPORT (1 << 24)
434
456#define FUSE_CAP_EXPLICIT_INVAL_DATA (1 << 25)
457
472#define FUSE_CAP_EXPIRE_ONLY (1 << 26)
473
479#define FUSE_CAP_SETXATTR_EXT (1 << 27)
480
488#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1 << 28)
489
500#define FUSE_CAP_PASSTHROUGH (1 << 29)
501
508#define FUSE_CAP_NO_EXPORT_SUPPORT (1 << 30)
509
520#define FUSE_IOCTL_COMPAT (1 << 0)
521#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
522#define FUSE_IOCTL_RETRY (1 << 2)
523#define FUSE_IOCTL_DIR (1 << 4)
524
525#define FUSE_IOCTL_MAX_IOV 256
526
538struct fuse_conn_info {
542 uint32_t proto_major;
543
547 uint32_t proto_minor;
548
552 uint32_t max_write;
553
566 uint32_t max_read;
567
571 uint32_t max_readahead;
572
578 uint32_t capable;
579
590 uint32_t want;
591
620 uint32_t max_background;
621
630 uint32_t congestion_threshold;
631
647 uint32_t time_gran;
648
665#define FUSE_BACKING_STACKED_UNDER (0)
666#define FUSE_BACKING_STACKED_OVER (1)
667 uint32_t max_backing_stack_depth;
668
677 uint32_t no_interrupt : 1;
678
679 /* reserved bits for future use */
680 uint32_t padding : 31;
681
686 uint64_t capable_ext;
687
696 uint64_t want_ext;
697
701 uint32_t reserved[16];
702};
703
704struct fuse_session;
705struct fuse_pollhandle;
706struct fuse_conn_info_opts;
707
750struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
751
759void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
760 struct fuse_conn_info *conn);
761
768int fuse_daemonize(int foreground);
769
775int fuse_version(void);
776
782const char *fuse_pkgversion(void);
783
789void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
790
791/* ----------------------------------------------------------- *
792 * Data buffer *
793 * ----------------------------------------------------------- */
794
805 FUSE_BUF_IS_FD = (1 << 1),
806
815
823 FUSE_BUF_FD_RETRY = (1 << 3)
825
867
874struct fuse_buf {
878 size_t size;
879
883 enum fuse_buf_flags flags;
884
890 void *mem;
891
897 int fd;
898
904 off_t pos;
905
912 size_t mem_size;
913};
914
923struct fuse_bufvec {
927 size_t count;
928
932 size_t idx;
933
937 size_t off;
938
942 struct fuse_buf buf[1];
943};
944
949struct libfuse_version
950{
951 uint32_t major;
952 uint32_t minor;
953 uint32_t hotfix;
954 uint32_t padding;
955};
956
957/* Initialize bufvec with a single buffer of given size */
958#define FUSE_BUFVEC_INIT(size__) \
959 ((struct fuse_bufvec) { \
960 /* .count= */ 1, \
961 /* .idx = */ 0, \
962 /* .off = */ 0, \
963 /* .buf = */ { /* [0] = */ { \
964 /* .size = */ (size__), \
965 /* .flags = */ (enum fuse_buf_flags) 0, \
966 /* .mem = */ NULL, \
967 /* .fd = */ -1, \
968 /* .pos = */ 0, \
969 /* .mem_size = */ 0, \
970 } } \
971 } )
972
979size_t fuse_buf_size(const struct fuse_bufvec *bufv);
980
989ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
990 enum fuse_buf_copy_flags flags);
991
992/* ----------------------------------------------------------- *
993 * Signal handling *
994 * ----------------------------------------------------------- */
995
1011int fuse_set_signal_handlers(struct fuse_session *se);
1012
1028int fuse_set_fail_signal_handlers(struct fuse_session *se);
1029
1041void fuse_remove_signal_handlers(struct fuse_session *se);
1042
1048#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1054struct fuse_loop_config *fuse_loop_cfg_create(void);
1055
1059void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1060
1064void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1065 unsigned int value);
1066
1070void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1071 unsigned int value);
1072
1076void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1077 unsigned int value);
1078
1085void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1086 struct fuse_loop_config_v1 *v1_conf);
1087#endif
1088
1096bool fuse_set_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1097
1104void fuse_unset_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1105
1113bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1114
1115/*
1116 * DO NOT USE: Not part of public API, for internal test use only.
1117 * The function signature or any use of it is not guaranteeed to
1118 * remain stable. And neither are results of what this function does.
1119 */
1121
1122
1123
1124/* ----------------------------------------------------------- *
1125 * Compatibility stuff *
1126 * ----------------------------------------------------------- */
1127
1128#if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
1129# error only API version 30 or greater is supported
1130#endif
1131
1132#ifdef __cplusplus
1133}
1134#endif
1135
1136
1137/*
1138 * This interface uses 64 bit off_t.
1139 *
1140 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
1141 */
1142
1143#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1144_Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
1145#else
1146struct _fuse_off_t_must_be_64bit_dummy_struct \
1147 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
1148#endif
1149
1150#endif /* FUSE_COMMON_H_ */
void fuse_unset_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn)
int fuse_set_fail_signal_handlers(struct fuse_session *se)
bool fuse_set_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
int fuse_set_signal_handlers(struct fuse_session *se)
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
Definition buffer.c:22
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
Definition helper.c:412
fuse_buf_flags
@ FUSE_BUF_FD_SEEK
@ FUSE_BUF_FD_RETRY
@ FUSE_BUF_IS_FD
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
Definition buffer.c:284
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
Definition helper.c:466
bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
const char * fuse_pkgversion(void)
Definition fuse.c:5211
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
int fuse_version(void)
Definition fuse.c:5206
void fuse_remove_signal_handlers(struct fuse_session *se)
fuse_buf_copy_flags
@ FUSE_BUF_SPLICE_NONBLOCK
@ FUSE_BUF_FORCE_SPLICE
@ FUSE_BUF_NO_SPLICE
@ FUSE_BUF_SPLICE_MOVE
int fuse_daemonize(int foreground)
Definition helper.c:253
uint64_t lock_owner
uint32_t writepage
Definition fuse_common.h:66
uint32_t poll_events
uint32_t cache_readdir
Definition fuse_common.h:95
uint32_t nonseekable
Definition fuse_common.h:84
int32_t backing_id
uint32_t parallel_direct_writes
uint32_t padding
uint32_t noflush
Definition fuse_common.h:99
uint64_t compat_flags
uint32_t flush
Definition fuse_common.h:80
uint32_t direct_io
Definition fuse_common.h:69
uint32_t keep_cache
Definition fuse_common.h:75