fix compiler warnings
Some checks failed
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2023-12-14 13:45:08 -06:00
parent d21fcfd1c6
commit 5a61bdf2b0
6 changed files with 380 additions and 357 deletions

View File

@ -57,10 +57,9 @@ public:
remote::file_offset &length, const remote::file_offset &length, const remote::file_offset &length, const remote::file_offset &length, const
remote::file_handle &handle) = 0;*/ remote::file_handle &handle) = 0;*/
[[nodiscard]] virtual auto fuse_fgetattr(const char *path, remote::stat &st, [[nodiscard]] virtual auto
bool &directory, fuse_fgetattr(const char *path, remote::stat &r_stat, bool &directory,
const remote::file_handle &handle) const remote::file_handle &handle) -> packet::error_type = 0;
-> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_fsetattr_x(const char *path, [[nodiscard]] virtual auto fuse_fsetattr_x(const char *path,
const remote::setattr_x &attr, const remote::setattr_x &attr,
@ -77,8 +76,8 @@ public:
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type = 0; -> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_getattr(const char *path, remote::stat &st, [[nodiscard]] virtual auto fuse_getattr(const char *path,
bool &directory) remote::stat &r_stat, bool &directory)
-> packet::error_type = 0; -> packet::error_type = 0;
/*[[nodiscard]] virtual packet::error_type fuse_getxattr(const char *path, /*[[nodiscard]] virtual packet::error_type fuse_getxattr(const char *path,
@ -167,11 +166,11 @@ public:
std::int32_t &flags, std::uint32_t position) = 0;*/ std::int32_t &flags, std::uint32_t position) = 0;*/
[[nodiscard]] virtual auto fuse_statfs(const char *path, std::uint64_t frsize, [[nodiscard]] virtual auto fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &st) remote::statfs &r_stat)
-> packet::error_type = 0; -> packet::error_type = 0;
[[nodiscard]] virtual auto [[nodiscard]] virtual auto
fuse_statfs_x(const char *path, std::uint64_t bsize, remote::statfs_x &st) fuse_statfs_x(const char *path, std::uint64_t bsize, remote::statfs_x &r_stat)
-> packet::error_type = 0; -> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_truncate(const char *path, [[nodiscard]] virtual auto fuse_truncate(const char *path,

View File

@ -36,7 +36,7 @@
#include "utils/Base64.hpp" #include "utils/Base64.hpp"
#include "utils/path_utils.hpp" #include "utils/path_utils.hpp"
#define REPERTORY_DIRECTORY_PAGE_SIZE std::size_t(100u) #define REPERTORY_DIRECTORY_PAGE_SIZE std::size_t(100U)
namespace repertory { namespace repertory {
template <typename drive> template <typename drive>

View File

@ -46,8 +46,8 @@ private:
remote::file_info &file_info) remote::file_info &file_info)
-> packet::error_type; -> packet::error_type;
void populate_stat(const char *path, bool directory, remote::stat &st, void populate_stat(const char *path, bool directory, remote::stat &r_stat,
const struct _stat64 &st1); const struct _stat64 &unix_st);
public: public:
// FUSE Layer // FUSE Layer
@ -69,7 +69,7 @@ public:
&mode, const remote::file_offset &offset, const remote::file_offset &mode, const remote::file_offset &offset, const remote::file_offset
&length, const remote::file_handle &handle) override ;*/ &length, const remote::file_handle &handle) override ;*/
auto fuse_fgetattr(const char *path, remote::stat &st, bool &directory, auto fuse_fgetattr(const char *path, remote::stat &r_stat, bool &directory,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
@ -85,7 +85,7 @@ public:
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
auto fuse_getattr(const char *path, remote::stat &st, bool &directory) auto fuse_getattr(const char *path, remote::stat &r_stat, bool &directory)
-> packet::error_type override; -> packet::error_type override;
/*packet::error_type fuse_getxattr(const char *path, const char *name, char /*packet::error_type fuse_getxattr(const char *path, const char *name, char
@ -174,11 +174,11 @@ public:
char *value, const remote::file_size &size, const std::int32_t &flags, char *value, const remote::file_size &size, const std::int32_t &flags,
std::uint32_t position) override ;*/ std::uint32_t position) override ;*/
auto fuse_statfs(const char *path, std::uint64_t frsize, remote::statfs &st) auto fuse_statfs(const char *path, std::uint64_t frsize,
-> packet::error_type override; remote::statfs &r_stat) -> packet::error_type override;
auto fuse_statfs_x(const char *path, std::uint64_t bsize, auto fuse_statfs_x(const char *path, std::uint64_t bsize,
remote::statfs_x &st) -> packet::error_type override; remote::statfs_x &r_stat) -> packet::error_type override;
auto fuse_truncate(const char *path, const remote::file_offset &size) auto fuse_truncate(const char *path, const remote::file_offset &size)
-> packet::error_type override; -> packet::error_type override;
@ -189,8 +189,8 @@ public:
std::uint64_t op0, std::uint64_t op1) std::uint64_t op0, std::uint64_t op1)
-> packet::error_type override; -> packet::error_type override;
void set_fuse_uid_gid(const remote::user_id &, void set_fuse_uid_gid(const remote::user_id & /* uid */,
const remote::group_id &) override {} const remote::group_id & /* gid */) override {}
// JSON Layer // JSON Layer
auto json_create_directory_snapshot(const std::string &path, json &json_data) auto json_create_directory_snapshot(const std::string &path, json &json_data)

View File

@ -1182,10 +1182,11 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
stbuf->f_files = 4294967295; stbuf->f_files = 4294967295;
stbuf->f_ffree = stbuf->f_files - provider_.get_total_item_count(); stbuf->f_ffree = stbuf->f_files - provider_.get_total_item_count();
stbuf->f_owner = getuid(); stbuf->f_owner = getuid();
strncpy(&stbuf->f_mntonname[0], get_mount_location().c_str(), MNAMELEN); strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(),
strncpy(&stbuf->f_mntfromname[0], get_mount_location().size());
strncpy(&stbuf->f_mntfromname[0U],
(utils::create_volume_label(config_.get_provider_type())).c_str(), (utils::create_volume_label(config_.get_provider_type())).c_str(),
MNAMELEN); sizeof(stbuf->f_mntfromname) - 1U);
return api_error::success; return api_error::success;
} }

View File

