Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
184 lines (157 sloc) 6.32 KB
/*
* YADFS.h
* yadfs
*
* Created by Cayzac Julien on 5/19/11.
* Copyright 2011 -. All rights reserved.
*
*/
#pragma once
#include <fuse.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <iostream>
#include <boost/thread.hpp>
#include "datastore.h"
#include "update_listener.h"
class YADFS: public UpdateListener::Delegate {
private:
DataStore mDataStore;
UpdateListener mUpdateListener;
volatile bool mQuitRequested;
boost::thread mUpdateListenerThread;
private:
YADFS(const YADFS&);
YADFS& operator=(const YADFS&);
YADFS(const std::string& server);
~YADFS();
// UpdateListener::Delegate
bool quitRequested();
void onMoved(int64_t transaction_id, const std::string& oldPath, const std::string& newPath);
void onStored(int64_t transaction_id, const std::string& path);
//
int fgetattr_impl(const char *path, struct stat *stbuf, fuse_file_info *fi);
int readlink_impl(const char *path, char *buf, size_t size);
int readdir_impl(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fi);
int mknod_impl(const char *path, mode_t mode, dev_t rdev);
int mkdir_impl(const char *path, mode_t mode);
int unlink_impl(const char *path);
int rmdir_impl(const char *path);
int symlink_impl(const char *from, const char *to);
int rename_impl(const char *from, const char *to);
int exchange_impl(const char *path1, const char *path2, unsigned long options);
int link_impl(const char *from, const char *to);
int fsetattr_x_impl(const char *path, setattr_x *attr, fuse_file_info *fi);
int setattr_x_impl(const char *path, setattr_x *attr);
int getxtimes_impl(const char *path, timespec *bkuptime, timespec *crtime);
int create_impl(const char *path, mode_t mode, fuse_file_info *fi);
int open_impl(const char *path, fuse_file_info *fi);
int read_impl(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fi);
int write_impl(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fi);
int statfs_impl(const char *path, struct statvfs *stbuf);
int flush_impl(const char *path, fuse_file_info *fi);
int release_impl(const char *path, fuse_file_info *fi);
int fsync_impl(const char *path, int isdatasync, fuse_file_info *fi);
int setxattr_impl(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t position);
int getxattr_impl(const char *path, const char *name, char *value, size_t size, uint32_t position);
int listxattr_impl(const char *path, char *list, size_t size);
int removexattr_impl(const char *path, const char *name);
static YADFS* get() {
fuse_context* f(fuse_get_context());
if (f) return (YADFS*) (f->private_data);
return 0;
}
/*
static void* static_init(fuse_conn_info *conn) {
FUSE_ENABLE_XTIMES(conn);
return new YADFS();
}
static void static_destroy(void *userdata) {
delete (YADFS*) userdata;
}
*/
static int static_fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fi) {
return get()->fgetattr_impl(path, stbuf, fi);
}
static int static_getattr(const char* path, struct stat* stbuf) {
return static_fgetattr(path, stbuf, 0);
}
static int static_readlink(const char *path, char *buf, size_t size) {
return get()->readlink_impl(path, buf, size);
}
static int static_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fi) {
return get()->readdir_impl(path,buf,filler,offset,fi);
}
static int static_mknod(const char *path, mode_t mode, dev_t rdev) {
return get()->mknod_impl(path, mode, rdev);
}
static int static_mkdir(const char *path, mode_t mode) {
return get()->mkdir_impl(path, mode);
}
static int static_unlink(const char *path) {
return get()->unlink_impl(path);
}
static int static_rmdir(const char *path) {
return get()->rmdir_impl(path);
}
static int static_symlink(const char *from, const char *to) {
return get()->symlink_impl(from, to);
}
static int static_rename(const char *from, const char *to) {
return get()->rename_impl(from, to);
}
static int static_exchange(const char *path1, const char *path2, unsigned long options) {
return get()->exchange_impl(path1, path2, options);
}
static int static_link(const char *from, const char *to) {
return get()->link_impl(from, to);
}
static int static_fsetattr_x(const char *path, setattr_x *attr, fuse_file_info *fi) {
return get()->fsetattr_x_impl(path, attr, fi);
}
static int static_setattr_x(const char *path, setattr_x *attr) {
return get()->setattr_x_impl(path, attr);
}
static int static_getxtimes(const char *path, timespec *bkuptime, timespec *crtime) {
return get()->getxtimes_impl(path, bkuptime, crtime);
}
static int static_create(const char *path, mode_t mode, fuse_file_info *fi) {
return get()->create_impl(path, mode, fi);
}
static int static_open(const char *path, fuse_file_info *fi) {
return get()->open_impl(path, fi);
}
static int static_read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fi) {
return get()->read_impl(path, buf, size, offset, fi);
}
static int static_write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fi) {
return get()->write_impl(path, buf, size, offset, fi);
}
static int static_statfs(const char *path, struct statvfs *stbuf) {
return get()->statfs_impl(path, stbuf);
}
static int static_flush(const char *path, fuse_file_info *fi) {
return get()->flush_impl(path, fi);
}
static int static_release(const char *path, fuse_file_info *fi) {
return get()->release_impl(path, fi);
}
static int static_fsync(const char *path, int isdatasync, fuse_file_info *fi) {
return get()->fsync_impl(path, isdatasync, fi);
}
static int static_setxattr(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t position) {
return get()->setxattr_impl(path, name, value, size, flags, position);
}
static int static_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t position) {
return get()->getxattr_impl(path, name, value, size, position);
}
static int static_listxattr(const char *path, char *list, size_t size) {
return get()->listxattr_impl(path, list, size);
}
static int static_removexattr(const char *path, const char *name) {
return get()->removexattr_impl(path, name);
}
public:
static int run(const std::string& server, const std::string& mountpoint, const std::string& name);
};