mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
dll: fuse: help system refactoring
This commit is contained in:
parent
4b9945d9bf
commit
3f3c02f3ce
@ -18,6 +18,28 @@
|
||||
#include <dll/library.h>
|
||||
#include <fuse/fuse.h>
|
||||
|
||||
#define FSP_FUSE_CORE_OPT(n, f, v) { n, offsetof(struct fsp_fuse_core_opt_data, f), v }
|
||||
|
||||
struct fsp_fuse_core_opt_data
|
||||
{
|
||||
struct fsp_fuse_env *env;
|
||||
int debug;
|
||||
int help;
|
||||
};
|
||||
|
||||
static struct fuse_opt fsp_fuse_core_opts[] =
|
||||
{
|
||||
FSP_FUSE_CORE_OPT("-d", debug, 1),
|
||||
FSP_FUSE_CORE_OPT("debug", debug, 1),
|
||||
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("-h", 'h'),
|
||||
FUSE_OPT_KEY("--help", 'h'),
|
||||
FUSE_OPT_KEY("-V", 'V'),
|
||||
FUSE_OPT_KEY("--version", 'V'),
|
||||
FUSE_OPT_END,
|
||||
};
|
||||
|
||||
struct fuse_chan
|
||||
{
|
||||
PWSTR MountPoint;
|
||||
@ -103,11 +125,14 @@ FSP_FUSE_API struct fuse_chan *fsp_fuse_mount(struct fsp_fuse_env *env,
|
||||
struct fuse_chan *ch = 0;
|
||||
int Size;
|
||||
|
||||
if (0 == mountpoint)
|
||||
mountpoint = "";
|
||||
|
||||
Size = MultiByteToWideChar(CP_UTF8, 0, mountpoint, -1, 0, 0);
|
||||
if (0 == Size)
|
||||
goto fail;
|
||||
|
||||
ch = MemAlloc(sizeof *ch + Size);
|
||||
ch = MemAlloc(sizeof *ch + Size * sizeof(WCHAR));
|
||||
if (0 == ch)
|
||||
goto fail;
|
||||
|
||||
@ -119,8 +144,6 @@ FSP_FUSE_API struct fuse_chan *fsp_fuse_mount(struct fsp_fuse_env *env,
|
||||
return ch;
|
||||
|
||||
fail:
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L"Invalid mount point.");
|
||||
|
||||
MemFree(ch);
|
||||
|
||||
return 0;
|
||||
@ -135,8 +158,34 @@ FSP_FUSE_API void fsp_fuse_unmount(struct fsp_fuse_env *env,
|
||||
FSP_FUSE_API int fsp_fuse_is_lib_option(struct fsp_fuse_env *env,
|
||||
const char *opt)
|
||||
{
|
||||
// !!!: NEEDIMPL
|
||||
return 0;
|
||||
return fsp_fuse_opt_match(env, fsp_fuse_core_opts, opt);
|
||||
}
|
||||
|
||||
static int fsp_fuse_core_opt_proc(void *opt_data0, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
struct fsp_fuse_core_opt_data *opt_data = opt_data0;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return 1;
|
||||
case 'h':
|
||||
#if 0
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||
"Core options:\n"
|
||||
" -d -o debug enable debug output (implies -f)\n"
|
||||
"\n");
|
||||
#endif
|
||||
opt_data->help = 1;
|
||||
return 1;
|
||||
case 'V':
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||
L"" LIBRARY_NAME "-FUSE version %d.%d",
|
||||
FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION);
|
||||
opt_data->help = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static NTSTATUS fsp_fuse_svcstart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
||||
@ -159,11 +208,21 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env,
|
||||
struct fuse_chan *ch, struct fuse_args *args,
|
||||
const struct fuse_operations *ops, size_t opsize, void *data)
|
||||
{
|
||||
struct fsp_fuse_core_opt_data opt_data;
|
||||
struct fuse *f = 0;
|
||||
PWSTR ServiceName = FspDiagIdent();
|
||||
FSP_FSCTL_VOLUME_PARAMS VolumeParams;
|
||||
PWSTR ErrorMessage = L".";
|
||||
NTSTATUS Result;
|
||||
|
||||
memset(&opt_data, 0, sizeof opt_data);
|
||||
opt_data.env = env;
|
||||
|
||||
if (-1 == fsp_fuse_opt_parse(env, args, &opt_data, fsp_fuse_core_opts, fsp_fuse_core_opt_proc))
|
||||
return 0;
|
||||
if (opt_data.help)
|
||||
return 0;
|
||||
|
||||
memset(&VolumeParams, 0, sizeof VolumeParams);
|
||||
#if 0
|
||||
/* initialize VolumeParams from command line args */
|
||||
@ -193,11 +252,21 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env,
|
||||
|
||||
Result = FspFileSystemCreate(L"" FSP_FSCTL_NET_DEVICE_NAME, &VolumeParams, 0, &f->FileSystem);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
ErrorMessage = L": cannot create " LIBRARY_NAME " file system object.";
|
||||
goto fail;
|
||||
}
|
||||
|
||||
Result = FspFileSystemSetMountPoint(f->FileSystem, ch->MountPoint);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto fail;
|
||||
if (L'\0' != ch->MountPoint)
|
||||
{
|
||||
Result = FspFileSystemSetMountPoint(f->FileSystem,
|
||||
L'*' == ch->MountPoint[0] && L'\0' == ch->MountPoint[1] ? 0 : ch->MountPoint);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
ErrorMessage = L": cannot set mount point.";
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
f->Ops = ops;
|
||||
f->OpSize = opsize;
|
||||
@ -209,7 +278,7 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env,
|
||||
return f;
|
||||
|
||||
fail:
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L"Unable to create FUSE file system.");
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L"Unable to create FUSE file system%s");
|
||||
|
||||
if (0 != f)
|
||||
{
|
||||
|
@ -18,9 +18,9 @@
|
||||
#include <dll/library.h>
|
||||
#include <fuse/fuse.h>
|
||||
|
||||
#define FSP_FUSE_DEFAULT_OPT(n, f, v) { n, offsetof(struct fsp_fuse_default_opt_data, f), v }
|
||||
#define FSP_FUSE_MAIN_OPT(n, f, v) { n, offsetof(struct fsp_fuse_main_opt_data, f), v }
|
||||
|
||||
struct fsp_fuse_default_opt_data
|
||||
struct fsp_fuse_main_opt_data
|
||||
{
|
||||
struct fsp_fuse_env *env;
|
||||
char *mountpoint;
|
||||
@ -28,10 +28,24 @@ struct fsp_fuse_default_opt_data
|
||||
int foreground;
|
||||
};
|
||||
|
||||
static int fsp_fuse_default_opt_proc(void *data0, const char *arg, int key,
|
||||
static struct fuse_opt fsp_fuse_main_opts[] =
|
||||
{
|
||||
FSP_FUSE_MAIN_OPT("-d", foreground, 1),
|
||||
FSP_FUSE_MAIN_OPT("debug", foreground, 1),
|
||||
FSP_FUSE_MAIN_OPT("-f", foreground, 1),
|
||||
FSP_FUSE_MAIN_OPT("-s", singlethread, 1),
|
||||
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("-h", 'h'),
|
||||
FUSE_OPT_KEY("--help", 'h'),
|
||||
FUSE_OPT_KEY("-ho", 'H'),
|
||||
FUSE_OPT_END,
|
||||
};
|
||||
|
||||
static int fsp_fuse_main_opt_proc(void *opt_data0, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
struct fsp_fuse_default_opt_data *data = data0;
|
||||
struct fsp_fuse_main_opt_data *opt_data = opt_data0;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
@ -41,35 +55,38 @@ static int fsp_fuse_default_opt_proc(void *data0, const char *arg, int key,
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||
"usage: %s mountpoint [options]\n"
|
||||
"\n"
|
||||
" -o opt,[opt...] mount options\n"
|
||||
" -h --help print help\n"
|
||||
" -V --version print version\n"
|
||||
" -o opt,[opt...] mount options\n"
|
||||
" -h --help print help\n"
|
||||
" -V --version print version\n"
|
||||
"\n"
|
||||
"FUSE options:\n"
|
||||
" -d -o debug enable debug output (implies -f)\n"
|
||||
" -f foreground operation\n"
|
||||
" -s disable multi-threaded operation\n"
|
||||
" -d -o debug enable debug output (implies -f)\n"
|
||||
" -f foreground operation\n"
|
||||
" -s disable multi-threaded operation\n"
|
||||
"\n",
|
||||
FspDiagIdent());
|
||||
fsp_fuse_opt_add_arg(data->env, outargs, "-h");
|
||||
return 0;
|
||||
case 'V':
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||
L"WinFsp-FUSE v%d.%d",
|
||||
FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION);
|
||||
return 1;
|
||||
case 'H':
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||
"FUSE options:\n"
|
||||
" -d -o debug enable debug output (implies -f)\n"
|
||||
" -f foreground operation\n"
|
||||
" -s disable multi-threaded operation\n"
|
||||
"\n");
|
||||
fsp_fuse_opt_add_arg(opt_data->env, outargs, "-h");
|
||||
return 0;
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
if (0 == data->mountpoint)
|
||||
if (0 == opt_data->mountpoint)
|
||||
{
|
||||
size_t size = lstrlenA(arg) + 1;
|
||||
data->mountpoint = data->env->memalloc(size);
|
||||
if (0 == data->mountpoint)
|
||||
opt_data->mountpoint = opt_data->env->memalloc(size);
|
||||
if (0 == opt_data->mountpoint)
|
||||
return -1;
|
||||
memcpy(data->mountpoint, arg, size);
|
||||
memcpy(opt_data->mountpoint, arg, size);
|
||||
}
|
||||
else
|
||||
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||
L"invalid argument \"%S\"", arg);
|
||||
L"Invalid argument \"%S\"", arg);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -78,39 +95,24 @@ FSP_FUSE_API int fsp_fuse_parse_cmdline(struct fsp_fuse_env *env,
|
||||
struct fuse_args *args,
|
||||
char **mountpoint, int *multithreaded, int *foreground)
|
||||
{
|
||||
static struct fuse_opt opts[] =
|
||||
{
|
||||
FSP_FUSE_DEFAULT_OPT("-d", foreground, 1),
|
||||
FSP_FUSE_DEFAULT_OPT("debug", foreground, 1),
|
||||
FSP_FUSE_DEFAULT_OPT("-f", foreground, 1),
|
||||
FSP_FUSE_DEFAULT_OPT("-s", singlethread, 1),
|
||||
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("-h", 'h'),
|
||||
FUSE_OPT_KEY("--help", 'h'),
|
||||
FUSE_OPT_KEY("--ho", 'h'),
|
||||
FUSE_OPT_KEY("-V", 'V'),
|
||||
FUSE_OPT_KEY("--version", 'V'),
|
||||
FUSE_OPT_END,
|
||||
};
|
||||
struct fsp_fuse_default_opt_data data;
|
||||
struct fsp_fuse_main_opt_data opt_data;
|
||||
|
||||
memset(&data, 0, sizeof data);
|
||||
data.env = env;
|
||||
memset(&opt_data, 0, sizeof opt_data);
|
||||
opt_data.env = env;
|
||||
|
||||
if (-1 == fsp_fuse_opt_parse(env, args, &data, opts, fsp_fuse_default_opt_proc))
|
||||
if (-1 == fsp_fuse_opt_parse(env, args, &opt_data, fsp_fuse_main_opts, fsp_fuse_main_opt_proc))
|
||||
return -1;
|
||||
|
||||
if (0 != mountpoint)
|
||||
*mountpoint = data.mountpoint;
|
||||
*mountpoint = opt_data.mountpoint;
|
||||
else
|
||||
env->memfree(mountpoint);
|
||||
|
||||
if (0 != multithreaded)
|
||||
*multithreaded = !data.singlethread;
|
||||
*multithreaded = !opt_data.singlethread;
|
||||
|
||||
if (0 != foreground)
|
||||
*foreground = data.foreground;
|
||||
*foreground = opt_data.foreground;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -161,12 +163,12 @@ exit:
|
||||
if (signal_handlers)
|
||||
env->remove_signal_handlers(f/* !!!: REVISIT */);
|
||||
|
||||
if (0 != ch)
|
||||
fsp_fuse_unmount(env, mountpoint, ch);
|
||||
|
||||
if (0 != f)
|
||||
fsp_fuse_destroy(env, f);
|
||||
|
||||
if (0 != ch)
|
||||
fsp_fuse_unmount(env, mountpoint, ch);
|
||||
|
||||
env->memfree(mountpoint);
|
||||
|
||||
fsp_fuse_opt_free_args(env, &args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user