Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
231 lines (193 sloc) 6.58 KB
/*
* YADFS.cpp
* yadfs
*
* Created by Cayzac Julien on 5/19/11.
* Copyright 2011 -. All rights reserved.
*
*/
#include <string.h>
#include <errno.h>
#include "yadfs.h"
#include "datastore.h"
#include "utils.h"
YADFS::YADFS(const std::string& server)
: mDataStore(check_create_state_directory(server)+"/datastore.kch")
, mUpdateListener(server, *this)
, mQuitRequested(false)
{
// Starts the update listemer
mUpdateListenerThread = boost::thread(mUpdateListener);
}
YADFS::~YADFS() {
mQuitRequested=true;
mUpdateListenerThread.join();
}
bool YADFS::quitRequested() {
return mQuitRequested;
}
void YADFS::onMoved(int64_t transaction_id, const std::string& oldPath, const std::string& newPath) {
// TODO: move entities in the DataStore
}
void YADFS::onStored(int64_t transaction_id, const std::string& path) {
// TODO: fetch entity's metadata from server
// TODO: compare entity's SHA-256 with local ones
// TODO: fetch entity's content from server or local equivalent if it exists (TODO: use reference counting?)
// TODO: store entity's metadata and content in DataStore
}
int YADFS::fgetattr_impl(const char *p, struct stat *stbuf, fuse_file_info *fi) {
memset(stbuf, 0, sizeof(struct stat));
std::string path(p);
// TODO: fetch entity's metadata from DataStore
// TODO: fill the stat struct
if (path=="/") {
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 3; // why 3?
return 0;
}
return -ENOENT;
}
int YADFS::readlink_impl(const char *p, char *buf, size_t size) {
std::string path(p);
// TODO: support symlinks
return -ENOENT;
}
int YADFS::readdir_impl(const char *p, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fi) {
std::string path(p);
// TODO: fetch entity's metadata from DataStore
// TODO: fill with the directories entries stored in metadata (X-yad-dir-entry?)
if (path != "/")
return -ENOENT;
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
return 0;
}
int YADFS::mknod_impl(const char *p, mode_t mode, dev_t rdev) {
std::string path(p);
// TODO: support special files
return -ENOSYS;
}
int YADFS::mkdir_impl(const char *p, mode_t mode) {
std::string path(p);
// TODO: Create entity's metadata in DataStore, and add it to server's pending transaction
return -ENOSYS;
}
int YADFS::unlink_impl(const char *p) {
std::string path(p);
// TODO: decrease link count in entity's metadata, and add it to server's pending transaction
return -ENOSYS;
}
int YADFS::rmdir_impl(const char *path) {
// TODO: remove entity in DataStore, and add it to server's pending transaction
return -ENOSYS;
}
int YADFS::symlink_impl(const char *from, const char *to) {
// TODO: create link in DataStore, and add it to server's pending transaction
return -ENOSYS;
}
int YADFS::rename_impl(const char *from, const char *to) {
// TODO: create link in DataStore, and add it to server's pending transaction
return -ENOSYS;
}
int YADFS::exchange_impl(const char *path1, const char *path2, unsigned long options) {
return -ENOSYS;
}
int YADFS::link_impl(const char *from, const char *to) {
return -ENOSYS;
}
int YADFS::fsetattr_x_impl(const char *path, struct setattr_x *attr, struct fuse_file_info *fi) {
return -ENOENT;
}
int YADFS::setattr_x_impl(const char *path, struct setattr_x *attr) {
return -ENOENT;
}
int YADFS::getxtimes_impl(const char *path, struct timespec *bkuptime,
struct timespec *crtime) {
return -ENOENT;
}
int YADFS::create_impl(const char *path, mode_t mode, struct fuse_file_info *fi) {
return -ENOSYS;
}
int YADFS::open_impl(const char *path, struct fuse_file_info *fi) {
// TODO: Fill fi with info from DataStore
return -ENOENT;
}
int YADFS::read_impl(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
// TODO: Read entity's content from DataStore
return -ENOSYS;
}
int YADFS::write_impl(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
// TODO: Write entity's content in DataStore
return -ENOSYS;
}
int YADFS::statfs_impl(const char *path, struct statvfs *stbuf) {
memset(stbuf, 0, sizeof(*stbuf));
stbuf->f_files = 2; /* For . and .. in the root */
return 0;
}
int YADFS::flush_impl(const char *path, struct fuse_file_info *fi) {
return 0;
}
int YADFS::release_impl(const char *path, struct fuse_file_info *fi) {
return 0;
}
int YADFS::fsync_impl(const char *path, int isdatasync, struct fuse_file_info *fi) {
// TODO: push pending changes to server
return 0;
}
int YADFS::setxattr_impl(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t position) {
return -ENOTSUP;
}
int YADFS::getxattr_impl(const char *path, const char *name, char *value, size_t size, uint32_t position) {
return -ENOATTR;
}
int YADFS::listxattr_impl(const char *path, char *list, size_t size) {
return 0;
}
int YADFS::removexattr_impl(const char *path, const char *name) {
return -ENOATTR;
}
int YADFS::run(const std::string& server, const std::string& mountpoint, const std::string& name) {
fuse_operations operations;
memset(&operations, 0, sizeof(fuse_operations));
operations.getattr = static_getattr;
operations.fgetattr = static_fgetattr;
// operations.readlink = static_readlink;
operations.readdir = static_readdir;
// operations.mknod = static_mknod;
operations.mkdir = static_mkdir;
operations.symlink = static_symlink;
operations.unlink = static_unlink;
operations.rmdir = static_rmdir;
operations.rename = static_rename;
operations.link = static_link;
operations.create = static_create;
operations.open = static_open;
operations.read = static_read;
operations.write = static_write;
// operations.statfs = static_statfs;
// operations.flush = static_flush;
// operations.release = static_release;
// operations.fsync = static_fsync;
// operations.setxattr = static_setxattr;
// operations.getxattr = static_getxattr;
// operations.listxattr = static_listxattr;
// operations.removexattr = static_removexattr;
// operations.exchange = static_exchange;
// operations.getxtimes = static_getxtimes;
// operations.setattr_x = static_setattr_x;
// operations.fsetattr_x = static_fsetattr_x;
fuse_args args = { 0, 0, 0 };
fuse_opt_add_arg(&args, "-d");
// fuse_opt_add_arg(&args, "-olocal");
fuse_opt_add_arg(&args, "-onoappledouble");
fuse_opt_add_arg(&args, "-onoapplexattr");
std::string volname_arg("-ovolname=");
volname_arg += name;
fuse_opt_add_arg(&args, &volname_arg[0]);
fuse_opt_add_arg(&args, &mountpoint[0]);
YADFS* yadfs = new YADFS(server);
int result = fuse_main(args.argc, args.argv, &operations, yadfs);
delete yadfs;
return result;
}