From 066840e4d1cd1b4a210e17c16d6a40a389a632a8 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 27 Jul 2012 15:07:38 +0000 Subject: Fix compilation against various versions of fuse library Usage C++0x to remove lots of code duplication in wrappers Move code for FuseAppBase into it's own folder --- libfusepp/Jamfile.jam | 5 + libfusepp/fuseapp.cpp | 271 +++++++++++++++++++++++++++++++++++++++++ libfusepp/fuseapp.h | 54 +++++++++ netfs/Jamfile.jam | 3 + netfs/fuseapp.cpp | 325 -------------------------------------------------- netfs/fuseapp.h | 54 --------- 6 files changed, 333 insertions(+), 379 deletions(-) create mode 100644 libfusepp/Jamfile.jam create mode 100644 libfusepp/fuseapp.cpp create mode 100644 libfusepp/fuseapp.h delete mode 100644 netfs/fuseapp.cpp delete mode 100644 netfs/fuseapp.h diff --git a/libfusepp/Jamfile.jam b/libfusepp/Jamfile.jam new file mode 100644 index 0000000..1ba4a26 --- /dev/null +++ b/libfusepp/Jamfile.jam @@ -0,0 +1,5 @@ +project + : usage-requirements + . + ; + diff --git a/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp new file mode 100644 index 0000000..e81a116 --- /dev/null +++ b/libfusepp/fuseapp.cpp @@ -0,0 +1,271 @@ +#include "fuseapp.h" +#include +#include +#include +#include +#include +#include + +static FuseAppBase * fuseApp; + +FuseAppBase::FuseAppBase() +{ +} +FuseAppBase::~FuseAppBase() +{ +} +void * FuseAppBase::init(fuse_conn_info*) +{ + return NULL; +} +int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) +{ + return 1; +} +int FuseAppBase::access(const char *, int) +{ + return -ENOSYS; +} +int FuseAppBase::chmod(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::chown(const char *, uid_t, gid_t) +{ + return -ENOSYS; +} +int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flush(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::getattr(const char *, struct stat *) +{ + return -ENOSYS; +} +int FuseAppBase::getxattr(const char *, const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::link(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::listxattr(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::mkdir(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::mknod(const char *, mode_t, dev_t) +{ + return -ENOSYS; +} +int FuseAppBase::open(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::opendir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readlink(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::release(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::releasedir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::removexattr(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rename(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rmdir(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) +{ + return -ENOSYS; +} +int FuseAppBase::statfs(const char *, struct statvfs *) +{ + return -ENOSYS; +} +int FuseAppBase::symlink(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::truncate(const char *, off_t) +{ + return -ENOSYS; +} +int FuseAppBase::unlink(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) +{ + return -ENOSYS; +} +int FuseAppBase::utimens(const char *, const struct timespec[2]) +{ + return -ENOSYS; +} +int FuseAppBase::bmap(const char *, size_t, uint64_t *) +{ + return -ENOSYS; +} +int FuseAppBase::onError(const std::exception & e) throw() +{ + fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + return -ENOSYS; +} + +template +class fuseCall { + public: + template + static int helper(Args ... a) + { + try { + return (fuseApp->*f)(a...); + } + catch (const std::exception & ex) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + return helper(a...); + } + catch (...) { + fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); + return -ENOSYS; + } + } +}; +static void * fuseInit (struct fuse_conn_info *conn) +{ + return fuseApp->init(conn); +} +static void fuseDestroy(void *) +{ + delete fuseApp; +} + +int +FuseAppBase::run(int & argc, char** & argv, FuseAppBase * fa) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = fa; + struct fuse_operations operations = { + fuseCall::helper<&FuseAppBase::getattr>, + fuseCall::helper<&FuseAppBase::readlink>, + NULL, // getdir deprecated + fuseCall::helper<&FuseAppBase::mknod>, + fuseCall::helper<&FuseAppBase::mkdir>, + fuseCall::helper<&FuseAppBase::unlink>, + fuseCall::helper<&FuseAppBase::rmdir>, + fuseCall::helper<&FuseAppBase::symlink>, + fuseCall::helper<&FuseAppBase::rename>, + fuseCall::helper<&FuseAppBase::link>, + fuseCall::helper<&FuseAppBase::chmod>, + fuseCall::helper<&FuseAppBase::chown>, + fuseCall::helper<&FuseAppBase::truncate>, + NULL, // utime deprecated + fuseCall::helper<&FuseAppBase::open>, + fuseCall::helper<&FuseAppBase::read>, + fuseCall::helper<&FuseAppBase::write>, + fuseCall::helper<&FuseAppBase::statfs>, + fuseCall::helper<&FuseAppBase::flush>, + fuseCall::helper<&FuseAppBase::release>, + fuseCall::helper<&FuseAppBase::fsync>, + fuseCall::helper<&FuseAppBase::setxattr>, + fuseCall::helper<&FuseAppBase::getxattr>, + fuseCall::helper<&FuseAppBase::listxattr>, + fuseCall::helper<&FuseAppBase::removexattr>, + fuseCall::helper<&FuseAppBase::opendir>, + fuseCall::helper<&FuseAppBase::readdir>, + fuseCall::helper<&FuseAppBase::releasedir>, + fuseCall::helper<&FuseAppBase::fsyncdir>, + fuseInit, + fuseDestroy, + fuseCall::helper<&FuseAppBase::access>, + fuseCall::helper<&FuseAppBase::create>, + fuseCall::helper<&FuseAppBase::ftruncate>, + fuseCall::helper<&FuseAppBase::fgetattr> +#if (FUSE_MINOR_VERSION >= 6) + , + fuseCall::helper<&FuseAppBase::lock>, + fuseCall::helper<&FuseAppBase::utimens>, + fuseCall::helper<&FuseAppBase::bmap> +#if (FUSE_MINOR_VERSION >= 8) + , + 0, // flag_nullpath_ok +#if (FUSE_MINOR_VERSION >= 9) + 0, // flag_nopath + 0, // flag_utime_omit_ok +#endif + 0, // flag_reserved + NULL, // ioctl + NULL // poll +#if (FUSE_MINOR_VERSION >= 9) + , + NULL, // writebuf + NULL, // readbuf + NULL // flock +#endif +#endif +#endif + }; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + if (fuse_opt_parse(&args, fuseApp, fuse_opts, + fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { + exit(1); + } + return fuse_main(args.argc, args.argv, &operations, fa); +} + diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h new file mode 100644 index 0000000..c823721 --- /dev/null +++ b/libfusepp/fuseapp.h @@ -0,0 +1,54 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include +#include + +class FuseAppBase { + public: + FuseAppBase(); + virtual ~FuseAppBase() = 0; + virtual void * init (struct fuse_conn_info * info); + virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); + virtual int access(const char *, int); + virtual int chmod(const char *, mode_t); + virtual int chown(const char *, uid_t, gid_t); + virtual int create(const char *, mode_t, struct fuse_file_info *); + virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); + virtual int flush(const char *, struct fuse_file_info *); + virtual int fsync(const char *, int, struct fuse_file_info *); + virtual int fsyncdir(const char *, int, struct fuse_file_info *); + virtual int ftruncate(const char *, off_t, struct fuse_file_info *); + virtual int getattr(const char *, struct stat *); + virtual int getxattr(const char *, const char *, char *, size_t); + virtual int link(const char *, const char *); + virtual int listxattr(const char *, char *, size_t); + virtual int mkdir(const char *, mode_t); + virtual int mknod(const char *, mode_t, dev_t); + virtual int open(const char *, struct fuse_file_info *); + virtual int opendir(const char *, struct fuse_file_info *); + virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); + virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); + virtual int readlink(const char *, char *, size_t); + virtual int release(const char *, struct fuse_file_info *); + virtual int releasedir(const char *, struct fuse_file_info *); + virtual int removexattr(const char *, const char *); + virtual int rename(const char *, const char *); + virtual int rmdir(const char *); + virtual int setxattr(const char *, const char *, const char *, size_t, int); + virtual int statfs(const char *, struct statvfs *); + virtual int symlink(const char *, const char *); + virtual int truncate(const char *, off_t); + virtual int unlink(const char *); + virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); + virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); + virtual int utimens(const char *, const struct timespec tv[2]); + virtual int bmap(const char *, size_t blocksize, uint64_t *idx); + virtual int onError(const std::exception & err) throw(); + + static int run(int &, char ** &, FuseAppBase *); +}; + +#endif + diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 7f5fbee..5ed3a22 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -37,6 +37,7 @@ lib netfsCommon : cpp-pch pchFuse : pchCommon pchFuse.hpp : _FILE_OFFSET_BITS=64 ../libmisc + ../libfusepp netfsComms netfsComms boost_thread @@ -69,9 +70,11 @@ cpp-pch pchCommon : pchCommon.hpp : exe netfs : pchFuse [ glob fuse*.cpp ] + [ glob ../libfusepp/fuse*.cpp ] : _FILE_OFFSET_BITS=64 ../libmisc + ../libfusepp netfsComms netfsComms netfsCommon diff --git a/netfs/fuseapp.cpp b/netfs/fuseapp.cpp deleted file mode 100644 index 6f58ec2..0000000 --- a/netfs/fuseapp.cpp +++ /dev/null @@ -1,325 +0,0 @@ -#include "pchFuse.hpp" -#include "fuseapp.h" -#include -#include -#include -#include -#include -#include - -static FuseAppBase * fuseApp; - -FuseAppBase::FuseAppBase() -{ -} -FuseAppBase::~FuseAppBase() -{ -} -void * FuseAppBase::init(fuse_conn_info*) -{ - return NULL; -} -int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) -{ - return 1; -} -int FuseAppBase::access(const char *, int) -{ - return -ENOSYS; -} -int FuseAppBase::chmod(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::chown(const char *, uid_t, gid_t) -{ - return -ENOSYS; -} -int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flush(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::getattr(const char *, struct stat *) -{ - return -ENOSYS; -} -int FuseAppBase::getxattr(const char *, const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::link(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::listxattr(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::mkdir(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::mknod(const char *, mode_t, dev_t) -{ - return -ENOSYS; -} -int FuseAppBase::open(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::opendir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readlink(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::release(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::releasedir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::removexattr(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rename(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rmdir(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) -{ - return -ENOSYS; -} -int FuseAppBase::statfs(const char *, struct statvfs *) -{ - return -ENOSYS; -} -int FuseAppBase::symlink(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::truncate(const char *, off_t) -{ - return -ENOSYS; -} -int FuseAppBase::unlink(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) -{ - return -ENOSYS; -} -int FuseAppBase::utimens(const char *, const struct timespec[2]) -{ - return -ENOSYS; -} -int FuseAppBase::bmap(const char *, size_t, uint64_t *) -{ - return -ENOSYS; -} -int FuseAppBase::onError(const std::exception & e) throw() -{ - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); - return -ENOSYS; -} - -template -static int fuseCall(A a) -{ - try { - return (fuseApp->*f)(a); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return fuseCall(a); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } -} -template -static int fuseCall(A a, B b) -{ - try { - return (fuseApp->*f)(a, b); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return fuseCall(a, b); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } -} -template -static int fuseCall(A a, B b, C c) -{ - try { - return (fuseApp->*f)(a, b, c); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return fuseCall(a, b, c); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } -} -template -static int fuseCall(A a, B b, C c, D d) -{ - try { - return (fuseApp->*f)(a, b, c, d); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return fuseCall(a, b, c, d); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } -} -template -static int fuseCall(A a, B b, C c, D d, E e) -{ - try { - return (fuseApp->*f)(a, b, c, d, e); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return fuseCall(a, b, c, d, e); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } -} -static void * fuseInit (struct fuse_conn_info *conn) -{ - return fuseApp->init(conn); -} -static void fuseDestroy(void *) -{ - delete fuseApp; -} - -int -FuseAppBase::run(int & argc, char** & argv, FuseAppBase * fa) -{ - struct fuse_opt fuse_opts[] = { - { NULL, 0, 0 } - }; - fuseApp = fa; - struct fuse_operations operations = { - fuseCall, - fuseCall, - NULL, // getdir deprecated - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - NULL, // utime deprecated - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseInit, - fuseDestroy, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - fuseCall, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - }; - struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - if (fuse_opt_parse(&args, fuseApp, fuse_opts, - fuseCall) == -1) { - exit(1); - } - return fuse_main(args.argc, args.argv, &operations, fa); -} - diff --git a/netfs/fuseapp.h b/netfs/fuseapp.h deleted file mode 100644 index c823721..0000000 --- a/netfs/fuseapp.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef FUSEAPP_H -#define FUSEAPP_H - -#define FUSE_USE_VERSION 26 -#include -#include - -class FuseAppBase { - public: - FuseAppBase(); - virtual ~FuseAppBase() = 0; - virtual void * init (struct fuse_conn_info * info); - virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); - virtual int access(const char *, int); - virtual int chmod(const char *, mode_t); - virtual int chown(const char *, uid_t, gid_t); - virtual int create(const char *, mode_t, struct fuse_file_info *); - virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); - virtual int flush(const char *, struct fuse_file_info *); - virtual int fsync(const char *, int, struct fuse_file_info *); - virtual int fsyncdir(const char *, int, struct fuse_file_info *); - virtual int ftruncate(const char *, off_t, struct fuse_file_info *); - virtual int getattr(const char *, struct stat *); - virtual int getxattr(const char *, const char *, char *, size_t); - virtual int link(const char *, const char *); - virtual int listxattr(const char *, char *, size_t); - virtual int mkdir(const char *, mode_t); - virtual int mknod(const char *, mode_t, dev_t); - virtual int open(const char *, struct fuse_file_info *); - virtual int opendir(const char *, struct fuse_file_info *); - virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); - virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - virtual int readlink(const char *, char *, size_t); - virtual int release(const char *, struct fuse_file_info *); - virtual int releasedir(const char *, struct fuse_file_info *); - virtual int removexattr(const char *, const char *); - virtual int rename(const char *, const char *); - virtual int rmdir(const char *); - virtual int setxattr(const char *, const char *, const char *, size_t, int); - virtual int statfs(const char *, struct statvfs *); - virtual int symlink(const char *, const char *); - virtual int truncate(const char *, off_t); - virtual int unlink(const char *); - virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); - virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); - virtual int utimens(const char *, const struct timespec tv[2]); - virtual int bmap(const char *, size_t blocksize, uint64_t *idx); - virtual int onError(const std::exception & err) throw(); - - static int run(int &, char ** &, FuseAppBase *); -}; - -#endif - -- cgit v1.2.3