3 Commits

Author SHA1 Message Date
3d9ed2dfe8 spelling
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2024-11-09 09:17:04 -06:00
c8cc0feae5 winfsp unit tests and fixes 2024-11-09 09:16:17 -06:00
1d53cd8e8b refactor 2024-11-09 07:22:33 -06:00
12 changed files with 520 additions and 401 deletions

View File

@ -170,6 +170,7 @@ pugixml_project
puint32 puint32
pvoid pvoid
pwstr pwstr
rdrw
remote_winfsp remote_winfsp
renterd renterd
richtext richtext

View File

@ -49,9 +49,9 @@ private:
[[nodiscard]] auto get_next_handle() -> std::uint64_t; [[nodiscard]] auto get_next_handle() -> std::uint64_t;
[[nodiscard]] auto [[nodiscard]] auto populate_file_info(const std::string &api_path,
populate_file_info(const std::string &api_path, remote::file_info &file_info)
remote::file_info &file_info) -> packet::error_type; -> packet::error_type;
void populate_file_info(const std::string &api_path, const UINT64 &file_size, void populate_file_info(const std::string &api_path, const UINT64 &file_size,
const UINT32 &attributes, const UINT32 &attributes,
@ -72,14 +72,14 @@ public:
[[nodiscard]] auto fuse_chmod(const char *path, const remote::file_mode &mode) [[nodiscard]] auto fuse_chmod(const char *path, const remote::file_mode &mode)
-> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_chown(const char *path, const remote::user_id &uid,
fuse_chown(const char *path, const remote::user_id &uid, const remote::group_id &gid)
const remote::group_id &gid) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto
fuse_create(const char *path, const remote::file_mode &mode, fuse_create(const char *path, const remote::file_mode &mode,
const remote::open_flags &flags, const remote::open_flags &flags, remote::file_handle &handle)
remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto fuse_destroy() -> packet::error_type override; [[nodiscard]] auto fuse_destroy() -> packet::error_type override;
@ -88,25 +88,28 @@ public:
remote::file_offset &length, const remote::file_handle &handle) override remote::file_offset &length, const remote::file_handle &handle) override
;*/ ;*/
[[nodiscard]] auto fuse_fgetattr( [[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &r_stat,
const char *path, remote::stat &r_stat, bool &directory, bool &directory,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto fuse_fsetattr_x( [[nodiscard]] auto fuse_fsetattr_x(const char *path,
const char *path, const remote::setattr_x &attr, const remote::setattr_x &attr,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_fsync(const char *path, const std::int32_t &datasync,
fuse_fsync(const char *path, const std::int32_t &datasync, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto fuse_ftruncate( [[nodiscard]] auto fuse_ftruncate(const char *path,
const char *path, const remote::file_offset &size, const remote::file_offset &size,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_getattr(const char *path, remote::stat &r_stat,
fuse_getattr(const char *path, remote::stat &r_stat, bool &directory)
bool &directory) -> packet::error_type override; -> packet::error_type override;
/*[[nodiscard]] packet::error_type fuse_getxattr(const char *path, const char /*[[nodiscard]] packet::error_type fuse_getxattr(const char *path, const char
*name, char *value, const remote::file_size &size) override ; *name, char *value, const remote::file_size &size) override ;
@ -115,9 +118,10 @@ public:
*name, char *value, const remote::file_size &size, std::uint32_t position) *name, char *value, const remote::file_size &size, std::uint32_t position)
override ;*/ override ;*/
[[nodiscard]] auto [[nodiscard]] auto fuse_getxtimes(const char *path,
fuse_getxtimes(const char *path, remote::file_time &bkuptime, remote::file_time &bkuptime,
remote::file_time &crtime) -> packet::error_type override; remote::file_time &crtime)
-> packet::error_type override;
[[nodiscard]] auto fuse_init() -> packet::error_type override; [[nodiscard]] auto fuse_init() -> packet::error_type override;
@ -125,28 +129,30 @@ public:
*buffer, const remote::file_size &size) override ;*/ *buffer, const remote::file_size &size) override ;*/
[[nodiscard]] auto [[nodiscard]] auto
fuse_mkdir(const char *path, fuse_mkdir(const char *path, const remote::file_mode &mode)
const remote::file_mode &mode) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_open(const char *path,
fuse_open(const char *path, const remote::open_flags &flags, const remote::open_flags &flags,
remote::file_handle &handle) -> packet::error_type override; remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto fuse_opendir(const char *path, remote::file_handle &handle) [[nodiscard]] auto fuse_opendir(const char *path, remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_read(const char *path, char *buffer,
fuse_read(const char *path, char *buffer, const remote::file_size &read_size, const remote::file_size &read_size,
const remote::file_offset &read_offset, const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto fuse_rename(const char *from, [[nodiscard]] auto fuse_rename(const char *from, const char *to)
const char *to) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto
fuse_readdir(const char *path, const remote::file_offset &offset, fuse_readdir(const char *path, const remote::file_offset &offset,
const remote::file_handle &handle, const remote::file_handle &handle, std::string &item_path)
std::string &item_path) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto fuse_release(const char *path, [[nodiscard]] auto fuse_release(const char *path,
const remote::file_handle &handle) const remote::file_handle &handle)
@ -160,8 +166,8 @@ public:
* char *name) override * char *name) override
* ;*/ * ;*/
[[nodiscard]] auto [[nodiscard]] auto fuse_rmdir(const char *path)
fuse_rmdir(const char *path) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto fuse_setattr_x(const char *path, remote::setattr_x &attr) [[nodiscard]] auto fuse_setattr_x(const char *path, remote::setattr_x &attr)
-> packet::error_type override; -> packet::error_type override;
@ -178,8 +184,8 @@ public:
const remote::file_time &crtime) const remote::file_time &crtime)
-> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_setvolname(const char *volname)
fuse_setvolname(const char *volname) -> packet::error_type override; -> packet::error_type override;
/*[[nodiscard]] packet::error_type fuse_setxattr(const char *path, const char /*[[nodiscard]] packet::error_type fuse_setxattr(const char *path, const char
*name, const char *value, const remote::file_size &size, const std::int32_t *name, const char *value, const remote::file_size &size, const std::int32_t
@ -189,67 +195,70 @@ public:
char *name, const char *value, const remote::file_size &size, const char *name, const char *value, const remote::file_size &size, const
std::int32_t &flags, std::uint32_t position) override ;*/ std::int32_t &flags, std::uint32_t position) override ;*/
[[nodiscard]] auto [[nodiscard]] auto fuse_statfs(const char *path, std::uint64_t frsize,
fuse_statfs(const char *path, std::uint64_t frsize, remote::statfs &r_stat)
remote::statfs &r_stat) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_statfs_x(const char *path, std::uint64_t bsize,
fuse_statfs_x(const char *path, std::uint64_t bsize, remote::statfs_x &r_stat)
remote::statfs_x &r_stat) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_truncate(const char *path,
fuse_truncate(const char *path, const remote::file_offset &size)
const remote::file_offset &size) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_unlink(const char *path)
fuse_unlink(const char *path) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_utimens(const char *path, const remote::file_time *tv,
fuse_utimens(const char *path, const remote::file_time *tv, std::uint64_t op0, std::uint64_t op0, std::uint64_t op1)
std::uint64_t op1) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto fuse_write(const char *path, const char *buffer,
fuse_write(const char *path, const char *buffer, const remote::file_size &write_size,
const remote::file_size &write_size, const remote::file_offset &write_offset,
const remote::file_offset &write_offset, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto fuse_write_base64( [[nodiscard]] auto fuse_write_base64(const char *path, const char *buffer,
const char *path, const char *buffer, const remote::file_size &write_size, const remote::file_size &write_size,
const remote::file_offset &write_offset, const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
void set_fuse_uid_gid(const remote::user_id &, void set_fuse_uid_gid(const remote::user_id &,
const remote::group_id &) override {} const remote::group_id &) override {}
// JSON Layer // JSON Layer
[[nodiscard]] auto [[nodiscard]] auto winfsp_get_dir_buffer(PVOID /*file_desc*/,
winfsp_get_dir_buffer(PVOID /*file_desc*/, PVOID *& /*ptr*/)
PVOID *& /*ptr*/) -> packet::error_type override { -> packet::error_type override {
return static_cast<packet::error_type>(STATUS_INVALID_HANDLE); return static_cast<packet::error_type>(STATUS_INVALID_HANDLE);
} }
[[nodiscard]] auto json_create_directory_snapshot( [[nodiscard]] auto json_create_directory_snapshot(const std::string &path,
const std::string &path, json &json_data) -> packet::error_type override; json &json_data)
-> packet::error_type override;
[[nodiscard]] auto json_read_directory_snapshot( [[nodiscard]] auto json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle, const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type override; std::uint32_t page, json &json_data) -> packet::error_type override;
[[nodiscard]] auto json_release_directory_snapshot( [[nodiscard]] auto
const std::string &path, json_release_directory_snapshot(const std::string &path,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
// WinFSP Layer // WinFSP Layer
[[nodiscard]] auto winfsp_can_delete(PVOID file_desc, PWSTR file_name) [[nodiscard]] auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
-> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_cleanup(PVOID file_desc, PWSTR file_name,
winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags, UINT32 flags, BOOLEAN &was_deleted)
BOOLEAN &was_closed) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_close(PVOID file_desc)
winfsp_close(PVOID file_desc) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto
winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access, winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
@ -264,57 +273,63 @@ public:
remote::file_info *file_info) remote::file_info *file_info)
-> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto winfsp_get_security_by_name(
PWSTR file_name, PUINT32 attributes,
std::uint64_t * /*security_descriptor_size*/,
std::wstring & /*str_descriptor*/) -> packet::error_type override;
[[nodiscard]] auto winfsp_get_volume_info(
UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto
winfsp_mounted(const std::wstring &location) -> packet::error_type override; winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
std::uint64_t * /*security_descriptor_size*/,
std::wstring & /*str_descriptor*/)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_get_volume_info(UINT64 &total_size,
winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT64 &free_size,
PVOID *file_desc, remote::file_info *file_info, std::string &volume_label)
std::string &normalized_name) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_mounted(const std::wstring &location)
winfsp_overwrite(PVOID file_desc, UINT32 attributes, -> packet::error_type override;
BOOLEAN replace_attributes, UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_open(PWSTR file_name, UINT32 create_options,
winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 granted_access, PVOID *file_desc,
PUINT32 bytes_transferred) -> packet::error_type override; remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, PWSTR marker, BOOLEAN replace_attributes,
json &itemList) -> packet::error_type override; UINT64 /*allocation_size*/,
remote::file_info *file_info)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
winfsp_rename(PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name, UINT32 length, PUINT32 bytes_transferred)
BOOLEAN replace_if_exists) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
PWSTR marker, json &itemList)
-> packet::error_type override;
[[nodiscard]] auto winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists)
-> packet::error_type override;
[[nodiscard]] auto winfsp_set_basic_info( [[nodiscard]] auto 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 override; remote::file_info *file_info) -> packet::error_type override;
[[nodiscard]] auto winfsp_set_file_size( [[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type override; remote::file_info *file_info)
-> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto winfsp_unmounted(const std::wstring &location)
winfsp_unmounted(const std::wstring &location) -> packet::error_type override; -> packet::error_type override;
[[nodiscard]] auto [[nodiscard]] auto
winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
BOOLEAN write_to_end, BOOLEAN constrained_io, BOOLEAN write_to_end, BOOLEAN constrained_io,
PUINT32 bytes_transferred, PUINT32 bytes_transferred, remote::file_info *file_info)
remote::file_info *file_info) -> packet::error_type override; -> packet::error_type override;
}; };
} // namespace remote_fuse } // namespace remote_fuse
} // namespace repertory } // namespace repertory

View File

@ -85,10 +85,10 @@ public:
UINT32 flags{}; UINT32 flags{};
DECODE_OR_RETURN(request, flags); DECODE_OR_RETURN(request, flags);
BOOLEAN was_closed{}; BOOLEAN was_deleted{};
ret = this->winfsp_cleanup(file_desc, file_name.data(), flags, ret = this->winfsp_cleanup(file_desc, file_name.data(), flags,
was_closed); was_deleted);
response.encode(was_closed); response.encode(was_deleted);
return ret; return ret;
}}); }});

