refactor
This commit is contained in:
parent
d20ed07066
commit
92295506a7
@ -42,7 +42,7 @@ remote_winfsp_drive::winfsp_service::winfsp_service(
|
||||
lock_data &lock, remote_winfsp_drive &drive,
|
||||
std::vector<std::string> drive_args, app_config &config)
|
||||
: Service(&(L"RepertoryRemote_" +
|
||||
utils::string::from_utf8(lock.get_unique_id()))[0u]),
|
||||
utils::string::from_utf8(lock.get_unique_id()))[0U]),
|
||||
config_(config),
|
||||
lock_(lock),
|
||||
drive_(drive),
|
||||
@ -54,22 +54,22 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
const auto mount_location = utils::string::to_lower(
|
||||
utils::path::absolute((drive_args_.size() > 1u) ? drive_args_[1u] : ""));
|
||||
const auto mount_location = utils::string::to_lower(utils::path::absolute(
|
||||
(drive_args_.size() > 1U) ? drive_args_.at(1U) : ""));
|
||||
const auto drive_letter =
|
||||
((mount_location.size() == 2u) ||
|
||||
((mount_location.size() == 3u) && (mount_location[2u] == '\\'))) &&
|
||||
(mount_location[1u] == ':');
|
||||
((mount_location.size() == 2U) ||
|
||||
((mount_location.size() == 3U) && (mount_location.at(2U) == '\\'))) &&
|
||||
(mount_location[1U] == ':');
|
||||
|
||||
auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED;
|
||||
if ((drive_letter && not utils::file::directory(mount_location).exists())) {
|
||||
auto unicode_mount_location = utils::string::from_utf8(mount_location);
|
||||
host_.SetFileSystemName(&unicode_mount_location[0u]);
|
||||
host_.SetFileSystemName(&unicode_mount_location[0U]);
|
||||
if (config_.get_enable_mount_manager()) {
|
||||
unicode_mount_location =
|
||||
std::wstring(L"\\\\.\\") + unicode_mount_location[0u] + L":";
|
||||
std::wstring(L"\\\\.\\") + unicode_mount_location[0U] + L":";
|
||||
}
|
||||
ret = host_.Mount(&unicode_mount_location[0u]);
|
||||
ret = host_.Mount(&unicode_mount_location[0U]);
|
||||
} else {
|
||||
std::cerr << (drive_letter ? "Mount location in use: "
|
||||
: "Mount location not supported: ")
|
||||
@ -136,15 +136,15 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
|
||||
remote::file_info fi{};
|
||||
std::string normalized_name;
|
||||
BOOLEAN exists = 0;
|
||||
const auto ret = remote_instance_->winfsp_create(
|
||||
auto ret = remote_instance_->winfsp_create(
|
||||
file_name, create_options, granted_access, attributes, allocation_size,
|
||||
file_desc, &fi, normalized_name, exists);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
set_file_info(ofi->FileInfo, fi);
|
||||
const auto file_path = utils::string::from_utf8(normalized_name);
|
||||
wcsncpy(ofi->NormalizedName, &file_path[0], wcslen(&file_path[0]));
|
||||
wcsncpy(ofi->NormalizedName, file_path.data(), wcslen(file_path.c_str()));
|
||||
ofi->NormalizedNameSize =
|
||||
static_cast<UINT16>(wcslen(&file_path[0]) * sizeof(WCHAR));
|
||||
static_cast<UINT16>(wcslen(file_path.c_str()) * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -153,7 +153,7 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
|
||||
auto remote_winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_flush(file_desc, &fi);
|
||||
auto ret = remote_instance_->winfsp_flush(file_desc, &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
return ret;
|
||||
}
|
||||
@ -161,7 +161,7 @@ auto remote_winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
|
||||
auto remote_winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_get_file_info(file_desc, &fi);
|
||||
auto ret = remote_instance_->winfsp_get_file_info(file_desc, &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
return ret;
|
||||
}
|
||||
@ -170,16 +170,16 @@ auto remote_winfsp_drive::GetSecurityByName(
|
||||
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) -> NTSTATUS {
|
||||
std::wstring string_descriptor;
|
||||
std::uint64_t sds = descriptor_size ? *descriptor_size : 0;
|
||||
std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size;
|
||||
auto ret = remote_instance_->winfsp_get_security_by_name(
|
||||
file_name, attributes, descriptor_size ? &sds : nullptr,
|
||||
string_descriptor);
|
||||
*descriptor_size = static_cast<SIZE_T>(sds);
|
||||
if ((ret == STATUS_SUCCESS) && *descriptor_size) {
|
||||
PSECURITY_DESCRIPTOR sd = nullptr;
|
||||
ULONG sz2 = 0u;
|
||||
PSECURITY_DESCRIPTOR sd{nullptr};
|
||||
ULONG sz2{0U};
|
||||
if (::ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
&string_descriptor[0u], SDDL_REVISION_1, &sd, &sz2)) {
|
||||
string_descriptor.data(), SDDL_REVISION_1, &sd, &sz2)) {
|
||||
if (sz2 > *descriptor_size) {
|
||||
ret = STATUS_BUFFER_TOO_SMALL;
|
||||
} else {
|
||||
@ -196,15 +196,15 @@ auto remote_winfsp_drive::GetSecurityByName(
|
||||
|
||||
auto remote_winfsp_drive::GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS {
|
||||
std::string volume_label;
|
||||
const auto ret = remote_instance_->winfsp_get_volume_info(
|
||||
auto ret = remote_instance_->winfsp_get_volume_info(
|
||||
volume_info->TotalSize, volume_info->FreeSize, volume_label);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
const auto byte_size =
|
||||
static_cast<UINT16>(volume_label.size() * sizeof(WCHAR));
|
||||
wcscpy_s(&volume_info->VolumeLabel[0u], 32,
|
||||
&utils::string::from_utf8(volume_label)[0u]);
|
||||
wcscpy_s(&volume_info->VolumeLabel[0U], 32,
|
||||
utils::string::from_utf8(volume_label).c_str());
|
||||
volume_info->VolumeLabelLength =
|
||||
std::min(static_cast<UINT16>(64u), byte_size);
|
||||
std::min(static_cast<UINT16>(64U), byte_size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -214,7 +214,7 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
|
||||
if (not config_.get_enable_mount_manager()) {
|
||||
file_system_host->SetPrefix(
|
||||
&(L"\\repertory\\" +
|
||||
std::wstring(file_system_host->FileSystemName()).substr(0, 1))[0u]);
|
||||
std::wstring(file_system_host->FileSystemName()).substr(0U, 1U))[0U]);
|
||||
}
|
||||
file_system_host->SetFileSystemName(std::wstring{REPERTORY_W}.data());
|
||||
file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
|
||||
@ -258,8 +258,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
|
||||
c = std::make_unique<console_consumer>(config_.get_event_level());
|
||||
}
|
||||
event_system::instance().start();
|
||||
const auto ret =
|
||||
winfsp_service(lock_, *this, parsed_drive_args, config_).Run();
|
||||
auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run();
|
||||
event_system::instance().raise<drive_mount_result>(std::to_string(ret));
|
||||
event_system::instance().stop();
|
||||
c.reset();
|
||||
@ -290,7 +289,7 @@ auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
|
||||
OpenFileInfo *ofi) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
std::string normalize_name;
|
||||
const auto ret =
|
||||
auto ret =
|
||||
remote_instance_->winfsp_open(file_name, create_options, granted_access,
|
||||
file_desc, &fi, normalize_name);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
@ -310,7 +309,7 @@ auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT64 allocation_size,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_overwrite(
|
||||
auto ret = remote_instance_->winfsp_overwrite(
|
||||
file_desc, attributes, replace_attributes, allocation_size, &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
return ret;
|
||||
@ -347,10 +346,10 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
PVOID buffer, ULONG buffer_length,
|
||||
PULONG bytes_transferred) -> NTSTATUS {
|
||||
json item_list;
|
||||
NTSTATUS ret = remote_instance_->winfsp_read_directory(file_desc, pattern,
|
||||
marker, item_list);
|
||||
auto ret = remote_instance_->winfsp_read_directory(file_desc, pattern, marker,
|
||||
item_list);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
PVOID *directory_buffer = nullptr;
|
||||
PVOID *directory_buffer{nullptr};
|
||||
if ((ret = remote_instance_->winfsp_get_dir_buffer(
|
||||
file_desc, directory_buffer)) == STATUS_SUCCESS) {
|
||||
if (FspFileSystemAcquireDirectoryBuffer(
|
||||
@ -425,7 +424,7 @@ auto remote_winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT64 change_time,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_set_basic_info(
|
||||
auto ret = remote_instance_->winfsp_set_basic_info(
|
||||
file_desc, attributes, creation_time, last_access_time, last_write_time,
|
||||
change_time, &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
@ -452,8 +451,8 @@ auto remote_winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
|
||||
BOOLEAN set_allocation_size,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_set_file_size(
|
||||
file_desc, new_size, set_allocation_size, &fi);
|
||||
auto ret = remote_instance_->winfsp_set_file_size(file_desc, new_size,
|
||||
set_allocation_size, &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
return ret;
|
||||
}
|
||||
@ -480,7 +479,7 @@ auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc,
|
||||
PULONG bytes_transferred,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
const auto ret = remote_instance_->winfsp_write(
|
||||
auto ret = remote_instance_->winfsp_write(
|
||||
file_desc, buffer, offset, length, write_to_end, constrained_io,
|
||||
reinterpret_cast<PUINT32>(bytes_transferred), &fi);
|
||||
set_file_info(*file_info, fi);
|
||||
|
@ -181,6 +181,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
|
||||
file.reset();
|
||||
|
||||
if (directory_buffer != nullptr) {
|
||||
std::cout << "delete 1" << std::endl;
|
||||
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
|
||||
}
|
||||
|
||||
@ -283,6 +284,7 @@ VOID winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {
|
||||
}
|
||||
fm_->close(handle);
|
||||
if (directory_buffer != nullptr) {
|
||||
std::cout << "delete 2" << std::endl;
|
||||
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
|
||||
}
|
||||
}
|
||||
@ -922,10 +924,10 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
if (error == api_error::success) {
|
||||
directory_iterator iterator(std::move(list));
|
||||
auto status_result = STATUS_SUCCESS;
|
||||
auto *directory_buffer =
|
||||
file->get_open_data(handle).directory_buffer;
|
||||
auto **directory_buffer =
|
||||
&file->get_open_data(handle).directory_buffer;
|
||||
if (FspFileSystemAcquireDirectoryBuffer(
|
||||
&directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
|
||||
directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
|
||||
&status_result) != 0U) {
|
||||
directory_item dir_item{};
|
||||
auto offset =
|
||||
@ -969,15 +971,15 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
display_name.data());
|
||||
|
||||
FspFileSystemFillDirectoryBuffer(
|
||||
&directory_buffer, directory_info, &status_result);
|
||||
directory_buffer, directory_info, &status_result);
|
||||
}
|
||||
|
||||
FspFileSystemReleaseDirectoryBuffer(&directory_buffer);
|
||||
FspFileSystemReleaseDirectoryBuffer(directory_buffer);
|
||||
}
|
||||
|
||||
if (status_result == STATUS_SUCCESS) {
|
||||
FspFileSystemReadDirectoryBuffer(&directory_buffer, marker,
|
||||
buffer, buffer_length,
|
||||
FspFileSystemReadDirectoryBuffer(directory_buffer, marker, buffer,
|
||||
buffer_length,
|
||||
bytes_transferred);
|
||||
if (error == api_error::directory_end_of_files) {
|
||||
error = api_error::success;
|
||||
|
Loading…
x
Reference in New Issue
Block a user