@ -81,17 +81,18 @@ auto remote_server::populate_file_info(const std::string &api_path,
} }
void remote_server::populate_stat(const char *path, bool directory, void remote_server::populate_stat(const char *path, bool directory,
remote::stat &st, const struct _stat64 &st1) { remote::stat &r_stat,
st.st_nlink = static_cast<remote::file_nlink>( const struct _stat64 &unix_st) {
r_stat.st_nlink = static_cast<remote::file_nlink>(
directory ? 2 + drive_.get_directory_item_count( directory ? 2 + drive_.get_directory_item_count(
utils::path::create_api_path(path)) utils::path::create_api_path(path))
: 1); : 1);
st.st_atimespec = utils::time64_to_unix_time(st1.st_atime); r_stat.st_atimespec = utils::time64_to_unix_time(unix_st.st_atime);
st.st_birthtimespec = utils::time64_to_unix_time(st1.st_ctime); r_stat.st_birthtimespec = utils::time64_to_unix_time(unix_st.st_ctime);
st.st_ctimespec = utils::time64_to_unix_time(st1.st_ctime); r_stat.st_ctimespec = utils::time64_to_unix_time(unix_st.st_ctime);
st.st_mtimespec = utils::time64_to_unix_time(st1.st_mtime); r_stat.st_mtimespec = utils::time64_to_unix_time(unix_st.st_mtime);
st.st_size = static_cast<remote::file_size>(st1.st_size); r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size);
st.st_mode = st1.st_mode; r_stat.st_mode = unix_st.st_mode;
} }
// FUSE Layer // FUSE Layer
@ -149,19 +150,20 @@ construct_path(path); auto res = HasOpenFileCompatInfo(handle, EBADF); if (res
return ret; return ret;
}*/ }*/
auto remote_server::fuse_fgetattr(const char *path, remote::stat &st, auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
bool &directory, bool &directory,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type { -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
memset(&st, 0, sizeof(remote::stat)); memset(&r_stat, 0, sizeof(remote::stat));
auto res = has_compat_open_info(handle, EBADF); auto res = has_compat_open_info(handle, EBADF);
if (res == 0) { if (res == 0) {
directory = utils::file::is_directory(file_path); directory = utils::file::is_directory(file_path);
struct _stat64 st1 {}; struct _stat64 unix_st {};
if ((res = _fstat64(static_cast<int>(handle), &st1)) == 0) { res = _fstat64(static_cast<int>(handle), &unix_st);
populate_stat(path, directory, st, st1); if (res == 0) {
populate_stat(path, directory, r_stat, unix_st);
} }
} }
@ -190,11 +192,11 @@ auto remote_server::fuse_fsync(const char *path,
if (res == 0) { if (res == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
auto os_handle = auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle))); reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) { if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT; errno = EFAULT;
if (::FlushFileBuffers(os_handle)) { if (::FlushFileBuffers(os_handle) != 0) {
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -216,14 +218,14 @@ auto remote_server::fuse_ftruncate(const char *path,
if (res == 0) { if (res == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
auto os_handle = auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle))); reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) { if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT; errno = EFAULT;
FILE_END_OF_FILE_INFO fi{}; FILE_END_OF_FILE_INFO eof_inf{};
fi.EndOfFile.QuadPart = static_cast<LONGLONG>(size); eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &fi, if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &eof_inf,
sizeof(FILE_END_OF_FILE_INFO))) { sizeof(FILE_END_OF_FILE_INFO)) != 0) {
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -235,17 +237,17 @@ auto remote_server::fuse_ftruncate(const char *path,
return ret; return ret;
} }
auto remote_server::fuse_getattr(const char *path, remote::stat &st, auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
bool &directory) -> packet::error_type { bool &directory) -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
memset(&st, 0, sizeof(remote::stat)); memset(&r_st, 0, sizeof(remote::stat));
directory = utils::file::is_directory(file_path); directory = utils::file::is_directory(file_path);
struct _stat64 st1 {}; struct _stat64 st1 {};
const auto res = _stat64(file_path.c_str(), &st1); const auto res = _stat64(file_path.c_str(), &st1);
if (res == 0) { if (res == 0) {
populate_stat(path, directory, st, st1); populate_stat(path, directory, r_st, st1);
} }
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
@ -305,7 +307,7 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
auto res = -1; auto res = -1;
errno = ENOENT; errno = ENOENT;
if (::PathIsDirectoryW(unicode_file_path.c_str())) { if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) {
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
handle = static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>( handle = static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>(
new directory_iterator(std::move(list)))); new directory_iterator(std::move(list))));
@ -332,16 +334,16 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
utils::unix_open_flags_to_flags_and_perms(mode, flags, perms); utils::unix_open_flags_to_flags_and_perms(mode, flags, perms);
const auto create_op = (open_flags & _O_CREAT); const auto create_op = (open_flags & _O_CREAT);
if (create_op && directory_op) { if ((create_op != 0) && directory_op) {
ret = -EINVAL; ret = -EINVAL;
} else if (directory_op) { } else if (directory_op) {
ret = -EACCES; ret = -EACCES;
} else { } else {
int fd = -1; int file = -1;
const auto res = const auto res =
_sopen_s(&fd, file_path.c_str(), open_flags, _SH_DENYNO, perms); _sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms);
if (res == 0) { if (res == 0) {
handle = static_cast<remote::file_handle>(fd); handle = static_cast<remote::file_handle>(file);
ret = 0; ret = 0;
set_compat_open_info(handle, file_path); set_compat_open_info(handle, file_path);
} else { } else {
@ -367,10 +369,10 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
const auto open_flags = const auto open_flags =
utils::unix_open_flags_to_flags_and_perms(0, flags, perms) & utils::unix_open_flags_to_flags_and_perms(0, flags, perms) &
(~_O_CREAT); (~_O_CREAT);
int fd = -1; int file = -1;
res = _sopen_s(&fd, file_path.c_str(), open_flags, _SH_DENYNO, 0); res = _sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, 0);
if (res == 0) { if (res == 0) {
handle = static_cast<remote::file_handle>(fd); handle = static_cast<remote::file_handle>(file);
set_compat_open_info(handle, file_path); set_compat_open_info(handle, file_path);
} else { } else {
res = -1; res = -1;
@ -383,32 +385,33 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
} }
auto remote_server::fuse_read(const char *path, char *buffer, auto remote_server::fuse_read(const char *path, char *buffer,
const remote::file_size &readSize, const remote::file_size &read_size,
const remote::file_offset &readOffset, const remote::file_offset &read_offset,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type { -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto &b = *reinterpret_cast<data_buffer *>(buffer); auto &data = *reinterpret_cast<data_buffer *>(buffer);
auto res = 0; auto res = 0;
if (readSize > std::numeric_limits<std::size_t>::max()) { if (read_size > std::numeric_limits<std::size_t>::max()) {
res = -1; res = -1;
errno = ERANGE; errno = ERANGE;
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) { } else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
auto os_handle = auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle))); reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) { if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT; errno = EFAULT;
auto file = native_file::attach(os_handle); auto file = native_file::attach(os_handle);
std::uint64_t file_size = 0u; std::uint64_t file_size{};
if (file->get_file_size(file_size)) { if (file->get_file_size(file_size)) {
b.resize(utils::calculate_read_size( data.resize(utils::calculate_read_size(
file_size, static_cast<std::size_t>(readSize), readOffset)); file_size, static_cast<std::size_t>(read_size), read_offset));
if (b.size() > 0) { if (!data.empty()) {
std::size_t bytes_read = 0u; std::size_t bytes_read{};
if (file->read_bytes(&b[0u], b.size(), readOffset, bytes_read)) { if (file->read_bytes(data.data(), data.size(), read_offset,
bytes_read)) {
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -420,7 +423,7 @@ auto remote_server::fuse_read(const char *path, char *buffer,
} }
} }
const auto ret = ((res < 0) ? -errno : static_cast<int>(b.size())); const auto ret = ((res < 0) ? -errno : static_cast<int>(data.size()));
if (ret < 0) { if (ret < 0) {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
} }
@ -445,16 +448,17 @@ auto remote_server::fuse_write(const char *path, const char *buffer,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type { -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
std::size_t bytes_written = 0u; std::size_t bytes_written{};
auto res = 0; auto res = 0;
if (write_size > std::numeric_limits<std::size_t>::max()) { if (write_size > std::numeric_limits<std::size_t>::max()) {
res = -1; res = -1;
errno = ERANGE; errno = ERANGE;
} else { } else {
if ((res = has_compat_open_info(handle, EBADF)) == 0) { res = has_compat_open_info(handle, EBADF);
if (res == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
auto os_handle = auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle))); reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) { if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT; errno = EFAULT;
@ -488,7 +492,7 @@ auto remote_server::fuse_write_base64(
auto remote_server::fuse_readdir(const char *path, auto remote_server::fuse_readdir(const char *path,
const remote::file_offset &offset, const remote::file_offset &offset,
const remote::file_handle &handle, const remote::file_handle &handle,
std::string &itemPath) -> packet::error_type { std::string &item_path) -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = 0; auto res = 0;
if (offset > std::numeric_limits<std::size_t>::max()) { if (offset > std::numeric_limits<std::size_t>::max()) {
@ -496,11 +500,11 @@ auto remote_server::fuse_readdir(const char *path,
res = -1; res = -1;
} else { } else {
auto *iterator = reinterpret_cast<directory_iterator *>(handle); auto *iterator = reinterpret_cast<directory_iterator *>(handle);
if (iterator) { if (iterator == nullptr) {
res = iterator->get(static_cast<std::size_t>(offset), itemPath);
} else {
res = -1; res = -1;
errno = EFAULT; errno = EFAULT;
} else {
res = iterator->get(static_cast<std::size_t>(offset), item_path);
} }
} }
@ -602,39 +606,44 @@ construct_path(path); const auto ret = STATUS_NOT_IMPLEMENTED;
}*/ }*/
auto remote_server::fuse_statfs(const char *path, std::uint64_t frsize, auto remote_server::fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &st) -> packet::error_type { remote::statfs &r_stat) -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto total_bytes = drive_.get_total_drive_space(); const auto total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space(); const auto total_used = drive_.get_used_drive_space();
const auto used_blocks = utils::divide_with_ceiling( const auto used_blocks = utils::divide_with_ceiling(
total_used, static_cast<std::uint64_t>(frsize)); total_used, static_cast<std::uint64_t>(frsize));
st.f_files = 4294967295; r_stat.f_files = 4294967295;
st.f_blocks = utils::divide_with_ceiling(total_bytes, r_stat.f_blocks = utils::divide_with_ceiling(
static_cast<std::uint64_t>(frsize)); total_bytes, static_cast<std::uint64_t>(frsize));
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0; r_stat.f_bavail = r_stat.f_bfree =
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count(); r_stat.f_blocks == 0U ? 0 : (r_stat.f_blocks - used_blocks);
r_stat.f_ffree = r_stat.f_favail =
r_stat.f_files - drive_.get_total_item_count();
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0); RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
return 0; return 0;
} }
auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize, auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
remote::statfs_x &st) -> packet::error_type { remote::statfs_x &r_stat)
-> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto total_bytes = drive_.get_total_drive_space(); const auto total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space(); const auto total_used = drive_.get_used_drive_space();
const auto used_blocks = const auto used_blocks =
utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(bsize)); utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(bsize));
st.f_blocks = utils::divide_with_ceiling(total_bytes, r_stat.f_blocks = utils::divide_with_ceiling(
static_cast<std::uint64_t>(bsize)); total_bytes, static_cast<std::uint64_t>(bsize));
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0; r_stat.f_bavail = r_stat.f_bfree =
st.f_files = 4294967295; r_stat.f_blocks == 0U ? 0 : (r_stat.f_blocks - used_blocks);
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count(); r_stat.f_files = 4294967295;
strncpy(&st.f_mntfromname[0u], r_stat.f_ffree = r_stat.f_favail =
r_stat.f_files - drive_.get_total_item_count();
strncpy(&r_stat.f_mntfromname[0U],
(utils::create_volume_label(config_.get_provider_type())).c_str(), (utils::create_volume_label(config_.get_provider_type())).c_str(),
sizeof(st.f_mntfromname) - 1U); sizeof(r_stat.f_mntfromname) - 1U);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0); RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
return 0; return 0;
@ -650,19 +659,19 @@ auto remote_server::fuse_truncate(const char *path,
const auto flags_and_attributes = const auto flags_and_attributes =
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_BACKUP_SEMANTICS |
(::PathIsDirectoryW(unicode_file_path.c_str()) (::PathIsDirectoryW(unicode_file_path.c_str()) != 0
? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS ? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS
: 0); : 0);
const auto os_handle = ::CreateFileW( auto *os_handle = ::CreateFileW(
unicode_file_path.c_str(), FILE_GENERIC_READ | FILE_GENERIC_WRITE, unicode_file_path.c_str(), FILE_GENERIC_READ | FILE_GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, static_cast<DWORD>(flags_and_attributes), nullptr); OPEN_EXISTING, static_cast<DWORD>(flags_and_attributes), nullptr);
if (os_handle != INVALID_HANDLE_VALUE) { if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT; errno = EFAULT;
FILE_END_OF_FILE_INFO fi{}; FILE_END_OF_FILE_INFO eof_inf{};
fi.EndOfFile.QuadPart = static_cast<LONGLONG>(size); eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &fi, if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &eof_inf,
sizeof(FILE_END_OF_FILE_INFO))) { sizeof(FILE_END_OF_FILE_INFO)) != 0) {
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -693,10 +702,10 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
const auto flags_and_attributes = const auto flags_and_attributes =
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_BACKUP_SEMANTICS |
(::PathIsDirectoryW(unicode_file_path.c_str()) (::PathIsDirectoryW(unicode_file_path.c_str()) != 0
? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS ? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS
: 0); : 0);
const auto os_handle = ::CreateFileW( auto *os_handle = ::CreateFileW(
unicode_file_path.c_str(), FILE_WRITE_ATTRIBUTES, unicode_file_path.c_str(), FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, static_cast<DWORD>(flags_and_attributes), nullptr); OPEN_EXISTING, static_cast<DWORD>(flags_and_attributes), nullptr);
@ -706,29 +715,30 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
FILETIME *access_time_ptr = nullptr; FILETIME *access_time_ptr = nullptr;
FILETIME *write_time_ptr = nullptr; FILETIME *write_time_ptr = nullptr;
if (not tv[0u] || (op0 == UTIME_NOW)) { if ((tv[0U] == 0U) || (op0 == UTIME_NOW)) {
const auto now = utils::get_file_time_now(); const auto now = utils::get_file_time_now();
access_time.dwHighDateTime = access_time.dwHighDateTime =
static_cast<DWORD>((now >> 32u) & 0xFFFFFFFF); static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
access_time.dwLowDateTime = now & 0xFFFFFFFF; access_time.dwLowDateTime = now & 0xFFFFFFFF;
access_time_ptr = &access_time; access_time_ptr = &access_time;
} else if (op0 != UTIME_OMIT) { } else if (op0 != UTIME_OMIT) {
utils::unix_time_to_filetime(tv[0u], access_time); utils::unix_time_to_filetime(tv[0U], access_time);
access_time_ptr = &access_time; access_time_ptr = &access_time;
} }
if (not tv[1] || (op1 == UTIME_NOW)) { if ((tv[1U] == 0U) || (op1 == UTIME_NOW)) {
const auto now = utils::get_file_time_now(); const auto now = utils::get_file_time_now();
write_time.dwHighDateTime = static_cast<DWORD>((now >> 32u) & 0xFFFFFFFF); write_time.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
write_time.dwLowDateTime = now & 0xFFFFFFFF; write_time.dwLowDateTime = now & 0xFFFFFFFF;
write_time_ptr = &write_time; write_time_ptr = &write_time;
} else if (op1 != UTIME_OMIT) { } else if (op1 != UTIME_OMIT) {
utils::unix_time_to_filetime(tv[1], write_time); utils::unix_time_to_filetime(tv[1U], write_time);
write_time_ptr = &write_time; write_time_ptr = &write_time;
} }
errno = EFAULT; errno = EFAULT;
if (::SetFileTime(os_handle, nullptr, access_time_ptr, write_time_ptr)) { if (::SetFileTime(os_handle, nullptr, access_time_ptr, write_time_ptr) !=
0) {
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -771,8 +781,8 @@ auto remote_server::json_read_directory_snapshot(
std::uint32_t page, json &json_data) -> packet::error_type { std::uint32_t page, json &json_data) -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle); auto *iterator = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset = 0u; std::size_t offset{};
int res; int res{};
json item_json; json item_json;
while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
(res = iterator->get_json( (res = iterator->get_json(
@ -803,14 +813,14 @@ auto remote_server::json_release_directory_snapshot(
// WinFSP Layer // WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/) auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
FILE_DISPOSITION_INFO dispositionInfo = {TRUE}; FILE_DISPOSITION_INFO dispositionInfo = {TRUE};
ret = ::SetFileInformationByHandle(handle, FileDispositionInfo, ret = ::SetFileInformationByHandle(handle, FileDispositionInfo,
&dispositionInfo, &dispositionInfo,
sizeof(FILE_DISPOSITION_INFO)) sizeof(FILE_DISPOSITION_INFO)) != 0
? STATUS_SUCCESS ? STATUS_SUCCESS
: FspNtStatusFromWin32(::GetLastError()); : FspNtStatusFromWin32(::GetLastError());
} }
@ -824,10 +834,10 @@ auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
-> packet::error_type { -> packet::error_type {
const auto file_path = get_open_file_path(file_desc); const auto file_path = get_open_file_path(file_desc);
was_closed = FALSE; was_closed = FALSE;
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
const auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); const auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if (flags & FileSystemBase::CleanupDelete) { if ((flags & FileSystemBase::CleanupDelete) != 0U) {
::CloseHandle(handle); ::CloseHandle(handle);
remove_open_info(file_desc); remove_open_info(file_desc);
was_closed = TRUE; was_closed = TRUE;
@ -840,7 +850,7 @@ auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type { auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
const auto file_path = get_open_file_path(file_desc); const auto file_path = get_open_file_path(file_desc);
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) { if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) {
::CloseHandle(handle); ::CloseHandle(handle);
remove_open_info(file_desc); remove_open_info(file_desc);
@ -858,22 +868,22 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
-> packet::error_type { -> packet::error_type {
const auto file_path = utils::string::from_utf8(utils::path::combine( const auto file_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)})); mount_location_, {utils::string::to_utf8(file_name)}));
exists = utils::file::is_file(utils::path::combine( exists = static_cast<BOOLEAN>(utils::file::is_file(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)})); mount_location_, {utils::string::to_utf8(file_name)})));
auto create_flags = FILE_FLAG_BACKUP_SEMANTICS; auto create_flags = FILE_FLAG_BACKUP_SEMANTICS;
if (create_options & FILE_DIRECTORY_FILE) { if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
create_flags |= FILE_FLAG_POSIX_SEMANTICS; create_flags |= FILE_FLAG_POSIX_SEMANTICS;
attributes |= FILE_ATTRIBUTE_DIRECTORY; attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else { } else {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY); attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
} }
if (not attributes) { if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL; attributes = FILE_ATTRIBUTE_NORMAL;
} }
const auto handle = ::CreateFileW( auto *handle = ::CreateFileW(
file_path.c_str(), granted_access, file_path.c_str(), granted_access,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
CREATE_NEW, static_cast<DWORD>(create_flags) | attributes, nullptr); CREATE_NEW, static_cast<DWORD>(create_flags) | attributes, nullptr);
@ -896,13 +906,12 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info) auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if ((ret = ::FlushFileBuffers(handle) ret = ::FlushFileBuffers(handle) ? ret
? ret : FspNtStatusFromWin32(::GetLastError());
: FspNtStatusFromWin32(::GetLastError())) == if (ret == STATUS_SUCCESS) {
STATUS_SUCCESS) {
ret = populate_file_info(construct_api_path(get_open_file_path(handle)), ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
*file_info); *file_info);
} }
@ -916,7 +925,7 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
auto remote_server::winfsp_get_file_info(PVOID file_desc, auto remote_server::winfsp_get_file_info(PVOID file_desc,
remote::file_info *file_info) remote::file_info *file_info)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
ret = populate_file_info(construct_api_path(get_open_file_path(handle)), ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
@ -936,23 +945,23 @@ auto remote_server::winfsp_get_security_by_name(PWSTR file_name,
mount_location_, {utils::string::to_utf8(file_name)})); mount_location_, {utils::string::to_utf8(file_name)}));
auto ret = STATUS_BUFFER_OVERFLOW; auto ret = STATUS_BUFFER_OVERFLOW;
if (not descriptor_size || if ((descriptor_size == nullptr) ||
(*descriptor_size <= std::numeric_limits<SIZE_T>::max())) { (*descriptor_size <= std::numeric_limits<SIZE_T>::max())) {
auto *descriptor = descriptor_size auto *descriptor = descriptor_size == nullptr
? static_cast<PSECURITY_DESCRIPTOR>(::LocalAlloc( ? nullptr
LPTR, static_cast<SIZE_T>(*descriptor_size))) : static_cast<PSECURITY_DESCRIPTOR>(::LocalAlloc(
: nullptr; LPTR, static_cast<SIZE_T>(*descriptor_size)));
if (((ret = drive_.get_security_by_name(file_name, attributes, descriptor, ret = drive_.get_security_by_name(file_name, attributes, descriptor,
descriptor_size)) == descriptor_size);
STATUS_SUCCESS) && if ((ret == STATUS_SUCCESS) && (descriptor_size != nullptr)) {
descriptor_size) { ULONG str_size{};
ULONG str_size = 0u;
const auto security_info = const auto security_info =
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION; DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
LPWSTR str; LPWSTR str{};
if (::ConvertSecurityDescriptorToStringSecurityDescriptorW( if (::ConvertSecurityDescriptorToStringSecurityDescriptorW(
descriptor, SDDL_REVISION_1, security_info, &str, &str_size)) { descriptor, SDDL_REVISION_1, security_info, &str, &str_size) !=
0) {
string_descriptor = std::wstring(str, wcslen(str)); string_descriptor = std::wstring(str, wcslen(str));
::LocalFree(str); ::LocalFree(str);
} else { } else {
@ -992,11 +1001,11 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
mount_location_, {utils::string::to_utf8(file_name)})); mount_location_, {utils::string::to_utf8(file_name)}));
auto create_flags = FILE_FLAG_BACKUP_SEMANTICS; auto create_flags = FILE_FLAG_BACKUP_SEMANTICS;
if (create_options & FILE_DELETE_ON_CLOSE) { if ((create_options & FILE_DELETE_ON_CLOSE) != 0U) {
create_flags |= FILE_FLAG_DELETE_ON_CLOSE; create_flags |= FILE_FLAG_DELETE_ON_CLOSE;
} }
const auto handle = ::CreateFileW( auto *handle = ::CreateFileW(
file_path.c_str(), granted_access, file_path.c_str(), granted_access,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, static_cast<DWORD>(create_flags), nullptr); OPEN_EXISTING, static_cast<DWORD>(create_flags), nullptr);
@ -1022,24 +1031,24 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
UINT64 /*allocation_size*/, UINT64 /*allocation_size*/,
remote::file_info *file_info) remote::file_info *file_info)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if (replace_attributes) { if (replace_attributes != 0U) {
if (not attributes) { if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL; attributes = FILE_ATTRIBUTE_NORMAL;
} }
FILE_BASIC_INFO basic_info{}; FILE_BASIC_INFO basic_info{};
basic_info.FileAttributes = attributes; basic_info.FileAttributes = attributes;
if (not ::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info, if (::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO))) { sizeof(FILE_BASIC_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} }
} else if (attributes) { } else if (attributes != 0U) {
FILE_ATTRIBUTE_TAG_INFO tag_info{}; FILE_ATTRIBUTE_TAG_INFO tag_info{};
if (not ::GetFileInformationByHandleEx(handle, FileAttributeTagInfo, if (::GetFileInformationByHandleEx(
&tag_info, handle, FileAttributeTagInfo, &tag_info,
sizeof(FILE_ATTRIBUTE_TAG_INFO))) { sizeof(FILE_ATTRIBUTE_TAG_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} else { } else {
FILE_BASIC_INFO basic_info{}; FILE_BASIC_INFO basic_info{};
@ -1047,9 +1056,8 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
attributes | (tag_info.FileAttributes & attributes | (tag_info.FileAttributes &
static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL)); static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL));
if ((basic_info.FileAttributes != tag_info.FileAttributes)) { if ((basic_info.FileAttributes != tag_info.FileAttributes)) {
if (not ::SetFileInformationByHandle(handle, FileBasicInfo, if (::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
&basic_info, sizeof(FILE_BASIC_INFO)) == 0) {
sizeof(FILE_BASIC_INFO))) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} }
} }
@ -1061,7 +1069,7 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
ret = ret =
::SetFileInformationByHandle(handle, FileAllocationInfo, ::SetFileInformationByHandle(handle, FileAllocationInfo,
&allocationInfo, &allocationInfo,
sizeof(FILE_ALLOCATION_INFO)) sizeof(FILE_ALLOCATION_INFO)) != 0
? populate_file_info( ? populate_file_info(
construct_api_path(get_open_file_path(handle)), *file_info) construct_api_path(get_open_file_path(handle)), *file_info)
: FspNtStatusFromWin32(::GetLastError()); : FspNtStatusFromWin32(::GetLastError());
@ -1076,17 +1084,18 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytes_transferred) UINT32 length, PUINT32 bytes_transferred)
-> packet::error_type { -> packet::error_type {
*bytes_transferred = 0u; *bytes_transferred = 0U;
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if ((ret == STATUS_SUCCESS) && length) { if ((ret == STATUS_SUCCESS) && (length != 0U)) {
OVERLAPPED overlapped{}; OVERLAPPED overlapped{};
overlapped.Offset = static_cast<DWORD>(offset); overlapped.Offset = static_cast<DWORD>(offset);
overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32); overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32);
ret = ::ReadFile(handle, buffer, length, ret = ::ReadFile(handle, buffer, length,
reinterpret_cast<LPDWORD>(bytes_transferred), &overlapped) reinterpret_cast<LPDWORD>(bytes_transferred),
&overlapped) != 0
? STATUS_SUCCESS ? STATUS_SUCCESS
: FspNtStatusFromWin32(::GetLastError()); : FspNtStatusFromWin32(::GetLastError());
} }
@ -1110,11 +1119,11 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
utils::path::create_api_path(ofi.path.substr(mount_location_.size())); utils::path::create_api_path(ofi.path.substr(mount_location_.size()));
auto items = drive_.get_directory_items(api_path); auto items = drive_.get_directory_items(api_path);
directory_iterator iterator(std::move(items)); directory_iterator iterator(std::move(items));
auto offset = marker auto offset = marker == nullptr
? iterator.get_next_directory_offset( ? 0
: iterator.get_next_directory_offset(
utils::path::create_api_path(utils::path::combine( utils::path::create_api_path(utils::path::combine(
api_path, {utils::string::to_utf8(marker)}))) api_path, {utils::string::to_utf8(marker)})));
: 0;
json item; json item;
while (iterator.get_json(offset++, item) == 0) { while (iterator.get_json(offset++, item) == 0) {
item_list.emplace_back(item); item_list.emplace_back(item);
@ -1137,7 +1146,8 @@ auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
mount_location_, {utils::string::to_utf8(new_file_name)})); mount_location_, {utils::string::to_utf8(new_file_name)}));
const auto ret = const auto ret =
::MoveFileExW(from_path.c_str(), to_path.c_str(), ::MoveFileExW(from_path.c_str(), to_path.c_str(),
replace_if_exists ? MOVEFILE_REPLACE_EXISTING : 0) replace_if_exists == 0U ? 0 : MOVEFILE_REPLACE_EXISTING) !=
0
? STATUS_SUCCESS ? STATUS_SUCCESS
: FspNtStatusFromWin32(::GetLastError()); : FspNtStatusFromWin32(::GetLastError());
@ -1150,12 +1160,12 @@ auto remote_server::winfsp_set_basic_info(
PVOID file_desc, UINT32 attributes, UINT64 creation_time, PVOID file_desc, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time, UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info) -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if (attributes == INVALID_FILE_ATTRIBUTES) { if (attributes == INVALID_FILE_ATTRIBUTES) {
attributes = 0; attributes = 0U;
} else if (not attributes) { } else if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL; attributes = FILE_ATTRIBUTE_NORMAL;
} }
@ -1167,7 +1177,7 @@ auto remote_server::winfsp_set_basic_info(
basic_info.LastWriteTime.QuadPart = static_cast<LONGLONG>(last_write_time); basic_info.LastWriteTime.QuadPart = static_cast<LONGLONG>(last_write_time);
basic_info.ChangeTime.QuadPart = static_cast<LONGLONG>(change_time); basic_info.ChangeTime.QuadPart = static_cast<LONGLONG>(change_time);
ret = ::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info, ret = ::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO)) sizeof(FILE_BASIC_INFO)) != 0
? populate_file_info( ? populate_file_info(
construct_api_path(get_open_file_path(handle)), *file_info) construct_api_path(get_open_file_path(handle)), *file_info)
: FspNtStatusFromWin32(::GetLastError()); : FspNtStatusFromWin32(::GetLastError());
@ -1181,23 +1191,22 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) remote::file_info *file_info)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if (set_allocation_size) { if (set_allocation_size != 0U) {
FILE_ALLOCATION_INFO allocation_info{}; FILE_ALLOCATION_INFO allocation_info{};
allocation_info.AllocationSize.QuadPart = static_cast<LONGLONG>(new_size); allocation_info.AllocationSize.QuadPart = static_cast<LONGLONG>(new_size);
if (not ::SetFileInformationByHandle(handle, FileAllocationInfo, if (::SetFileInformationByHandle(handle, FileAllocationInfo,
&allocation_info, &allocation_info,
sizeof(FILE_ALLOCATION_INFO))) { sizeof(FILE_ALLOCATION_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} }
} else { } else {
FILE_END_OF_FILE_INFO end_of_file_info{}; FILE_END_OF_FILE_INFO eof_inf{};
end_of_file_info.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size); eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
if (not ::SetFileInformationByHandle(handle, FileEndOfFileInfo, if (::SetFileInformationByHandle(handle, FileEndOfFileInfo, &eof_inf,
&end_of_file_info, sizeof(FILE_END_OF_FILE_INFO)) == 0) {
sizeof(FILE_END_OF_FILE_INFO))) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} }
} }
@ -1226,17 +1235,17 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PUINT32 bytes_transferred, PUINT32 bytes_transferred,
remote::file_info *file_info) remote::file_info *file_info)
-> packet::error_type { -> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
*bytes_transferred = 0; *bytes_transferred = 0U;
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE); auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
if (length) { if (length != 0U) {
auto should_write = true; auto should_write = true;
LARGE_INTEGER file_size{}; LARGE_INTEGER file_size{};
OVERLAPPED overlapped{}; OVERLAPPED overlapped{};
if (constrained_io) { if (constrained_io != 0U) {
if (not ::GetFileSizeEx(handle, &file_size)) { if (::GetFileSizeEx(handle, &file_size) == 0) {
ret = FspNtStatusFromWin32(::GetLastError()); ret = FspNtStatusFromWin32(::GetLastError());
} else if (offset >= static_cast<UINT64>(file_size.QuadPart)) { } else if (offset >= static_cast<UINT64>(file_size.QuadPart)) {
ret = STATUS_SUCCESS; ret = STATUS_SUCCESS;
@ -1252,7 +1261,7 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32u); overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32u);
ret = ::WriteFile(handle, buffer, length, ret = ::WriteFile(handle, buffer, length,
reinterpret_cast<LPDWORD>(bytes_transferred), reinterpret_cast<LPDWORD>(bytes_transferred),
&overlapped) &overlapped) != 0
? populate_file_info( ? populate_file_info(
construct_api_path(get_open_file_path(handle)), construct_api_path(get_open_file_path(handle)),
*file_info) *file_info)

View File

@ -64,23 +64,24 @@ winfsp_drive::winfsp_service::winfsp_service(
host_(drive), host_(drive),
config_(config) {} config_(config) {}
auto winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS { auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
-> NTSTATUS {
const auto mount_location = utils::string::to_lower( const auto mount_location = utils::string::to_lower(
utils::path::absolute((drive_args_.size() > 1u) ? drive_args_[1u] : "")); utils::path::absolute((drive_args_.size() > 1U) ? drive_args_[1U] : ""));
const auto drive_letter = const auto drive_letter =
((mount_location.size() == 2u) || ((mount_location.size() == 2U) ||
((mount_location.size() == 3u) && (mount_location[2u] == '\\'))) && ((mount_location.size() == 3U) && (mount_location[2U] == '\\'))) &&
(mount_location[1u] == ':'); (mount_location[1U] == ':');
auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED; auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED;
if ((drive_letter && not utils::file::is_directory(mount_location))) { if ((drive_letter && not utils::file::is_directory(mount_location))) {
auto unicode_mount_location = utils::string::from_utf8(mount_location); auto unicode_mount_location = utils::string::from_utf8(mount_location);
host_.SetFileSystemName(&unicode_mount_location[0U]); host_.SetFileSystemName(unicode_mount_location.data());
if (config_.get_enable_mount_manager()) { if (config_.get_enable_mount_manager()) {
unicode_mount_location = unicode_mount_location =
std::wstring(L"\\\\.\\") + unicode_mount_location[0U] + L":"; std::wstring(L"\\\\.\\") + unicode_mount_location[0U] + L":";
} }
ret = host_.Mount(&unicode_mount_location[0U]); ret = host_.Mount(unicode_mount_location.data());
} else { } else {
std::cerr << (drive_letter ? "Mount location in use: " std::cerr << (drive_letter ? "Mount location in use: "
: "Mount location not supported: ") : "Mount location not supported: ")
@ -110,7 +111,7 @@ auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
winfsp_drive::winfsp_drive(app_config &config, lock_data &lock, winfsp_drive::winfsp_drive(app_config &config, lock_data &lock,
i_provider &provider) i_provider &provider)
: FileSystemBase(), provider_(provider), config_(config), lock_(lock) { : provider_(provider), config_(config), lock_(lock) {
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) { E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach(); std::thread([this]() { this->shutdown(); }).detach();
}); });
@ -124,12 +125,12 @@ auto winfsp_drive::CanDelete(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
if (f->is_directory()) { if (file->is_directory()) {
error = provider_.get_directory_item_count(api_path) error = provider_.get_directory_item_count(api_path) != 0U
? api_error::directory_not_empty ? api_error::directory_not_empty
: api_error::success; : api_error::success;
} else { } else {
@ -149,17 +150,17 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
std::string api_path; std::string api_path;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
const auto directory = f->is_directory(); const auto directory = file->is_directory();
if (flags & FspCleanupDelete) { if ((flags & FspCleanupDelete) != 0U) {
auto *directory_buffer = f->get_open_data(handle).directory_buffer; auto *directory_buffer = file->get_open_data(handle).directory_buffer;
f.reset(); file.reset();
if (directory_buffer) { if (directory_buffer != nullptr) {
FspFileSystemDeleteDirectoryBuffer(&directory_buffer); FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
} }
@ -177,7 +178,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
} }
} }
} else { } else {
if ((flags & FspCleanupSetArchiveBit) && not directory) { if (((flags & FspCleanupSetArchiveBit) != 0U) && not directory) {
api_meta_map meta; api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) { if (provider_.get_item_meta(api_path, meta) == api_error::success) {
auto res = provider_.set_item_meta( auto res = provider_.set_item_meta(
@ -191,10 +192,10 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
} }
} }
if (flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime | if ((flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
FspCleanupSetChangeTime)) { FspCleanupSetChangeTime)) != 0U) {
const auto now = utils::get_file_time_now(); const auto now = utils::get_file_time_now();
if (flags & FspCleanupSetLastAccessTime) { if ((flags & FspCleanupSetLastAccessTime) != 0U) {
auto res = provider_.set_item_meta(api_path, META_ACCESSED, auto res = provider_.set_item_meta(api_path, META_ACCESSED,
std::to_string(now)); std::to_string(now));
if (res != api_error::success) { if (res != api_error::success) {
@ -204,7 +205,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
} }
} }
if (flags & FspCleanupSetLastWriteTime) { if ((flags & FspCleanupSetLastWriteTime) != 0U) {
auto res = provider_.set_item_meta(api_path, META_WRITTEN, auto res = provider_.set_item_meta(api_path, META_WRITTEN,
std::to_string(now)); std::to_string(now));
if (res != api_error::success) { if (res != api_error::success) {
@ -214,7 +215,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
} }
} }
if (flags & FspCleanupSetChangeTime) { if ((flags & FspCleanupSetChangeTime) != 0U) {
auto res = provider_.set_item_meta( auto res = provider_.set_item_meta(
api_path, {{META_CHANGED, std::to_string(now)}, api_path, {{META_CHANGED, std::to_string(now)},
{META_MODIFIED, std::to_string(now)}}); {META_MODIFIED, std::to_string(now)}});
@ -226,9 +227,9 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
} }
} }
if (flags & FspCleanupSetAllocationSize) { if ((flags & FspCleanupSetAllocationSize) != 0U) {
UINT64 allocation_size = auto allocation_size =
utils::divide_with_ceiling(f->get_file_size(), utils::divide_with_ceiling(file->get_file_size(),
WINFSP_ALLOCATION_UNIT) * WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT; WINFSP_ALLOCATION_UNIT;
SetFileSize(file_node, file_desc, allocation_size, TRUE, nullptr); SetFileSize(file_node, file_desc, allocation_size, TRUE, nullptr);
@ -243,17 +244,17 @@ VOID winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {
std::string api_path; std::string api_path;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
PVOID directory_buffer = nullptr; PVOID directory_buffer = nullptr;
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
directory_buffer = f->get_open_data(handle).directory_buffer; directory_buffer = file->get_open_data(handle).directory_buffer;
f.reset(); file.reset();
} }
fm_->close(handle); fm_->close(handle);
if (directory_buffer) { if (directory_buffer != nullptr) {
FspFileSystemDeleteDirectoryBuffer(&directory_buffer); FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
} }
} }
@ -269,21 +270,21 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
// (ConvertSecurityDescriptorToStringSecurityDescriptor/ConvertStringSecurityDescriptorToSecurityDescriptor) // (ConvertSecurityDescriptorToStringSecurityDescriptor/ConvertStringSecurityDescriptorToSecurityDescriptor)
auto error = api_error::error; auto error = api_error::error;
if (create_options & FILE_DIRECTORY_FILE) { if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
attributes |= FILE_ATTRIBUTE_DIRECTORY; attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else { } else {
attributes &= ~FILE_ATTRIBUTE_DIRECTORY; attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
} }
if (not attributes) { if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL; attributes = FILE_ATTRIBUTE_NORMAL;
} }
const auto now = utils::get_file_time_now(); const auto now = utils::get_file_time_now();
auto meta = create_meta_attributes( auto meta = create_meta_attributes(
now, attributes, now, now, attributes & FILE_ATTRIBUTE_DIRECTORY, 0U, "", now, attributes, now, now, (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U,
0U, now, 0U, 0U, 0U, 0U, "", 0U, now, 0U, 0U, 0U,
(attributes & FILE_ATTRIBUTE_DIRECTORY) (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U
? "" ? ""
: utils::path::combine(config_.get_cache_directory(), : utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}), {utils::create_uuid_string()}),
@ -294,14 +295,14 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
open_file_data ofd{}; open_file_data ofd{};
std::uint64_t handle{}; std::uint64_t handle{};
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (attributes & FILE_ATTRIBUTE_DIRECTORY) { if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U) {
error = provider_.create_directory(api_path, meta); error = provider_.create_directory(api_path, meta);
if (error == api_error::success) { if (error == api_error::success) {
error = fm_->open(api_path, true, ofd, handle, f); error = fm_->open(api_path, true, ofd, handle, file);
} }
} else { } else {
error = fm_->create(api_path, meta, ofd, handle, f); error = fm_->create(api_path, meta, ofd, handle, file);
} }
if (error == api_error::success) { if (error == api_error::success) {
@ -320,13 +321,13 @@ auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::success; auto error = api_error::success;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
error = api_error::invalid_handle; error = api_error::invalid_handle;
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
error = f->native_operation([&](native_handle op_handle) { error = file->native_operation([&](native_handle op_handle) {
if (not ::FlushFileBuffers(op_handle)) { if (::FlushFileBuffers(op_handle) == 0) {
return api_error::os_error; return api_error::os_error;
} }
@ -336,7 +337,7 @@ auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
// Populate file information // Populate file information
api_meta_map meta; api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) { if (provider_.get_item_meta(api_path, meta) == api_error::success) {
populate_file_info(f->get_file_size(), meta, *file_info); populate_file_info(file->get_file_size(), meta, *file_info);
} }
} }
} }
@ -368,14 +369,14 @@ auto winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
api_meta_map meta; api_meta_map meta;
if ((error = provider_.get_item_meta(api_path, meta)) == error = provider_.get_item_meta(api_path, meta);
api_error::success) { if (error == api_error::success) {
populate_file_info(f->get_file_size(), meta, *file_info); populate_file_info(file->get_file_size(), meta, *file_info);
} }
} }
} }
@ -424,24 +425,24 @@ auto winfsp_drive::get_security_by_name(PWSTR file_name, PUINT32 attributes,
api_meta_map meta{}; api_meta_map meta{};
auto error = provider_.get_item_meta(api_path, meta); auto error = provider_.get_item_meta(api_path, meta);
if (error == api_error::success) { if (error == api_error::success) {
if (attributes) { if (attributes != nullptr) {
*attributes = utils::get_attributes_from_meta(meta); *attributes = utils::get_attributes_from_meta(meta);
} }
if (descriptor_size) { if (descriptor_size != nullptr) {
ULONG sz{}; ULONG size{};
PSECURITY_DESCRIPTOR sd{}; PSECURITY_DESCRIPTOR sec_desc{};
if (::ConvertStringSecurityDescriptorToSecurityDescriptor( if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)", "O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sd, &sz)) { SDDL_REVISION_1, &sec_desc, &size) != 0) {
if (sz > *descriptor_size) { if (size > *descriptor_size) {
error = api_error::buffer_too_small; error = api_error::buffer_too_small;
} else { } else {
::CopyMemory(descriptor, sd, sz); ::CopyMemory(descriptor, sec_desc, size);
} }
*descriptor_size = sz; *descriptor_size = size;
::LocalFree(sd); ::LocalFree(sec_desc);
} else { } else {
error = api_error::os_error; error = api_error::os_error;
} }
@ -456,10 +457,10 @@ auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
SIZE_T *descriptor_size) -> NTSTATUS { SIZE_T *descriptor_size) -> NTSTATUS {
const auto api_path = const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name)); utils::path::create_api_path(utils::string::to_utf8(file_name));
std::uint64_t sds = descriptor_size ? *descriptor_size : 0U; std::uint64_t sds = descriptor_size == nullptr ? 0U : *descriptor_size;
auto ret = get_security_by_name(file_name, attributes, descriptor, auto ret = get_security_by_name(file_name, attributes, descriptor,
sds > 0U ? &sds : nullptr); sds > 0U ? &sds : nullptr);
if (sds) { if (sds != 0U) {
*descriptor_size = static_cast<SIZE_T>(sds); *descriptor_size = static_cast<SIZE_T>(sds);
} }
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret); RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
@ -494,7 +495,7 @@ auto winfsp_drive::GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS {
const auto total_used = provider_.get_used_drive_space(); const auto total_used = provider_.get_used_drive_space();
volume_info->FreeSize = total_bytes - total_used; volume_info->FreeSize = total_bytes - total_used;
volume_info->TotalSize = total_bytes; volume_info->TotalSize = total_bytes;
wcscpy_s(&volume_info->VolumeLabel[0U], 32, &volume_label[0U]); wcscpy_s(&volume_info->VolumeLabel[0U], 32, volume_label.data());
volume_info->VolumeLabelLength = volume_info->VolumeLabelLength =
std::min(static_cast<UINT16>(64), std::min(static_cast<UINT16>(64),
static_cast<UINT16>(volume_label.size() * sizeof(WCHAR))); static_cast<UINT16>(volume_label.size() * sizeof(WCHAR)));
@ -507,8 +508,9 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host); auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
if (not config_.get_enable_mount_manager()) { if (not config_.get_enable_mount_manager()) {
file_system_host->SetPrefix( file_system_host->SetPrefix(
&(L"\\repertory\\" + (L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0, 1))[0u]); std::wstring(file_system_host->FileSystemName()).substr(0, 1))
.data());
} }
file_system_host->SetFileSystemName(REPERTORY_W); file_system_host->SetFileSystemName(REPERTORY_W);
file_system_host->SetFlushAndPurgeOnCleanup(TRUE); file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
@ -545,10 +547,10 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
} }
} }
logging_consumer l(config_.get_log_directory(), config_.get_event_level()); logging_consumer log(config_.get_log_directory(), config_.get_event_level());
std::unique_ptr<console_consumer> c; std::unique_ptr<console_consumer> cons;
if (enable_console) { if (enable_console) {
c = std::make_unique<console_consumer>(); cons = std::make_unique<console_consumer>();
} }
event_system::instance().start(); event_system::instance().start();
auto svc = winfsp_service(lock_, *this, parsed_drive_args, config_); auto svc = winfsp_service(lock_, *this, parsed_drive_args, config_);
@ -556,7 +558,7 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
event_system::instance().raise<drive_mount_result>(std::to_string(ret)); event_system::instance().raise<drive_mount_result>(std::to_string(ret));
event_system::instance().stop(); event_system::instance().stop();
c.reset(); cons.reset();
return static_cast<int>(ret); return static_cast<int>(ret);
} }
@ -628,7 +630,7 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
auto error = provider_.is_directory(api_path, directory); auto error = provider_.is_directory(api_path, directory);
if (error == api_error::success) { if (error == api_error::success) {
error = api_error::directory_not_found; error = api_error::directory_not_found;
if ((create_options & FILE_DIRECTORY_FILE) && not directory) { if (((create_options & FILE_DIRECTORY_FILE) != 0U) && not directory) {
} else { } else {
error = api_error::success; error = api_error::success;
if (not directory && if (not directory &&
@ -642,14 +644,14 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
if (error == api_error::success) { if (error == api_error::success) {
open_file_data ofd{}; open_file_data ofd{};
std::uint64_t handle{}; std::uint64_t handle{};
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
error = fm_->open(api_path, directory, ofd, handle, f); error = fm_->open(api_path, directory, ofd, handle, file);
if (error == api_error::success) { if (error == api_error::success) {
api_meta_map meta; api_meta_map meta;
if ((error = provider_.get_item_meta(api_path, meta)) == error = provider_.get_item_meta(api_path, meta);
api_error::success) { if (error == api_error::success) {
populate_file_info(f->get_api_path(), f->get_file_size(), meta, populate_file_info(file->get_api_path(), file->get_file_size(),
*ofi); meta, *ofi);
*file_desc = reinterpret_cast<PVOID>(handle); *file_desc = reinterpret_cast<PVOID>(handle);
} }
} }
@ -670,27 +672,29 @@ auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, f)) { if (fm_->get_open_file(handle, true, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
api_meta_map meta{}; api_meta_map meta{};
if ((error = provider_.get_item_meta(api_path, meta)) == error = provider_.get_item_meta(api_path, meta);
api_error::success) { if (error == api_error::success) {
error = api_error::file_in_use; error = api_error::file_in_use;
if (not fm_->is_processing(api_path)) { if (not fm_->is_processing(api_path)) {
if ((error = f->resize(0)) == api_error::success) { error = file->resize(0U);
if (error == api_error::success) {
filesystem_item existing_fsi{}; filesystem_item existing_fsi{};
if ((error = provider_.get_filesystem_item( error =
api_path, false, existing_fsi)) == api_error::success) { provider_.get_filesystem_item(api_path, false, existing_fsi);
if (error == api_error::success) {
// Handle replace attributes // Handle replace attributes
if (replace_attributes) { if (replace_attributes != 0U) {
if (not attributes) { if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL; attributes = FILE_ATTRIBUTE_NORMAL;
} }
meta[META_ATTRIBUTES] = std::to_string(attributes); meta[META_ATTRIBUTES] = std::to_string(attributes);
error = provider_.set_item_meta(api_path, meta); error = provider_.set_item_meta(api_path, meta);
} else if (attributes) { // Handle merge attributes } else if (attributes != 0U) { // Handle merge attributes
const auto current_attributes = const auto current_attributes =
utils::get_attributes_from_meta(meta); utils::get_attributes_from_meta(meta);
const auto merged_attributes = attributes | current_attributes; const auto merged_attributes = attributes | current_attributes;
@ -704,7 +708,7 @@ auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
} }
// Populate file information // Populate file information
populate_file_info(f->get_file_size(), meta, *file_info); populate_file_info(file->get_file_size(), meta, *file_info);
} }
} }
} }
@ -729,8 +733,9 @@ void winfsp_drive::populate_file_info(const std::string &api_path,
utils::string::replace_copy(api_path, '/', '\\')); utils::string::replace_copy(api_path, '/', '\\'));
wcscpy_s(ofi.NormalizedName, ofi.NormalizedNameSize / sizeof(WCHAR), wcscpy_s(ofi.NormalizedName, ofi.NormalizedNameSize / sizeof(WCHAR),
&file_path[0U]); file_path.data());
ofi.NormalizedNameSize = (UINT16)(wcslen(&file_path[0U]) * sizeof(WCHAR)); ofi.NormalizedNameSize =
static_cast<UINT16>(wcslen(file_path.data()) * sizeof(WCHAR));
populate_file_info(file_size, meta, ofi.FileInfo); populate_file_info(file_size, meta, ofi.FileInfo);
} }
@ -740,9 +745,9 @@ auto winfsp_drive::populate_file_info(const std::string &api_path,
api_meta_map meta{}; api_meta_map meta{};
auto ret = provider_.get_item_meta(api_path, meta); auto ret = provider_.get_item_meta(api_path, meta);
if (ret == api_error::success) { if (ret == api_error::success) {
FSP_FSCTL_FILE_INFO fi{}; FSP_FSCTL_FILE_INFO info{};
populate_file_info(utils::string::to_uint64(meta[META_SIZE]), meta, fi); populate_file_info(utils::string::to_uint64(meta[META_SIZE]), meta, info);
set_file_info(file_info, fi); set_file_info(file_info, info);
} }
return ret; return ret;
@ -753,7 +758,8 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
FSP_FSCTL_FILE_INFO &file_info) { FSP_FSCTL_FILE_INFO &file_info) {
file_info.FileSize = file_size; file_info.FileSize = file_size;
file_info.AllocationSize = file_info.AllocationSize =
utils::divide_with_ceiling(file_size ? file_size : WINFSP_ALLOCATION_UNIT, utils::divide_with_ceiling(file_size == 0U ? WINFSP_ALLOCATION_UNIT
: file_size,
WINFSP_ALLOCATION_UNIT) * WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT; WINFSP_ALLOCATION_UNIT;
file_info.ChangeTime = utils::get_changed_time_from_meta(meta); file_info.ChangeTime = utils::get_changed_time_from_meta(meta);
@ -776,20 +782,21 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
if (length > 0U) { if (length > 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
data_buffer data; data_buffer data;
if ((error = f->read(length, offset, data)) == api_error::success) { error = file->read(length, offset, data);
if (error == api_error::success) {
*bytes_transferred = static_cast<ULONG>(data.size()); *bytes_transferred = static_cast<ULONG>(data.size());
if ((length > 0) && (data.size() != length)) { if ((length > 0) && (data.size() != length)) {
::SetLastError(ERROR_HANDLE_EOF); ::SetLastError(ERROR_HANDLE_EOF);
} }
if (not data.empty()) { if (not data.empty()) {
::CopyMemory(buffer, &data[0U], data.size()); ::CopyMemory(buffer, data.data(), data.size());
data.clear(); data.clear();
auto res = provider_.set_item_meta( auto res = provider_.set_item_meta(
api_path, META_ACCESSED, api_path, META_ACCESSED,
@ -822,46 +829,47 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
bool exists{}; bool exists{};
error = provider_.is_directory(api_path, exists); error = provider_.is_directory(api_path, exists);
if (error == api_error::success) { if (error == api_error::success) {
if (exists) { if (exists) {
directory_item_list list{}; directory_item_list list{};
if ((error = provider_.get_directory_items(api_path, list)) == error = provider_.get_directory_items(api_path, list);
api_error::success) { if (error == api_error::success) {
directory_iterator iterator(std::move(list)); directory_iterator iterator(std::move(list));
auto status_result = STATUS_SUCCESS; auto status_result = STATUS_SUCCESS;
auto *directory_buffer = f->get_open_data(handle).directory_buffer; auto *directory_buffer =
file->get_open_data(handle).directory_buffer;
if (FspFileSystemAcquireDirectoryBuffer( if (FspFileSystemAcquireDirectoryBuffer(
&directory_buffer, static_cast<BOOLEAN>(nullptr == marker), &directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
&status_result)) { &status_result) != 0U) {
directory_item di{}; directory_item dir_item{};
auto offset = auto offset =
marker marker == nullptr
? iterator.get_next_directory_offset( ? 0U
: iterator.get_next_directory_offset(
utils::path::create_api_path(utils::path::combine( utils::path::create_api_path(utils::path::combine(
api_path, {utils::string::to_utf8(marker)}))) api_path, {utils::string::to_utf8(marker)})));
: 0U; while ((error = iterator.get_directory_item(
while ((error = iterator.get_directory_item(offset++, di)) == offset++, dir_item)) == api_error::success) {
api_error::success) { if (utils::path::is_ads_file_path(dir_item.api_path) ||
if (utils::path::is_ads_file_path(di.api_path) || dir_item.api_path == "." || dir_item.api_path == "..") {
di.api_path == "." || di.api_path == "..") {
continue; continue;
} }
if (di.meta.empty()) { if (dir_item.meta.empty()) {
utils::error::raise_api_path_error(__FUNCTION__, di.api_path, utils::error::raise_api_path_error(
api_error::error, __FUNCTION__, dir_item.api_path, api_error::error,
"item meta is empty"); "item meta is empty");
continue; continue;
} }
const auto display_name = utils::string::from_utf8( const auto display_name = utils::string::from_utf8(
utils::path::strip_to_file_name(di.api_path)); utils::path::strip_to_file_name(dir_item.api_path));
union { union {
UINT8 B[FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) + UINT8 B[FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) +
((MAX_PATH + 1) * sizeof(WCHAR))]; ((MAX_PATH + 1) * sizeof(WCHAR))];
@ -872,12 +880,14 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
::ZeroMemory(directory_info, sizeof(*directory_info)); ::ZeroMemory(directory_info, sizeof(*directory_info));
directory_info->Size = static_cast<UINT16>( directory_info->Size = static_cast<UINT16>(
FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) + FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) +
(std::min((size_t)MAX_PATH, display_name.size()) * (std::min(static_cast<size_t>(MAX_PATH),
display_name.size()) *
sizeof(WCHAR))); sizeof(WCHAR)));
populate_file_info(di.size, di.meta, directory_info->FileInfo); populate_file_info(dir_item.size, dir_item.meta,
directory_info->FileInfo);
::wcscpy_s(&directory_info->FileNameBuf[0U], MAX_PATH, ::wcscpy_s(&directory_info->FileNameBuf[0U], MAX_PATH,
&display_name[0U]); display_name.data());
FspFileSystemFillDirectoryBuffer( FspFileSystemFillDirectoryBuffer(
&directory_buffer, directory_info, &status_result); &directory_buffer, directory_info, &status_result);
@ -923,11 +933,13 @@ auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
error = provider_.is_file(from_api_path, exists); error = provider_.is_file(from_api_path, exists);
if (error == api_error::success) { if (error == api_error::success) {
if (exists) { if (exists) {
error = fm_->rename_file(from_api_path, to_api_path, replace_if_exists); error =
fm_->rename_file(from_api_path, to_api_path, replace_if_exists != 0U);
} else { } else {
error = provider_.is_directory(from_api_path, exists); error = provider_.is_directory(from_api_path, exists);
if (error == api_error::success && exists) if (error == api_error::success && exists) {
error = fm_->rename_directory(from_api_path, to_api_path); error = fm_->rename_directory(from_api_path, to_api_path);
}
} }
} }
@ -945,35 +957,36 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, f)) { if (fm_->get_open_file(handle, false, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
if (attributes == INVALID_FILE_ATTRIBUTES) { if (attributes == INVALID_FILE_ATTRIBUTES) {
attributes = 0; attributes = 0;
} else if (attributes == 0) { } else if (attributes == 0) {
attributes = f->is_directory() ? FILE_ATTRIBUTE_DIRECTORY attributes = file->is_directory() ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL; : FILE_ATTRIBUTE_NORMAL;
} }
api_meta_map meta; api_meta_map meta;
if (attributes) { if (attributes != 0U) {
if ((attributes & FILE_ATTRIBUTE_NORMAL) && if (((attributes & FILE_ATTRIBUTE_NORMAL) != 0U) &&
(attributes != FILE_ATTRIBUTE_NORMAL)) { (attributes != FILE_ATTRIBUTE_NORMAL)) {
attributes &= ~(FILE_ATTRIBUTE_NORMAL); attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
} }
meta[META_ATTRIBUTES] = std::to_string(attributes); meta[META_ATTRIBUTES] = std::to_string(attributes);
} }
if (creation_time && (creation_time != 0xFFFFFFFFFFFFFFFF)) { if ((creation_time != 0U) && (creation_time != 0xFFFFFFFFFFFFFFFF)) {
meta[META_CREATION] = std::to_string(creation_time); meta[META_CREATION] = std::to_string(creation_time);
} }
if (last_access_time && (last_access_time != 0xFFFFFFFFFFFFFFFF)) { if ((last_access_time != 0U) &&
(last_access_time != 0xFFFFFFFFFFFFFFFF)) {
meta[META_ACCESSED] = std::to_string(last_access_time); meta[META_ACCESSED] = std::to_string(last_access_time);
} }
if (last_write_time && (last_write_time != 0xFFFFFFFFFFFFFFFF)) { if ((last_write_time != 0U) && (last_write_time != 0xFFFFFFFFFFFFFFFF)) {
meta[META_WRITTEN] = std::to_string(last_write_time); meta[META_WRITTEN] = std::to_string(last_write_time);
} }
if (change_time && (change_time != 0xFFFFFFFFFFFFFFFF)) { if ((change_time != 0U) && (change_time != 0xFFFFFFFFFFFFFFFF)) {
meta[META_CHANGED] = std::to_string(change_time); meta[META_CHANGED] = std::to_string(change_time);
meta[META_MODIFIED] = std::to_string(change_time); meta[META_MODIFIED] = std::to_string(change_time);
} }
@ -1015,43 +1028,44 @@ auto winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, f)) { if (fm_->get_open_file(handle, true, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
i_open_file::native_operation_callback allocator; i_open_file::native_operation_callback allocator;
if (set_allocation_size) { if (set_allocation_size != 0U) {
allocator = [&](native_handle handle) -> api_error { allocator = [&](native_handle cur_handle) -> api_error {
std::string meta_allocation_size; std::string meta_allocation_size;
utils::calculate_allocation_size(false, 0, new_size, utils::calculate_allocation_size(false, 0, new_size,
meta_allocation_size); meta_allocation_size);
FILE_ALLOCATION_INFO allocation_info{}; FILE_ALLOCATION_INFO allocation_info{};
allocation_info.AllocationSize.QuadPart = new_size; allocation_info.AllocationSize.QuadPart =
return ::SetFileInformationByHandle(handle, FileAllocationInfo, static_cast<LONGLONG>(new_size);
return ::SetFileInformationByHandle(cur_handle, FileAllocationInfo,
&allocation_info, &allocation_info,
sizeof(allocation_info)) sizeof(allocation_info)) != 0
? api_error::success ? api_error::success
: api_error::os_error; : api_error::os_error;
}; };
} else { } else {
allocator = [&](native_handle handle) -> api_error { allocator = [&](native_handle cur_handle) -> api_error {
FILE_END_OF_FILE_INFO end_of_file_info{}; FILE_END_OF_FILE_INFO end_of_file_info{};
end_of_file_info.EndOfFile.QuadPart = new_size; end_of_file_info.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
return ::SetFileInformationByHandle(handle, FileEndOfFileInfo, return ::SetFileInformationByHandle(cur_handle, FileEndOfFileInfo,
&end_of_file_info, &end_of_file_info,
sizeof(end_of_file_info)) sizeof(end_of_file_info)) != 0
? api_error::success ? api_error::success
: api_error::os_error; : api_error::os_error;
}; };
} }
error = f->native_operation(new_size, allocator); error = file->native_operation(new_size, allocator);
if (file_info) { if (file_info != nullptr) {
// Populate file information // Populate file information
api_meta_map meta; api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) { if (provider_.get_item_meta(api_path, meta) == api_error::success) {
populate_file_info(f->get_file_size(), meta, *file_info); populate_file_info(file->get_file_size(), meta, *file_info);
} }
} }
} }
@ -1099,21 +1113,21 @@ auto winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) { if (handle != 0U) {
std::shared_ptr<i_open_file> f; std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, f)) { if (fm_->get_open_file(handle, true, file)) {
api_path = f->get_api_path(); api_path = file->get_api_path();
if (write_to_end) { if (write_to_end != 0U) {
offset = f->get_file_size(); offset = file->get_file_size();
} }
auto should_write = true; auto should_write = true;
if (constrained_io) { if (constrained_io != 0U) {
if (offset >= f->get_file_size()) { if (offset >= file->get_file_size()) {
error = api_error::success; error = api_error::success;
should_write = false; should_write = false;
} else if (offset + length > f->get_file_size()) { } else if (offset + length > file->get_file_size()) {
length = static_cast<ULONG>(f->get_file_size() - offset); length = static_cast<ULONG>(file->get_file_size() - offset);
} }
} }
@ -1121,15 +1135,15 @@ auto winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
if (length > 0U) { if (length > 0U) {
std::size_t bytes_written{}; std::size_t bytes_written{};
data_buffer data(length); data_buffer data(length);
std::memcpy(&data[0U], buffer, length); std::memcpy(data.data(), buffer, length);
if ((error = f->write(offset, data, bytes_written)) == error = file->write(offset, data, bytes_written);
api_error::success) { if (error == api_error::success) {
*bytes_transferred = static_cast<ULONG>(bytes_written); *bytes_transferred = static_cast<ULONG>(bytes_written);
// Populate file information // Populate file information
api_meta_map meta; api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) { if (provider_.get_item_meta(api_path, meta) == api_error::success) {
populate_file_info(f->get_file_size(), meta, *file_info); populate_file_info(file->get_file_size(), meta, *file_info);
} }
} }
} }