5 Commits

Author SHA1 Message Date
26667fdcd6 fix
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2024-07-27 08:28:23 -05:00
681a3eec53 fixes 2024-07-27 08:23:20 -05:00
2a5df890f7 fix sign 2024-07-27 08:13:23 -05:00
ae0059591c fix directory caching 2024-07-27 08:12:43 -05:00
8655becf1e fix directory caching 2024-07-27 07:54:46 -05:00
12 changed files with 208 additions and 194 deletions

View File

@ -33,8 +33,9 @@ public:
using execute_callback = std::function<void(directory_iterator &)>; using execute_callback = std::function<void(directory_iterator &)>;
private: private:
struct open_directory { struct open_directory final {
std::shared_ptr<directory_iterator> iterator{}; std::shared_ptr<directory_iterator> iterator;
std::vector<std::uint64_t> handles{};
std::chrono::system_clock::time_point last_update{ std::chrono::system_clock::time_point last_update{
std::chrono::system_clock::now()}; std::chrono::system_clock::now()};
}; };
@ -60,15 +61,15 @@ public:
void execute_action(const std::string &api_path, void execute_action(const std::string &api_path,
const execute_callback &execute); const execute_callback &execute);
[[nodiscard]] auto get_directory(directory_iterator *iterator) [[nodiscard]] auto
-> std::shared_ptr<directory_iterator>; get_directory(std::uint64_t handle) -> std::shared_ptr<directory_iterator>;
[[nodiscard]] auto remove_directory(const std::string &api_path) [[nodiscard]] auto remove_directory(const std::string &api_path)
-> std::shared_ptr<directory_iterator>; -> std::shared_ptr<directory_iterator>;
void remove_directory(directory_iterator *iterator); void remove_directory(std::uint64_t handle);
void set_directory(const std::string &api_path, void set_directory(const std::string &api_path, std::uint64_t handle,
std::shared_ptr<directory_iterator> iterator); std::shared_ptr<directory_iterator> iterator);
}; };
} // namespace repertory } // namespace repertory

View File

@ -38,6 +38,7 @@ public:
private: private:
directory_cache directory_cache_; directory_cache directory_cache_;
std::atomic<std::uint64_t> next_handle_{0U};
private: private:
[[nodiscard]] auto construct_path(std::string path) -> std::string; [[nodiscard]] auto construct_path(std::string path) -> std::string;
@ -46,6 +47,8 @@ private:
[[nodiscard]] static auto empty_as_zero(const json &data) -> std::string; [[nodiscard]] static auto empty_as_zero(const json &data) -> std::string;
[[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) -> packet::error_type; remote::file_info &file_info) -> packet::error_type;
@ -58,9 +61,6 @@ private:
[[nodiscard]] auto update_to_windows_format(json &item) -> json &; [[nodiscard]] auto update_to_windows_format(json &item) -> json &;
protected:
void delete_open_directory(void *dir) override;
public: public:
// FUSE Layer // FUSE Layer
[[nodiscard]] auto fuse_access(const char *path, const std::int32_t &mask) [[nodiscard]] auto fuse_access(const char *path, const std::int32_t &mask)

View File

@ -49,18 +49,16 @@ protected:
private: private:
std::unordered_map<remote::file_handle, compat_open_info> compat_lookup_; std::unordered_map<remote::file_handle, compat_open_info> compat_lookup_;
std::recursive_mutex compat_mutex_; std::recursive_mutex compat_mutex_;
std::unordered_map<std::string, std::vector<void *>> directory_lookup_; std::unordered_map<std::string, std::vector<std::uint64_t>> directory_lookup_;
std::recursive_mutex directory_mutex_; std::recursive_mutex directory_mutex_;
std::unordered_map<native_handle, open_info> file_lookup_; std::unordered_map<native_handle, open_info> file_lookup_;
mutable std::recursive_mutex file_mutex_; mutable std::recursive_mutex file_mutex_;
protected: protected:
void add_directory(const std::string &client_id, void *dir); void add_directory(const std::string &client_id, std::uint64_t handle);
void close_all(const std::string &client_id); void close_all(const std::string &client_id);
virtual void delete_open_directory(void *dir) = 0;
#if defined(_WIN32) #if defined(_WIN32)
[[nodiscard]] auto get_directory_buffer(const native_handle &handle, [[nodiscard]] auto get_directory_buffer(const native_handle &handle,
PVOID *&buffer) -> bool; PVOID *&buffer) -> bool;
@ -73,7 +71,7 @@ protected:
open_info &oi) -> bool; open_info &oi) -> bool;
[[nodiscard]] auto has_open_directory(const std::string &client_id, [[nodiscard]] auto has_open_directory(const std::string &client_id,
void *dir) -> bool; std::uint64_t handle) -> bool;
[[nodiscard]] auto has_compat_open_info(const remote::file_handle &handle, [[nodiscard]] auto has_compat_open_info(const remote::file_handle &handle,
int error_return) -> int; int error_return) -> int;
@ -91,7 +89,8 @@ protected:
void remove_compat_open_info(const remote::file_handle &handle); void remove_compat_open_info(const remote::file_handle &handle);
auto remove_directory(const std::string &client_id, void *dir) -> bool; auto remove_directory(const std::string &client_id,
std::uint64_t handle) -> bool;
void remove_open_info(const native_handle &handle); void remove_open_info(const native_handle &handle);