View File

@ -29,11 +29,11 @@ class i_remote_instance : public virtual i_remote_json {
INTERFACE_SETUP(i_remote_instance); INTERFACE_SETUP(i_remote_instance);
public: public:
virtual auto winfsp_can_delete(PVOID file_desc, virtual auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags, virtual auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type = 0; BOOLEAN &was_deleted) -> packet::error_type = 0;
virtual auto winfsp_close(PVOID file_desc) -> packet::error_type = 0; virtual auto winfsp_close(PVOID file_desc) -> packet::error_type = 0;
@ -41,72 +41,76 @@ public:
UINT32 granted_access, UINT32 file_attributes, UINT32 granted_access, UINT32 file_attributes,
UINT64 allocation_size, PVOID *file_desc, UINT64 allocation_size, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name, std::string &normalized_name, BOOLEAN &exists)
BOOLEAN &exists) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto winfsp_flush(PVOID file_desc, remote::file_info *file_info) virtual auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type = 0; -> packet::error_type = 0;
virtual auto winfsp_get_dir_buffer(PVOID file_desc, virtual auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
PVOID *&ptr) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto winfsp_get_file_info(PVOID file_desc,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto virtual auto
winfsp_get_file_info(PVOID file_desc, winfsp_get_security_by_name(PWSTR file_name, PUINT32 file_attributes,
remote::file_info *file_info) -> packet::error_type = 0; std::uint64_t *security_descriptor_size,
std::wstring &str_descriptor)
-> packet::error_type = 0;
virtual auto winfsp_get_security_by_name( virtual auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
PWSTR file_name, PUINT32 file_attributes, std::string &volume_label)
std::uint64_t *security_descriptor_size, -> packet::error_type = 0;
std::wstring &str_descriptor) -> packet::error_type = 0;
virtual auto virtual auto winfsp_mounted(const std::wstring &location)
winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size, -> packet::error_type = 0;
std::string &volume_label) -> packet::error_type = 0;
virtual auto virtual auto winfsp_open(PWSTR file_name, UINT32 create_options,
winfsp_mounted(const std::wstring &location) -> packet::error_type = 0; UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type = 0;
virtual auto virtual auto winfsp_overwrite(PVOID file_desc, UINT32 file_attributes,
winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access, BOOLEAN replace_file_attributes,
PVOID *file_desc, remote::file_info *file_info, UINT64 allocation_size,
std::string &normalized_name) -> packet::error_type = 0; remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto
winfsp_overwrite(PVOID file_desc, UINT32 file_attributes,
BOOLEAN replace_file_attributes, UINT64 allocation_size,
remote::file_info *file_info) -> packet::error_type = 0;
virtual auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, virtual auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, UINT32 length, PUINT32 bytes_transferred)
PUINT32 bytes_transferred) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto winfsp_read_directory(PVOID file_desc, PWSTR pattern, virtual auto winfsp_read_directory(PVOID file_desc, PWSTR pattern,
PWSTR marker, PWSTR marker, json &itemList)
json &itemList) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto virtual auto winfsp_rename(PVOID file_desc, PWSTR file_name,
winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name, PWSTR new_file_name, BOOLEAN replace_if_exists)
BOOLEAN replace_if_exists) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto virtual auto winfsp_set_basic_info(PVOID file_desc, UINT32 file_attributes,
winfsp_set_basic_info(PVOID file_desc, UINT32 file_attributes, UINT64 creation_time,
UINT64 creation_time, UINT64 last_access_time, UINT64 last_access_time,
UINT64 last_write_time, UINT64 change_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type = 0; remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto virtual auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
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 = 0; -> packet::error_type = 0;
virtual auto virtual auto winfsp_unmounted(const std::wstring &location)
winfsp_unmounted(const std::wstring &location) -> packet::error_type = 0; -> packet::error_type = 0;
virtual auto virtual auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 length, BOOLEAN write_to_end,
BOOLEAN write_to_end, BOOLEAN constrained_io, BOOLEAN constrained_io, PUINT32 bytes_transferred,
PUINT32 bytes_transferred, remote::file_info *file_info)
remote::file_info *file_info) -> packet::error_type = 0; -> packet::error_type = 0;
}; };
using remote_instance_factory = using remote_instance_factory =

