opendir/readdir/releasedir

This commit is contained in:
Sebastian Messmer 2014-11-12 15:34:01 +01:00
parent c1ef981368
commit 194f1cba48

View File

@ -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