15 #include "fuse_misc.h" 17 #include "fuse_lowlevel.h" 26 #include <sys/param.h> 28 #define FUSE_HELPER_OPT(t, p) \ 29 { t, offsetof(struct fuse_cmdline_opts, p), 1 } 31 static const struct fuse_opt fuse_helper_opts[] = {
32 FUSE_HELPER_OPT(
"-h", show_help),
33 FUSE_HELPER_OPT(
"--help", show_help),
34 FUSE_HELPER_OPT(
"-V", show_version),
35 FUSE_HELPER_OPT(
"--version", show_version),
36 FUSE_HELPER_OPT(
"-d", debug),
37 FUSE_HELPER_OPT(
"debug", debug),
38 FUSE_HELPER_OPT(
"-d", foreground),
39 FUSE_HELPER_OPT(
"debug", foreground),
42 FUSE_HELPER_OPT(
"-f", foreground),
43 FUSE_HELPER_OPT(
"-s", singlethread),
44 FUSE_HELPER_OPT(
"fsname=", nodefault_subtype),
47 FUSE_HELPER_OPT(
"subtype=", nodefault_subtype),
50 FUSE_HELPER_OPT(
"clone_fd", clone_fd),
51 FUSE_HELPER_OPT(
"max_idle_threads=%u", max_idle_threads),
55 struct fuse_conn_info_opts {
57 int no_remote_posix_lock;
66 int no_auto_inval_data;
68 int no_readdirplus_auto;
72 int no_writeback_cache;
76 unsigned max_readahead;
77 unsigned max_background;
78 unsigned congestion_threshold;
81 int set_max_readahead;
82 int set_max_background;
83 int set_congestion_threshold;
87 #define CONN_OPTION(t, p, v) \ 88 { t, offsetof(struct fuse_conn_info_opts, p), v } 89 static const struct fuse_opt conn_info_opt_spec[] = {
90 CONN_OPTION(
"max_write=%u", max_write, 0),
91 CONN_OPTION(
"max_write=", set_max_write, 1),
92 CONN_OPTION(
"max_readahead=%u", max_readahead, 0),
93 CONN_OPTION(
"max_readahead=", set_max_readahead, 1),
94 CONN_OPTION(
"max_background=%u", max_background, 0),
95 CONN_OPTION(
"max_background=", set_max_background, 1),
96 CONN_OPTION(
"congestion_threshold=%u", congestion_threshold, 0),
97 CONN_OPTION(
"congestion_threshold=", set_congestion_threshold, 1),
98 CONN_OPTION(
"sync_read", sync_read, 1),
99 CONN_OPTION(
"async_read", async_read, 1),
100 CONN_OPTION(
"atomic_o_trunc", atomic_o_trunc, 1),
101 CONN_OPTION(
"no_remote_lock", no_remote_posix_lock, 1),
102 CONN_OPTION(
"no_remote_lock", no_remote_flock, 1),
103 CONN_OPTION(
"no_remote_flock", no_remote_flock, 1),
104 CONN_OPTION(
"no_remote_posix_lock", no_remote_posix_lock, 1),
105 CONN_OPTION(
"splice_write", splice_write, 1),
106 CONN_OPTION(
"no_splice_write", no_splice_write, 1),
107 CONN_OPTION(
"splice_move", splice_move, 1),
108 CONN_OPTION(
"no_splice_move", no_splice_move, 1),
109 CONN_OPTION(
"splice_read", splice_read, 1),
110 CONN_OPTION(
"no_splice_read", no_splice_read, 1),
111 CONN_OPTION(
"auto_inval_data", auto_inval_data, 1),
112 CONN_OPTION(
"no_auto_inval_data", no_auto_inval_data, 1),
113 CONN_OPTION(
"readdirplus=no", no_readdirplus, 1),
114 CONN_OPTION(
"readdirplus=yes", no_readdirplus, 0),
115 CONN_OPTION(
"readdirplus=yes", no_readdirplus_auto, 1),
116 CONN_OPTION(
"readdirplus=auto", no_readdirplus, 0),
117 CONN_OPTION(
"readdirplus=auto", no_readdirplus_auto, 0),
118 CONN_OPTION(
"async_dio", async_dio, 1),
119 CONN_OPTION(
"no_async_dio", no_async_dio, 1),
120 CONN_OPTION(
"writeback_cache", writeback_cache, 1),
121 CONN_OPTION(
"no_writeback_cache", no_writeback_cache, 1),
122 CONN_OPTION(
"time_gran=%u", time_gran, 0),
123 CONN_OPTION(
"time_gran=", set_time_gran, 1),
130 printf(
" -h --help print help\n" 131 " -V --version print version\n" 132 " -d -o debug enable debug output (implies -f)\n" 133 " -f foreground operation\n" 134 " -s disable multi-threaded operation\n" 135 " -o clone_fd use separate fuse device fd for each thread\n" 136 " (may improve performance)\n" 137 " -o max_idle_threads the maximum number of idle worker threads\n" 138 " allowed (default: 10)\n");
141 static int fuse_helper_opt_proc(
void *data,
const char *arg,
int key,
145 struct fuse_cmdline_opts *opts = data;
149 if (!opts->mountpoint) {
150 char mountpoint[PATH_MAX];
151 if (realpath(arg, mountpoint) == NULL) {
153 "fuse: bad mount point `%s': %s\n",
154 arg, strerror(errno));
159 fprintf(stderr,
"fuse: invalid argument `%s'\n", arg);
171 static int add_default_subtype(
const char *progname,
struct fuse_args *args)
176 const char *basename = strrchr(progname,
'/');
177 if (basename == NULL)
179 else if (basename[1] !=
'\0')
182 subtype_opt = (
char *) malloc(strlen(basename) + 64);
183 if (subtype_opt == NULL) {
184 fprintf(stderr,
"fuse: memory allocation failed\n");
188 sprintf(subtype_opt,
"-ofsname=%s", basename);
190 sprintf(subtype_opt,
"-osubtype=%s", basename);
198 struct fuse_cmdline_opts *opts)
200 memset(opts, 0,
sizeof(
struct fuse_cmdline_opts));
202 opts->max_idle_threads = 10;
205 fuse_helper_opt_proc) == -1)
212 if (!opts->nodefault_subtype)
213 if (add_default_subtype(args->
argv[0], args) == -1)
228 perror(
"fuse_daemonize: pipe");
238 perror(
"fuse_daemonize: fork");
243 (void) read(waiter[0], &completed,
sizeof(completed));
247 if (setsid() == -1) {
248 perror(
"fuse_daemonize: setsid");
254 nullfd = open(
"/dev/null", O_RDWR, 0);
256 (void) dup2(nullfd, 0);
257 (void) dup2(nullfd, 1);
258 (void) dup2(nullfd, 2);
265 (void) write(waiter[1], &completed,
sizeof(completed));
275 size_t op_size,
void *user_data)
279 struct fuse_cmdline_opts opts;
285 if (opts.show_version) {
286 printf(
"FUSE library version %s\n", PACKAGE_VERSION);
292 if (opts.show_help) {
293 if(args.
argv[0][0] !=
'\0')
294 printf(
"usage: %s [options] <mountpoint>\n\n",
296 printf(
"FUSE options:\n");
303 if (!opts.show_help &&
305 fprintf(stderr,
"error: no mountpoint specified\n");
311 fuse = fuse_new_31(&args, op, op_size, user_data);
333 if (opts.singlethread)
337 loop_config.
clone_fd = opts.clone_fd;
338 loop_config.max_idle_threads = opts.max_idle_threads;
339 res = fuse_loop_mt_32(fuse, &loop_config);
350 free(opts.mountpoint);
359 if(opts->set_max_write)
361 if(opts->set_max_background)
363 if(opts->set_congestion_threshold)
365 if(opts->set_time_gran)
367 if(opts->set_max_readahead)
370 #define LL_ENABLE(cond,cap) \ 371 if (cond) conn->want |= (cap) 372 #define LL_DISABLE(cond,cap) \ 373 if (cond) conn->want &= ~(cap) 405 struct fuse_conn_info_opts *opts;
407 opts = calloc(1,
sizeof(
struct fuse_conn_info_opts));
409 fprintf(stderr,
"calloc failed\n");
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
#define FUSE_CAP_ASYNC_DIO
#define FUSE_OPT_KEY_NONOPT
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
#define FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_READDIRPLUS
#define FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_SPLICE_READ
#define FUSE_CAP_AUTO_INVAL_DATA
int fuse_opt_add_opt(char **opts, const char *opt)
#define FUSE_CAP_FLOCK_LOCKS
int fuse_daemonize(int foreground)
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *private_data)
#define FUSE_ARGS_INIT(argc, argv)
#define FUSE_CAP_SPLICE_WRITE
void fuse_cmdline_help(void)
void fuse_lib_help(struct fuse_args *args)
unsigned congestion_threshold
int fuse_set_signal_handlers(struct fuse_session *se)
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_destroy(struct fuse *f)
void fuse_opt_free_args(struct fuse_args *args)
struct fuse_session * fuse_get_session(struct fuse *f)
int fuse_loop(struct fuse *f)
#define FUSE_OPT_KEY(templ, key)
#define FUSE_OPT_KEY_KEEP
int fuse_mount(struct fuse *f, const char *mountpoint)
void fuse_lowlevel_version(void)
#define FUSE_CAP_SPLICE_MOVE
void fuse_unmount(struct fuse *f)
void fuse_remove_signal_handlers(struct fuse_session *se)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_CAP_ASYNC_READ
#define FUSE_CAP_READDIRPLUS_AUTO