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