parent
7924fa1191
commit
0a513322b7
@ -1,134 +1,135 @@
|
||||
#include "webfuse/filesystem/empty_filesystem.hpp"
|
||||
#include <errno.h>
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
status empty_filesystem::access(std::string const & path, access_mode mode)
|
||||
int empty_filesystem::access(std::string const & path, int mode)
|
||||
{
|
||||
if (path == "/")
|
||||
{
|
||||
return status::good;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
status empty_filesystem::getattr(std::string const & path, file_attributes & attr)
|
||||
int empty_filesystem::getattr(std::string const & path, struct stat * attr)
|
||||
{
|
||||
if (path == "/")
|
||||
{
|
||||
attr.inode = 1;
|
||||
attr.nlink = 1;
|
||||
attr.mode = filemode(filemode::dir | 0x444);
|
||||
return status::good;
|
||||
attr->st_ino = 1;
|
||||
attr->st_nlink = 1;
|
||||
attr->st_mode = S_IFDIR | 0x444;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
status empty_filesystem::readlink(std::string const & path, std::string & out)
|
||||
int empty_filesystem::readlink(std::string const & path, std::string & out)
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
status empty_filesystem::symlink(std::string const & target, std::string const & linkpath)
|
||||
int empty_filesystem::symlink(std::string const & target, std::string const & linkpath)
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
status empty_filesystem::link(std::string const & old_path, std::string const & new_path)
|
||||
int empty_filesystem::link(std::string const & old_path, std::string const & new_path)
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
status empty_filesystem::rename(std::string const & old_path, std::string const & new_path)
|
||||
int empty_filesystem::rename(std::string const & old_path, std::string const & new_path, int flags)
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
status empty_filesystem::chmod(std::string const & path, filemode mode)
|
||||
int empty_filesystem::chmod(std::string const & path, mode_t mode)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::chown(std::string const & path, user_id uid, group_id gid)
|
||||
int empty_filesystem::chown(std::string const & path, uid_t uid, gid_t gid)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::truncate(std::string const & path, uint64_t offset, filehandle handle)
|
||||
int empty_filesystem::truncate(std::string const & path, uint64_t size, uint64_t handle)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::fsync(std::string const & path, bool is_datasync, filehandle handle)
|
||||
int empty_filesystem::fsync(std::string const & path, bool is_datasync, uint64_t handle)
|
||||
{
|
||||
return status::good;
|
||||
return 0;
|
||||
}
|
||||
|
||||
status empty_filesystem::open(std::string const & path, openflags flags, filehandle & handle)
|
||||
int empty_filesystem::open(std::string const & path, int flags, uint64_t & handle)
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
status empty_filesystem::mknod(std::string const & path, filemode mode, uint64_t rdev)
|
||||
int empty_filesystem::mknod(std::string const & path, mode_t mode, dev_t rdev)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
|
||||
}
|
||||
status empty_filesystem::create(std::string const & path, filemode mode, filehandle & handle)
|
||||
int empty_filesystem::create(std::string const & path, mode_t mode, uint64_t & handle)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::release(std::string const & path, filehandle handle)
|
||||
int empty_filesystem::release(std::string const & path, uint64_t handle)
|
||||
{
|
||||
return status::good;
|
||||
return 0;
|
||||
}
|
||||
|
||||
status empty_filesystem::unlink(std::string const & path)
|
||||
int empty_filesystem::unlink(std::string const & path)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
|
||||
int empty_filesystem::read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, uint64_t handle)
|
||||
{
|
||||
return status::bad_ebadf;
|
||||
return -EBADF;
|
||||
}
|
||||
status empty_filesystem::write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
|
||||
int empty_filesystem::write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, uint64_t handle)
|
||||
{
|
||||
return status::bad_ebadf;
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
status empty_filesystem::mkdir(std::string const & path, filemode mode)
|
||||
int empty_filesystem::mkdir(std::string const & path, mode_t mode)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::readdir(std::string const & path, std::vector<std::string> & entries, filehandle handle)
|
||||
int empty_filesystem::readdir(std::string const & path, std::vector<std::string> & entries, uint64_t handle)
|
||||
{
|
||||
if (path == "/")
|
||||
{
|
||||
return status::good;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return status::bad_enoent;
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
status empty_filesystem::rmdir(std::string const & path)
|
||||
int empty_filesystem::rmdir(std::string const & path)
|
||||
{
|
||||
return status::bad_eperm;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
status empty_filesystem::statfs(std::string const & path, filesystem_statistics & statistics)
|
||||
int empty_filesystem::statfs(std::string const & path, struct statvfs * statistics)
|
||||
{
|
||||
return status::bad_enosys;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
#ifndef WEBFUSE_MESSAGEBUILDER_HPP
|
||||
#define WEBFUSE_MESSAGEBUILDER_HPP
|
||||
|
||||
#include "webfuse/message_type.hpp"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
class message
|
||||
{
|
||||
message(message const &) = delete;
|
||||
message& operator=(message const &) = delete;
|
||||
public:
|
||||
explicit message(message_type msg_type);
|
||||
~message() = default;
|
||||
message(message && other);
|
||||
message& operator=(message && other);
|
||||
|
||||
void set_id(uint32_t value);
|
||||
uint32_t get_id() const;
|
||||
|
||||
void add_bool(bool value);
|
||||
void add_u8(uint8_t value);
|
||||
void add_i8(int8_t value);
|
||||
void add_i32(int32_t value);
|
||||
void add_u32(uint32_t value);
|
||||
void add_u64(uint64_t value);
|
||||
void add_str(std::string const &value);
|
||||
void add_data(char const * buffer, size_t size);
|
||||
void add_strings(std::vector<std::string> const & list);
|
||||
|
||||
unsigned char * get_data(size_t &size);
|
||||
|
||||
private:
|
||||
uint32_t id;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,158 @@
|
||||
#include "webfuse/ws/messagereader.hpp"
|
||||
#include "webfuse/filesystem/status.hpp"
|
||||
#include "webfuse/filesystem/fileattributes.hpp"
|
||||
#include "webfuse/filesystem/filemode.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
messagereader::messagereader(std::string & value)
|
||||
: data(std::move(value))
|
||||
, pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
messagereader::messagereader(messagereader && other)
|
||||
{
|
||||
this->data = std::move(other.data);
|
||||
this->pos = other.pos;
|
||||
}
|
||||
|
||||
messagereader& messagereader::operator=(messagereader && other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
this->data = std::move(other.data);
|
||||
this->pos = other.pos;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
int messagereader::read_result()
|
||||
{
|
||||
status value(read_i32());
|
||||
return value.to_fusestatus();
|
||||
}
|
||||
|
||||
void messagereader::read_attr(struct stat * attr)
|
||||
{
|
||||
attr->st_ino = static_cast<ino_t>(read_u64());
|
||||
attr->st_nlink = static_cast<nlink_t>(read_u64());
|
||||
attr->st_mode = read_mode();
|
||||
attr->st_uid = static_cast<uid_t>(read_u32());
|
||||
attr->st_gid = static_cast<gid_t>(read_u32());
|
||||
attr->st_rdev = static_cast<dev_t>(read_u64());
|
||||
attr->st_size = static_cast<off_t>(read_u64());
|
||||
attr->st_blocks = static_cast<blkcnt64_t>(read_u64());
|
||||
attr->st_atim.tv_sec = static_cast<time_t>(read_u64());
|
||||
attr->st_atim.tv_nsec = static_cast<long>(read_u32());
|
||||
attr->st_mtim.tv_sec = static_cast<time_t>(read_u64());
|
||||
attr->st_mtim.tv_nsec = static_cast<long>(read_u32());
|
||||
attr->st_ctim.tv_sec = static_cast<time_t>(read_u64());
|
||||
attr->st_ctim.tv_nsec = static_cast<long>(read_u32());
|
||||
}
|
||||
|
||||
mode_t messagereader::read_mode()
|
||||
{
|
||||
filemode mode(read_u32());
|
||||
return mode.to_mode();
|
||||
}
|
||||
|
||||
|
||||
uint8_t messagereader::read_u8()
|
||||
{
|
||||
if (pos < data.size())
|
||||
{
|
||||
uint8_t value = static_cast<uint8_t>(data[pos]);
|
||||
pos++;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t messagereader::read_u32()
|
||||
{
|
||||
if ((pos + 3) < data.size())
|
||||
{
|
||||
uint32_t value =
|
||||
((static_cast<uint32_t>(data[pos ]) & 0xff) << 24) |
|
||||
((static_cast<uint32_t>(data[pos + 1]) & 0xff) << 16) |
|
||||
((static_cast<uint32_t>(data[pos + 2]) & 0xff) << 8) |
|
||||
((static_cast<uint32_t>(data[pos + 3]) & 0xff) );
|
||||
pos += 4;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t messagereader::read_u64()
|
||||
{
|
||||
if ((pos + 7) < data.size())
|
||||
{
|
||||
uint32_t value =
|
||||
(static_cast<uint64_t>(data[pos ] & 0xff) << 56) |
|
||||
(static_cast<uint64_t>(data[pos + 1] & 0xff) << 48) |
|
||||
(static_cast<uint64_t>(data[pos + 2] & 0xff) << 40) |
|
||||
(static_cast<uint64_t>(data[pos + 3] & 0xff) << 32) |
|
||||
(static_cast<uint64_t>(data[pos + 4] & 0xff) << 24) |
|
||||
(static_cast<uint64_t>(data[pos + 5] & 0xff) << 16) |
|
||||
(static_cast<uint64_t>(data[pos + 6] & 0xff) << 8) |
|
||||
(static_cast<uint64_t>(data[pos + 7] & 0xff) );
|
||||
pos += 8;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t messagereader::read_i32()
|
||||
{
|
||||
uint32_t value = read_u32();
|
||||
return static_cast<int32_t>(value);
|
||||
}
|
||||
|
||||
std::string messagereader::read_str()
|
||||
{
|
||||
return std::move(read_bytes());
|
||||
}
|
||||
|
||||
std::string messagereader::read_bytes()
|
||||
{
|
||||
uint32_t size = read_u32();
|
||||
if ((pos + size) <= data.size())
|
||||
{
|
||||
std::string const value(&data[pos], size);
|
||||
pos += size;
|
||||
return std::move(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
void messagereader::read_strings(std::vector<std::string> &entries)
|
||||
{
|
||||
uint32_t const count = read_u32();
|
||||
for(uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
std::string entry = read_str();
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
#ifndef WEBFUSE_MESSAGEWRITER_HPP
|
||||
#define WEBFUSE_MESSAGEWRITER_HPP
|
||||
|
||||
#include "webfuse/message_type.hpp"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
class messagewriter
|
||||
{
|
||||
messagewriter(messagewriter const &) = delete;
|
||||
messagewriter& operator=(messagewriter const &) = delete;
|
||||
public:
|
||||
explicit messagewriter(message_type msg_type);
|
||||
~messagewriter() = default;
|
||||
messagewriter(messagewriter && other);
|
||||
messagewriter& operator=(messagewriter && other);
|
||||
|
||||
void set_id(uint32_t value);
|
||||
uint32_t get_id() const;
|
||||
|
||||
void write_bool(bool value);
|
||||
void write_u8(uint8_t value);
|
||||
void write_i8(int8_t value);
|
||||
void write_i32(int32_t value);
|
||||
void write_u32(uint32_t value);
|
||||
void write_u64(uint64_t value);
|
||||
void write_str(std::string const &value);
|
||||
void write_data(char const * buffer, size_t size);
|
||||
void write_strings(std::vector<std::string> const & list);
|
||||
|
||||
void write_access_mode(int value);
|
||||
|
||||
unsigned char * get_data(size_t &size);
|
||||
|
||||
private:
|
||||
uint32_t id;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in new issue