Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librefuse fuse_main(3): Support general fuse options via...
details: https://anonhg.NetBSD.org/src/rev/95322b631c1b
branches: trunk
changeset: 349014:95322b631c1b
user: pho <pho%NetBSD.org@localhost>
date: Sun Nov 20 13:28:32 2016 +0000
description:
fuse_main(3): Support general fuse options via fuse_parse_cmdline(3)
* Prototypes for fuse_new(3), fuse_mount(3), and fuse_unmount(3) now
matches to the original fuse interface.
* Add fuse_daemonize(3): needs to have a different prototype,
otherwise we can't use puffs_daemon(3).
* Remove fuse_setup(3) and fuse_teardown(3). These obsolete functions
has already been removed from the original interface.
* fuse_main(3) now supports the following command-line options
compatible with the original fuse:
-h, --help print help message
-V, --version print library version (currently does nothing)
-d, -o debug enable debug output (PUFFS_FLAG_OPDUMP), implies -f
-f foreground mode
-s single threaded mode (always enabled for now)
-o fsname=NAME explicitly set the name of the file system
* fuse_main(3) now daemonizes the process by default. This is for the
compatibility with the original fuse.
diffstat:
lib/librefuse/fuse.h | 24 +-
lib/librefuse/refuse.3 | 22 +-
lib/librefuse/refuse.c | 381 +++++++++++++++++++-----------------------------
3 files changed, 173 insertions(+), 254 deletions(-)
diffs (truncated from 606 to 300 lines):
diff -r 715e27095a45 -r 95322b631c1b lib/librefuse/fuse.h
--- a/lib/librefuse/fuse.h Sun Nov 20 13:26:28 2016 +0000
+++ b/lib/librefuse/fuse.h Sun Nov 20 13:28:32 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fuse.h,v 1.21 2008/08/01 15:54:09 dillo Exp $ */
+/* $NetBSD: fuse.h,v 1.22 2016/11/20 13:28:32 pho Exp $ */
/*
* Copyright © 2007 Alistair Crooks. All rights reserved.
@@ -150,22 +150,20 @@
};
-struct fuse_chan *fuse_mount(const char *, struct fuse_args *);
-struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *,
+struct fuse *fuse_new(struct fuse_args *,
const struct fuse_operations *, size_t, void *);
+int fuse_mount(struct fuse *, const char *);
+void fuse_unmount(struct fuse *);
+
+int fuse_daemonize(struct fuse *);
+
int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
int fuse_loop(struct fuse *);
struct fuse_context *fuse_get_context(void);
void fuse_exit(struct fuse *);
void fuse_destroy(struct fuse *);
-void fuse_unmount(const char *, struct fuse_chan *);
-
-struct fuse *fuse_setup(int, char **, const struct fuse_operations *,
- size_t, char **, int *, int *);
-void fuse_teardown(struct fuse *, char *);
-
#if FUSE_USE_VERSION == 22
#define fuse_unmount fuse_unmount_compat22
#endif
@@ -173,17 +171,13 @@
void fuse_unmount_compat22(const char *);
#if FUSE_USE_VERSION >= 26
-#define fuse_main(argc, argv, op, arg) \
- fuse_main_real(argc, argv, op, sizeof(*(op)), arg)
-#define fuse_setup fuse_setup26
+#define fuse_main(argc, argv, op, user_data) \
+ fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
#else
#define fuse_main(argc, argv, op) \
fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
#endif
-struct fuse *fuse_setup26(int, char **, const struct fuse_operations *,
- size_t, char **, int *, void *);
-
#ifdef __cplusplus
}
#endif
diff -r 715e27095a45 -r 95322b631c1b lib/librefuse/refuse.3
--- a/lib/librefuse/refuse.3 Sun Nov 20 13:26:28 2016 +0000
+++ b/lib/librefuse/refuse.3 Sun Nov 20 13:28:32 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: refuse.3,v 1.12 2016/11/15 00:34:19 pho Exp $
+.\" $NetBSD: refuse.3,v 1.13 2016/11/20 13:28:32 pho Exp $
.\"
.\" Copyright © 2007 Alistair Crooks. All rights reserved.
.\"
@@ -83,13 +83,21 @@
.Fa "const struct fuse_opt *descriptions" "fuse_opt_proc_t processingfunc"
.Fc
.Ft int
-.Fo fuse_teardown
-.Fa "struct fuse *fuse" "char *mountpoint"
+.Fo fuse_new
+.Fa "struct fuse_args *args" "const struct fuse_operations *ops"
+.Fa "size_t opssize" "void *userdata"
+.Fc
+.Ft int
+.Fo fuse_mount
+.Fa "struct fuse *fuse" "const char *mountpoint"
.Fc
-.Ft struct fuse *
-.Fo fuse_setup
-.Fa "int argc" "char **argv" "const struct fuse_operations *ops"
-.Fa "size_t opssize" "char **mountpoint" "int *multithreaded" "int *fd"
+.Ft int
+.Fo fuse_unmount
+.Fa "struct fuse* fuse"
+.Fc
+.Ft int
+.Fo fuse_daemonize
+.Fa "struct fuse *fuse"
.Fc
.Ft int
.Fo puffs_fuse_node_getattr
diff -r 715e27095a45 -r 95322b631c1b lib/librefuse/refuse.c
--- a/lib/librefuse/refuse.c Sun Nov 20 13:26:28 2016 +0000
+++ b/lib/librefuse/refuse.c Sun Nov 20 13:28:32 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: refuse.c,v 1.97 2016/11/17 14:20:25 pho Exp $ */
+/* $NetBSD: refuse.c,v 1.98 2016/11/20 13:28:32 pho Exp $ */
/*
* Copyright © 2007 Alistair Crooks. All rights reserved.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: refuse.c,v 1.97 2016/11/17 14:20:25 pho Exp $");
+__RCSID("$NetBSD: refuse.c,v 1.98 2016/11/20 13:28:32 pho Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -40,7 +40,10 @@
#include <err.h>
#include <errno.h>
#include <fuse.h>
+#include <fuse_lowlevel.h>
+#include <fuse_opt.h>
#include <paths.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -51,39 +54,24 @@
typedef uint64_t fuse_ino_t;
-struct fuse_config {
- uid_t uid;
- gid_t gid;
- mode_t umask;
- double entry_timeout;
- double negative_timeout;
- double attr_timeout;
- double ac_attr_timeout;
- int ac_attr_timeout_set;
- int debug;
- int hard_remove;
- int use_ino;
- int readdir_ino;
- int set_mode;
- int set_uid;
- int set_gid;
- int direct_io;
- int kernel_cache;
- int auto_cache;
- int intr;
- int intr_signal;
+struct refuse_config {
+ int debug;
+ char *fsname;
};
-struct fuse_chan {
- const char *dir;
- struct fuse_args *args;
- struct puffs_usermount *pu;
- int dead;
+#define REFUSE_OPT(t, p, v) \
+ { t, offsetof(struct refuse_config, p), v }
+
+static struct fuse_opt refuse_opts[] = {
+ REFUSE_OPT("debug" , debug , 1),
+ REFUSE_OPT("fsname=%s", fsname, 0),
+ FUSE_OPT_END
};
/* this is the private fuse structure */
struct fuse {
- struct fuse_chan *fc; /* fuse channel pointer */
+ struct puffs_usermount *pu;
+ int dead;
struct fuse_operations op; /* switch table of operations */
int compat; /* compat level -
* not used in puffs_fuse */
@@ -97,7 +85,6 @@
pthread_mutex_t lock;
pthread_rwlock_t tree_lock;
void *user_data;
- struct fuse_config conf;
int intr_installed;
};
@@ -339,103 +326,6 @@
return fill_dirbuf(h, name, dino, dtype);
}
-/* place the refuse file system name into `name' */
-static void
-set_refuse_mount_name(char **argv, char *name, size_t size)
-{
- char *slash;
-
- if (argv == NULL || *argv == NULL) {
- (void) strlcpy(name, "refuse", size);
- } else {
- if ((slash = strrchr(*argv, '/')) == NULL) {
- slash = *argv;
- } else {
- slash += 1;
- }
- if (strncmp(*argv, "refuse:", 7) == 0) {
- /* we've already done this */
- (void) strlcpy(name, *argv, size);
- } else {
- (void) snprintf(name, size, "refuse:%s", slash);
- }
- }
-}
-
-
-/* this function exposes struct fuse to userland */
-static struct fuse *
-fuse_setup_real(int argc, char **argv, const struct fuse_operations *ops,
- size_t size, char **mountpoint, int *multithreaded, int *fd,
- void *user_data)
-{
- struct fuse_chan *fc;
- struct fuse_args *args;
- struct fuse *fuse;
- char name[64];
- int i;
-
- /* set up the proper name */
- set_refuse_mount_name(argv, name, sizeof(name));
-
- /* grab the pthread context key */
- if (!create_context_key()) {
- return NULL;
- }
-
- /* stuff name into fuse_args */
- args = fuse_opt_deep_copy_args(argc, argv);
- if (args->argc > 0) {
- free(args->argv[0]);
- }
- if ((args->argv[0] = strdup(name)) == NULL) {
- fuse_opt_free_args(args);
- return NULL;
- }
-
- /* count back from the end over arguments starting with '-' */
- for (i = argc - 1 ; i > 0 && *argv[i] == '-' ; --i) {
- }
-
- fc = fuse_mount(*mountpoint = argv[i], args);
- fuse = fuse_new(fc, args, ops, size, user_data);
-
- fuse_opt_free_args(args);
- free(args);
-
- /* XXX - wait for puffs to become multi-threaded */
- if (multithreaded) {
- *multithreaded = 0;
- }
-
- /* XXX - this is unused */
- if (fd) {
- *fd = 0;
- }
-
- return fuse;
-}
-
-#ifdef fuse_setup
-#undef fuse_setup
-#endif
-
-struct fuse *
-fuse_setup(int argc, char **argv, const struct fuse_operations *ops,
- size_t size, char **mountpoint, int *multithreaded, int *fd)
-{
- return fuse_setup_real(argc, argv, ops, size, mountpoint,
- multithreaded, fd, NULL);
-}
-
-struct fuse *
-fuse_setup26(int argc, char **argv, const struct fuse_operations *ops,
- size_t size, char **mountpoint, int *multithreaded, void *user_data)
-{
- return fuse_setup_real(argc, argv, ops, size, mountpoint,
- multithreaded, NULL, user_data);
-}
-
#define FUSE_ERR_UNLINK(fuse, file) if (fuse->op.unlink) fuse->op.unlink(file)
#define FUSE_ERR_RMDIR(fuse, dir) if (fuse->op.rmdir) fuse->op.rmdir(dir)
@@ -1232,73 +1122,136 @@
/* ARGSUSED3 */
int
fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
- size_t size, void *userdata)
+ size_t size, void *user_data)
{
- struct fuse *fuse;
- char *mountpoint;
- int multithreaded;
- int fd;
+ struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
Home |
Main Index |
Thread Index |
Old Index