View File

@ -50,19 +50,20 @@ public:
auto json_create_directory_snapshot(const std::string &path, json &json_data) auto json_create_directory_snapshot(const std::string &path, json &json_data)
-> packet::error_type override; -> packet::error_type override;
auto json_read_directory_snapshot( auto json_read_directory_snapshot(const std::string &path,
const std::string &path, const remote::file_handle &handle, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type override; std::uint32_t page, json &json_data)
-> packet::error_type override;
auto json_release_directory_snapshot(const std::string &path, auto json_release_directory_snapshot(const std::string &path,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
auto winfsp_can_delete(PVOID file_desc, auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type override; -> packet::error_type override;
auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags, auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type override; BOOLEAN &was_deleted) -> packet::error_type override;
auto winfsp_close(PVOID file_desc) -> packet::error_type override; auto winfsp_close(PVOID file_desc) -> packet::error_type override;
@ -75,32 +76,33 @@ public:
auto winfsp_flush(PVOID file_desc, remote::file_info *file_info) auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type override; -> packet::error_type override;
auto winfsp_get_dir_buffer(PVOID file_desc, auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
PVOID *&ptr) -> packet::error_type override; -> packet::error_type override;
auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type override; -> packet::error_type override;
auto winfsp_get_security_by_name( auto winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
PWSTR file_name, PUINT32 attributes, std::uint64_t *descriptor_size, std::uint64_t *descriptor_size,
std::wstring &string_descriptor) -> packet::error_type override; std::wstring &string_descriptor)
-> packet::error_type override;
auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size, auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) std::string &volume_label)
-> packet::error_type override; -> packet::error_type override;
auto auto winfsp_mounted(const std::wstring &location)
winfsp_mounted(const std::wstring &location) -> packet::error_type override; -> packet::error_type override;
auto winfsp_open(PWSTR file_name, UINT32 create_options, auto winfsp_open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID *file_desc, UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info, std::string &normalized_name)
std::string &normalized_name) -> packet::error_type override; -> packet::error_type override;
auto auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
winfsp_overwrite(PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, UINT64 allocation_size,
BOOLEAN replace_attributes, UINT64 allocation_size, remote::file_info *file_info)
remote::file_info *file_info) -> packet::error_type override; -> packet::error_type override;
auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
PUINT32 bytes_transferred) -> packet::error_type override; PUINT32 bytes_transferred) -> packet::error_type override;
@ -111,23 +113,24 @@ public:
auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name, auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type override; BOOLEAN replace_if_exists) -> packet::error_type override;
auto winfsp_set_basic_info( auto winfsp_set_basic_info(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, UINT64 creation_time, UINT64 creation_time, UINT64 last_access_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type override; remote::file_info *file_info)
-> packet::error_type override;
auto winfsp_set_file_size( auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type override; remote::file_info *file_info)
-> packet::error_type override;
auto auto winfsp_unmounted(const std::wstring &location)
winfsp_unmounted(const std::wstring &location) -> packet::error_type override; -> packet::error_type override;
auto auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, BOOLEAN write_to_end, BOOLEAN constrained_io,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, remote::file_info *file_info)
PUINT32 bytes_transferred, -> packet::error_type override;
remote::file_info *file_info) -> packet::error_type override;
}; };
} // namespace remote_winfsp } // namespace remote_winfsp
} // namespace repertory } // namespace repertory

