From 6aa9095865017c06a61f0cb10c1f1231a89b761c Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 19:23:11 -0500 Subject: Implement fgetattr and read --- src/operations.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/operations.cc') diff --git a/src/operations.cc b/src/operations.cc index 355ffc3..897b193 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -25,8 +25,10 @@ #include #include #include +#include #include +#include #include #include #include @@ -75,6 +77,19 @@ int Getattr(const char* const path, struct stat* output) noexcept { } } +int Fgetattr(const char*, struct stat* const output, + struct fuse_file_info* const file_info) noexcept { + try { + *output = reinterpret_cast(file_info->fh)->Stat(); + return 0; + } catch (const std::system_error& e) { + return -e.code().value(); + } catch (...) { + LOG(ERROR) << "getattr: caught unexpected value"; + return -ENOTRECOVERABLE; + } +} + template int OpenResource(const char* const path, const int flags, uint64_t* const handle) noexcept { @@ -131,6 +146,22 @@ int Open(const char* const path, fuse_file_info* const file_info) noexcept { return OpenResource(path, file_info->flags, &file_info->fh); } +int Read(const char*, char* const buffer, const size_t bytes, + const off_t offset, fuse_file_info* const file_info) noexcept { + LOG(INFO) << "read with offset " << offset; + try { + auto* const file = reinterpret_cast(file_info->fh); + const std::vector read = file->Read(offset, bytes); + std::memcpy(buffer, read.data(), read.size()); + return static_cast(read.size()); + } catch (const std::system_error& e) { + return -e.code().value(); + } catch (...) { + LOG(ERROR) << "read: caught unexpected value"; + return -ENOTRECOVERABLE; + } +} + int Utimens(const char* const path, const timespec times[2]) noexcept { try { root_->UTimeNs( @@ -230,9 +261,11 @@ fuse_operations FuseOperations(File* const root) { result.destroy = &Destroy; result.getattr = &Getattr; + result.fgetattr = &Fgetattr; result.mknod = &Mknod; result.open = &Open; + result.read = &Read; result.utimens = &Utimens; result.release = &Release; result.unlink = &Unlink; -- cgit v1.2.3