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_handle &handle) = 0;*/
[[nodiscard]] virtual auto fuse_fgetattr(const char *path, remote::stat &st,
bool &directory,
const remote::file_handle &handle)
-> packet::error_type = 0;
[[nodiscard]] virtual auto
fuse_fgetattr(const char *path, remote::stat &r_stat, bool &directory,
const remote::file_handle &handle) -> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_fsetattr_x(const char *path,
const remote::setattr_x &attr,
@ -77,8 +76,8 @@ public:
const remote::file_handle &handle)
-> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_getattr(const char *path, remote::stat &st,
bool &directory)
[[nodiscard]] virtual auto fuse_getattr(const char *path,
remote::stat &r_stat, bool &directory)
-> packet::error_type = 0;
/*[[nodiscard]] virtual packet::error_type fuse_getxattr(const char *path,
@ -167,11 +166,11 @@ public:
std::int32_t &flags, std::uint32_t position) = 0;*/
[[nodiscard]] virtual auto fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &st)
remote::statfs &r_stat)
-> packet::error_type = 0;
[[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;
[[nodiscard]] virtual auto fuse_truncate(const char *path,

View File

@ -36,7 +36,7 @@
#include "utils/Base64.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 {
template <typename drive>

View File

@ -46,8 +46,8 @@ private:
remote::file_info &file_info)
-> packet::error_type;
void populate_stat(const char *path, bool directory, remote::stat &st,
const struct _stat64 &st1);
void populate_stat(const char *path, bool directory, remote::stat &r_stat,
const struct _stat64 &unix_st);
public:
// FUSE Layer
@ -69,7 +69,7 @@ public:
&mode, const remote::file_offset &offset, const remote::file_offset
&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)
-> packet::error_type override;
@ -85,7 +85,7 @@ public:
const remote::file_handle &handle)
-> 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 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,
std::uint32_t position) override ;*/
auto fuse_statfs(const char *path, std::uint64_t frsize, remote::statfs &st)
-> packet::error_type override;
auto fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &r_stat) -> packet::error_type override;
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)
-> packet::error_type override;
@ -189,8 +189,8 @@ public:
std::uint64_t op0, std::uint64_t op1)
-> packet::error_type override;
void set_fuse_uid_gid(const remote::user_id &,
const remote::group_id &) override {}
void set_fuse_uid_gid(const remote::user_id & /* uid */,
const remote::group_id & /* gid */) override {}
// JSON Layer
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_ffree = stbuf->f_files - provider_.get_total_item_count();
stbuf->f_owner = getuid();
strncpy(&stbuf->f_mntonname[0], get_mount_location().c_str(), MNAMELEN);
strncpy(&stbuf->f_mntfromname[0],
strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(),
get_mount_location().size());
strncpy(&stbuf->f_mntfromname[0U],
(utils::create_volume_label(config_.get_provider_type())).c_str(),
MNAMELEN);
sizeof(stbuf->f_mntfromname) - 1U);
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,
remote::stat &st, const struct _stat64 &st1) {
st.st_nlink = static_cast<remote::file_nlink>(
remote::stat &r_stat,
const struct _stat64 &unix_st) {
r_stat.st_nlink = static_cast<remote::file_nlink>(
directory ? 2 + drive_.get_directory_item_count(
utils::path::create_api_path(path))
: 1);
st.st_atimespec = utils::time64_to_unix_time(st1.st_atime);
st.st_birthtimespec = utils::time64_to_unix_time(st1.st_ctime);
st.st_ctimespec = utils::time64_to_unix_time(st1.st_ctime);
st.st_mtimespec = utils::time64_to_unix_time(st1.st_mtime);
st.st_size = static_cast<remote::file_size>(st1.st_size);
st.st_mode = st1.st_mode;
r_stat.st_atimespec = utils::time64_to_unix_time(unix_st.st_atime);
r_stat.st_birthtimespec = utils::time64_to_unix_time(unix_st.st_ctime);
r_stat.st_ctimespec = utils::time64_to_unix_time(unix_st.st_ctime);
r_stat.st_mtimespec = utils::time64_to_unix_time(unix_st.st_mtime);
r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size);
r_stat.st_mode = unix_st.st_mode;
}
// FUSE Layer
@ -149,19 +150,20 @@ construct_path(path); auto res = HasOpenFileCompatInfo(handle, EBADF); if (res
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,
const remote::file_handle &handle)
-> packet::error_type {
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);
if (res == 0) {
directory = utils::file::is_directory(file_path);
struct _stat64 st1 {};
if ((res = _fstat64(static_cast<int>(handle), &st1)) == 0) {
populate_stat(path, directory, st, st1);
struct _stat64 unix_st {};
res = _fstat64(static_cast<int>(handle), &unix_st);
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) {
res = -1;
errno = EBADF;
auto os_handle =
auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT;
if (::FlushFileBuffers(os_handle)) {
if (::FlushFileBuffers(os_handle) != 0) {
res = 0;
errno = 0;
}
@ -216,14 +218,14 @@ auto remote_server::fuse_ftruncate(const char *path,
if (res == 0) {
res = -1;
errno = EBADF;
auto os_handle =
auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT;
FILE_END_OF_FILE_INFO fi{};
fi.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &fi,
sizeof(FILE_END_OF_FILE_INFO))) {
FILE_END_OF_FILE_INFO eof_inf{};
eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &eof_inf,
sizeof(FILE_END_OF_FILE_INFO)) != 0) {
res = 0;
errno = 0;
}
@ -235,17 +237,17 @@ auto remote_server::fuse_ftruncate(const char *path,
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 {
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);
struct _stat64 st1 {};
const auto res = _stat64(file_path.c_str(), &st1);
if (res == 0) {
populate_stat(path, directory, st, st1);
populate_stat(path, directory, r_st, st1);
}
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;
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));
handle = static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>(
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);
const auto create_op = (open_flags & _O_CREAT);
if (create_op && directory_op) {
if ((create_op != 0) && directory_op) {
ret = -EINVAL;
} else if (directory_op) {
ret = -EACCES;
} else {
int fd = -1;
int file = -1;
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) {
handle = static_cast<remote::file_handle>(fd);
handle = static_cast<remote::file_handle>(file);
ret = 0;
set_compat_open_info(handle, file_path);
} else {
@ -367,10 +369,10 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
const auto open_flags =
utils::unix_open_flags_to_flags_and_perms(0, flags, perms) &
(~_O_CREAT);
int fd = -1;
res = _sopen_s(&fd, file_path.c_str(), open_flags, _SH_DENYNO, 0);
int file = -1;
res = _sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, 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);
} else {
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,
const remote::file_size &readSize,
const remote::file_offset &readOffset,
const remote::file_size &read_size,
const remote::file_offset &read_offset,
const remote::file_handle &handle)
-> packet::error_type {
const auto file_path = construct_path(path);
auto &b = *reinterpret_cast<data_buffer *>(buffer);
auto &data = *reinterpret_cast<data_buffer *>(buffer);
auto res = 0;
if (readSize > std::numeric_limits<std::size_t>::max()) {
if (read_size > std::numeric_limits<std::size_t>::max()) {
res = -1;
errno = ERANGE;
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
res = -1;
errno = EBADF;
auto os_handle =
auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT;
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)) {
b.resize(utils::calculate_read_size(
file_size, static_cast<std::size_t>(readSize), readOffset));
if (b.size() > 0) {
std::size_t bytes_read = 0u;
if (file->read_bytes(&b[0u], b.size(), readOffset, bytes_read)) {
data.resize(utils::calculate_read_size(
file_size, static_cast<std::size_t>(read_size), read_offset));
if (!data.empty()) {
std::size_t bytes_read{};
if (file->read_bytes(data.data(), data.size(), read_offset,
bytes_read)) {
res = 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) {
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)
-> packet::error_type {
const auto file_path = construct_path(path);
std::size_t bytes_written = 0u;
std::size_t bytes_written{};
auto res = 0;
if (write_size > std::numeric_limits<std::size_t>::max()) {
res = -1;
errno = ERANGE;
} else {
if ((res = has_compat_open_info(handle, EBADF)) == 0) {
res = has_compat_open_info(handle, EBADF);
if (res == 0) {
res = -1;
errno = EBADF;
auto os_handle =
auto *os_handle =
reinterpret_cast<HANDLE>(_get_osfhandle(static_cast<int>(handle)));
if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT;
@ -488,7 +492,7 @@ auto remote_server::fuse_write_base64(
auto remote_server::fuse_readdir(const char *path,
const remote::file_offset &offset,
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);
auto res = 0;
if (offset > std::numeric_limits<std::size_t>::max()) {
@ -496,11 +500,11 @@ auto remote_server::fuse_readdir(const char *path,
res = -1;
} else {
auto *iterator = reinterpret_cast<directory_iterator *>(handle);
if (iterator) {
res = iterator->get(static_cast<std::size_t>(offset), itemPath);
} else {
if (iterator == nullptr) {
res = -1;
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,
remote::statfs &st) -> packet::error_type {
remote::statfs &r_stat) -> packet::error_type {
const auto file_path = construct_path(path);
const auto total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space();
const auto used_blocks = utils::divide_with_ceiling(
total_used, static_cast<std::uint64_t>(frsize));
st.f_files = 4294967295;
st.f_blocks = utils::divide_with_ceiling(total_bytes,
static_cast<std::uint64_t>(frsize));
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0;
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count();
r_stat.f_files = 4294967295;
r_stat.f_blocks = utils::divide_with_ceiling(
total_bytes, static_cast<std::uint64_t>(frsize));
r_stat.f_bavail = r_stat.f_bfree =
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);
return 0;
}
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 total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space();
const auto used_blocks =
utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(bsize));
st.f_blocks = utils::divide_with_ceiling(total_bytes,
static_cast<std::uint64_t>(bsize));
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0;
st.f_files = 4294967295;
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count();
strncpy(&st.f_mntfromname[0u],
r_stat.f_blocks = utils::divide_with_ceiling(
total_bytes, static_cast<std::uint64_t>(bsize));
r_stat.f_bavail = r_stat.f_bfree =
r_stat.f_blocks == 0U ? 0 : (r_stat.f_blocks - used_blocks);
r_stat.f_files = 4294967295;
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(),
sizeof(st.f_mntfromname) - 1U);
sizeof(r_stat.f_mntfromname) - 1U);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
return 0;
@ -650,19 +659,19 @@ auto remote_server::fuse_truncate(const char *path,
const auto flags_and_attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(::PathIsDirectoryW(unicode_file_path.c_str())
(::PathIsDirectoryW(unicode_file_path.c_str()) != 0
? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS
: 0);
const auto os_handle = ::CreateFileW(
auto *os_handle = ::CreateFileW(
unicode_file_path.c_str(), FILE_GENERIC_READ | FILE_GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, static_cast<DWORD>(flags_and_attributes), nullptr);
if (os_handle != INVALID_HANDLE_VALUE) {
errno = EFAULT;
FILE_END_OF_FILE_INFO fi{};
fi.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &fi,
sizeof(FILE_END_OF_FILE_INFO))) {
FILE_END_OF_FILE_INFO eof_inf{};
eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(size);
if (::SetFileInformationByHandle(os_handle, FileEndOfFileInfo, &eof_inf,
sizeof(FILE_END_OF_FILE_INFO)) != 0) {
res = 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 =
FILE_FLAG_BACKUP_SEMANTICS |
(::PathIsDirectoryW(unicode_file_path.c_str())
(::PathIsDirectoryW(unicode_file_path.c_str()) != 0
? FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_POSIX_SEMANTICS
: 0);
const auto os_handle = ::CreateFileW(
auto *os_handle = ::CreateFileW(
unicode_file_path.c_str(), FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 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 *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();
access_time.dwHighDateTime =
static_cast<DWORD>((now >> 32u) & 0xFFFFFFFF);
static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
access_time.dwLowDateTime = now & 0xFFFFFFFF;
access_time_ptr = &access_time;
} 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;
}
if (not tv[1] || (op1 == UTIME_NOW)) {
if ((tv[1U] == 0U) || (op1 == UTIME_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_ptr = &write_time;
} 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;
}
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;
errno = 0;
}
@ -771,8 +781,8 @@ auto remote_server::json_read_directory_snapshot(
std::uint32_t page, json &json_data) -> packet::error_type {
const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset = 0u;
int res;
std::size_t offset{};
int res{};
json item_json;
while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
(res = iterator->get_json(
@ -803,14 +813,14 @@ auto remote_server::json_release_directory_snapshot(
// WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
-> 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);
if (ret == STATUS_SUCCESS) {
FILE_DISPOSITION_INFO dispositionInfo = {TRUE};
ret = ::SetFileInformationByHandle(handle, FileDispositionInfo,
&dispositionInfo,
sizeof(FILE_DISPOSITION_INFO))
sizeof(FILE_DISPOSITION_INFO)) != 0
? STATUS_SUCCESS
: FspNtStatusFromWin32(::GetLastError());
}
@ -824,10 +834,10 @@ auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
-> packet::error_type {
const auto file_path = get_open_file_path(file_desc);
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);
if (ret == STATUS_SUCCESS) {
if (flags & FileSystemBase::CleanupDelete) {
if ((flags & FileSystemBase::CleanupDelete) != 0U) {
::CloseHandle(handle);
remove_open_info(file_desc);
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 {
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) {
::CloseHandle(handle);
remove_open_info(file_desc);
@ -858,22 +868,22 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
-> packet::error_type {
const auto file_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
exists = utils::file::is_file(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
exists = static_cast<BOOLEAN>(utils::file::is_file(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)})));
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;
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
}
if (not attributes) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
const auto handle = ::CreateFileW(
auto *handle = ::CreateFileW(
file_path.c_str(), granted_access,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 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)
-> 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);
if (ret == STATUS_SUCCESS) {
if ((ret = ::FlushFileBuffers(handle)
? ret
: FspNtStatusFromWin32(::GetLastError())) ==
STATUS_SUCCESS) {
ret = ::FlushFileBuffers(handle) ? ret
: FspNtStatusFromWin32(::GetLastError());
if (ret == STATUS_SUCCESS) {
ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
*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,
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);
if (ret == STATUS_SUCCESS) {
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)}));
auto ret = STATUS_BUFFER_OVERFLOW;
if (not descriptor_size ||
if ((descriptor_size == nullptr) ||
(*descriptor_size <= std::numeric_limits<SIZE_T>::max())) {
auto *descriptor = descriptor_size
? static_cast<PSECURITY_DESCRIPTOR>(::LocalAlloc(
LPTR, static_cast<SIZE_T>(*descriptor_size)))
: nullptr;
if (((ret = drive_.get_security_by_name(file_name, attributes, descriptor,
descriptor_size)) ==
STATUS_SUCCESS) &&
descriptor_size) {
ULONG str_size = 0u;
auto *descriptor = descriptor_size == nullptr
? nullptr
: static_cast<PSECURITY_DESCRIPTOR>(::LocalAlloc(
LPTR, static_cast<SIZE_T>(*descriptor_size)));
ret = drive_.get_security_by_name(file_name, attributes, descriptor,
descriptor_size);
if ((ret == STATUS_SUCCESS) && (descriptor_size != nullptr)) {
ULONG str_size{};
const auto security_info =
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
LPWSTR str;
LPWSTR str{};
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));
::LocalFree(str);
} else {
@ -992,11 +1001,11 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
mount_location_, {utils::string::to_utf8(file_name)}));
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;
}
const auto handle = ::CreateFileW(
auto *handle = ::CreateFileW(
file_path.c_str(), granted_access,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 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*/,
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);
if (ret == STATUS_SUCCESS) {
if (replace_attributes) {
if (not attributes) {
if (replace_attributes != 0U) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
FILE_BASIC_INFO basic_info{};
basic_info.FileAttributes = attributes;
if (not ::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO))) {
if (::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
}
} else if (attributes) {
} else if (attributes != 0U) {
FILE_ATTRIBUTE_TAG_INFO tag_info{};
if (not ::GetFileInformationByHandleEx(handle, FileAttributeTagInfo,
&tag_info,
sizeof(FILE_ATTRIBUTE_TAG_INFO))) {
if (::GetFileInformationByHandleEx(
handle, FileAttributeTagInfo, &tag_info,
sizeof(FILE_ATTRIBUTE_TAG_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
} else {
FILE_BASIC_INFO basic_info{};
@ -1047,9 +1056,8 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
attributes | (tag_info.FileAttributes &
static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL));
if ((basic_info.FileAttributes != tag_info.FileAttributes)) {
if (not ::SetFileInformationByHandle(handle, FileBasicInfo,
&basic_info,
sizeof(FILE_BASIC_INFO))) {
if (::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
}
}
@ -1061,7 +1069,7 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
ret =
::SetFileInformationByHandle(handle, FileAllocationInfo,
&allocationInfo,
sizeof(FILE_ALLOCATION_INFO))
sizeof(FILE_ALLOCATION_INFO)) != 0
? populate_file_info(
construct_api_path(get_open_file_path(handle)), *file_info)
: 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,
UINT32 length, PUINT32 bytes_transferred)
-> 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);
if ((ret == STATUS_SUCCESS) && length) {
if ((ret == STATUS_SUCCESS) && (length != 0U)) {
OVERLAPPED overlapped{};
overlapped.Offset = static_cast<DWORD>(offset);
overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32);
ret = ::ReadFile(handle, buffer, length,
reinterpret_cast<LPDWORD>(bytes_transferred), &overlapped)
reinterpret_cast<LPDWORD>(bytes_transferred),
&overlapped) != 0
? STATUS_SUCCESS
: 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()));
auto items = drive_.get_directory_items(api_path);
directory_iterator iterator(std::move(items));
auto offset = marker
? iterator.get_next_directory_offset(
auto offset = marker == nullptr
? 0
: iterator.get_next_directory_offset(
utils::path::create_api_path(utils::path::combine(
api_path, {utils::string::to_utf8(marker)})))
: 0;
api_path, {utils::string::to_utf8(marker)})));
json item;
while (iterator.get_json(offset++, item) == 0) {
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)}));
const auto ret =
::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
: FspNtStatusFromWin32(::GetLastError());
@ -1150,12 +1160,12 @@ auto remote_server::winfsp_set_basic_info(
PVOID file_desc, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
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);
if (ret == STATUS_SUCCESS) {
if (attributes == INVALID_FILE_ATTRIBUTES) {
attributes = 0;
} else if (not attributes) {
attributes = 0U;
} else if (attributes == 0U) {
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.ChangeTime.QuadPart = static_cast<LONGLONG>(change_time);
ret = ::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,
sizeof(FILE_BASIC_INFO))
sizeof(FILE_BASIC_INFO)) != 0
? populate_file_info(
construct_api_path(get_open_file_path(handle)), *file_info)
: FspNtStatusFromWin32(::GetLastError());
@ -1181,23 +1191,22 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
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);
if (ret == STATUS_SUCCESS) {
if (set_allocation_size) {
if (set_allocation_size != 0U) {
FILE_ALLOCATION_INFO allocation_info{};
allocation_info.AllocationSize.QuadPart = static_cast<LONGLONG>(new_size);
if (not ::SetFileInformationByHandle(handle, FileAllocationInfo,
&allocation_info,
sizeof(FILE_ALLOCATION_INFO))) {
if (::SetFileInformationByHandle(handle, FileAllocationInfo,
&allocation_info,
sizeof(FILE_ALLOCATION_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
}
} else {
FILE_END_OF_FILE_INFO end_of_file_info{};
end_of_file_info.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
if (not ::SetFileInformationByHandle(handle, FileEndOfFileInfo,
&end_of_file_info,
sizeof(FILE_END_OF_FILE_INFO))) {
FILE_END_OF_FILE_INFO eof_inf{};
eof_inf.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
if (::SetFileInformationByHandle(handle, FileEndOfFileInfo, &eof_inf,
sizeof(FILE_END_OF_FILE_INFO)) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
}
}
@ -1226,17 +1235,17 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
const auto handle = reinterpret_cast<HANDLE>(file_desc);
*bytes_transferred = 0;
auto *handle = reinterpret_cast<HANDLE>(file_desc);
*bytes_transferred = 0U;
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
if (length) {
if (length != 0U) {
auto should_write = true;
LARGE_INTEGER file_size{};
OVERLAPPED overlapped{};
if (constrained_io) {
if (not ::GetFileSizeEx(handle, &file_size)) {
if (constrained_io != 0U) {
if (::GetFileSizeEx(handle, &file_size) == 0) {
ret = FspNtStatusFromWin32(::GetLastError());
} else if (offset >= static_cast<UINT64>(file_size.QuadPart)) {
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);
ret = ::WriteFile(handle, buffer, length,
reinterpret_cast<LPDWORD>(bytes_transferred),
&overlapped)
&overlapped) != 0
? populate_file_info(
construct_api_path(get_open_file_path(handle)),
*file_info)

View File

@ -64,23 +64,24 @@ winfsp_drive::winfsp_service::winfsp_service(
host_(drive),
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(
utils::path::absolute((drive_args_.size() > 1u) ? drive_args_[1u] : ""));
utils::path::absolute((drive_args_.size() > 1U) ? drive_args_[1U] : ""));
const auto drive_letter =
((mount_location.size() == 2u) ||
((mount_location.size() == 3u) && (mount_location[2u] == '\\'))) &&
(mount_location[1u] == ':');
((mount_location.size() == 2U) ||
((mount_location.size() == 3U) && (mount_location[2U] == '\\'))) &&
(mount_location[1U] == ':');
auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED;
if ((drive_letter && not utils::file::is_directory(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()) {
unicode_mount_location =
std::wstring(L"\\\\.\\") + unicode_mount_location[0U] + L":";
}
ret = host_.Mount(&unicode_mount_location[0U]);
ret = host_.Mount(unicode_mount_location.data());
} else {
std::cerr << (drive_letter ? "Mount location in use: "
: "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,
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 &) {
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
if (f->is_directory()) {
error = provider_.get_directory_item_count(api_path)
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
if (file->is_directory()) {
error = provider_.get_directory_item_count(api_path) != 0U
? api_error::directory_not_empty
: api_error::success;
} else {
@ -149,17 +150,17 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
std::string api_path;
auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
const auto directory = f->is_directory();
if (flags & FspCleanupDelete) {
auto *directory_buffer = f->get_open_data(handle).directory_buffer;
f.reset();
const auto directory = file->is_directory();
if ((flags & FspCleanupDelete) != 0U) {
auto *directory_buffer = file->get_open_data(handle).directory_buffer;
file.reset();
if (directory_buffer) {
if (directory_buffer != nullptr) {
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
}
@ -177,7 +178,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
}
}
} else {
if ((flags & FspCleanupSetArchiveBit) && not directory) {
if (((flags & FspCleanupSetArchiveBit) != 0U) && not directory) {
api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) {
auto res = provider_.set_item_meta(
@ -191,10 +192,10 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
}
}
if (flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
FspCleanupSetChangeTime)) {
if ((flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
FspCleanupSetChangeTime)) != 0U) {
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,
std::to_string(now));
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,
std::to_string(now));
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(
api_path, {{META_CHANGED, 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) {
UINT64 allocation_size =
utils::divide_with_ceiling(f->get_file_size(),
if ((flags & FspCleanupSetAllocationSize) != 0U) {
auto allocation_size =
utils::divide_with_ceiling(file->get_file_size(),
WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
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;
auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
if (handle != 0U) {
PVOID directory_buffer = nullptr;
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
directory_buffer = f->get_open_data(handle).directory_buffer;
f.reset();
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
directory_buffer = file->get_open_data(handle).directory_buffer;
file.reset();
}
fm_->close(handle);
if (directory_buffer) {
if (directory_buffer != nullptr) {
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
}
}
@ -269,21 +270,21 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
// (ConvertSecurityDescriptorToStringSecurityDescriptor/ConvertStringSecurityDescriptorToSecurityDescriptor)
auto error = api_error::error;
if (create_options & FILE_DIRECTORY_FILE) {
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
}
if (not attributes) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
const auto now = utils::get_file_time_now();
auto meta = create_meta_attributes(
now, attributes, now, now, attributes & FILE_ATTRIBUTE_DIRECTORY, 0U, "",
0U, now, 0U, 0U, 0U,
(attributes & FILE_ATTRIBUTE_DIRECTORY)
now, attributes, now, now, (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U,
0U, "", 0U, now, 0U, 0U, 0U,
(attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U
? ""
: utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
@ -294,14 +295,14 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
open_file_data ofd{};
std::uint64_t handle{};
std::shared_ptr<i_open_file> f;
if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
std::shared_ptr<i_open_file> file;
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U) {
error = provider_.create_directory(api_path, meta);
if (error == api_error::success) {
error = fm_->open(api_path, true, ofd, handle, f);
error = fm_->open(api_path, true, ofd, handle, file);
}
} else {
error = fm_->create(api_path, meta, ofd, handle, f);
error = fm_->create(api_path, meta, ofd, handle, file);
}
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
if (handle != 0U) {
error = api_error::invalid_handle;
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
error = f->native_operation([&](native_handle op_handle) {
if (not ::FlushFileBuffers(op_handle)) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
error = file->native_operation([&](native_handle op_handle) {
if (::FlushFileBuffers(op_handle) == 0) {
return api_error::os_error;
}
@ -336,7 +337,7 @@ auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
// Populate file information
api_meta_map meta;
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
api_meta_map meta;
if ((error = provider_.get_item_meta(api_path, meta)) ==
api_error::success) {
populate_file_info(f->get_file_size(), meta, *file_info);
error = provider_.get_item_meta(api_path, meta);
if (error == api_error::success) {
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{};
auto error = provider_.get_item_meta(api_path, meta);
if (error == api_error::success) {
if (attributes) {
if (attributes != nullptr) {
*attributes = utils::get_attributes_from_meta(meta);
}
if (descriptor_size) {
ULONG sz{};
PSECURITY_DESCRIPTOR sd{};
if (descriptor_size != nullptr) {
ULONG size{};
PSECURITY_DESCRIPTOR sec_desc{};
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sd, &sz)) {
if (sz > *descriptor_size) {
SDDL_REVISION_1, &sec_desc, &size) != 0) {
if (size > *descriptor_size) {
error = api_error::buffer_too_small;
} else {
::CopyMemory(descriptor, sd, sz);
::CopyMemory(descriptor, sec_desc, size);
}
*descriptor_size = sz;
::LocalFree(sd);
*descriptor_size = size;
::LocalFree(sec_desc);
} else {
error = api_error::os_error;
}
@ -456,10 +457,10 @@ auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
SIZE_T *descriptor_size) -> NTSTATUS {
const auto api_path =
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,
sds > 0U ? &sds : nullptr);
if (sds) {
if (sds != 0U) {
*descriptor_size = static_cast<SIZE_T>(sds);
}
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();
volume_info->FreeSize = total_bytes - total_used;
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 =
std::min(static_cast<UINT16>(64),
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);
if (not config_.get_enable_mount_manager()) {
file_system_host->SetPrefix(
&(L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0, 1))[0u]);
(L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0, 1))
.data());
}
file_system_host->SetFileSystemName(REPERTORY_W);
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());
std::unique_ptr<console_consumer> c;
logging_consumer log(config_.get_log_directory(), config_.get_event_level());
std::unique_ptr<console_consumer> cons;
if (enable_console) {
c = std::make_unique<console_consumer>();
cons = std::make_unique<console_consumer>();
}
event_system::instance().start();
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().stop();
c.reset();
cons.reset();
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);
if (error == api_error::success) {
error = api_error::directory_not_found;
if ((create_options & FILE_DIRECTORY_FILE) && not directory) {
if (((create_options & FILE_DIRECTORY_FILE) != 0U) && not directory) {
} else {
error = api_error::success;
if (not directory &&
@ -642,14 +644,14 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
if (error == api_error::success) {
open_file_data ofd{};
std::uint64_t handle{};
std::shared_ptr<i_open_file> f;
error = fm_->open(api_path, directory, ofd, handle, f);
std::shared_ptr<i_open_file> file;
error = fm_->open(api_path, directory, ofd, handle, file);
if (error == api_error::success) {
api_meta_map meta;
if ((error = provider_.get_item_meta(api_path, meta)) ==
api_error::success) {
populate_file_info(f->get_api_path(), f->get_file_size(), meta,
*ofi);
error = provider_.get_item_meta(api_path, meta);
if (error == api_error::success) {
populate_file_info(file->get_api_path(), file->get_file_size(),
meta, *ofi);
*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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, true, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, file)) {
api_path = file->get_api_path();
api_meta_map meta{};
if ((error = provider_.get_item_meta(api_path, meta)) ==
api_error::success) {
error = provider_.get_item_meta(api_path, meta);
if (error == api_error::success) {
error = api_error::file_in_use;
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{};
if ((error = provider_.get_filesystem_item(
api_path, false, existing_fsi)) == api_error::success) {
error =
provider_.get_filesystem_item(api_path, false, existing_fsi);
if (error == api_error::success) {
// Handle replace attributes
if (replace_attributes) {
if (not attributes) {
if (replace_attributes != 0U) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
meta[META_ATTRIBUTES] = std::to_string(attributes);
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 =
utils::get_attributes_from_meta(meta);
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_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, '/', '\\'));
wcscpy_s(ofi.NormalizedName, ofi.NormalizedNameSize / sizeof(WCHAR),
&file_path[0U]);
ofi.NormalizedNameSize = (UINT16)(wcslen(&file_path[0U]) * sizeof(WCHAR));
file_path.data());
ofi.NormalizedNameSize =
static_cast<UINT16>(wcslen(file_path.data()) * sizeof(WCHAR));
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{};
auto ret = provider_.get_item_meta(api_path, meta);
if (ret == api_error::success) {
FSP_FSCTL_FILE_INFO fi{};
populate_file_info(utils::string::to_uint64(meta[META_SIZE]), meta, fi);
set_file_info(file_info, fi);
FSP_FSCTL_FILE_INFO info{};
populate_file_info(utils::string::to_uint64(meta[META_SIZE]), meta, info);
set_file_info(file_info, info);
}
return ret;
@ -753,7 +758,8 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
FSP_FSCTL_FILE_INFO &file_info) {
file_info.FileSize = file_size;
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;
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
if (handle != 0U) {
if (length > 0U) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
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());
if ((length > 0) && (data.size() != length)) {
::SetLastError(ERROR_HANDLE_EOF);
}
if (not data.empty()) {
::CopyMemory(buffer, &data[0U], data.size());
::CopyMemory(buffer, data.data(), data.size());
data.clear();
auto res = provider_.set_item_meta(
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
bool exists{};
error = provider_.is_directory(api_path, exists);
if (error == api_error::success) {
if (exists) {
directory_item_list list{};
if ((error = provider_.get_directory_items(api_path, list)) ==
api_error::success) {
error = provider_.get_directory_items(api_path, list);
if (error == api_error::success) {
directory_iterator iterator(std::move(list));
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(
&directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
&status_result)) {
directory_item di{};
&status_result) != 0U) {
directory_item dir_item{};
auto offset =
marker
? iterator.get_next_directory_offset(
marker == nullptr
? 0U
: iterator.get_next_directory_offset(
utils::path::create_api_path(utils::path::combine(
api_path, {utils::string::to_utf8(marker)})))
: 0U;
while ((error = iterator.get_directory_item(offset++, di)) ==
api_error::success) {
if (utils::path::is_ads_file_path(di.api_path) ||
di.api_path == "." || di.api_path == "..") {
api_path, {utils::string::to_utf8(marker)})));
while ((error = iterator.get_directory_item(
offset++, dir_item)) == api_error::success) {
if (utils::path::is_ads_file_path(dir_item.api_path) ||
dir_item.api_path == "." || dir_item.api_path == "..") {
continue;
}
if (di.meta.empty()) {
utils::error::raise_api_path_error(__FUNCTION__, di.api_path,
api_error::error,
"item meta is empty");
if (dir_item.meta.empty()) {
utils::error::raise_api_path_error(
__FUNCTION__, dir_item.api_path, api_error::error,
"item meta is empty");
continue;
}
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 {
UINT8 B[FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) +
((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));
directory_info->Size = static_cast<UINT16>(
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)));
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,
&display_name[0U]);
display_name.data());
FspFileSystemFillDirectoryBuffer(
&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);
if (error == api_error::success) {
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 {
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);
}
}
}
@ -945,35 +957,36 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
auto error = api_error::invalid_handle;
auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, false, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
if (attributes == INVALID_FILE_ATTRIBUTES) {
attributes = 0;
} else if (attributes == 0) {
attributes = f->is_directory() ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL;
attributes = file->is_directory() ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL;
}
api_meta_map meta;
if (attributes) {
if ((attributes & FILE_ATTRIBUTE_NORMAL) &&
if (attributes != 0U) {
if (((attributes & FILE_ATTRIBUTE_NORMAL) != 0U) &&
(attributes != FILE_ATTRIBUTE_NORMAL)) {
attributes &= ~(FILE_ATTRIBUTE_NORMAL);
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
}
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);
}
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);
}
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);
}
if (change_time && (change_time != 0xFFFFFFFFFFFFFFFF)) {
if ((change_time != 0U) && (change_time != 0xFFFFFFFFFFFFFFFF)) {
meta[META_CHANGED] = 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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, true, f)) {
api_path = f->get_api_path();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, file)) {
api_path = file->get_api_path();
i_open_file::native_operation_callback allocator;
if (set_allocation_size) {
allocator = [&](native_handle handle) -> api_error {
if (set_allocation_size != 0U) {
allocator = [&](native_handle cur_handle) -> api_error {
std::string meta_allocation_size;
utils::calculate_allocation_size(false, 0, new_size,
meta_allocation_size);
FILE_ALLOCATION_INFO allocation_info{};
allocation_info.AllocationSize.QuadPart = new_size;
return ::SetFileInformationByHandle(handle, FileAllocationInfo,
allocation_info.AllocationSize.QuadPart =
static_cast<LONGLONG>(new_size);
return ::SetFileInformationByHandle(cur_handle, FileAllocationInfo,
&allocation_info,
sizeof(allocation_info))
sizeof(allocation_info)) != 0
? api_error::success
: api_error::os_error;
};
} else {
allocator = [&](native_handle handle) -> api_error {
allocator = [&](native_handle cur_handle) -> api_error {
FILE_END_OF_FILE_INFO end_of_file_info{};
end_of_file_info.EndOfFile.QuadPart = new_size;
return ::SetFileInformationByHandle(handle, FileEndOfFileInfo,
end_of_file_info.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
return ::SetFileInformationByHandle(cur_handle, FileEndOfFileInfo,
&end_of_file_info,
sizeof(end_of_file_info))
sizeof(end_of_file_info)) != 0
? api_error::success
: api_error::os_error;
};
}
error = f->native_operation(new_size, allocator);
if (file_info) {
error = file->native_operation(new_size, allocator);
if (file_info != nullptr) {
// Populate file information
api_meta_map meta;
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 handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle) {
std::shared_ptr<i_open_file> f;
if (fm_->get_open_file(handle, true, f)) {
api_path = f->get_api_path();
if (write_to_end) {
offset = f->get_file_size();
if (handle != 0U) {
std::shared_ptr<i_open_file> file;
if (fm_->get_open_file(handle, true, file)) {
api_path = file->get_api_path();
if (write_to_end != 0U) {
offset = file->get_file_size();
}
auto should_write = true;
if (constrained_io) {
if (offset >= f->get_file_size()) {
if (constrained_io != 0U) {
if (offset >= file->get_file_size()) {
error = api_error::success;
should_write = false;
} else if (offset + length > f->get_file_size()) {
length = static_cast<ULONG>(f->get_file_size() - offset);
} else if (offset + length > file->get_file_size()) {
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) {
std::size_t bytes_written{};
data_buffer data(length);
std::memcpy(&data[0U], buffer, length);
if ((error = f->write(offset, data, bytes_written)) ==
api_error::success) {
std::memcpy(data.data(), buffer, length);
error = file->write(offset, data, bytes_written);
if (error == api_error::success) {
*bytes_transferred = static_cast<ULONG>(bytes_written);
// Populate file information
api_meta_map meta;
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);
}
}
}