Separated fuse implementation from fuse interface

This commit is contained in:
Sebastian Messmer 2014-11-04 18:03:59 +01:00
parent 6e44f4a326
commit ec6955ec25
12 changed files with 241 additions and 187 deletions

View File

@ -1,5 +1,5 @@
add_subdirectory(fuse)
add_subdirectory(fusepp)
add_library(cryfs_lib CryDevice.cpp)
target_link_libraries(cryfs_lib cryfs_fuse)
target_link_libraries(cryfs_lib fusepp)

View File

@ -1,7 +1,8 @@
#pragma once
#ifndef CRYFS_LIB_CRYDEVICE_H_
#define CRYFS_LIB_CRYDEVICE_H_
#include "fuse/Fuse.h"
#include "fusepp/Fuse.h"
namespace cryfs {
@ -9,8 +10,6 @@ class CryDevice {
public:
CryDevice();
virtual ~CryDevice();
private:
Fuse _fuse;
};
}

View File

@ -0,0 +1,5 @@
#include "CryFuse.h"
namespace cryfs {
} /* namespace cryfs */

163
src/cryfs_lib/CryFuse.h Normal file
View File

@ -0,0 +1,163 @@
#pragma once
#ifndef CRYFS_LIB_CRYFUSE_H_
#define CRYFS_LIB_CRYFUSE_H_
#include "fusepp/Fuse.h"
namespace cryfs {
class CryFuse: public fusepp::Fuse {
public:
int getattr(const char *path, struct stat *stbuf) override {
printf("Called non-implemented getattr(%s, _)\n", path);
return 0;
}
int fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) override {
printf("Called non-implemented fgetattr(%s, _, _)\n", path);
return 0;
}
int readlink(const char *path, char *buf, size_t size) override {
printf("Called non-implemented readlink(%s, _, %d)\n", path, size);
return 0;
}
int mknod(const char *path, mode_t mode, dev_t rdev) override {
printf("Called non-implemented mknod(%s, %d, _)\n", path, mode);
return 0;
}
int mkdir(const char *path, mode_t mode) override {
printf("Called non-implemented mkdir(%s, %d)\n", path, mode);
return 0;
}
int unlink(const char *path) override {
printf("Called non-implemented unlink(%s)\n", path);
return 0;
}
int rmdir(const char *path) override {
printf("Called non-implemented rmdir(%s)\n", path);
return 0;
}
int symlink(const char *from, const char *to) override {
printf("Called non-implemented symlink(%s, %s)\n", from, to);
return 0;
}
int rename(const char *from, const char *to) override {
printf("Called non-implemented rename(%s, %s)\n", from, to);
return 0;
}
int link(const char *from, const char *to) override {
printf("Called non-implemented link(%s, %s)\n", from, to);
return 0;
}
int chmod(const char *path, mode_t mode) override {
printf("Called non-implemented chmod(%s, %d)\n", path, mode);
return 0;
}
int chown(const char *path, uid_t uid, gid_t gid) override {
printf("Called non-implemented chown(%s, %d, %d)\n", path, uid, gid);
return 0;
}
int truncate(const char *path, off_t size) override {
printf("Called non-implemented truncate(%s, %d)\n", path, size);
return 0;
}
int ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) override {
printf("Called non-implemented ftruncate(%s, %d)\n", path, size);
return 0;
}
int utimens(const char *path, const timespec times[2]) override {
printf("Called non-implemented utimens(%s, _)\n", path);
return 0;
}
int open(const char *path, fuse_file_info *fileinfo) override {
printf("Called non-implemented open(%s)\n", path);
return 0;
}
int release(const char *path, fuse_file_info *fileinfo) override {
printf("Called non-implemented release(%s)\n", path);
return 0;
}
int read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) override {
printf("Called non-implemented read(%s, _, %d, %d, _)\n", path, size, offset);
return 0;
}
int write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) override {
printf("Called non-implemented write(%s, _, %d, %d, _)\n", path, size, offset);
return 0;
}
int statfs(const char *path, struct statvfs *fsstat) override {
printf("Called non-implemented statfs(%s)\n", path);
return 0;
}
int flush(const char *path, fuse_file_info *fileinfo) override {
printf("Called non-implemented flush(%s)\n", path);
return 0;
}
int fsync(const char *path, int flags, fuse_file_info *fileinfo) override {
printf("Called non-implemented fsync(%s, %d, _)\n", path, flags);
return 0;
}
int opendir(const char *path, fuse_file_info *fileinfo) override {
printf("Called non-implemented opendir(%s, _)\n", path);
return 0;
}
int readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) override {
printf("Called non-implemented readdir(%s, _, _, %d, _)\n", path, offset);
return 0;
}
int releasedir(const char *path, fuse_file_info *fileinfo) override {
printf("Called non-implemented releasedir(%s, _)\n", path);
return 0;
}
int fsyncdir(const char *path, int datasync, fuse_file_info *fileinfo) override {
printf("Called non-implemented fsyncdir(%s, %d, _)\n", path, datasync);
return 0;
}
void* init(fuse_conn_info *conn) override {
printf("Called non-implemented init()\n");
return this;
}
void destroy(void *userdata) override {
printf("Called non-implemented destroy()\n");
}
int access(const char *path, int mask) override {
printf("Called non-implemented access(%s, %d)\n", path, mask);
return 0;
}
int create(const char *path, mode_t mode, fuse_file_info *fileinfo) override {
printf("Called non-implemented create(%s, %d, _)\n", path, mode);
return 0;
}
};
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYFUSE_H_ */