View File

@ -49,23 +49,23 @@ private:
[[nodiscard]] auto get_next_handle() -> std::uint64_t; [[nodiscard]] auto get_next_handle() -> std::uint64_t;
[[nodiscard]] auto [[nodiscard]] auto populate_file_info(const std::string &api_path,
populate_file_info(const std::string &api_path, 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 &r_stat, void populate_stat(const char *path, bool directory, remote::stat &r_stat,
const struct _stat64 &unix_st); const struct _stat64 &unix_st);
public: public:
// FUSE Layer // FUSE Layer
auto fuse_access(const char *path, auto fuse_access(const char *path, const std::int32_t &mask)
const std::int32_t &mask) -> packet::error_type override; -> packet::error_type override;
auto fuse_chflags(const char *path, auto fuse_chflags(const char *path, std::uint32_t flags)
std::uint32_t flags) -> packet::error_type override; -> packet::error_type override;
auto fuse_chmod(const char *path, auto fuse_chmod(const char *path, const remote::file_mode &mode)
const remote::file_mode &mode) -> packet::error_type override; -> packet::error_type override;
auto fuse_chown(const char *path, const remote::user_id &uid, auto fuse_chown(const char *path, const remote::user_id &uid,
const remote::group_id &gid) -> packet::error_type override; const remote::group_id &gid) -> packet::error_type override;
@ -84,16 +84,16 @@ public:
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
auto auto fuse_fsync(const char *path, const std::int32_t &datasync,
fuse_fsync(const char *path, const std::int32_t &datasync, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
auto fuse_ftruncate(const char *path, const remote::file_offset &size, auto fuse_ftruncate(const char *path, const remote::file_offset &size,
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 &r_stat, auto fuse_getattr(const char *path, remote::stat &r_stat, bool &directory)
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
*value, const remote::file_size &size) override ; *value, const remote::file_size &size) override ;
@ -110,41 +110,43 @@ public:
const remote::file_size &size) override const remote::file_size &size) override
;*/ ;*/
auto fuse_mkdir(const char *path, auto fuse_mkdir(const char *path, const remote::file_mode &mode)
const remote::file_mode &mode) -> packet::error_type override; -> packet::error_type override;
auto fuse_opendir(const char *path, auto fuse_opendir(const char *path, remote::file_handle &handle)
remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
auto fuse_create(const char *path, const remote::file_mode &mode, auto fuse_create(const char *path, const remote::file_mode &mode,
const remote::open_flags &flags, const remote::open_flags &flags, remote::file_handle &handle)
remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
auto fuse_open(const char *path, const remote::open_flags &flags, auto fuse_open(const char *path, const remote::open_flags &flags,
remote::file_handle &handle) -> packet::error_type override; remote::file_handle &handle) -> packet::error_type override;
auto auto fuse_read(const char *path, char *buffer,
fuse_read(const char *path, char *buffer, const remote::file_size &read_size, const remote::file_size &read_size,
const remote::file_offset &read_offset, const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
auto fuse_rename(const char *from, auto fuse_rename(const char *from, const char *to)
const char *to) -> packet::error_type override; -> packet::error_type override;
auto auto fuse_write(const char *path, const char *buffer,
fuse_write(const char *path, const char *buffer, const remote::file_size &write_size,
const remote::file_size &write_size, const remote::file_offset &write_offset,
const remote::file_offset &write_offset, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type override; -> packet::error_type override;
auto fuse_write_base64( auto fuse_write_base64(const char *path, const char *buffer,
const char *path, const char *buffer, const remote::file_size &write_size, const remote::file_size &write_size,
const remote::file_offset &write_offset, const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type override; const remote::file_handle &handle)
-> packet::error_type override;
auto fuse_readdir(const char *path, const remote::file_offset &offset, auto fuse_readdir(const char *path, const remote::file_offset &offset,
const remote::file_handle &handle, const remote::file_handle &handle, std::string &item_path)
std::string &item_path) -> packet::error_type override; -> packet::error_type override;
auto fuse_release(const char *path, const remote::file_handle &handle) auto fuse_release(const char *path, const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
@ -157,8 +159,8 @@ public:
auto fuse_rmdir(const char *path) -> packet::error_type override; auto fuse_rmdir(const char *path) -> packet::error_type override;
auto fuse_setattr_x(const char *path, auto fuse_setattr_x(const char *path, remote::setattr_x &attr)
remote::setattr_x &attr) -> packet::error_type override; -> packet::error_type override;
auto fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) auto fuse_setbkuptime(const char *path, const remote::file_time &bkuptime)
-> packet::error_type override; -> packet::error_type override;
@ -191,8 +193,8 @@ public:
auto fuse_unlink(const char *path) -> packet::error_type override; auto fuse_unlink(const char *path) -> packet::error_type override;
auto fuse_utimens(const char *path, const remote::file_time *tv, auto fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op0, std::uint64_t op1)
std::uint64_t op1) -> packet::error_type override; -> packet::error_type override;
void set_fuse_uid_gid(const remote::user_id & /* uid */, void set_fuse_uid_gid(const remote::user_id & /* uid */,
const remote::group_id & /* gid */) override {} const remote::group_id & /* gid */) override {}
@ -201,20 +203,21 @@ public:
auto json_create_directory_snapshot(const std::string &path, json &json_data) auto json_create_directory_snapshot(const std::string &path, json &json_data)
-> packet::error_type override; -> packet::error_type override;
auto json_read_directory_snapshot( auto json_read_directory_snapshot(const std::string &path,
const std::string &path, const remote::file_handle &handle, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type override; std::uint32_t page, json &json_data)
-> packet::error_type override;
auto json_release_directory_snapshot(const std::string &path, auto json_release_directory_snapshot(const std::string &path,
const remote::file_handle &handle) const remote::file_handle &handle)
-> packet::error_type override; -> packet::error_type override;
// WinFSP Layer // WinFSP Layer
auto winfsp_can_delete(PVOID file_desc, auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type override; -> packet::error_type override;
auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags, auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type override; BOOLEAN &was_deleted) -> packet::error_type override;
auto winfsp_close(PVOID file_desc) -> packet::error_type override; auto winfsp_close(PVOID file_desc) -> packet::error_type override;
@ -227,32 +230,33 @@ public:
auto winfsp_flush(PVOID file_desc, remote::file_info *file_info) auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type override; -> packet::error_type override;
auto winfsp_get_dir_buffer(PVOID file_desc, auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
PVOID *&ptr) -> packet::error_type override; -> packet::error_type override;
auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type override; -> packet::error_type override;
auto winfsp_get_security_by_name( auto winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
PWSTR file_name, PUINT32 attributes, std::uint64_t *descriptor_size, std::uint64_t *descriptor_size,
std::wstring &string_descriptor) -> packet::error_type override; std::wstring &string_descriptor)
-> packet::error_type override;
auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size, auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) std::string &volume_label)
-> packet::error_type override; -> packet::error_type override;
auto auto winfsp_mounted(const std::wstring &location)
winfsp_mounted(const std::wstring &location) -> packet::error_type override; -> packet::error_type override;
auto winfsp_open(PWSTR file_name, UINT32 create_options, auto winfsp_open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID *file_desc, UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info, std::string &normalized_name)
std::string &normalized_name) -> packet::error_type override; -> packet::error_type override;
auto auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
winfsp_overwrite(PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, UINT64 allocation_size,
BOOLEAN replace_attributes, UINT64 allocation_size, remote::file_info *file_info)
remote::file_info *file_info) -> packet::error_type override; -> packet::error_type override;
auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
PUINT32 bytes_transferred) -> packet::error_type override; PUINT32 bytes_transferred) -> packet::error_type override;
@ -263,23 +267,24 @@ public:
auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name, auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type override; BOOLEAN replace_if_exists) -> packet::error_type override;
auto winfsp_set_basic_info( auto winfsp_set_basic_info(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, UINT64 creation_time, UINT64 creation_time, UINT64 last_access_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type override; remote::file_info *file_info)
-> packet::error_type override;
auto winfsp_set_file_size( auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type override; remote::file_info *file_info)
-> packet::error_type override;
auto auto winfsp_unmounted(const std::wstring &location)
winfsp_unmounted(const std::wstring &location) -> packet::error_type override; -> packet::error_type override;
auto auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, BOOLEAN write_to_end, BOOLEAN constrained_io,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, remote::file_info *file_info)
PUINT32 bytes_transferred, -> packet::error_type override;
remote::file_info *file_info) -> packet::error_type override;
}; };
} // namespace remote_winfsp } // namespace remote_winfsp
} // namespace repertory } // namespace repertory

