Implemented basic fuse interface
This commit is contained in:
parent
08c3ab0b38
commit
6e44f4a326
@ -1 +1,5 @@
|
||||
add_subdirectory(fuse)
|
||||
|
||||
add_library(cryfs_lib CryDevice.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib cryfs_fuse)
|
||||
|
@ -1,12 +1,16 @@
|
||||
#ifndef CRYFS_LIB_CRYDEVICE_H_
|
||||
#define CRYFS_LIB_CRYDEVICE_H_
|
||||
|
||||
#include "fuse/Fuse.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryDevice {
|
||||
public:
|
||||
CryDevice();
|
||||
virtual ~CryDevice();
|
||||
private:
|
||||
Fuse _fuse;
|
||||
};
|
||||
|
||||
}
|
||||
|
3
src/cryfs_lib/fuse/CMakeLists.txt
Normal file
3
src/cryfs_lib/fuse/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_library(cryfs_fuse Fuse.cpp)
|
||||
|
||||
target_link_libraries(cryfs_fuse fuse)
|
198
src/cryfs_lib/fuse/Fuse.cpp
Normal file
198
src/cryfs_lib/fuse/Fuse.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#include "Fuse.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::string;
|
||||
|
||||
#define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data)
|
||||
|
||||
namespace {
|
||||
int getattr(const char *path, struct stat *stbuf) {
|
||||
return FUSE_OBJ->getattr(path, stbuf);
|
||||
}
|
||||
|
||||
int fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fgetattr(path, stbuf, fileinfo);
|
||||
}
|
||||
|
||||
int readlink(const char *path, char *buf, size_t size) {
|
||||
return FUSE_OBJ->readlink(path, buf, size);
|
||||
}
|
||||
|
||||
int mknod(const char *path, mode_t mode, dev_t rdev) {
|
||||
return FUSE_OBJ->mknod(path, mode, rdev);
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode) {
|
||||
return FUSE_OBJ->mkdir(path, mode);
|
||||
}
|
||||
|
||||
int unlink(const char *path) {
|
||||
return FUSE_OBJ->unlink(path);
|
||||
}
|
||||
|
||||
int rmdir(const char *path) {
|
||||
return FUSE_OBJ->rmdir(path);
|
||||
}
|
||||
|
||||
int symlink(const char *from, const char *to) {
|
||||
return FUSE_OBJ->symlink(from, to);
|
||||
}
|
||||
|
||||
int rename(const char *from, const char *to) {
|
||||
return FUSE_OBJ->rename(from, to);
|
||||
}
|
||||
|
||||
int link(const char *from, const char *to) {
|
||||
return FUSE_OBJ->link(from, to);
|
||||
}
|
||||
|
||||
int chmod(const char *path, mode_t mode) {
|
||||
return FUSE_OBJ->chmod(path, mode);
|
||||
}
|
||||
|
||||
int chown(const char *path, uid_t uid, gid_t gid) {
|
||||
return FUSE_OBJ->chown(path, uid, gid);
|
||||
}
|
||||
|
||||
int truncate(const char *path, off_t size) {
|
||||
return FUSE_OBJ->truncate(path, size);
|
||||
}
|
||||
|
||||
int ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->ftruncate(path, size, fileinfo);
|
||||
}
|
||||
|
||||
int utimens(const char *path, const timespec times[2]) {
|
||||
return FUSE_OBJ->utimens(path, times);
|
||||
}
|
||||
|
||||
int open(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->open(path, fileinfo);
|
||||
}
|
||||
|
||||
int release(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->release(path, fileinfo);
|
||||
}
|
||||
|
||||
int read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->read(path, buf, size, offset, fileinfo);
|
||||
}
|
||||
|
||||
int write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->write(path, buf, size, offset, fileinfo);
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statvfs *fsstat) {
|
||||
return FUSE_OBJ->statfs(path, fsstat);
|
||||
}
|
||||
|
||||
int flush(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->flush(path, fileinfo);
|
||||
}
|
||||
|
||||
int fsync(const char *path, int flags, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fsync(path, flags, fileinfo);
|
||||
}
|
||||
|
||||
//int setxattr(const char*, const char*, const char*, size_t, int)
|
||||
//int getxattr(const char*, const char*, char*, size_t)
|
||||
//int listxattr(const char*, char*, size_t)
|
||||
//int removexattr(const char*, const char*)
|
||||
|
||||
int opendir(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->opendir(path, fileinfo);
|
||||
}
|
||||
|
||||
int readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->readdir(path, buf, filler, offset, fileinfo);
|
||||
}
|
||||
|
||||
int releasedir(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->releasedir(path, fileinfo);
|
||||
}
|
||||
|
||||
int fsyncdir(const char *path, int datasync, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fsyncdir(path, datasync, fileinfo);
|
||||
}
|
||||
|
||||
void* init(fuse_conn_info *conn) {
|
||||
return FUSE_OBJ->init(conn);
|
||||
}
|
||||
|
||||
void destroy(void *userdata) {
|
||||
return FUSE_OBJ->destroy(userdata);
|
||||
}
|
||||
|
||||
int access(const char *path, int mask) {
|
||||
return FUSE_OBJ->access(path, mask);
|
||||
}
|
||||
|
||||
int create(const char *path, mode_t mode, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->create(path, mode, fileinfo);
|
||||
}
|
||||
|
||||
/*int lock(const char*, fuse_file_info*, int cmd, flock*)
|
||||
int bmap(const char*, size_t blocksize, uint64_t *idx)
|
||||
int ioctl(const char*, int cmd, void *arg, fuse_file_info*, unsigned int flags, void *data)
|
||||
int poll(const char*, fuse_file_info*, fuse_pollhandle *ph, unsigned *reventsp)
|
||||
int write_buf(const char*, fuse_bufvec *buf, off_t off, fuse_file_info*)
|
||||
int read_buf(const chas*, struct fuse_bufvec **bufp, size_t size, off_T off, fuse_file_info*)
|
||||
int flock(const char*, fuse_file_info*, int op)
|
||||
int fallocate(const char*, int, off_t, off_t, fuse_file_info*)*/
|
||||
|
||||
fuse_operations *operations() {
|
||||
static unique_ptr<fuse_operations> singleton(nullptr);
|
||||
|
||||
if (!singleton) {
|
||||
singleton = make_unique<fuse_operations>();
|
||||
singleton->getattr = &getattr;
|
||||
singleton->fgetattr = &fgetattr;
|
||||
singleton->readlink = &readlink;
|
||||
singleton->mknod = &mknod;
|
||||
singleton->mkdir = &mkdir;
|
||||
singleton->unlink = &unlink;
|
||||
singleton->rmdir = &rmdir;
|
||||
singleton->symlink = &symlink;
|
||||
singleton->rename = &rename;
|
||||
singleton->link = &link;
|
||||
singleton->chmod = &chmod;
|
||||
singleton->chown = &chown;
|
||||
singleton->truncate = &truncate;
|
||||
singleton->utimens = &utimens;
|
||||
singleton->open = &open;
|
||||
singleton->read = &read;
|
||||
singleton->write = &write;
|
||||
singleton->statfs = &statfs;
|
||||
singleton->flush = &flush;
|
||||
singleton->release = &release;
|
||||
singleton->fsync = &fsync;
|
||||
/*#ifdef HAVE_SYS_XATTR_H
|
||||
singleton->setxattr = &setxattr;
|
||||
singleton->getxattr = &getxattr;
|
||||
singleton->listxattr = &listxattr;
|
||||
singleton->removexattr = &removexattr;
|
||||
#endif*/
|
||||
singleton->opendir = &opendir;
|
||||
singleton->readdir = &readdir;
|
||||
singleton->releasedir = &releasedir;
|
||||
singleton->fsyncdir = &fsyncdir;
|
||||
singleton->init = &init;
|
||||
singleton->destroy = &destroy;
|
||||
singleton->access = &access;
|
||||
singleton->create = &create;
|
||||
singleton->ftruncate = &ftruncate;
|
||||
}
|
||||
|
||||
return singleton.get();
|
||||
}
|
||||
}
|
||||
|
||||
Fuse::~Fuse() {
|
||||
}
|
||||
|
||||
void Fuse::run(int argc, char **argv) {
|
||||
fuse_main(argc, argv, operations(), (void*)this);
|
||||
}
|
168
src/cryfs_lib/fuse/Fuse.h
Normal file
168
src/cryfs_lib/fuse/Fuse.h
Normal file
@ -0,0 +1,168 @@
|
||||
#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_ */
|
7
src/cryfs_lib/fuse/params.h
Normal file
7
src/cryfs_lib/fuse/params.h
Normal file
@ -0,0 +1,7 @@
|
||||
#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_ */
|
10
src/main.cpp
10
src/main.cpp
@ -6,14 +6,10 @@
|
||||
|
||||
#include "cryfs_lib/CryDevice.h"
|
||||
|
||||
int main ()
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
|
||||
cryfs::CryDevice device;
|
||||
#ifdef NDEBUG
|
||||
printf("Release build");
|
||||
#else
|
||||
printf("Debug build");
|
||||
#endif
|
||||
Fuse fuse;
|
||||
fuse.run(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user