View File

@ -1,3 +0,0 @@
add_library(cryfs_fuse Fuse.cpp)
target_link_libraries(cryfs_fuse fuse)

View File

@ -1,168 +0,0 @@
#pragma once
#ifndef CRYFS_LIB_FUSE_FUSE_H_
#define CRYFS_LIB_FUSE_FUSE_H_
#include "params.h"
#include <fuse.h>
#include <cstdio>
#include <string>
#include <sys/stat.h>
class Fuse {
public:
virtual ~Fuse();
void run(int argc, char **argv);
int getattr(const char *path, struct stat *stbuf) {
printf("Called getattr(%s, _)\n", path);
return 0;
}
int fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) {
printf("Called fgetattr(%s, _, _)\n", path);
return 0;
}
int readlink(const char *path, char *buf, size_t size) {
printf("Called readlink(%s, _, %d)\n", path, size);
return 0;
}
int mknod(const char *path, mode_t mode, dev_t rdev) {
printf("Called mknod(%s, %d, _)\n", path, mode);
return 0;
}
int mkdir(const char *path, mode_t mode) {
printf("Called mkdir(%s, %d)\n", path, mode);
return 0;
}
int unlink(const char *path) {
printf("Called unlink(%s)\n", path);
return 0;
}
int rmdir(const char *path) {
printf("Called rmdir(%s)\n", path);
return 0;
}
int symlink(const char *from, const char *to) {
printf("Called symlink(%s, %s)\n", from, to);
return 0;
}
int rename(const char *from, const char *to) {
printf("Called rename(%s, %s)\n", from, to);
return 0;
}
int link(const char *from, const char *to) {
printf("Called link(%s, %s)\n", from, to);
return 0;
}
int chmod(const char *path, mode_t mode) {
printf("Called chmod(%s, %d)\n", path, mode);
return 0;
}
int chown(const char *path, uid_t uid, gid_t gid) {
printf("Called chown(%s, %d, %d)\n", path, uid, gid);
return 0;
}
int truncate(const char *path, off_t size) {
printf("Called truncate(%s, %d)\n", path, size);
return 0;
}
int ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) {
printf("Called ftruncate(%s, %d)\n", path, size);
return 0;
}
int utimens(const char *path, const timespec times[2]) {
printf("Called utimens(%s, _)\n", path);
return 0;
}
int open(const char *path, fuse_file_info *fileinfo) {
printf("Called open(%s)\n", path);
return 0;
}
int release(const char *path, fuse_file_info *fileinfo) {
printf("Called release(%s)\n", path);
return 0;
}
int read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
printf("Called read(%s, _, %d, %d, _)\n", path, size, offset);
return 0;
}
int write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
printf("Called write(%s, _, %d, %d, _)\n", path, size, offset);
return 0;
}
int statfs(const char *path, struct statvfs *fsstat) {
printf("Called statfs(%s)\n", path);
return 0;
}
int flush(const char *path, fuse_file_info *fileinfo) {
printf("Called flush(%s)\n", path);
return 0;
}
int fsync(const char *path, int flags, fuse_file_info *fileinfo) {
printf("Called fsync(%s, %d, _)\n", path, flags);
return 0;
}
int opendir(const char *path, fuse_file_info *fileinfo) {
printf("Called opendir(%s, _)\n", path);
return 0;
}
int readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
printf("Called readdir(%s, _, _, %d, _)\n", path, offset);
return 0;
}
int releasedir(const char *path, fuse_file_info *fileinfo) {
printf("Called releasedir(%s, _)\n", path);
return 0;
}
int fsyncdir(const char *path, int datasync, fuse_file_info *fileinfo) {
printf("Called fsyncdir(%s, %d, _)\n", path, datasync);
return 0;
}
void* init(fuse_conn_info *conn) {
printf("Called init()\n");
return this;
}
void destroy(void *userdata) {
printf("Called destroy()\n");
}
int access(const char *path, int mask) {
printf("Called access(%s, %d)\n", path, mask);
return 0;
}
int create(const char *path, mode_t mode, fuse_file_info *fileinfo) {
printf("Called create(%s, %d, _)\n", path, mode);
return 0;
}
};
#endif /* CRYFS_LIB_FUSE_FUSE_H_ */