View File

@ -26,9 +26,7 @@
#include "comm/packet/client_pool.hpp" #include "comm/packet/client_pool.hpp"
#include "comm/packet/packet.hpp" #include "comm/packet/packet.hpp"
#include "comm/packet/packet_server.hpp" #include "comm/packet/packet_server.hpp"
#include "drives/directory_iterator.hpp"
#include "drives/fuse/remotefuse/i_remote_instance.hpp" #include "drives/fuse/remotefuse/i_remote_instance.hpp"
#include "drives/remote/i_remote_json.hpp"
#include "drives/remote/remote_open_file_table.hpp" #include "drives/remote/remote_open_file_table.hpp"
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp" #include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
#include "types/remote.hpp" #include "types/remote.hpp"
@ -337,7 +335,7 @@ public:
DECODE_OR_RETURN(request, length); DECODE_OR_RETURN(request, length);
data_buffer buffer(length); data_buffer buffer(length);
UINT32 bytes_transferred = 0; UINT32 bytes_transferred{0};
ret = this->winfsp_read(file_desc, buffer.data(), offset, length, ret = this->winfsp_read(file_desc, buffer.data(), offset, length,
&bytes_transferred); &bytes_transferred);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
@ -492,7 +490,7 @@ public:
auto *buffer = request->current_pointer(); auto *buffer = request->current_pointer();
UINT32 bytes_transferred = 0; UINT32 bytes_transferred{0};
remote::file_info file_info{}; remote::file_info file_info{};
ret = this->winfsp_write(file_desc, buffer, offset, length, ret = this->winfsp_write(file_desc, buffer, offset, length,
write_to_end, constrained_io, write_to_end, constrained_io,
@ -508,7 +506,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -523,7 +521,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -538,7 +536,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -546,14 +544,14 @@ public:
remote::file_mode mode; remote::file_mode mode;
DECODE_OR_RETURN(request, mode); DECODE_OR_RETURN(request, mode);
return this->fuse_chmod(&path[0], mode); return this->fuse_chmod(path.c_str(), mode);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_chown", {"::fuse_chown",
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -564,14 +562,14 @@ public:
remote::group_id gid{}; remote::group_id gid{};
DECODE_OR_RETURN(request, gid); DECODE_OR_RETURN(request, gid);
return this->fuse_chown(&path[0], uid, gid); return this->fuse_chown(path.c_str(), uid, gid);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_create", {"::fuse_create",
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -603,7 +601,7 @@ public:
/*handlerLookup_.insert({"::fuse_fallocate", /*handlerLookup_.insert({"::fuse_fallocate",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -620,15 +618,15 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
return this->fuse_fallocate(&path[0], mode, offset, return this->fuse_fallocate(path.c_str(), mode,
length, handle); offset, length, handle);
}});*/ }});*/
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_fgetattr", {"::fuse_fgetattr",
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -659,7 +657,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -677,7 +675,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -688,14 +686,14 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
return this->fuse_fsync(&path[0], dataSync, handle); return this->fuse_fsync(path.c_str(), dataSync, handle);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_ftruncate", {"::fuse_ftruncate",
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -706,14 +704,14 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
return this->fuse_ftruncate(&path[0], size, handle); return this->fuse_ftruncate(path.c_str(), size, handle);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_getattr", {"::fuse_getattr",
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -726,7 +724,7 @@ public:
remote::stat st{}; remote::stat st{};
bool directory = false; bool directory = false;
ret = this->fuse_getattr(&path[0], st, directory); ret = this->fuse_getattr(path.c_str(), st, directory);
if (ret == 0) { if (ret == 0) {
st.st_uid = uid; st.st_uid = uid;
st.st_gid = gid; st.st_gid = gid;
@ -738,7 +736,7 @@ public:
/*handlerLookup_.insert({"::fuse_getxattr", /*handlerLookup_.insert({"::fuse_getxattr",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -749,13 +747,13 @@ public:
remote::file_size size; remote::file_size size;
DECODE_OR_RETURN(request, size); DECODE_OR_RETURN(request, size);
return this->fuse_getxattr(&path[0], &name[0], return this->fuse_getxattr(path.c_str(), &name[0],
nullptr, size); nullptr, size);
}}); }});
handlerLookup_.insert({"::fuse_getxattr_osx", handlerLookup_.insert({"::fuse_getxattr_osx",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -769,22 +767,23 @@ public:
std::uint32_t position; std::uint32_t position;
DECODE_OR_RETURN(request, position); DECODE_OR_RETURN(request, position);
return this->fuse_getxattr_osx(&path[0], &name[0], return this->fuse_getxattr_osx(path.c_str(),
nullptr, size, position); &name[0], nullptr, size, position);
}});*/ }});*/
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_getxtimes", {"::fuse_getxtimes",
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
remote::file_time bkuptime{}; remote::file_time bkuptime{};
remote::file_time crtime{}; remote::file_time crtime{};
if ((ret = this->fuse_getxtimes(&path[0], bkuptime, crtime)) == 0) { if ((ret = this->fuse_getxtimes(path.c_str(), bkuptime, crtime)) ==
0) {
response.encode(bkuptime); response.encode(bkuptime);
response.encode(crtime); response.encode(crtime);
} }
@ -799,7 +798,7 @@ public:
/*handlerLookup_.insert({"::remote_fuseListxattr", /*handlerLookup_.insert({"::remote_fuseListxattr",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -807,7 +806,7 @@ public:
remote::file_size size; remote::file_size size;
DECODE_OR_RETURN(request, size); DECODE_OR_RETURN(request, size);
return this->fuse_listxattr(&path[0], nullptr, return this->fuse_listxattr(path.c_str(), nullptr,
size); size);
}});*/ }});*/
handler_lookup_.insert( handler_lookup_.insert(
@ -815,7 +814,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -823,14 +822,14 @@ public:
remote::file_mode mode; remote::file_mode mode;
DECODE_OR_RETURN(request, mode); DECODE_OR_RETURN(request, mode);
return this->fuse_mkdir(&path[0], mode); return this->fuse_mkdir(path.c_str(), mode);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_open", {"::fuse_open",
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -839,7 +838,7 @@ public:
DECODE_OR_RETURN(request, flags); DECODE_OR_RETURN(request, flags);
remote::file_handle handle; remote::file_handle handle;
if ((ret = this->fuse_open(&path[0], flags, handle)) >= 0) { if ((ret = this->fuse_open(path.c_str(), flags, handle)) >= 0) {
#if defined(_WIN32) #if defined(_WIN32)
this->set_compat_client_id(handle, client_id); this->set_compat_client_id(handle, client_id);
#else #else
@ -854,14 +853,14 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
remote::file_handle handle = 0; remote::file_handle handle{0};
if ((ret = this->fuse_opendir(&path[0], handle)) >= 0) { if ((ret = this->fuse_opendir(path.c_str(), handle)) >= 0) {
this->add_directory(client_id, reinterpret_cast<void *>(handle)); this->add_directory(client_id, handle);
response.encode(handle); response.encode(handle);
} }
return ret; return ret;
@ -871,7 +870,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -886,10 +885,10 @@ public:
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
data_buffer buffer; data_buffer buffer;
if ((ret = if ((ret = this->fuse_read(path.c_str(),
this->fuse_read(&path[0], reinterpret_cast<char *>(&buffer), reinterpret_cast<char *>(&buffer),
read_size, read_offset, handle)) > 0) { read_size, read_offset, handle)) > 0) {
response.encode(&buffer[0], buffer.size()); response.encode(buffer.data(), buffer.size());
} }
return ret; return ret;
}}); }});
@ -898,7 +897,7 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -909,12 +908,11 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
if (this->has_open_directory(client_id, if (this->has_open_directory(client_id, handle)) {
reinterpret_cast<void *>(handle))) { std::string file_path;
std::string filePath; ret = this->fuse_readdir(path.c_str(), offset, handle, file_path);
ret = this->fuse_readdir(&path[0], offset, handle, filePath);
if (ret == 0) { if (ret == 0) {
response.encode(filePath); response.encode(file_path);
} }
} else { } else {
ret = -EBADF; ret = -EBADF;
@ -927,7 +925,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t, [this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -935,14 +933,14 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
return this->fuse_release(&path[0], handle); return this->fuse_release(path.c_str(), handle);
}}); }});
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_releasedir", {"::fuse_releasedir",
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -950,9 +948,8 @@ public:
remote::file_handle handle; remote::file_handle handle;
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
ret = this->fuse_releasedir(&path[0], handle); ret = this->fuse_releasedir(path.c_str(), handle);
if (this->remove_directory(client_id, if (this->remove_directory(client_id, handle)) {
reinterpret_cast<void *>(handle))) {
return ret; return ret;
} }
return -EBADF; return -EBADF;
@ -960,7 +957,7 @@ public:
/*handlerLookup_.insert({"::fuse_removexattr", /*handlerLookup_.insert({"::fuse_removexattr",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -968,7 +965,8 @@ public:
std::string name; std::string name;
DECODE_OR_RETURN(request, name); DECODE_OR_RETURN(request, name);
return this->fuse_removexattr(&path[0], &name[0]); return this->fuse_removexattr(path.c_str(),
&name[0]);
}});*/ }});*/
handler_lookup_.insert( handler_lookup_.insert(
{"::fuse_rename", {"::fuse_rename",
@ -1072,7 +1070,7 @@ public:
/*handlerLookup_.insert({"::fuse_setxattr", /*handlerLookup_.insert({"::fuse_setxattr",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -1093,7 +1091,7 @@ public:
std::int32_t flags; std::int32_t flags;
DECODE_OR_RETURN(request, flags); DECODE_OR_RETURN(request, flags);
ret = this->fuse_setxattr(&path[0], &name[0], ret = this->fuse_setxattr(path.c_str(), &name[0],
&value[0], size, flags); &value[0], size, flags);
} }
return ret; return ret;
@ -1101,7 +1099,7 @@ public:
handlerLookup_.insert({"::fuse_setxattr_osx", handlerLookup_.insert({"::fuse_setxattr_osx",
[this](std::uint32_t serviceFlags, const std::string [this](std::uint32_t serviceFlags, const std::string
&client_id, std::uint64_t threadId, const std::string &method, packet &client_id, std::uint64_t threadId, const std::string &method, packet
*request, packet &response) -> packet::error_type { auto ret = 0; *request, packet &response) -> packet::error_type { auto ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -1125,8 +1123,8 @@ public:
std::uint32_t position; std::uint32_t position;
DECODE_OR_RETURN(request, position); DECODE_OR_RETURN(request, position);
ret = this->fuse_setxattr_osx(&path[0], &name[0], ret = this->fuse_setxattr_osx(path.c_str(),
&value[0], size, flags, position); &name[0], &value[0], size, flags, position);
} }
return ret; return ret;
}});*/ }});*/
@ -1301,8 +1299,7 @@ public:
if ((ret = this->json_create_directory_snapshot(path.data(), if ((ret = this->json_create_directory_snapshot(path.data(),
json_data)) == 0) { json_data)) == 0) {
this->add_directory(client_id, this->add_directory(client_id,
reinterpret_cast<void *>( json_data["handle"].get<std::uint64_t>());
json_data["handle"].get<std::uint64_t>()));
response.encode(json_data.dump(0)); response.encode(json_data.dump(0));
} }
return ret; return ret;
@ -1312,7 +1309,7 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &response) -> packet::error_type { packet &response) -> packet::error_type {
std::int32_t ret = 0; std::int32_t ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -1324,8 +1321,7 @@ public:
DECODE_OR_RETURN(request, page); DECODE_OR_RETURN(request, page);
ret = -EBADF; ret = -EBADF;
if (this->has_open_directory(client_id, if (this->has_open_directory(client_id, handle)) {
reinterpret_cast<void *>(handle))) {
json json_data; json json_data;
json_data["directory_list"] = std::vector<json>(); json_data["directory_list"] = std::vector<json>();
json_data["page"] = page; json_data["page"] = page;
@ -1343,7 +1339,7 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t, [this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request, const std::string &, packet *request,
packet &) -> packet::error_type { packet &) -> packet::error_type {
auto ret = 0; std::int32_t ret{0};
std::string path; std::string path;
DECODE_OR_RETURN(request, path); DECODE_OR_RETURN(request, path);
@ -1352,8 +1348,7 @@ public:
DECODE_OR_RETURN(request, handle); DECODE_OR_RETURN(request, handle);
ret = this->json_release_directory_snapshot(path.data(), handle); ret = this->json_release_directory_snapshot(path.data(), handle);
if (this->remove_directory(client_id, if (this->remove_directory(client_id, handle)) {
reinterpret_cast<void *>(handle))) {
return ret; return ret;
} }
return -EBADF; return -EBADF;
@ -1430,12 +1425,6 @@ protected:
path = utils::path::create_api_path(path.substr(mount_location_.size())); path = utils::path::create_api_path(path.substr(mount_location_.size()));
return path; return path;
} }
void delete_open_directory(void *dir) override {
if (dir != nullptr) {
delete reinterpret_cast<directory_iterator *>(dir);
}
}
}; };
} // namespace repertory } // namespace repertory

