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