Skip to content

Commit

Permalink
Implement fgetattr
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Mar 6, 2024
1 parent edd55b2 commit 75ee42f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
59 changes: 46 additions & 13 deletions sources/lite_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#include <absl/base/thread_annotations.h>
#include <absl/strings/str_cat.h>
#include <absl/strings/string_view.h>

#include <absl/utility/utility.h>
#include <fuse.h>

#include <cerrno>
#include <cstdint>
#include <memory>
#include <utility>

Expand Down Expand Up @@ -68,18 +70,19 @@ namespace lite_format

namespace
{
class LegacyNameTranslator : public NameTranslator
{
public:
INJECT(LegacyNameTranslator(ANNOTATED(tNameMasterKey, const key_type&) name_master_key))
: name_master_key_(name_master_key)
{
}
// class LegacyNameTranslator : public NameTranslator
// {
// public:
// INJECT(LegacyNameTranslator(ANNOTATED(tNameMasterKey, const key_type&)
// name_master_key))
// : name_master_key_(name_master_key)
// {
// }

private:
key_type name_master_key_;
ThreadLocal name_aes_siv_;
};
// private:
// key_type name_master_key_;
// ThreadLocal name_aes_siv_;
// };

class NoOpNameTranslator : public NameTranslator
{
Expand Down Expand Up @@ -223,6 +226,31 @@ namespace lite_format
StreamOpener& opener_;
bool readdir_plus_;
};

Base* get_base(fuse_file_info* info)
{
return reinterpret_cast<Base*>(static_cast<uintptr_t>(info->fh));
}

File* get_file_checked(fuse_file_info* info)
{
auto fp = get_base(info)->as_file();
if (!fp)
{
throwVFSException(EISDIR);
}
return fp;
}

Directory* get_dir_checked(fuse_file_info* info)
{
auto fp = get_base(info)->as_dir();
if (!fp)
{
throwVFSException(ENOTDIR);
}
return fp;
}
} // namespace

void FuseHighLevelOps::initialize(fuse_conn_info* info)
Expand Down Expand Up @@ -314,10 +342,15 @@ namespace lite_format
fuse_file_info* info,
const fuse_context* ctx)
{
return -ENOSYS;
auto fp = get_base(info);
LockGuard<Base> lg(*fp);
fp->fstat(st);
return 0;
}
int FuseHighLevelOps::vopendir(const char* path, fuse_file_info* info, const fuse_context* ctx)
{
// auto dir = std::make_unique<DirectoryImpl>(
// root_.norm_path(path), opener_, name_trans_, read_dir_plus_);
return -ENOSYS;
}
int
Expand Down
6 changes: 3 additions & 3 deletions sources/lite_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace lite_format
public:
virtual File* as_file() noexcept { return nullptr; }
virtual Directory* as_dir() noexcept { return nullptr; }
virtual void lock(bool exclusive) ABSL_EXCLUSIVE_LOCK_FUNCTION() = 0;
virtual void lock(bool exclusive = true) ABSL_EXCLUSIVE_LOCK_FUNCTION() = 0;
virtual void unlock() noexcept ABSL_UNLOCK_FUNCTION() = 0;
virtual void fstat(fuse_stat* stat) ABSL_EXCLUSIVE_LOCKS_REQUIRED(*this) = 0;
};
Expand All @@ -80,7 +80,7 @@ namespace lite_format
securefs::Mutex m_lock;

public:
void lock(bool exclusive) override ABSL_EXCLUSIVE_LOCK_FUNCTION() { m_lock.lock(); }
void lock(bool exclusive = true) override ABSL_EXCLUSIVE_LOCK_FUNCTION() { m_lock.lock(); }
void unlock() noexcept override ABSL_UNLOCK_FUNCTION() { m_lock.unlock(); }
Directory* as_dir() noexcept override { return this; }

Expand Down Expand Up @@ -140,7 +140,7 @@ namespace lite_format
{
m_file_stream->utimens(ts);
}
void lock(bool exclusive) override ABSL_EXCLUSIVE_LOCK_FUNCTION()
void lock(bool exclusive = true) override ABSL_EXCLUSIVE_LOCK_FUNCTION()
{
m_lock.lock();
try
Expand Down

0 comments on commit 75ee42f

Please sign in to comment.