aboutsummaryrefslogtreecommitdiff
path: root/src/operations.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/operations.cc')
-rw-r--r--src/operations.cc33
1 files changed, 33 insertions, 0 deletions
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 <new>
#include <system_error>
#include <type_traits>
+#include <vector>
#include <dirent.h>
+#include <fcntl.h>
#include <glog/logging.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -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*>(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 <typename T>
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<File>(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*>(file_info->fh);
+ const std::vector<std::uint8_t> read = file->Read(offset, bytes);
+ std::memcpy(buffer, read.data(), read.size());
+ return static_cast<int>(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;