View File

@ -1041,18 +1041,18 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
} }
auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name, auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
UINT32 flags, BOOLEAN &was_closed) UINT32 flags, BOOLEAN &was_deleted)
-> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
const auto file_path = construct_path(relative_path); const auto file_path = construct_path(relative_path);
was_closed = 0; was_deleted = 0U;
const auto directory = utils::file::directory(file_path).exists(); const auto directory = utils::file::directory(file_path).exists();
if (flags & FileSystemBase::FspCleanupDelete) { if (flags & FileSystemBase::FspCleanupDelete) {
remove_all(file_path); remove_all(file_path);
was_closed = 1; was_deleted = 1U;
if (directory) { if (directory) {
rmdir(file_path.c_str()); rmdir(file_path.c_str());

View File

@ -136,7 +136,7 @@ auto remote_client::json_release_directory_snapshot(
} }
auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name, auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
UINT32 flags, BOOLEAN &was_closed) UINT32 flags, BOOLEAN &was_deleted)
-> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
@ -148,7 +148,7 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
get_open_file_path(handle), get_open_file_path(handle),
}; };
was_closed = 0; was_deleted = 0U;
packet request; packet request;
request.encode(file_desc); request.encode(file_desc);
@ -161,8 +161,8 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
packet_client_.send(function_name, request, response, service_flags), packet_client_.send(function_name, request, response, service_flags),
}; };
DECODE_OR_IGNORE(&response, was_closed); DECODE_OR_IGNORE(&response, was_deleted);
if (was_closed != 0U) { if (was_deleted != 0U) {
remove_all(file_path); remove_all(file_path);
} }

