1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

added dummy filesystem implementation

This commit is contained in:
Falk Werner 2022-11-14 19:02:46 +01:00
parent d9350e9725
commit bc024481f9
6 changed files with 394 additions and 5 deletions

View File

@ -10,6 +10,7 @@ pkg_check_modules(LWS REQUIRED IMPORTED_TARGET libwebsockets)
add_library(webfuse_static STATIC
src/webfuse/webfuse.cpp
src/webfuse/fuse.cpp
src/webfuse/filesystem.cpp
src/webfuse/filesystem/status.cpp
src/webfuse/filesystem/accessmode.cpp
src/webfuse/filesystem/openflags.cpp

311
src/webfuse/filesystem.cpp Normal file
View File

@ -0,0 +1,311 @@
#include "webfuse/filesystem.hpp"
namespace webfuse
{
filesystem::filesystem(ws_server& server)
: proxy(server)
{
}
filesystem::~filesystem()
{
}
status filesystem::access(std::string const & path, access_mode mode)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.access(path, mode);
}
}
status filesystem::getattr(std::string const & path, file_attributes & attr)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.getattr(path, attr);
}
}
status filesystem::readlink(std::string const & path, std::string & out)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.readlink(path, out);
}
}
status filesystem::symlink(std::string const & target, std::string const & linkpath)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.symlink(target, linkpath);
}
}
status filesystem::link(std::string const & old_path, std::string const & new_path)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.link(old_path, new_path);
}
}
status filesystem::rename(std::string const & old_path, std::string const & new_path)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.rename(old_path, new_path);
}
}
status filesystem::chmod(std::string const & path, filemode mode)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.chmod(path, mode);
}
}
status filesystem::chown(std::string const & path, user_id uid, group_id gid)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.chown(path, uid, gid);
}
}
status filesystem::truncate(std::string const & path, uint64_t offset, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.truncate(path, offset, handle);
}
}
status filesystem::fsync(std::string const & path, bool is_datasync, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.fsync(path, is_datasync, handle);
}
}
status filesystem::open(std::string const & path, openflags flags, filehandle & handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.open(path, flags, handle);
}
}
status filesystem::mknod(std::string const & path, filemode mode, uint64_t rdev)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.mknod(path, mode, rdev);
}
}
status filesystem::create(std::string const & path, filemode mode, filehandle & handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.create(path, mode, handle);
}
}
status filesystem::release(std::string const & path, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.release(path, handle);
}
}
status filesystem::unlink(std::string const & path)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.unlink(path);
}
}
status filesystem::read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.read(path, buffer, buffer_size, offset, handle);
}
}
status filesystem::write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.write(path, buffer, buffer_size, offset, handle);
}
}
status filesystem::mkdir(std::string const & path, filemode mode)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.mkdir(path, mode);
}
}
status filesystem::readdir(std::string const & path, std::vector<std::string> & entries, filehandle handle)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.readdir(path, entries, handle);
}
}
status filesystem::rmdir(std::string const & path)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.rmdir(path);
}
}
status filesystem::statfs(std::string const & path, filesystem_statistics & statistics)
{
try
{
std::string req;
auto resp = proxy.perform(req).get();
return status::bad_enoent;
}
catch(...)
{
return fallback.statfs(path, statistics);
}
}
}

View File

@ -0,0 +1,57 @@
#ifndef WEBFUSE_FILESYSTEM_HPP
#define WEBFUSE_FILESYSTEM_HPP
#include "webfuse/filesystem/filesystem_i.hpp"
#include "webfuse/filesystem/empty_filesystem.hpp"
#include "webfuse/ws/server.hpp"
namespace webfuse
{
class filesystem: public filesystem_i
{
filesystem(filesystem const &) = delete;
filesystem& operator=(filesystem const &) = delete;
filesystem(filesystem &&) = delete;
filesystem& operator=(filesystem &&) = delete;
public:
explicit filesystem(ws_server& server);
~filesystem() override;
status access(std::string const & path, access_mode mode) override;
status getattr(std::string const & path, file_attributes & attr) override;
status readlink(std::string const & path, std::string & out) override;
status symlink(std::string const & target, std::string const & linkpath) override;
status link(std::string const & old_path, std::string const & new_path) override;
status rename(std::string const & old_path, std::string const & new_path) override;
status chmod(std::string const & path, filemode mode) override;
status chown(std::string const & path, user_id uid, group_id gid) override;
status truncate(std::string const & path, uint64_t offset, filehandle handle) override;
status fsync(std::string const & path, bool is_datasync, filehandle handle) override;
status open(std::string const & path, openflags flags, filehandle & handle) override;
status mknod(std::string const & path, filemode mode, uint64_t rdev) override;
status create(std::string const & path, filemode mode, filehandle & handle) override;
status release(std::string const & path, filehandle handle) override;
status unlink(std::string const & path) override;
status read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, filehandle handle) override;
status write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, filehandle handle) override;
status mkdir(std::string const & path, filemode mode) override;
status readdir(std::string const & path, std::vector<std::string> & entries, filehandle handle) override;
status rmdir(std::string const & path) override;
status statfs(std::string const & path, filesystem_statistics & statistics) override;
private:
ws_server &proxy;
empty_filesystem fallback;
};
}
#endif

View File

@ -1,6 +1,6 @@
#include "webfuse/webfuse.hpp"
#include "webfuse/fuse.hpp"
#include "webfuse/filesystem/empty_filesystem.hpp"
#include "webfuse/filesystem.hpp"
#include "webfuse/ws/server.hpp"
namespace webfuse
@ -8,10 +8,10 @@ namespace webfuse
int app::run(int argc, char * argv[])
{
empty_filesystem filesystem;
fuse fuse_fs(filesystem);
ws_config config;
ws_server server(config);
filesystem filesystem(server);
fuse fuse_fs(filesystem);
return fuse_fs.run(argc, argv);
}

View File

@ -5,6 +5,7 @@
#include <iostream>
#include <thread>
#include <atomic>
#include <stdexcept>
extern "C"
{
@ -123,4 +124,21 @@ ws_server& ws_server::operator=(ws_server && other)
return *this;
}
std::future<std::string> ws_server::perform(std::string const & req)
{
std::promise<std::string> resp;
try
{
throw std::runtime_error("not implemented");
}
catch (std::exception const & ex)
{
resp.set_exception(std::current_exception());
}
return resp.get_future();
}
}

View File

@ -1,8 +1,9 @@
#ifndef WEBFUSE_WSSERVER_HPP
#define WEBFUSE_WSSERBER_HPP
#define WEBFUSE_WSSERVER_HPP
#include "webfuse/ws/config.hpp"
#include <future>
#include <string>
namespace webfuse
{
@ -15,6 +16,7 @@ public:
~ws_server();
ws_server(ws_server && other);
ws_server& operator=(ws_server && other);
std::future<std::string> perform(std::string const & req);
private:
class detail;
detail * d;