|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
#include "webfuse/filesystem.hpp"
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
namespace webfuse
|
|
|
|
|
{
|
|
|
|
@ -56,8 +59,14 @@ int filesystem::readlink(std::string const & path, std::string & out)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::readlink_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
int const result = reader.read_result();
|
|
|
|
|
if (0 == result)
|
|
|
|
|
{
|
|
|
|
|
out = reader.read_str();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -70,8 +79,10 @@ int filesystem::symlink(std::string const & target, std::string const & linkpath
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::symlink_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(target);
|
|
|
|
|
req.write_str(linkpath);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -84,8 +95,10 @@ int filesystem::link(std::string const & old_path, std::string const & new_path)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::link_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(old_path);
|
|
|
|
|
req.write_str(new_path);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -98,8 +111,11 @@ int filesystem::rename(std::string const & old_path, std::string const & new_pat
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::rename_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(old_path);
|
|
|
|
|
req.write_str(new_path);
|
|
|
|
|
req.write_rename_flags(flags);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -112,8 +128,10 @@ int filesystem::chmod(std::string const & path, mode_t mode)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::chmod_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_mode(mode);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -126,8 +144,11 @@ int filesystem::chown(std::string const & path, uid_t uid, gid_t gid)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::chown_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_uid(uid);
|
|
|
|
|
req.write_gid(gid);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -140,8 +161,11 @@ int filesystem::truncate(std::string const & path, uint64_t size, uint64_t handl
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::truncate_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_u64(size);
|
|
|
|
|
req.write_u64(handle);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -154,8 +178,11 @@ int filesystem::fsync(std::string const & path, bool is_datasync, uint64_t handl
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::fsync_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_bool(is_datasync);
|
|
|
|
|
req.write_u64(handle);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -168,8 +195,15 @@ int filesystem::open(std::string const & path, int flags, uint64_t & handle)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::open_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_openflags(flags);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
int result = reader.read_result();
|
|
|
|
|
if (0 == result)
|
|
|
|
|
{
|
|
|
|
|
handle = reader.read_u64();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -182,8 +216,11 @@ int filesystem::mknod(std::string const & path, mode_t mode, dev_t rdev)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::mknod_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_mode(mode);
|
|
|
|
|
req.write_u64(rdev);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -196,8 +233,15 @@ int filesystem::create(std::string const & path, mode_t mode, uint64_t & handle)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::create_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_mode(mode);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
int result = reader.read_result();
|
|
|
|
|
if (0 == result)
|
|
|
|
|
{
|
|
|
|
|
handle = reader.read_u64();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -210,8 +254,10 @@ int filesystem::release(std::string const & path, uint64_t handle)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::release_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_u64(handle);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -224,8 +270,9 @@ int filesystem::unlink(std::string const & path)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::unlink_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -238,8 +285,25 @@ int filesystem::read(std::string const & path, char * buffer, size_t buffer_size
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::read_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_u32(buffer_size);
|
|
|
|
|
req.write_u64(offset);
|
|
|
|
|
req.write_u64(handle);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
int result = reader.read_result();
|
|
|
|
|
if (result > 0)
|
|
|
|
|
{
|
|
|
|
|
std::string data = reader.read_bytes();
|
|
|
|
|
if (data.size() <= buffer_size)
|
|
|
|
|
{
|
|
|
|
|
memcpy(reinterpret_cast<void*>(buffer), reinterpret_cast<void const*>(data.data()), data.size());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("invalid message");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -252,8 +316,12 @@ int filesystem::write(std::string const & path, char const * buffer, size_t buff
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::write_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_data(buffer, buffer_size);
|
|
|
|
|
req.write_u64(offset);
|
|
|
|
|
req.write_u64(handle);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -266,8 +334,10 @@ int filesystem::mkdir(std::string const & path, mode_t mode)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::mkdir_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
req.write_mode(mode);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -300,8 +370,9 @@ int filesystem::rmdir(std::string const & path)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::rmdir_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
return reader.read_result();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
@ -314,8 +385,14 @@ int filesystem::statfs(std::string const & path, struct statvfs * statistics)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messagewriter req(message_type::statfs_req);
|
|
|
|
|
proxy.perform(std::move(req));
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
req.write_str(path);
|
|
|
|
|
auto reader = proxy.perform(std::move(req));
|
|
|
|
|
int result = reader.read_result();
|
|
|
|
|
if (0 == result)
|
|
|
|
|
{
|
|
|
|
|
reader.read_statistics(statistics);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
|