View File

@ -936,18 +936,18 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
} }
auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/, auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
UINT32 flags, BOOLEAN &was_closed) UINT32 flags, BOOLEAN &was_deleted)
-> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = get_open_file_path(file_desc); auto file_path = get_open_file_path(file_desc);
was_closed = FALSE; was_deleted = FALSE;
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 ((flags & FspCleanupDelete) != 0U) { if ((flags & FspCleanupDelete) != 0U) {
remove_and_close_all(file_desc); remove_and_close_all(file_desc);
was_closed = TRUE; was_deleted = TRUE;
} }
} }

View File

@ -114,8 +114,8 @@ auto remote_winfsp_drive::CanDelete(PVOID /*file_node*/, PVOID file_desc,
VOID remote_winfsp_drive::Cleanup(PVOID /*file_node*/, PVOID file_desc, VOID remote_winfsp_drive::Cleanup(PVOID /*file_node*/, PVOID file_desc,
PWSTR file_name, ULONG flags) { PWSTR file_name, ULONG flags) {
BOOLEAN was_closed{}; BOOLEAN was_deleted{};
remote_instance_->winfsp_cleanup(file_desc, file_name, flags, was_closed); remote_instance_->winfsp_cleanup(file_desc, file_name, flags, was_deleted);
} }
VOID remote_winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) { VOID remote_winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {

View File

@ -102,10 +102,10 @@ static void cleanup_test(remote_client &client) {
normalized_name, exists); normalized_name, exists);
EXPECT_EQ(STATUS_SUCCESS, ret); EXPECT_EQ(STATUS_SUCCESS, ret);
BOOLEAN was_closed = 0u; BOOLEAN was_deleted{0U};
EXPECT_EQ(STATUS_SUCCESS, EXPECT_EQ(STATUS_SUCCESS,
client.winfsp_cleanup(file_desc, &api_path[0], 0, was_closed)); client.winfsp_cleanup(file_desc, &api_path[0], 0, was_deleted));
EXPECT_FALSE(was_closed); EXPECT_FALSE(was_deleted);
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::file(test_file).remove()); EXPECT_TRUE(utils::file::file(test_file).remove());

View File

