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),
56 struct fuse_conn_info_opts {
58 int no_remote_posix_lock;
67 int no_auto_inval_data;
69 int no_readdirplus_auto;
73 int no_writeback_cache;
77 unsigned max_readahead;
78 unsigned max_background;
79 unsigned congestion_threshold;
82 int set_max_readahead;
83 int set_max_background;
84 int set_congestion_threshold;
88 #define CONN_OPTION(t, p, v) \ 89 { t, offsetof(struct fuse_conn_info_opts, p), v } 90 static const struct fuse_opt conn_info_opt_spec[] = {
91 CONN_OPTION(
"max_write=%u", max_write, 0),
92 CONN_OPTION(
"max_write=", set_max_write, 1),
93 CONN_OPTION(
"max_readahead=%u", max_readahead, 0),
94 CONN_OPTION(
"max_readahead=", set_max_readahead, 1),
95 CONN_OPTION(
"max_background=%u", max_background, 0),
96 CONN_OPTION(
"max_background=", set_max_background, 1),
97 CONN_OPTION(
"congestion_threshold=%u", congestion_threshold, 0),
98 CONN_OPTION(
"congestion_threshold=", set_congestion_threshold, 1),
99 CONN_OPTION(
"sync_read", sync_read, 1),
100 CONN_OPTION(
"async_read", async_read, 1),
101 CONN_OPTION(
"atomic_o_trunc", atomic_o_trunc, 1),
102 CONN_OPTION(
"no_remote_lock", no_remote_posix_lock, 1),
103 CONN_OPTION(
"no_remote_lock", no_remote_flock, 1),
104 CONN_OPTION(
"no_remote_flock", no_remote_flock, 1),
105 CONN_OPTION(
"no_remote_posix_lock", no_remote_posix_lock, 1),
106 CONN_OPTION(
"splice_write", splice_write, 1),
107 CONN_OPTION(
"no_splice_write", no_splice_write, 1),
108 CONN_OPTION(
"splice_move", splice_move, 1),
109 CONN_OPTION(
"no_splice_move", no_splice_move, 1),
110 CONN_OPTION(
"splice_read", splice_read, 1),
111 CONN_OPTION(
"no_splice_read", no_splice_read, 1),
112 CONN_OPTION(
"auto_inval_data", auto_inval_data, 1),
113 CONN_OPTION(
"no_auto_inval_data", no_auto_inval_data, 1),
114 CONN_OPTION(
"readdirplus=no", no_readdirplus, 1),
115 CONN_OPTION(
"readdirplus=yes", no_readdirplus, 0),
116 CONN_OPTION(
"readdirplus=yes", no_readdirplus_auto, 1),
117 CONN_OPTION(
"readdirplus=auto", no_readdirplus, 0),
118 CONN_OPTION(
"readdirplus=auto", no_readdirplus_auto, 0),
119 CONN_OPTION(
"async_dio", async_dio, 1),
120 CONN_OPTION(
"no_async_dio", no_async_dio, 1),
121 CONN_OPTION(
"writeback_cache", writeback_cache, 1),
122 CONN_OPTION(
"no_writeback_cache", no_writeback_cache, 1),
123 CONN_OPTION(
"time_gran=%u", time_gran, 0),
124 CONN_OPTION(
"time_gran=", set_time_gran, 1),
131 printf(
" -h --help print help\n" 132 " -V --version print version\n" 133 " -d -o debug enable debug output (implies -f)\n" 134 " -f foreground operation\n" 135 " -s disable multi-threaded operation\n" 136 " -o clone_fd use separate fuse device fd for each thread\n" 137 " (may improve performance)\n" 138 " -o max_idle_threads the maximum number of idle worker threads\n" 139 " allowed (default: 10)\n");
142 static int fuse_helper_opt_proc(
void *data,
const char *arg,
int key,
146 struct fuse_cmdline_opts *opts = data;
150 if (!opts->mountpoint) {
151 if (fuse_mnt_parse_fuse_fd(arg) != -1) {
155 char mountpoint[PATH_MAX] =
"";
156 if (realpath(arg, mountpoint) == NULL) {
158 "fuse: bad mount point `%s': %s\n",
159 arg, strerror(errno));
164 fuse_log(FUSE_LOG_ERR,
"fuse: invalid argument `%s'\n", arg);
176 static int add_default_subtype(
const char *progname,
struct fuse_args *args)
181 const char *basename = strrchr(progname,
'/');
182 if (basename == NULL)
184 else if (basename[1] !=
'\0')
187 subtype_opt = (
char *) malloc(strlen(basename) + 64);
188 if (subtype_opt == NULL) {
189 fuse_log(FUSE_LOG_ERR,
"fuse: memory allocation failed\n");
193 sprintf(subtype_opt,
"-ofsname=%s", basename);
195 sprintf(subtype_opt,
"-osubtype=%s", basename);
203 struct fuse_cmdline_opts *opts)
205 memset(opts, 0,
sizeof(
struct fuse_cmdline_opts));
207 opts->max_idle_threads = 10;
210 fuse_helper_opt_proc) == -1)
217 if (!opts->nodefault_subtype)
218 if (add_default_subtype(args->
argv[0], args) == -1)
233 perror(
"fuse_daemonize: pipe");
243 perror(
"fuse_daemonize: fork");
248 (void) read(waiter[0], &completed,
sizeof(completed));
252 if (setsid() == -1) {
253 perror(
"fuse_daemonize: setsid");
259 nullfd = open(
"/dev/null", O_RDWR, 0);
261 (void) dup2(nullfd, 0);
262 (void) dup2(nullfd, 1);
263 (void) dup2(nullfd, 2);
270 (void) write(waiter[1], &completed,
sizeof(completed));
280 size_t op_size,
void *user_data)
284 struct fuse_cmdline_opts opts;
290 if (opts.show_version) {
291 printf(
"FUSE library version %s\n", PACKAGE_VERSION);
297 if (opts.show_help) {
298 if(args.
argv[0][0] !=
'\0')
299 printf(
"usage: %s [options] <mountpoint>\n\n",
301 printf(
"FUSE options:\n");
308 if (!opts.show_help &&
310 fuse_log(FUSE_LOG_ERR,
"error: no mountpoint specified\n");
316 fuse = fuse_new_31(&args, op, op_size, user_data);
338 if (opts.singlethread)
342 loop_config.
clone_fd = opts.clone_fd;
344 res = fuse_loop_mt_32(fuse, &loop_config);
355 free(opts.mountpoint);
364 if(opts->set_max_write)
366 if(opts->set_max_background)
368 if(opts->set_congestion_threshold)
370 if(opts->set_time_gran)
372 if(opts->set_max_readahead)
375 #define LL_ENABLE(cond,cap) \ 376 if (cond) conn->want |= (cap) 377 #define LL_DISABLE(cond,cap) \ 378 if (cond) conn->want &= ~(cap) 410 struct fuse_conn_info_opts *opts;
412 opts = calloc(1,
sizeof(
struct fuse_conn_info_opts));
414 fuse_log(FUSE_LOG_ERR,
"calloc failed\n");
426 struct mount_opts *opts = NULL;
428 const char *argv[] = {
"",
"-o", options };
429 int argc =
sizeof(argv) /
sizeof(argv[0]);
432 opts = parse_mount_opts(&args);
436 fd = fuse_kern_mount(mountpoint, opts);
437 destroy_mount_opts(opts);
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *private_data)
void fuse_cmdline_help(void)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
struct fuse_session * fuse_get_session(struct fuse *f)
int fuse_set_signal_handlers(struct fuse_session *se)
#define FUSE_CAP_SPLICE_READ
int fuse_opt_add_opt(char **opts, const char *opt)
unsigned int max_idle_threads
#define FUSE_CAP_ASYNC_DIO
int fuse_open_channel(const char *mountpoint, const char *options)
#define FUSE_ARGS_INIT(argc, argv)
#define FUSE_CAP_FLOCK_LOCKS
#define FUSE_CAP_READDIRPLUS_AUTO
void fuse_lib_help(struct fuse_args *args)
int fuse_loop(struct fuse *f)
void fuse_lowlevel_version(void)
#define FUSE_CAP_ASYNC_READ
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
void fuse_unmount(struct fuse *f)
void fuse_remove_signal_handlers(struct fuse_session *se)
unsigned congestion_threshold
#define FUSE_CAP_WRITEBACK_CACHE
int fuse_mount(struct fuse *f, const char *mountpoint)
#define FUSE_CAP_READDIRPLUS
#define FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_POSIX_LOCKS
#define FUSE_OPT_KEY_NONOPT
void fuse_opt_free_args(struct fuse_args *args)
int fuse_daemonize(int foreground)
#define FUSE_OPT_KEY(templ, key)
#define FUSE_OPT_KEY_KEEP
#define FUSE_CAP_SPLICE_WRITE
void fuse_destroy(struct fuse *f)
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
#define FUSE_CAP_AUTO_INVAL_DATA
void fuse_log(enum fuse_log_level level, const char *fmt,...)