opendir/readdir/releasedir
This commit is contained in:
parent
d2cba6cfe6
commit
3b2de412c8
@ -268,45 +268,43 @@ int CryFuse::fsync(const path &path, int datasync, fuse_file_info *fileinfo) {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
int CryFuse::opendir(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("opendir(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
DIR *dp = ::opendir(real_path.c_str());
|
||||
if (dp == nullptr) {
|
||||
return -errno;
|
||||
}
|
||||
fileinfo->fh = (intptr_t)dp;
|
||||
try {
|
||||
fileinfo->fh = _device->openDir(path);
|
||||
return 0;
|
||||
} catch(CryErrnoException &e) {
|
||||
return -e.getErrno();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
int CryFuse::readdir(const path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
||||
UNUSED(path);
|
||||
//printf("readdir(%s, _, _, %zu, _)\n", path.c_str(), offset);
|
||||
UNUSED(offset);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
|
||||
DIR *dp = (DIR*)(uintptr_t)fileinfo->fh;
|
||||
struct dirent *de = ::readdir(dp);
|
||||
if (de == nullptr) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
do {
|
||||
if (filler(buf, de->d_name, nullptr, 0) != 0) {
|
||||
try {
|
||||
auto entries = _device->readDir(fileinfo->fh);
|
||||
for (const auto &entry : *entries) {
|
||||
//TODO Also give file attributes (third param of filler)
|
||||
if (filler(buf, entry.c_str(), nullptr, 0) != 0) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
} while ((de = ::readdir(dp)) != nullptr);
|
||||
|
||||
}
|
||||
return 0;
|
||||
} catch (CryErrnoException &e) {
|
||||
return -e.getErrno();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
int CryFuse::releasedir(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("releasedir(%s, _)\n", path.c_str());
|
||||
UNUSED(path);
|
||||
int retstat = closedir((DIR*)(uintptr_t)fileinfo->fh);
|
||||
return errcode_map(retstat);
|
||||
try {
|
||||
_device->closeDir(fileinfo->fh);
|
||||
return 0;
|
||||
} catch (CryErrnoException &e) {
|
||||
return -e.getErrno();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
@ -1,3 +1,3 @@
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryOpenDir.cpp CryOpenFileList.cpp IdList.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryOpenDir.cpp CryOpenFileList.cpp CryOpenDirList.cpp IdList.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib boost_filesystem)
|
||||
|
@ -9,13 +9,17 @@
|
||||
#include "CryErrnoException.h"
|
||||
#include "utils/pointer.h"
|
||||
|
||||
#include "CryOpenDir.h"
|
||||
|
||||
using namespace cryfs;
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
CryDevice::CryDevice(const bf::path &rootdir)
|
||||
:_rootdir(rootdir), _open_files() {
|
||||
:_rootdir(rootdir), _open_files(), _open_dirs() {
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
@ -126,3 +130,17 @@ void CryDevice::rename(const bf::path &from, const bf::path &to) {
|
||||
auto node = Load(from);
|
||||
node->rename(to);
|
||||
}
|
||||
|
||||
int CryDevice::openDir(const bf::path &path) {
|
||||
auto dir = LoadDir(path);
|
||||
return _open_dirs.open(*dir);
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> CryDevice::readDir(int descriptor) {
|
||||
return _open_dirs.get(descriptor)->readdir();
|
||||
}
|
||||
|
||||
void CryDevice::closeDir(int descriptor) {
|
||||
_open_dirs.close(descriptor);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "utils/macros.h"
|
||||
#include "CryOpenFileList.h"
|
||||
#include "CryOpenDirList.h"
|
||||
|
||||
namespace cryfs {
|
||||
class CryNode;
|
||||
@ -39,6 +40,10 @@ public:
|
||||
void unlink(const bf::path &path);
|
||||
void rename(const bf::path &from, const bf::path &to);
|
||||
|
||||
int openDir(const bf::path &path);
|
||||
std::unique_ptr<std::vector<std::string>> readDir(int descriptor);
|
||||
void closeDir(int descriptor);
|
||||
|
||||
const bf::path &RootDir() const;
|
||||
private:
|
||||
std::unique_ptr<CryNode> Load(const bf::path &path);
|
||||
@ -47,6 +52,7 @@ private:
|
||||
int openFile(const CryFile &file, int flags);
|
||||
const bf::path _rootdir;
|
||||
CryOpenFileList _open_files;
|
||||
CryOpenDirList _open_dirs;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDevice);
|
||||
};
|
||||
|
@ -45,7 +45,7 @@ void CryDir::rmdir() {
|
||||
CHECK_RETVAL(retval);
|
||||
}
|
||||
|
||||
unique_ptr<CryOpenDir> CryDir::opendir() {
|
||||
unique_ptr<CryOpenDir> CryDir::opendir() const {
|
||||
return make_unique<CryOpenDir>(device(), path());
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
std::unique_ptr<CryDir> createDir(const std::string &name, mode_t mode);
|
||||
void rmdir();
|
||||
|
||||
std::unique_ptr<CryOpenDir> opendir();
|
||||
std::unique_ptr<CryOpenDir> opendir() const;
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
||||
};
|
||||
|
25
src/cryfs_lib/CryOpenDirList.cpp
Normal file
25
src/cryfs_lib/CryOpenDirList.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <cryfs_lib/CryOpenDirList.h>
|
||||
#include "CryDir.h"
|
||||
#include "CryOpenDir.h"
|
||||
|
||||
using namespace cryfs;
|
||||
|
||||
CryOpenDirList::~CryOpenDirList() {
|
||||
}
|
||||
|
||||
CryOpenDirList::CryOpenDirList()
|
||||
:_open_dirs() {
|
||||
}
|
||||
|
||||
int CryOpenDirList::open(const CryDir &dir) {
|
||||
return _open_dirs.add(dir.opendir());
|
||||
}
|
||||
|
||||
CryOpenDir *CryOpenDirList::get(int descriptor) {
|
||||
return _open_dirs.get(descriptor);
|
||||
}
|
||||
|
||||
void CryOpenDirList::close(int descriptor) {
|
||||
//The destructor of the stored CryOpenDir closes the dir
|
||||
_open_dirs.remove(descriptor);
|
||||
}
|
28
src/cryfs_lib/CryOpenDirList.h
Normal file
28
src/cryfs_lib/CryOpenDirList.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef CRYFS_LIB_CRYOPENDIRLIST_H_
|
||||
#define CRYFS_LIB_CRYOPENDIRLIST_H_
|
||||
|
||||
#include "utils/macros.h"
|
||||
#include "IdList.h"
|
||||
|
||||
namespace cryfs {
|
||||
class CryOpenDir;
|
||||
class CryDir;
|
||||
|
||||
class CryOpenDirList {
|
||||
public:
|
||||
CryOpenDirList();
|
||||
virtual ~CryOpenDirList();
|
||||
|
||||
int open(const CryDir &rhs);
|
||||
CryOpenDir *get(int descriptor);
|
||||
void close(int descriptor);
|
||||
|
||||
private:
|
||||
IdList<CryOpenDir> _open_dirs;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryOpenDirList);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CRYFS_LIB_CRYOPENDIRLIST_H_ */
|
@ -20,6 +20,6 @@ CryOpenFile *CryOpenFileList::get(int descriptor) {
|
||||
}
|
||||
|
||||
void CryOpenFileList::close(int descriptor) {
|
||||
//The destructor of the stored CryFile::OpenFile closes the file
|
||||
//The destructor of the stored CryOpenFile closes the file
|
||||
_open_files.remove(descriptor);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef CRYFS_LIB_CRYOPENFILELIST_H_
|
||||
#define CRYFS_LIB_CRYOPENFILELIST_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "utils/macros.h"
|
||||
#include "IdList.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user