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#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
34 (!defined(__cplusplus) && defined(__STDC_VERSION__) && \
35 __STDC_VERSION__ >= 201112L)
36#define fuse_static_assert(condition, message) static_assert(condition, message)
37#else
38#define fuse_static_assert(condition, message)
39#endif
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
60 int32_t flags;
61
68 uint32_t writepage : 1;
69
71 uint32_t direct_io : 1;
72
77 uint32_t keep_cache : 1;
78
82 uint32_t flush : 1;
83
86 uint32_t nonseekable : 1;
87
88 /* Indicates that flock locks for this file should be
89 released. If set, lock_owner shall contain a valid value.
90 May only be set in ->release(). */
91 uint32_t flock_release : 1;
92
97 uint32_t cache_readdir : 1;
98
101 uint32_t noflush : 1;
102
106
108 uint32_t padding : 23;
109 uint32_t padding2 : 32;
110 uint32_t padding3 : 32;
111
115 uint64_t fh;
116
118 uint64_t lock_owner;
119
122 uint32_t poll_events;
123
127 int32_t backing_id;
128
130 uint64_t compat_flags;
131
132 uint64_t reserved[2];
133};
134fuse_static_assert(sizeof(struct fuse_file_info) == 64,
135 "fuse_file_info size mismatch");
136
147#if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
148struct fuse_loop_config_v1; /* forward declaration */
150#else
151struct fuse_loop_config_v1 {
152#endif
158
169 unsigned int max_idle_threads;
170};
171
172
173/**************************************************************************
174 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
175 **************************************************************************/
176
526
537#define FUSE_IOCTL_COMPAT (1 << 0)
538#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
539#define FUSE_IOCTL_RETRY (1 << 2)
540#define FUSE_IOCTL_DIR (1 << 4)
541
542#define FUSE_IOCTL_MAX_IOV 256
543
559 uint32_t proto_major;
560
564 uint32_t proto_minor;
565
569 uint32_t max_write;
570
583 uint32_t max_read;
584
589
595 uint32_t capable;
596
607 uint32_t want;
608
638
648
664 uint32_t time_gran;
665
682#define FUSE_BACKING_STACKED_UNDER (0)
683#define FUSE_BACKING_STACKED_OVER (1)
684 uint32_t max_backing_stack_depth;
685
694 uint32_t no_interrupt : 1;
695
696 /* reserved bits for future use */
697 uint32_t padding : 31;
698
703 uint64_t capable_ext;
704
713 uint64_t want_ext;
714
718 uint32_t reserved[16];
719};
720fuse_static_assert(sizeof(struct fuse_conn_info) == 128,
721 "Size of struct fuse_conn_info must be 128 bytes");
722
723struct fuse_session;
724struct fuse_pollhandle;
725struct fuse_conn_info_opts;
726
769struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
770
778void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
779 struct fuse_conn_info *conn);
780
787int fuse_daemonize(int foreground);
788
794int fuse_version(void);
795
801const char *fuse_pkgversion(void);
802
808void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
809
810/* ----------------------------------------------------------- *
811 * Data buffer *
812 * ----------------------------------------------------------- */
813
824 FUSE_BUF_IS_FD = (1 << 1),
825
834
842 FUSE_BUF_FD_RETRY = (1 << 3)
844
886
893struct fuse_buf {
897 size_t size;
898
903
909 void *mem;
910
916 int fd;
917
923 off_t pos;
924
931 size_t mem_size;
932};
933
946 size_t count;
947
951 size_t idx;
952
956 size_t off;
957
961 struct fuse_buf buf[1];
962};
963
969{
970 uint32_t major;
971 uint32_t minor;
972 uint32_t hotfix;
973 uint32_t padding;
974};
975
976/* Initialize bufvec with a single buffer of given size */
977#define FUSE_BUFVEC_INIT(size__) \
978 ((struct fuse_bufvec) { \
979 /* .count= */ 1, \
980 /* .idx = */ 0, \
981 /* .off = */ 0, \
982 /* .buf = */ { /* [0] = */ { \
983 /* .size = */ (size__), \
984 /* .flags = */ (enum fuse_buf_flags) 0, \
985 /* .mem = */ NULL, \
986 /* .fd = */ -1, \
987 /* .pos = */ 0, \
988 /* .mem_size = */ 0, \
989 } } \
990 } )
991
998size_t fuse_buf_size(const struct fuse_bufvec *bufv);
999
1008ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
1009 enum fuse_buf_copy_flags flags);
1010
1011/* ----------------------------------------------------------- *
1012 * Signal handling *
1013 * ----------------------------------------------------------- */
1014
1030int fuse_set_signal_handlers(struct fuse_session *se);
1031
1047int fuse_set_fail_signal_handlers(struct fuse_session *se);
1048
1060void fuse_remove_signal_handlers(struct fuse_session *se);
1061
1067#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1073struct fuse_loop_config *fuse_loop_cfg_create(void);
1074
1078void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1079
1083void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1084 unsigned int value);
1085
1089void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1090 unsigned int value);
1091
1095void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1096 unsigned int value);
1097
1104void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1105 struct fuse_loop_config_v1 *v1_conf);
1106#endif
1107
1108
1109static inline bool fuse_set_feature_flag(struct fuse_conn_info *conn,
1110 uint64_t flag)
1111{
1112 if (conn->capable_ext & flag) {
1113 conn->want_ext |= flag;
1114 return true;
1115 }
1116 return false;
1117}
1118
1119static inline void fuse_unset_feature_flag(struct fuse_conn_info *conn,
1120 uint64_t flag)
1121{
1122 conn->want_ext &= ~flag;
1123}
1124
1125static inline bool fuse_get_feature_flag(struct fuse_conn_info *conn,
1126 uint64_t flag)
1127{
1128 return conn->capable_ext & flag ? true : false;
1129}
1130
1131/* ----------------------------------------------------------- *
1132 * Compatibility stuff *
1133 * ----------------------------------------------------------- */
1134
1135#if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
1136# error only API version 30 or greater is supported
1137#endif
1138
1139#ifdef __cplusplus
1140}
1141#endif
1142
1143
1144/*
1145 * This interface uses 64 bit off_t.
1146 *
1147 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
1148 */
1149
1150#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1151_Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
1152#else
1153struct _fuse_off_t_must_be_64bit_dummy_struct \
1154 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
1155#endif
1156
1157#endif /* FUSE_COMMON_H_ */
int fuse_set_fail_signal_handlers(struct fuse_session *se)
int fuse_set_signal_handlers(struct fuse_session *se)
fuse_capability
@ FUSE_CAP_CURRENT_MAX
@ FUSE_CAP_POSIX_ACL
@ FUSE_CAP_READDIRPLUS
@ FUSE_CAP_NO_OPENDIR_SUPPORT
@ FUSE_CAP_PARALLEL_DIROPS
@ FUSE_CAP_ASYNC_DIO
@ FUSE_CAP_NO_EXPORT_SUPPORT
@ FUSE_CAP_WRITEBACK_CACHE
@ FUSE_CAP_IOCTL_DIR
@ FUSE_CAP_AUTO_INVAL_DATA
@ FUSE_CAP_SPLICE_READ
@ FUSE_CAP_SPLICE_MOVE
@ FUSE_CAP_POSIX_LOCKS
@ FUSE_CAP_HANDLE_KILLPRIV_V2
@ FUSE_CAP_HANDLE_KILLPRIV
@ FUSE_CAP_DONT_MASK
@ FUSE_CAP_ATOMIC_O_TRUNC
@ FUSE_CAP_SPLICE_WRITE
@ FUSE_CAP_PASSTHROUGH
@ FUSE_CAP_FLOCK_LOCKS
@ FUSE_CAP_EXPIRE_ONLY
@ FUSE_CAP_EXPORT_SUPPORT
@ FUSE_CAP_READDIRPLUS_AUTO
@ FUSE_CAP_NO_OPEN_SUPPORT
@ FUSE_CAP_DIRECT_IO_ALLOW_MMAP
@ FUSE_CAP_SETXATTR_EXT
@ FUSE_CAP_ASYNC_READ
@ FUSE_CAP_CACHE_SYMLINKS
@ FUSE_CAP_EXPLICIT_INVAL_DATA
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:416
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:463
const char * fuse_pkgversion(void)
Definition fuse.c:5218
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
int fuse_version(void)
Definition fuse.c:5213
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
enum fuse_buf_flags flags
size_t mem_size
void * mem
off_t pos
size_t size
uint32_t time_gran
uint32_t proto_major
uint32_t congestion_threshold
uint32_t proto_minor
uint32_t max_write
uint64_t capable_ext
uint32_t max_readahead
uint32_t no_interrupt
uint32_t max_read
uint32_t max_background
uint32_t capable
uint64_t want_ext
uint64_t lock_owner
uint32_t writepage
Definition fuse_common.h:68
uint32_t poll_events
uint32_t cache_readdir
Definition fuse_common.h:97
uint32_t nonseekable
Definition fuse_common.h:86
int32_t backing_id
uint32_t parallel_direct_writes
uint32_t padding
uint32_t noflush
uint64_t compat_flags
uint32_t flush
Definition fuse_common.h:82
uint32_t direct_io
Definition fuse_common.h:71
uint32_t keep_cache
Definition fuse_common.h:77
unsigned int max_idle_threads