View File

@ -46,9 +46,6 @@ private:
static auto to_handle(PVOID file_desc) -> native_handle; static auto to_handle(PVOID file_desc) -> native_handle;
#endif #endif
protected:
void delete_open_directory(void * /*dir*/) override {}
public: 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;

View File

@ -26,6 +26,7 @@
#if defined(_WIN32) #if defined(_WIN32)
#include "comm/packet/packet.hpp" #include "comm/packet/packet.hpp"
#include "drives/directory_cache.hpp"
#include "drives/remote/remote_server_base.hpp" #include "drives/remote/remote_server_base.hpp"
#include "drives/winfsp/i_winfsp_drive.hpp" #include "drives/winfsp/i_winfsp_drive.hpp"
@ -39,9 +40,15 @@ public:
: remote_server_base(config, drive, : remote_server_base(config, drive,
utils::string::to_lower(mount_location)) {} utils::string::to_lower(mount_location)) {}
private:
directory_cache directory_cache_;
std::atomic<std::uint64_t> next_handle_{0U};
private: private:
[[nodiscard]] auto construct_path(std::string path) -> std::string; [[nodiscard]] auto construct_path(std::string path) -> std::string;
[[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) -> packet::error_type; remote::file_info &file_info) -> packet::error_type;

View File

@ -22,9 +22,8 @@
#include "drives/directory_cache.hpp" #include "drives/directory_cache.hpp"
#include "drives/directory_iterator.hpp" #include "drives/directory_iterator.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "utils/utils.hpp"
namespace repertory { namespace repertory {
void directory_cache::execute_action(const std::string &api_path, void directory_cache::execute_action(const std::string &api_path,
@ -35,18 +34,17 @@ void directory_cache::execute_action(const std::string &api_path,
} }
} }
auto directory_cache::get_directory(directory_iterator *iterator) auto directory_cache::get_directory(std::uint64_t handle)
-> std::shared_ptr<directory_iterator> { -> std::shared_ptr<directory_iterator> {
if (iterator != nullptr) { recur_mutex_lock directory_lock(directory_mutex_);
recur_mutex_lock directory_lock(directory_mutex_); auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
const auto it = [handle](auto &&kv) -> bool {
std::find_if(directory_lookup_.begin(), directory_lookup_.end(), auto &&handles = kv.second.handles;
[&iterator](const auto &kv) -> bool { return std::find(handles.begin(), handles.end(),
return kv.second.iterator.get() == iterator; handle) != kv.second.handles.end();
}); });
if (it != directory_lookup_.end()) { if (it != directory_lookup_.end()) {
return it->second.iterator; return it->second.iterator;
}
} }
return nullptr; return nullptr;
@ -65,16 +63,18 @@ auto directory_cache::remove_directory(const std::string &api_path)
return ret; return ret;
} }
void directory_cache::remove_directory(directory_iterator *iterator) { void directory_cache::remove_directory(std::uint64_t handle) {
if (iterator != nullptr) { recur_mutex_lock directory_lock(directory_mutex_);
recur_mutex_lock directory_lock(directory_mutex_); auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
const auto it = [handle](auto &&kv) -> bool {
std::find_if(directory_lookup_.begin(), directory_lookup_.end(), auto &&handles = kv.second.handles;
[&iterator](const auto &kv) -> bool { return std::find(handles.begin(), handles.end(),
return kv.second.iterator.get() == iterator; handle) != kv.second.handles.end();
}); });
if (it != directory_lookup_.end()) { if (it != directory_lookup_.end()) {
directory_lookup_.erase(it->first); utils::remove_element_from(it->second.handles, handle);
if (it->second.handles.empty()) {
directory_lookup_.erase(it);
} }
} }
} }
@ -102,8 +102,11 @@ void directory_cache::service_function() {
} }
void directory_cache::set_directory( void directory_cache::set_directory(
const std::string &api_path, std::shared_ptr<directory_iterator> iterator) { const std::string &api_path, std::uint64_t handle,
std::shared_ptr<directory_iterator> iterator) {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
directory_lookup_[api_path] = {std::move(iterator)}; auto &entry = directory_lookup_[api_path];
entry.iterator = std::move(iterator);
entry.handles.push_back(handle);
} }
} // namespace repertory } // namespace repertory