View File

@ -1,7 +0,0 @@
#pragma once
#ifndef CRYFS_LIB_FUSE_PARAMS_H_
#define CRYFS_LIB_FUSE_PARAMS_H_
#define FUSE_USE_VERSION 26
#endif /* CRYFS_LIB_FUSE_PARAMS_H_ */

View File

@ -0,0 +1,3 @@
add_library(fusepp Fuse.cpp)
target_link_libraries(fusepp fuse)

View File

@ -1,11 +1,12 @@
#include "Fuse.h"
#include "../fusepp/Fuse.h"
#include <memory>
using std::unique_ptr;
using std::make_unique;
using std::string;
using namespace fusepp;
#define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data)
namespace {

View File

@ -0,0 +1,54 @@
#pragma once
#ifndef CRYFS_LIB_FUSEPP_FUSE_H_
#define CRYFS_LIB_FUSEPP_FUSE_H_
#include "params.h"
#include <fuse.h>
#include <cstdio>
#include <string>
#include <sys/stat.h>
namespace fusepp {
//TODO If performance suffers here, we could use template<class FuseImpl>
// and redirect the fuse calls directly to the FuseImpl class instead
// of using virtual functions.
class Fuse {
public:
virtual ~Fuse();
void run(int argc, char **argv);
virtual int getattr(const char *path, struct stat *stbuf) = 0;
virtual int fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) = 0;
virtual int readlink(const char *path, char *buf, size_t size) = 0;
virtual int mknod(const char *path, mode_t mode, dev_t rdev) = 0;
virtual int mkdir(const char *path, mode_t mode) = 0;
virtual int unlink(const char *path) = 0;
virtual int rmdir(const char *path) = 0;
virtual int symlink(const char *from, const char *to) = 0;
virtual int rename(const char *from, const char *to) = 0;
virtual int link(const char *from, const char *to) = 0;
virtual int chmod(const char *path, mode_t mode) = 0;
virtual int chown(const char *path, uid_t uid, gid_t gid) = 0;
virtual int truncate(const char *path, off_t size) = 0;
virtual int ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) = 0;
virtual int utimens(const char *path, const timespec times[2]) = 0;
virtual int open(const char *path, fuse_file_info *fileinfo) = 0;
virtual int release(const char *path, fuse_file_info *fileinfo) = 0;
virtual int read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) = 0;
virtual int write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) = 0;
virtual int statfs(const char *path, struct statvfs *fsstat) = 0;
virtual int flush(const char *path, fuse_file_info *fileinfo) = 0;
virtual int fsync(const char *path, int flags, fuse_file_info *fileinfo) = 0;
virtual int opendir(const char *path, fuse_file_info *fileinfo) = 0;
virtual int readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) = 0;
virtual int releasedir(const char *path, fuse_file_info *fileinfo) = 0;
virtual int fsyncdir(const char *path, int datasync, fuse_file_info *fileinfo) = 0;
virtual void* init(fuse_conn_info *conn) = 0;
virtual void destroy(void *userdata) = 0;
virtual int access(const char *path, int mask) = 0;
virtual int create(const char *path, mode_t mode, fuse_file_info *fileinfo) = 0;
};
}
#endif /* CRYFS_LIB_FUSEPP_FUSE_H_ */

View File

@ -0,0 +1,7 @@
#pragma once
#ifndef CRYFS_LIB_FUSEPP_PARAMS_H_
#define CRYFS_LIB_FUSEPP_PARAMS_H_
#define FUSE_USE_VERSION 26
#endif /* CRYFS_LIB_FUSEPP_PARAMS_H_ */

View File

@ -4,12 +4,12 @@
#include <cstdlib>
#include "buildconfig/BuildConfig.h"
#include "cryfs_lib/CryDevice.h"
#include "cryfs_lib/CryFuse.h"
int main (int argc, char *argv[])
{
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
Fuse fuse;
cryfs::CryFuse fuse;
fuse.run(argc, argv);
return 0;
}