13 #include "fuse_config.h"
15 #include "fuse_misc.h"
17 #include "fuse_lowlevel.h"
18 #include "mount_util.h"
27 #include <sys/param.h>
29 #define FUSE_HELPER_OPT(t, p) \
30 { t, offsetof(struct fuse_cmdline_opts, p), 1 }
32 static const struct fuse_opt fuse_helper_opts[] = {
33 FUSE_HELPER_OPT(
"-h", show_help),
34 FUSE_HELPER_OPT(
"--help", show_help),
35 FUSE_HELPER_OPT(
"-V", show_version),
36 FUSE_HELPER_OPT(
"--version", show_version),
37 FUSE_HELPER_OPT(
"-d", debug),
38 FUSE_HELPER_OPT(
"debug", debug),
39 FUSE_HELPER_OPT(
"-d", foreground),
40 FUSE_HELPER_OPT(
"debug", foreground),
43 FUSE_HELPER_OPT(
"-f", foreground),
44 FUSE_HELPER_OPT(
"-s", singlethread),
45 FUSE_HELPER_OPT(
"fsname=", nodefault_subtype),
48 FUSE_HELPER_OPT(
"subtype=", nodefault_subtype),
51 FUSE_HELPER_OPT(
"clone_fd", clone_fd),
52 FUSE_HELPER_OPT(
"max_idle_threads=%u", max_idle_threads),
53 FUSE_HELPER_OPT(
"max_threads=%u", max_threads),
57 struct fuse_conn_info_opts {
59 int no_remote_posix_lock;
68 int no_auto_inval_data;
70 int no_readdirplus_auto;
74 int no_writeback_cache;
78 unsigned max_readahead;
79 unsigned max_background;
80 unsigned congestion_threshold;
83 int set_max_readahead;
84 int set_max_background;
85 int set_congestion_threshold;
89 #define CONN_OPTION(t, p, v) \
90 { t, offsetof(struct fuse_conn_info_opts, p), v }
91 static const struct fuse_opt conn_info_opt_spec[] = {
92 CONN_OPTION(
"max_write=%u", max_write, 0),
93 CONN_OPTION(
"max_write=", set_max_write, 1),
94 CONN_OPTION(
"max_readahead=%u", max_readahead, 0),
95 CONN_OPTION(
"max_readahead=", set_max_readahead, 1),
96 CONN_OPTION(
"max_background=%u", max_background, 0),
97 CONN_OPTION(
"max_background=", set_max_background, 1),
98 CONN_OPTION(
"congestion_threshold=%u", congestion_threshold, 0),
99 CONN_OPTION(
"congestion_threshold=", set_congestion_threshold, 1),
100 CONN_OPTION(
"sync_read", sync_read, 1),
101 CONN_OPTION(
"async_read", async_read, 1),
102 CONN_OPTION(
"atomic_o_trunc", atomic_o_trunc, 1),
103 CONN_OPTION(
"no_remote_lock", no_remote_posix_lock, 1),
104 CONN_OPTION(
"no_remote_lock", no_remote_flock, 1),
105 CONN_OPTION(
"no_remote_flock", no_remote_flock, 1),
106 CONN_OPTION(
"no_remote_posix_lock", no_remote_posix_lock, 1),
107 CONN_OPTION(
"splice_write", splice_write, 1),
108 CONN_OPTION(
"no_splice_write", no_splice_write, 1),
109 CONN_OPTION(
"splice_move", splice_move, 1),
110 CONN_OPTION(
"no_splice_move", no_splice_move, 1),
111 CONN_OPTION(
"splice_read", splice_read, 1),
112 CONN_OPTION(
"no_splice_read", no_splice_read, 1),
113 CONN_OPTION(
"auto_inval_data", auto_inval_data, 1),
114 CONN_OPTION(
"no_auto_inval_data", no_auto_inval_data, 1),
115 CONN_OPTION(
"readdirplus=no", no_readdirplus, 1),
116 CONN_OPTION(
"readdirplus=yes", no_readdirplus, 0),
117 CONN_OPTION(
"readdirplus=yes", no_readdirplus_auto, 1),
118 CONN_OPTION(
"readdirplus=auto", no_readdirplus, 0),
119 CONN_OPTION(
"readdirplus=auto", no_readdirplus_auto, 0),
120 CONN_OPTION(
"async_dio", async_dio, 1),
121 CONN_OPTION(
"no_async_dio", no_async_dio, 1),
122 CONN_OPTION(
"writeback_cache", writeback_cache, 1),
123 CONN_OPTION(
"no_writeback_cache", no_writeback_cache, 1),
124 CONN_OPTION(
"time_gran=%u", time_gran, 0),
125 CONN_OPTION(
"time_gran=", set_time_gran, 1),
132 printf(
" -h --help print help\n"
133 " -V --version print version\n"
134 " -d -o debug enable debug output (implies -f)\n"
135 " -f foreground operation\n"
136 " -s disable multi-threaded operation\n"
137 " -o clone_fd use separate fuse device fd for each thread\n"
138 " (may improve performance)\n"
139 " -o max_idle_threads the maximum number of idle worker threads\n"
140 " allowed (default: -1)\n"
141 " -o max_threads the maximum number of worker threads\n"
142 " allowed (default: 10)\n");
145 static int fuse_helper_opt_proc(
void *data,
const char *arg,
int key,
153 if (!opts->mountpoint) {
154 if (fuse_mnt_parse_fuse_fd(arg) != -1) {
158 char mountpoint[PATH_MAX] =
"";
159 if (realpath(arg, mountpoint) == NULL) {
161 "fuse: bad mount point `%s': %s\n",
162 arg, strerror(errno));
167 fuse_log(FUSE_LOG_ERR,
"fuse: invalid argument `%s'\n", arg);
179 static int add_default_subtype(
const char *progname,
struct fuse_args *args)
184 const char *basename = strrchr(progname,
'/');
185 if (basename == NULL)
187 else if (basename[1] !=
'\0')
190 subtype_opt = (
char *) malloc(strlen(basename) + 64);
191 if (subtype_opt == NULL) {
192 fuse_log(FUSE_LOG_ERR,
"fuse: memory allocation failed\n");
196 sprintf(subtype_opt,
"-ofsname=%s", basename);
198 sprintf(subtype_opt,
"-osubtype=%s", basename);
205 int fuse_parse_cmdline_312(
struct fuse_args *args,
207 FUSE_SYMVER(
"fuse_parse_cmdline_312",
"fuse_parse_cmdline@@FUSE_3.12")
208 int fuse_parse_cmdline_312(struct
fuse_args *args,
213 opts->max_idle_threads = UINT_MAX;
214 opts->max_threads = 10;
217 fuse_helper_opt_proc) == -1)
224 if (!opts->nodefault_subtype)
225 if (add_default_subtype(args->argv[0], args) == -1)
236 FUSE_SYMVER(
"fuse_parse_cmdline_30",
"fuse_parse_cmdline@FUSE_3.0")
242 int rc = fuse_parse_cmdline_312(args, &opts);
245 memcpy(out_opts, &opts,
247 sizeof(opts.max_idle_threads));
261 perror(
"fuse_daemonize: pipe");
271 perror(
"fuse_daemonize: fork");
276 (void) read(waiter[0], &completed,
sizeof(completed));
280 if (setsid() == -1) {
281 perror(
"fuse_daemonize: setsid");
287 nullfd = open(
"/dev/null", O_RDWR, 0);
289 (void) dup2(nullfd, 0);
290 (void) dup2(nullfd, 1);
291 (void) dup2(nullfd, 2);
298 (void) write(waiter[1], &completed,
sizeof(completed));
308 size_t op_size,
void *user_data)
316 if (fuse_parse_cmdline(&args, &opts) != 0)
319 if (opts.show_version) {
320 printf(
"FUSE library version %s\n", PACKAGE_VERSION);
326 if (opts.show_help) {
327 if(args.
argv[0][0] !=
'\0')
328 printf(
"usage: %s [options] <mountpoint>\n\n",
330 printf(
"FUSE options:\n");
337 if (!opts.show_help &&
339 fuse_log(FUSE_LOG_ERR,
"error: no mountpoint specified\n");
367 if (opts.singlethread)
371 if (loop_config == NULL) {
380 res = fuse_loop_mt(fuse, loop_config);
392 free(opts.mountpoint);
401 if(opts->set_max_write)
403 if(opts->set_max_background)
405 if(opts->set_congestion_threshold)
407 if(opts->set_time_gran)
409 if(opts->set_max_readahead)
412 #define LL_ENABLE(cond,cap) \
413 if (cond) conn->want |= (cap)
414 #define LL_DISABLE(cond,cap) \
415 if (cond) conn->want &= ~(cap)
447 struct fuse_conn_info_opts *opts;
449 opts = calloc(1,
sizeof(
struct fuse_conn_info_opts));
451 fuse_log(FUSE_LOG_ERR,
"calloc failed\n");
463 struct mount_opts *opts = NULL;
465 const char *argv[] = {
"",
"-o", options };
466 int argc =
sizeof(argv) /
sizeof(argv[0]);
469 opts = parse_mount_opts(&args);
473 fd = fuse_kern_mount(mountpoint, opts);
474 destroy_mount_opts(opts);
struct fuse_session * fuse_get_session(struct fuse *f)
int fuse_mount(struct fuse *f, const char *mountpoint)
void fuse_destroy(struct fuse *f)
struct fuse * fuse_new_31(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data)
int fuse_loop(struct fuse *f)
void fuse_lib_help(struct fuse_args *args)
int fuse_open_channel(const char *mountpoint, const char *options)
void fuse_unmount(struct fuse *f)
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *private_data)
void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config, unsigned int value)
#define FUSE_CAP_AUTO_INVAL_DATA
int fuse_set_signal_handlers(struct fuse_session *se)
#define FUSE_CAP_SPLICE_READ
#define FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_ASYNC_READ
#define FUSE_CAP_SPLICE_WRITE
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
#define FUSE_CAP_POSIX_LOCKS
struct fuse_loop_config * fuse_loop_cfg_create(void)
void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config, unsigned int value)
#define FUSE_CAP_READDIRPLUS_AUTO
#define FUSE_CAP_ASYNC_DIO
void fuse_loop_cfg_destroy(struct fuse_loop_config *config)
#define FUSE_CAP_READDIRPLUS
void fuse_remove_signal_handlers(struct fuse_session *se)
#define FUSE_CAP_SPLICE_MOVE
int fuse_daemonize(int foreground)
void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config, unsigned int value)
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
#define FUSE_CAP_FLOCK_LOCKS
void fuse_log(enum fuse_log_level level, const char *fmt,...)
void fuse_cmdline_help(void)
int fuse_parse_cmdline_30(struct fuse_args *args, struct fuse_cmdline_opts *opts)
void fuse_lowlevel_version(void)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_opt_free_args(struct fuse_args *args)
#define FUSE_OPT_KEY(templ, key)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_OPT_KEY_NONOPT
#define FUSE_OPT_KEY_KEEP
#define FUSE_ARGS_INIT(argc, argv)
int fuse_opt_add_opt(char **opts, const char *opt)
unsigned congestion_threshold