libfuse: include/fuse_common.h Source File

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 HAVE_STATIC_ASSERT
34#define fuse_static_assert(condition, message) static_assert(condition, message)
35#else
36#define fuse_static_assert(condition, message)
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
56 struct fuse_file_info {
58 int32_t flags;
59
66 uint32_t writepage : 1;
67
69 uint32_t direct_io : 1;
70
75 uint32_t keep_cache : 1;
76
80 uint32_t flush : 1;
81
84 uint32_t nonseekable : 1;
85
86 /* Indicates that flock locks for this file should be
87 released. If set, lock_owner shall contain a valid value.
88 May only be set in ->release(). */
89 uint32_t flock_release : 1;
90
95 uint32_t cache_readdir : 1;
96
99 uint32_t noflush : 1;
100
103 uint32_t parallel_direct_writes : 1;
104
106 uint32_t padding : 23;
107 uint32_t padding2 : 32;
108 uint32_t padding3 : 32;
109
113 uint64_t fh;
114
116 uint64_t lock_owner;
117
120 uint32_t poll_events;
121
125 int32_t backing_id;
126
128 uint64_t compat_flags;
129
130 uint64_t reserved[2];
131};
132fuse_static_assert(sizeof(struct fuse_file_info) == 64,
133 "fuse_file_info size mismatch");
134
145#if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
146struct fuse_loop_config_v1; /* forward declaration */
147 struct fuse_loop_config {
148#else
149struct fuse_loop_config_v1 {
150#endif
155 int clone_fd;
156
167 unsigned int max_idle_threads;
168};
169
170
171/**************************************************************************
172 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
173 **************************************************************************/
174
185#define FUSE_CAP_ASYNC_READ (1 << 0)
186
193#define FUSE_CAP_POSIX_LOCKS (1 << 1)
194
202#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
203
214#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
215
222#define FUSE_CAP_DONT_MASK (1 << 6)
223
230#define FUSE_CAP_SPLICE_WRITE (1 << 7)
231
238#define FUSE_CAP_SPLICE_MOVE (1 << 8)
239
247#define FUSE_CAP_SPLICE_READ (1 << 9)
248
260#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
261
267#define FUSE_CAP_IOCTL_DIR (1 << 11)
268
289#define FUSE_CAP_AUTO_INVAL_DATA (1 << 12)
290
297#define FUSE_CAP_READDIRPLUS (1 << 13)
298
325#define FUSE_CAP_READDIRPLUS_AUTO (1 << 14)
326
336#define FUSE_CAP_ASYNC_DIO (1 << 15)
337
345#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
346
360#define FUSE_CAP_NO_OPEN_SUPPORT (1 << 17)
361
368#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
369
387#define FUSE_CAP_POSIX_ACL (1 << 19)
388
396#define FUSE_CAP_HANDLE_KILLPRIV (1 << 20)
397
413#define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 21)
414
426#define FUSE_CAP_CACHE_SYMLINKS (1 << 23)
427
441#define FUSE_CAP_NO_OPENDIR_SUPPORT (1 << 24)
442
464#define FUSE_CAP_EXPLICIT_INVAL_DATA (1 << 25)
465
480#define FUSE_CAP_EXPIRE_ONLY (1 << 26)
481
487#define FUSE_CAP_SETXATTR_EXT (1 << 27)
488
496#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1 << 28)
497
508#define FUSE_CAP_PASSTHROUGH (1 << 29)
509
516#define FUSE_CAP_NO_EXPORT_SUPPORT (1 << 30)
517
528#define FUSE_IOCTL_COMPAT (1 << 0)
529#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
530#define FUSE_IOCTL_RETRY (1 << 2)
531#define FUSE_IOCTL_DIR (1 << 4)
532
533#define FUSE_IOCTL_MAX_IOV 256
534
546 struct fuse_conn_info {
550 uint32_t proto_major;
551
555 uint32_t proto_minor;
556
560 uint32_t max_write;
561
574 uint32_t max_read;
575
579 uint32_t max_readahead;
580
586 uint32_t capable;
587
598 uint32_t want;
599
628 uint32_t max_background;
629
638 uint32_t congestion_threshold;
639
655 uint32_t time_gran;
656
673#define FUSE_BACKING_STACKED_UNDER (0)
674#define FUSE_BACKING_STACKED_OVER (1)
675 uint32_t max_backing_stack_depth;
676
685 uint32_t no_interrupt : 1;
686
687 /* reserved bits for future use */
688 uint32_t padding : 31;
689
694 uint64_t capable_ext;
695
704 uint64_t want_ext;
705
709 uint32_t reserved[16];
710};
711fuse_static_assert(sizeof(struct fuse_conn_info) == 128,
712 "Size of struct fuse_conn_info must be 128 bytes");
713
714struct fuse_session;
715struct fuse_pollhandle;
716struct fuse_conn_info_opts;
717
760struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
761
769void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
770 struct fuse_conn_info *conn);
771
778int fuse_daemonize(int foreground);
779
785int fuse_version(void);
786
792const char *fuse_pkgversion(void);
793
799void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
800
801/* ----------------------------------------------------------- *
802 * Data buffer *
803 * ----------------------------------------------------------- */
804
808 enum fuse_buf_flags {
815 FUSE_BUF_IS_FD = (1 << 1),
816
824 FUSE_BUF_FD_SEEK = (1 << 2),
825
833 FUSE_BUF_FD_RETRY = (1 << 3)
834};
835
839 enum fuse_buf_copy_flags {
849 FUSE_BUF_NO_SPLICE = (1 << 1),
850
857 FUSE_BUF_FORCE_SPLICE = (1 << 2),
858
866 FUSE_BUF_SPLICE_MOVE = (1 << 3),
867
875 FUSE_BUF_SPLICE_NONBLOCK= (1 << 4)
876};
877
884 struct fuse_buf {
888 size_t size;
889
893 enum fuse_buf_flags flags;
894
900 void *mem;
901
907 int fd;
908
914 off_t pos;
915
922 size_t mem_size;
923};
924
933 struct fuse_bufvec {
937 size_t count;
938
942 size_t idx;
943
947 size_t off;
948
952 struct fuse_buf buf[1];
953};
954
959 struct libfuse_version
960{
961 uint32_t major;
962 uint32_t minor;
963 uint32_t hotfix;
964 uint32_t padding;
965};
966
967/* Initialize bufvec with a single buffer of given size */
968#define FUSE_BUFVEC_INIT(size__) \
969 ((struct fuse_bufvec) { \
970 /* .count= */ 1, \
971 /* .idx = */ 0, \
972 /* .off = */ 0, \
973 /* .buf = */ { /* [0] = */ { \
974 /* .size = */ (size__), \
975 /* .flags = */ (enum fuse_buf_flags) 0, \
976 /* .mem = */ NULL, \
977 /* .fd = */ -1, \
978 /* .pos = */ 0, \
979 /* .mem_size = */ 0, \
980 } } \
981 } )
982
989size_t fuse_buf_size(const struct fuse_bufvec *bufv);
990
999ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
1000 enum fuse_buf_copy_flags flags);
1001
1002/* ----------------------------------------------------------- *
1003 * Signal handling *
1004 * ----------------------------------------------------------- */
1005
1021int fuse_set_signal_handlers(struct fuse_session *se);
1022
1038int fuse_set_fail_signal_handlers(struct fuse_session *se);
1039
1051void fuse_remove_signal_handlers(struct fuse_session *se);
1052
1058#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1064struct fuse_loop_config *fuse_loop_cfg_create(void);
1065
1069void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1070
1074void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1075 unsigned int value);
1076
1080void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1081 unsigned int value);
1082
1086void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1087 unsigned int value);
1088
1095void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1096 struct fuse_loop_config_v1 *v1_conf);
1097#endif
1098
1106bool fuse_set_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1107
1114void fuse_unset_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1115
1123bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
1124
1125/*
1126 * DO NOT USE: Not part of public API, for internal test use only.
1127 * The function signature or any use of it is not guaranteeed to
1128 * remain stable. And neither are results of what this function does.
1129 */
1130int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);
1131
1132
1133
1134/* ----------------------------------------------------------- *
1135 * Compatibility stuff *
1136 * ----------------------------------------------------------- */
1137
1138#if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
1139# error only API version 30 or greater is supported
1140#endif
1141
1142#ifdef __cplusplus
1143}
1144#endif
1145
1146
1147/*
1148 * This interface uses 64 bit off_t.
1149 *
1150 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
1151 */
1152
1153#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1154_Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
1155#else
1156struct _fuse_off_t_must_be_64bit_dummy_struct \
1157 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
1158#endif
1159
1160#endif /* FUSE_COMMON_H_ */
fuse_unset_feature_flag
void fuse_unset_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
Definition fuse_lowlevel.c:2050
fuse_convert_to_conn_want_ext
int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn)
Definition fuse_lowlevel.c:2000
fuse_set_fail_signal_handlers
int fuse_set_fail_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:163
fuse_set_feature_flag
bool fuse_set_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
Definition fuse_lowlevel.c:2035
fuse_set_signal_handlers
int fuse_set_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:138
fuse_buf_size
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
Definition buffer.c:22
fuse_apply_conn_info_opts
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_flags
Definition fuse_common.h:808
FUSE_BUF_FD_SEEK
@ FUSE_BUF_FD_SEEK
Definition fuse_common.h:824
FUSE_BUF_FD_RETRY
@ FUSE_BUF_FD_RETRY
Definition fuse_common.h:833
FUSE_BUF_IS_FD
@ FUSE_BUF_IS_FD
Definition fuse_common.h:815
fuse_buf_copy
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
Definition buffer.c:284
fuse_parse_conn_info_opts
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
Definition helper.c:466
fuse_get_feature_flag
bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
Definition fuse_lowlevel.c:2061
fuse_pkgversion
const char * fuse_pkgversion(void)
Definition fuse.c:5211
fuse_pollhandle_destroy
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
Definition fuse_lowlevel.c:1903
fuse_version
int fuse_version(void)
Definition fuse.c:5206
fuse_remove_signal_handlers
void fuse_remove_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:185
fuse_buf_copy_flags
fuse_buf_copy_flags
Definition fuse_common.h:839
FUSE_BUF_SPLICE_NONBLOCK
@ FUSE_BUF_SPLICE_NONBLOCK
Definition fuse_common.h:875
FUSE_BUF_FORCE_SPLICE
@ FUSE_BUF_FORCE_SPLICE
Definition fuse_common.h:857
FUSE_BUF_NO_SPLICE
@ FUSE_BUF_NO_SPLICE
Definition fuse_common.h:849
FUSE_BUF_SPLICE_MOVE
@ FUSE_BUF_SPLICE_MOVE
Definition fuse_common.h:866
fuse_daemonize
int fuse_daemonize(int foreground)
Definition helper.c:253
fuse_log.h
fuse_opt.h
fuse_args
Definition fuse_opt.h:109
fuse_buf
Definition fuse_common.h:884
fuse_buf::flags
enum fuse_buf_flags flags
Definition fuse_common.h:893
fuse_buf::mem_size
size_t mem_size
Definition fuse_common.h:922
fuse_buf::mem
void * mem
Definition fuse_common.h:900
fuse_buf::fd
int fd
Definition fuse_common.h:907
fuse_buf::pos
off_t pos
Definition fuse_common.h:914
fuse_buf::size
size_t size
Definition fuse_common.h:888
fuse_bufvec
Definition fuse_common.h:933
fuse_bufvec::off
size_t off
Definition fuse_common.h:947
fuse_bufvec::idx
size_t idx
Definition fuse_common.h:942
fuse_bufvec::count
size_t count
Definition fuse_common.h:937
fuse_conn_info
Definition fuse_common.h:546
fuse_conn_info::time_gran
uint32_t time_gran
Definition fuse_common.h:655
fuse_conn_info::proto_major
uint32_t proto_major
Definition fuse_common.h:550
fuse_conn_info::want
uint32_t want
Definition fuse_common.h:598
fuse_conn_info::congestion_threshold
uint32_t congestion_threshold
Definition fuse_common.h:638
fuse_conn_info::proto_minor
uint32_t proto_minor
Definition fuse_common.h:555
fuse_conn_info::max_write
uint32_t max_write
Definition fuse_common.h:560
fuse_conn_info::capable_ext
uint64_t capable_ext
Definition fuse_common.h:694
fuse_conn_info::max_readahead
uint32_t max_readahead
Definition fuse_common.h:579
fuse_conn_info::no_interrupt
uint32_t no_interrupt
Definition fuse_common.h:685
fuse_conn_info::max_read
uint32_t max_read
Definition fuse_common.h:574
fuse_conn_info::max_background
uint32_t max_background
Definition fuse_common.h:628
fuse_conn_info::capable
uint32_t capable
Definition fuse_common.h:586
fuse_conn_info::want_ext
uint64_t want_ext
Definition fuse_common.h:704
fuse_file_info
Definition fuse_common.h:56
fuse_file_info::lock_owner
uint64_t lock_owner
Definition fuse_common.h:116
fuse_file_info::fh
uint64_t fh
Definition fuse_common.h:113
fuse_file_info::writepage
uint32_t writepage
Definition fuse_common.h:66
fuse_file_info::poll_events
uint32_t poll_events
Definition fuse_common.h:120
fuse_file_info::cache_readdir
uint32_t cache_readdir
Definition fuse_common.h:95
fuse_file_info::nonseekable
uint32_t nonseekable
Definition fuse_common.h:84
fuse_file_info::backing_id
int32_t backing_id
Definition fuse_common.h:125
fuse_file_info::parallel_direct_writes
uint32_t parallel_direct_writes
Definition fuse_common.h:103
fuse_file_info::padding
uint32_t padding
Definition fuse_common.h:106
fuse_file_info::noflush
uint32_t noflush
Definition fuse_common.h:99
fuse_file_info::compat_flags
uint64_t compat_flags
Definition fuse_common.h:128
fuse_file_info::flush
uint32_t flush
Definition fuse_common.h:80
fuse_file_info::direct_io
uint32_t direct_io
Definition fuse_common.h:69
fuse_file_info::keep_cache
uint32_t keep_cache
Definition fuse_common.h:75
fuse_file_info::flags
int32_t flags
Definition fuse_common.h:58
fuse_loop_config
Definition fuse_common.h:147
fuse_loop_config::clone_fd
int clone_fd
Definition fuse_common.h:155
fuse_loop_config::max_idle_threads
unsigned int max_idle_threads
Definition fuse_common.h:167
libfuse_version
Definition fuse_common.h:960