@ -19,7 +19,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <array>
#if defined(_WIN32) #if defined(_WIN32)
// //
@ -31,7 +30,20 @@
namespace repertory { namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types); TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
static void test_file(auto &&file_path, auto &&flags) { static void test_file(auto mount_location, auto &&file_path, auto &&flags) {
SYSTEM_INFO sys_info{};
::GetSystemInfo(&sys_info);
DWORD bytes_per_sector{};
DWORD free_clusters{};
DWORD sectors_per_cluster{};
DWORD total_clusters{};
EXPECT_TRUE(::GetDiskFreeSpaceA(mount_location.c_str(), &sectors_per_cluster,
&bytes_per_sector, &free_clusters,
&total_clusters));
const auto buffer_size = 16U * sys_info.dwPageSize;
auto write_buffer = utils::generate_secure_random<data_buffer>(buffer_size);
auto handle = auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE, ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW,
@ -39,127 +51,121 @@ static void test_file(auto &&file_path, auto &&flags) {
ASSERT_NE(INVALID_HANDLE_VALUE, handle); ASSERT_NE(INVALID_HANDLE_VALUE, handle);
auto pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN); auto pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0, pointer); EXPECT_EQ(0U, pointer);
auto write_buffer = utils::generate_secure_random<data_buffer>(16U);
DWORD bytes_written{}; DWORD bytes_written{};
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), write_buffer.size(), EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), bytes_per_sector,
&bytes_written, nullptr)); &bytes_written, nullptr));
EXPECT_EQ(bytes_per_sector, bytes_written);
EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_written);
EXPECT_EQ(pointer + bytes_written, EXPECT_EQ(pointer + bytes_written,
::SetFilePointer(handle, 0, 0, FILE_CURRENT)); ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
pointer = ::SetFilePointer(handle, 2U * write_buffer.size(), 0, FILE_BEGIN); pointer = ::SetFilePointer(handle, 2U * bytes_per_sector, 0, FILE_BEGIN);
EXPECT_EQ(static_cast<DWORD>(2U * write_buffer.size()), pointer); EXPECT_EQ(2U * bytes_per_sector, pointer);
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), bytes_per_sector,
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), write_buffer.size(), &bytes_written, 0));
&bytes_written, nullptr)); EXPECT_EQ(bytes_per_sector, bytes_written);
EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_written);
EXPECT_EQ(pointer + bytes_written, EXPECT_EQ(pointer + bytes_written,
::SetFilePointer(handle, 0, 0, FILE_CURRENT)); ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN); pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer); EXPECT_EQ(0U, pointer);
data_buffer read_buffer{};
read_buffer.resize(buffer_size);
DWORD bytes_read{}; DWORD bytes_read{};
std::array<std::uint8_t, 16U> read_buffer{}; EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), bytes_per_sector,
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), read_buffer.size(),
&bytes_read, nullptr)); &bytes_read, nullptr));
EXPECT_EQ(bytes_per_sector, bytes_read);
EXPECT_EQ(static_cast<DWORD>(16U), bytes_read);
EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT)); EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0, EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read)); std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
for (auto idx = 0U; idx < 2U; ++idx) { for (auto idx = 0; idx < 2; ++idx) {
pointer = ::SetFilePointer(handle, 2U * write_buffer.size(), 0, FILE_BEGIN); read_buffer.clear();
EXPECT_EQ(2U * write_buffer.size(), pointer); read_buffer.resize(buffer_size);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), read_buffer.size(), pointer = ::SetFilePointer(handle, 2U * bytes_per_sector, 0, FILE_BEGIN);
&bytes_read, nullptr)); EXPECT_EQ(2U * bytes_per_sector, pointer);
EXPECT_EQ(static_cast<DWORD>(16U), bytes_read); EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), bytes_per_sector,
&bytes_read, 0));
EXPECT_EQ(bytes_per_sector, bytes_read);
EXPECT_EQ(pointer + bytes_read, EXPECT_EQ(pointer + bytes_read,
::SetFilePointer(handle, 0, 0, FILE_CURRENT)); ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0, EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read)); std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
} }
pointer = ::SetFilePointer(handle, 3U * write_buffer.size(), 0, FILE_BEGIN); read_buffer.clear();
EXPECT_EQ(3U * write_buffer.size(), pointer); read_buffer.resize(buffer_size);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), read_buffer.size(), pointer = ::SetFilePointer(handle, 3U * bytes_per_sector, 0, FILE_BEGIN);
EXPECT_EQ(3U * bytes_per_sector, pointer);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), bytes_per_sector,
&bytes_read, nullptr)); &bytes_read, nullptr));
EXPECT_EQ(static_cast<DWORD>(16U), bytes_read); EXPECT_EQ(0U, bytes_read);
EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), 2U * sys_info.dwPageSize,
&bytes_written, nullptr));
EXPECT_EQ(2U * sys_info.dwPageSize, bytes_written);
EXPECT_EQ(pointer + bytes_written,
::SetFilePointer(handle, 0, 0, FILE_CURRENT));
read_buffer.clear();
read_buffer.resize(buffer_size);
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), 2U * sys_info.dwPageSize,
&bytes_read, 0U));
EXPECT_EQ(2U * sys_info.dwPageSize, bytes_read);
EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
write_buffer = utils::generate_secure_random<data_buffer>(buffer_size);
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), 2U * sys_info.dwPageSize,
&bytes_written, nullptr));
EXPECT_EQ(2U * sys_info.dwPageSize, bytes_written);
EXPECT_EQ(pointer + bytes_written,
::SetFilePointer(handle, 0, 0, FILE_CURRENT));
read_buffer.clear();
read_buffer.resize(buffer_size);
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), 2U * sys_info.dwPageSize,
&bytes_read, nullptr));
EXPECT_EQ(2U * sys_info.dwPageSize, bytes_read);
EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(),
2U * sys_info.dwPageSize + bytes_per_sector,
&bytes_written, nullptr));
EXPECT_EQ(2U * sys_info.dwPageSize + bytes_per_sector, bytes_written);
EXPECT_EQ(pointer + bytes_written,
::SetFilePointer(handle, 0, 0, FILE_CURRENT));
read_buffer.clear();
read_buffer.resize(buffer_size);
pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(),
2U * sys_info.dwPageSize + bytes_per_sector,
&bytes_read, nullptr));
EXPECT_EQ(2U * sys_info.dwPageSize + bytes_per_sector, bytes_read);
EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT)); EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
EXPECT_EQ(0, EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read)); std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// Success = WriteFile(Handle, Buffer[0], 2 * SystemInfo.dwPageSize,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
//
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// memset(AllocBuffer[1], 0, AllocBufferSize);
// Success = ReadFile(Handle, Buffer[1], 2 * SystemInfo.dwPageSize,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
// ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred));
//
// Buffer[0] = AllocBuffer[0];
// Buffer[1] = AllocBuffer[0];
//
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// Success = WriteFile(Handle, Buffer[0], 2 * SystemInfo.dwPageSize,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
//
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// memset(AllocBuffer[1], 0, AllocBufferSize);
// Success = ReadFile(Handle, Buffer[1], 2 * SystemInfo.dwPageSize,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
// ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred));
//
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// Success =
// WriteFile(Handle, Buffer[0], 2 * SystemInfo.dwPageSize +
// BytesPerSector,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize + BytesPerSector == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
//
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
// ASSERT(0 == FilePointer);
// memset(AllocBuffer[1], 0, AllocBufferSize);
// Success =
// ReadFile(Handle, Buffer[1], 2 * SystemInfo.dwPageSize + BytesPerSector,
// &BytesTransferred, 0);
// ASSERT(Success);
// ASSERT(2 * SystemInfo.dwPageSize + BytesPerSector == BytesTransferred);
// ASSERT(FilePointer + BytesTransferred ==
// SetFilePointer(Handle, 0, 0, FILE_CURRENT));
// ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred));
//
EXPECT_TRUE(::CloseHandle(handle)); EXPECT_TRUE(::CloseHandle(handle));
handle = ::CreateFileA( handle = ::CreateFileA(
@ -168,46 +174,131 @@ static void test_file(auto &&file_path, auto &&flags) {
FILE_ATTRIBUTE_NORMAL | flags | FILE_FLAG_DELETE_ON_CLOSE, nullptr); FILE_ATTRIBUTE_NORMAL | flags | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
ASSERT_NE(INVALID_HANDLE_VALUE, handle); ASSERT_NE(INVALID_HANDLE_VALUE, handle);
// FilePointer = SetFilePointer(Handle, 0, 0, FILE_BEGIN); read_buffer.clear();
// ASSERT(0 == FilePointer); read_buffer.resize(buffer_size);
// memset(AllocBuffer[1], 0, AllocBufferSize); pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
// Success = EXPECT_EQ(0U, pointer);
// ReadFile(Handle, Buffer[1], 2 * SystemInfo.dwPageSize + BytesPerSector, EXPECT_TRUE(::ReadFile(handle, read_buffer.data(),
// &BytesTransferred, 0); 2U * sys_info.dwPageSize + bytes_per_sector,
// ASSERT(Success); &bytes_read, nullptr));
// ASSERT(2 * SystemInfo.dwPageSize + BytesPerSector == BytesTransferred); EXPECT_EQ(2U * sys_info.dwPageSize + bytes_per_sector, bytes_read);
// ASSERT(FilePointer + BytesTransferred == EXPECT_EQ(pointer + bytes_read, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
// SetFilePointer(Handle, 0, 0, FILE_CURRENT)); EXPECT_EQ(0,
// ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred)); std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
//
EXPECT_TRUE(::CloseHandle(handle)); EXPECT_TRUE(::CloseHandle(handle));
handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE, handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, 0, nullptr); OPEN_EXISTING, 0, nullptr);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle); EXPECT_EQ(INVALID_HANDLE_VALUE, handle);
ASSERT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError()); EXPECT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
}
static void test_append_file(auto mount_location, auto &&file_path,
auto &&flags, bool should_fail = false) {
SYSTEM_INFO sys_info{};
::GetSystemInfo(&sys_info);
DWORD bytes_per_sector{};
DWORD free_clusters{};
DWORD sectors_per_cluster{};
DWORD total_clusters{};
EXPECT_TRUE(::GetDiskFreeSpaceA(mount_location.c_str(), &sectors_per_cluster,
&bytes_per_sector, &free_clusters,
&total_clusters));
const auto buffer_size = 16U * sys_info.dwPageSize;
auto write_buffer = utils::generate_secure_random<data_buffer>(buffer_size);
auto handle =
CreateFileA(file_path.c_str(), FILE_APPEND_DATA, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL | flags, nullptr);
if (should_fail) {
EXPECT_EQ(INVALID_HANDLE_VALUE, handle);
return;
}
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
DWORD bytes_written{};
EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), bytes_per_sector,
&bytes_written, nullptr));
EXPECT_EQ(bytes_per_sector, bytes_written);
EXPECT_TRUE(::WriteFile(handle, write_buffer.data() + bytes_per_sector,
bytes_per_sector, &bytes_written, nullptr));
EXPECT_EQ(bytes_per_sector, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
handle = CreateFileA(
file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | flags | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
auto pointer = ::SetFilePointer(handle, 0, 0, FILE_BEGIN);
EXPECT_EQ(0U, pointer);
data_buffer read_buffer{};
read_buffer.resize(buffer_size);
DWORD bytes_read{};
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), 2U * bytes_per_sector,
&bytes_read, nullptr));
EXPECT_EQ(2U * bytes_per_sector, bytes_read);
EXPECT_EQ(0,
std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
EXPECT_TRUE(::CloseHandle(handle));
handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, 0, nullptr);
EXPECT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
} }
TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_flags) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_flags) {
auto file_path{ auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}), utils::path::combine(this->mount_location, {"test_file_5"}),
}; };
test_file(file_path, 0U); test_file(this->mount_location, file_path, 0U);
} }
TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_buffering) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_buffering) {
auto file_path{ auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}), utils::path::combine(this->mount_location, {"test_file_5"}),
}; };
test_file(file_path, FILE_FLAG_NO_BUFFERING); test_file(this->mount_location, file_path, FILE_FLAG_NO_BUFFERING);
} }
TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_write_through) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_write_through) {
auto file_path{ auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}), utils::path::combine(this->mount_location, {"test_file_5"}),
}; };
test_file(file_path, FILE_FLAG_WRITE_THROUGH); test_file(this->mount_location, file_path, FILE_FLAG_WRITE_THROUGH);
}
TYPED_TEST(winfsp_test, rdrw_can_append_file_no_flags) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}),
};
test_append_file(this->mount_location, file_path, 0U);
}
TYPED_TEST(winfsp_test, rdrw_can_append_file_no_buffering) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}),
};
test_append_file(this->mount_location, file_path, FILE_FLAG_NO_BUFFERING,
true);
}
TYPED_TEST(winfsp_test, rdrw_can_append_file_write_through) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_5"}),
};
test_append_file(this->mount_location, file_path, FILE_FLAG_WRITE_THROUGH);
} }
} // namespace repertory } // namespace repertory