View File

@ -669,8 +669,8 @@ auto fuse_drive::opendir_impl(std::string api_path,
} }
auto iter = std::make_shared<directory_iterator>(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
file_info->fh = reinterpret_cast<std::uint64_t>(iter.get()); file_info->fh = fm_->get_next_handle();
directory_cache_->set_directory(api_path, iter); directory_cache_->set_directory(api_path, file_info->fh, iter);
return api_error::success; return api_error::success;
} }
@ -716,8 +716,7 @@ auto fuse_drive::readdir_impl(std::string api_path, void *buf,
return res; return res;
} }
auto iter = directory_cache_->get_directory( auto iter = directory_cache_->get_directory(file_info->fh);
reinterpret_cast<directory_iterator *>(file_info->fh));
if (iter == nullptr) { if (iter == nullptr) {
return api_error::invalid_handle; return api_error::invalid_handle;
} }
@ -751,13 +750,12 @@ auto fuse_drive::release_impl(std::string /*api_path*/,
auto fuse_drive::releasedir_impl( auto fuse_drive::releasedir_impl(
std::string /*api_path*/, struct fuse_file_info *file_info) -> api_error { std::string /*api_path*/, struct fuse_file_info *file_info) -> api_error {
auto iter = directory_cache_->get_directory( auto iter = directory_cache_->get_directory(file_info->fh);
reinterpret_cast<directory_iterator *>(file_info->fh));
if (iter == nullptr) { if (iter == nullptr) {
return api_error::invalid_handle; return api_error::invalid_handle;
} }
directory_cache_->remove_directory(iter.get()); directory_cache_->remove_directory(file_info->fh);
return api_error::success; return api_error::success;
} }

View File

@ -73,12 +73,6 @@ auto remote_server::construct_path(const std::wstring &path) -> std::string {
return construct_path(utils::string::to_utf8(path)); return construct_path(utils::string::to_utf8(path));
} }
void remote_server::delete_open_directory(void *dir) {
directory_cache_.remove_directory(
reinterpret_cast<directory_iterator *>(dir));
remote_server_base::delete_open_directory(dir);
}
auto remote_server::empty_as_zero(const json &data) -> std::string { auto remote_server::empty_as_zero(const json &data) -> std::string {
if (data.empty() || data.get<std::string>().empty()) { if (data.empty() || data.get<std::string>().empty()) {
return "0"; return "0";
@ -86,6 +80,14 @@ auto remote_server::empty_as_zero(const json &data) -> std::string {
return data.get<std::string>(); return data.get<std::string>();
} }
auto remote_server::get_next_handle() -> std::uint64_t {
if (++next_handle_ == 0U) {
return ++next_handle_;
}
return next_handle_;
}
auto remote_server::populate_file_info(const std::string &api_path, auto remote_server::populate_file_info(const std::string &api_path,
remote::file_info &file_info) remote::file_info &file_info)
-> packet::error_type { -> packet::error_type {
@ -621,9 +623,9 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
auto iter = std::make_shared<directory_iterator>(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
directory_cache_.set_directory(path, iter); handle = get_next_handle();
directory_cache_.set_directory(path, handle, iter);
handle = reinterpret_cast<remote::file_handle>(iter.get());
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -682,13 +684,12 @@ auto remote_server::fuse_readdir(const char *path,
errno = ERANGE; errno = ERANGE;
res = -1; res = -1;
} else { } else {
auto iter = directory_cache_.get_directory( auto iter = directory_cache_.get_directory(handle);
reinterpret_cast<directory_iterator *>(handle)); if (iter == nullptr) {
if (iter != nullptr) {
res = iter->get(static_cast<std::size_t>(offset), item_path);
} else {
res = -1; res = -1;
errno = EFAULT; errno = EFAULT;
} else {
res = iter->get(static_cast<std::size_t>(offset), item_path);
} }
} }
@ -721,8 +722,7 @@ auto remote_server::fuse_releasedir(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
directory_cache_.remove_directory( directory_cache_.remove_directory(handle);
reinterpret_cast<directory_iterator *>(handle));
RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0); RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0);
return 0; return 0;
@ -1569,9 +1569,10 @@ auto remote_server::json_create_directory_snapshot(
if (utils::file::is_directory(file_path)) { if (utils::file::is_directory(file_path)) {
auto list = drive_.get_directory_items(api_path); auto list = drive_.get_directory_items(api_path);
auto iter = std::make_shared<directory_iterator>(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
directory_cache_.set_directory(api_path, iter); auto handle = get_next_handle();
directory_cache_.set_directory(api_path, handle, iter);
json_data["handle"] = reinterpret_cast<remote::file_handle>(iter.get()); json_data["handle"] = handle;
json_data["path"] = path; json_data["path"] = path;
json_data["page_count"] = utils::divide_with_ceiling( json_data["page_count"] = utils::divide_with_ceiling(
iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
@ -1589,22 +1590,26 @@ auto remote_server::json_read_directory_snapshot(
std::uint32_t page, json &json_data) -> packet::error_type { std::uint32_t page, json &json_data) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__); constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
int res{-EBADF};
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle); auto iter = directory_cache_.get_directory(handle);
std::size_t offset{}; if (iter != nullptr) {
int res{}; std::size_t offset{};
json item_json; json item_json;
while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && while (
(res = iterator->get_json( (json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
(page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++, item_json)) == (res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++,
0) { item_json)) == 0) {
json_data["directory_list"].emplace_back(item_json); json_data["directory_list"].emplace_back(item_json);
}
json_data["handle"] = handle;
json_data["path"] = path;
json_data["page"] = page;
json_data["page_count"] = utils::divide_with_ceiling(
iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
} }
json_data["handle"] = reinterpret_cast<remote::file_handle>(iterator);
json_data["path"] = path;
json_data["page"] = page;
json_data["page_count"] = utils::divide_with_ceiling(
iterator->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
auto ret = ((res < 0) ? -errno : 0); auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
@ -1616,8 +1621,7 @@ auto remote_server::json_release_directory_snapshot(
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__); constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
directory_cache_.remove_directory( directory_cache_.remove_directory(handle);
reinterpret_cast<directory_iterator *>(handle));
RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0); RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0);
return 0; return 0;
} }

View File

@ -27,11 +27,11 @@
namespace repertory { namespace repertory {
void remote_open_file_table::add_directory(const std::string &client_id, void remote_open_file_table::add_directory(const std::string &client_id,
void *dir) { std::uint64_t handle) {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id]; auto &list = directory_lookup_[client_id];
if (utils::collection_excludes(list, dir)) { if (utils::collection_excludes(list, handle)) {
directory_lookup_[client_id].emplace_back(dir); directory_lookup_[client_id].emplace_back(handle);
} }
} }
@ -72,7 +72,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
remove_open_info(handle); remove_open_info(handle);
} }
std::vector<void *> dirs; std::vector<std::uint64_t> dirs;
unique_recur_mutex_lock directory_lock(directory_mutex_); unique_recur_mutex_lock directory_lock(directory_mutex_);
for (auto &kv : directory_lookup_) { for (auto &kv : directory_lookup_) {
if (kv.first == client_id) { if (kv.first == client_id) {
@ -81,7 +81,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
} }
directory_lock.unlock(); directory_lock.unlock();
for (auto *dir : dirs) { for (auto &&dir : dirs) {
remove_directory(client_id, dir); remove_directory(client_id, dir);
} }
} }
@ -141,10 +141,10 @@ auto remote_open_file_table::get_open_file_path(const native_handle &handle)
} }
auto remote_open_file_table::has_open_directory(const std::string &client_id, auto remote_open_file_table::has_open_directory(const std::string &client_id,
void *dir) -> bool { std::uint64_t handle) -> bool {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id]; auto &list = directory_lookup_[client_id];
return (utils::collection_includes(list, dir)); return (utils::collection_includes(list, handle));
} }
auto remote_open_file_table::has_compat_open_info( auto remote_open_file_table::has_compat_open_info(
@ -204,17 +204,17 @@ void remote_open_file_table::remove_compat_open_info(
} }
auto remote_open_file_table::remove_directory(const std::string &client_id, auto remote_open_file_table::remove_directory(const std::string &client_id,
void *dir) -> bool { std::uint64_t handle) -> bool {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id]; auto &list = directory_lookup_[client_id];
if (utils::collection_includes(list, dir)) { if (utils::collection_includes(list, handle)) {
utils::remove_element_from(list, dir); utils::remove_element_from(list, handle);
delete_open_directory(dir);
if (directory_lookup_[client_id].empty()) { if (directory_lookup_[client_id].empty()) {
directory_lookup_.erase(client_id); directory_lookup_.erase(client_id);
} }
return true; return true;
} }
return false; return false;
} }

View File

@ -63,6 +63,14 @@ E_SIMPLE3(remote_winfsp_server_event, debug, true,
); );
// clang-format on // clang-format on
auto remote_server::get_next_handle() -> std::uint64_t {
if (++next_handle_ == 0U) {
return ++next_handle_;
}
return next_handle_;
}
auto remote_server::construct_path(std::string path) -> std::string { auto remote_server::construct_path(std::string path) -> std::string {
path = utils::path::combine(mount_location_, {path}); path = utils::path::combine(mount_location_, {path});
if (path == mount_location_) { if (path == mount_location_) {
@ -331,8 +339,11 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) { if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) {
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
handle = static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>( auto iter = std::make_shared<directory_iterator>(std::move(list));
new directory_iterator(std::move(list))));
handle = get_next_handle();
directory_cache_.set_directory(path, handle, iter);
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -531,7 +542,7 @@ auto remote_server::fuse_readdir(const char *path,
errno = ERANGE; errno = ERANGE;
res = -1; res = -1;
} else { } else {
auto *iter = reinterpret_cast<directory_iterator *>(handle); auto iter = directory_cache_.get_directory(handle);
if (iter == nullptr) { if (iter == nullptr) {
res = -1; res = -1;
errno = EFAULT; errno = EFAULT;
@ -817,10 +828,12 @@ auto remote_server::json_create_directory_snapshot(
if (utils::file::is_directory(file_path)) { if (utils::file::is_directory(file_path)) {
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
auto *iter = new directory_iterator(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
auto handle = get_next_handle();
directory_cache_.set_directory(api_path, handle, iter);
json_data["path"] = path; json_data["path"] = path;
json_data["handle"] = static_cast<remote::file_handle>( json_data["handle"] = handle;
reinterpret_cast<std::uintptr_t>(iter));
json_data["page_count"] = utils::divide_with_ceiling( json_data["page_count"] = utils::divide_with_ceiling(
iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
res = 0; res = 0;
@ -838,22 +851,25 @@ auto remote_server::json_read_directory_snapshot(
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__); constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto *iter = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset{}; int res{-EBADF};
int res{}; auto iter = directory_cache_.get_directory(handle);
json item_json; if (iter != nullptr) {
while ( std::size_t offset{};
(json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && json item_json;
(res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++, while (
item_json)) == 0) { (json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
json_data["directory_list"].emplace_back(item_json); (res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++,
item_json)) == 0) {
json_data["directory_list"].emplace_back(item_json);
}
json_data["handle"] = handle;
json_data["path"] = path;
json_data["page"] = page;
json_data["page_count"] = utils::divide_with_ceiling(
iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
} }
json_data["handle"] =
static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>(iter));
json_data["path"] = path;
json_data["page"] = page;
json_data["page_count"] = utils::divide_with_ceiling(
iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;

View File

@ -58,7 +58,7 @@ const auto DEFAULT_SIA_CONFIG = "{\n"
#if defined(_WIN32) #if defined(_WIN32)
" \"EnableMountManager\": false,\n" " \"EnableMountManager\": false,\n"
#endif #endif
" \"EventLevel\": \"normal\",\n" " \"EventLevel\": \"info\",\n"
" \"EvictionDelayMinutes\": 10,\n" " \"EvictionDelayMinutes\": 10,\n"
" \"EvictionUsesAccessedTime\": false,\n" " \"EvictionUsesAccessedTime\": false,\n"
" \"HighFreqIntervalSeconds\": 30,\n" " \"HighFreqIntervalSeconds\": 30,\n"
@ -106,7 +106,7 @@ const auto DEFAULT_S3_CONFIG = "{\n"
#if defined(_WIN32) #if defined(_WIN32)
" \"EnableMountManager\": false,\n" " \"EnableMountManager\": false,\n"
#endif #endif
" \"EventLevel\": \"normal\",\n" " \"EventLevel\": \"info\",\n"
" \"EvictionDelayMinutes\": 10,\n" " \"EvictionDelayMinutes\": 10,\n"
" \"EvictionUsesAccessedTime\": false,\n" " \"EvictionUsesAccessedTime\": false,\n"
" \"HighFreqIntervalSeconds\": 30,\n" " \"HighFreqIntervalSeconds\": 30,\n"