Fix IdList and implement statfs()

This commit is contained in:
Sebastian Messmer 2014-11-12 22:38:12 +01:00
parent 31aa6228bb
commit df80fdfb74
5 changed files with 26 additions and 16 deletions

View File

@ -14,15 +14,6 @@ using fusepp::path;
namespace cryfs {
namespace {
int errcode_map(int exit_status) {
if (exit_status < 0) {
return -errno;
}
return exit_status;
}
}
CryFuse::CryFuse(CryDevice *device)
:_device(device) {
}
@ -235,10 +226,13 @@ int CryFuse::write(const path &path, const char *buf, size_t size, off_t offset,
//TODO
int CryFuse::statfs(const path &path, struct statvfs *fsstat) {
printf("HALF-IMPLEMENTED: statfs(%s, _)\n", path.c_str());
auto real_path = _device->RootDir() / path;
int retstat = ::statvfs(real_path.c_str(), fsstat);
return errcode_map(retstat);
//printf("statfs(%s, _)\n", path.c_str());
try {
_device->statfs(path, fsstat);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO

View File

@ -148,3 +148,8 @@ void CryDevice::utimens(const bf::path &path, const timespec times[2]) {
auto node = Load(path);
node->utimens(times);
}
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
int retval = ::statvfs(path.c_str(), fsstat);
CHECK_RETVAL(retval);
}

View File

@ -5,6 +5,7 @@
#include <boost/filesystem.hpp>
#include <memory>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include "utils/macros.h"
#include "CryOpenFileList.h"
@ -43,6 +44,7 @@ public:
std::unique_ptr<std::vector<std::string>> readDir(int descriptor);
void closeDir(int descriptor);
void utimens(const bf::path &path, const timespec times[2]);
void statfs(const bf::path &path, struct statvfs *fsstat);
const bf::path &RootDir() const;
private:

View File

@ -3,6 +3,7 @@
#include <map>
#include <memory>
#include <mutex>
#include "utils/macros.h"
namespace cryfs {
@ -19,13 +20,15 @@ public:
void remove(int id);
private:
std::map<int, std::unique_ptr<Entry>> _entries;
int _id_counter;
mutable std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(IdList<Entry>)
};
template<class Entry>
IdList<Entry>::IdList()
: _entries() {
: _entries(), _id_counter(0), _mutex() {
}
template<class Entry>
@ -34,8 +37,9 @@ IdList<Entry>::~IdList() {
template<class Entry>
int IdList<Entry>::add(std::unique_ptr<Entry> entry) {
std::lock_guard<std::mutex> lock(_mutex);
//TODO Reuse IDs (ids = descriptors)
int new_id = _entries.size();
int new_id = ++_id_counter;
_entries[new_id] = std::move(entry);
return new_id;
}
@ -47,11 +51,14 @@ Entry *IdList<Entry>::get(int id) {
template<class Entry>
const Entry *IdList<Entry>::get(int id) const {
return _entries.at(id).get();
std::lock_guard<std::mutex> lock(_mutex);
const Entry *result = _entries.at(id).get();
return result;
}
template<class Entry>
void IdList<Entry>::remove(int id) {
std::lock_guard<std::mutex> lock(_mutex);
_entries.erase(id);
}

View File

@ -11,6 +11,7 @@ namespace bf = boost::filesystem;
using namespace fusepp;
#define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data)
#define UNUSED(obj) (void)obj
namespace {
int fusepp_getattr(const char *path, struct stat *stbuf) {
@ -131,6 +132,7 @@ void* fusepp_init(fuse_conn_info *conn) {
void fusepp_destroy(void *userdata) {
auto f = FUSE_OBJ;
assert(userdata == f);
UNUSED(userdata); //In the Release build, the assert doesn't run
f->destroy();
}