This commit is contained in:
Scott E. Graves 2024-11-07 09:57:21 -06:00
parent 2945793de9
commit 876a1e9cd8
4 changed files with 53 additions and 56 deletions

View File

@ -50,10 +50,10 @@ public:
private:
app_config &config_;
lock_data &lock_;
remote_winfsp_drive &drive_;
const std::vector<std::string> drive_args_;
FileSystemHost host_;
lock_data &lock_;
protected:
auto OnStart(ULONG, PWSTR *) -> NTSTATUS override;
@ -75,8 +75,8 @@ private:
static void set_file_info(FileInfo &dest, const remote::file_info &src);
public:
auto CanDelete(PVOID file_node, PVOID file_desc,
PWSTR file_name) -> NTSTATUS override;
auto CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name)
-> NTSTATUS override;
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name,
ULONG flags) override;
@ -88,11 +88,11 @@ public:
UINT64 allocation_size, PVOID *file_node, PVOID *file_desc,
OpenFileInfo *ofi) -> NTSTATUS override;
auto Flush(PVOID file_node, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS override;
auto Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info)
-> NTSTATUS override;
auto GetFileInfo(PVOID file_node, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS override;
auto GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info)
-> NTSTATUS override;
auto GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
@ -107,8 +107,8 @@ public:
auto Mounted(PVOID host) -> NTSTATUS override;
auto Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
PVOID *file_node, PVOID *file_desc,
OpenFileInfo *ofi) -> NTSTATUS override;
PVOID *file_node, PVOID *file_desc, OpenFileInfo *ofi)
-> NTSTATUS override;
auto Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
BOOLEAN replace_attributes, UINT64 allocation_size,
@ -122,8 +122,8 @@ public:
PULONG bytes_transferred) -> NTSTATUS override;
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists) -> NTSTATUS override;
PWSTR new_file_name, BOOLEAN replace_if_exists)
-> NTSTATUS override;
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,
UINT64 creation_time, UINT64 last_access_time,
@ -131,15 +131,15 @@ public:
FileInfo *file_info) -> NTSTATUS override;
auto SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
FileInfo *file_info) -> NTSTATUS override;
BOOLEAN set_allocation_size, FileInfo *file_info)
-> NTSTATUS override;
VOID Unmounted(PVOID host) override;
auto Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
ULONG length, BOOLEAN write_to_end, BOOLEAN constrained_io,
PULONG bytes_transferred,
FileInfo *file_info) -> NTSTATUS override;
PULONG bytes_transferred, FileInfo *file_info)
-> NTSTATUS override;
void shutdown() { ::GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); }

View File

@ -53,11 +53,11 @@ private:
~winfsp_service() override = default;
private:
lock_data &lock_;
winfsp_drive &drive_;
const std::vector<std::string> drive_args_;
FileSystemHost host_;
app_config &config_;
winfsp_drive &drive_;
std::vector<std::string> drive_args_;
FileSystemHost host_;
lock_data &lock_;
protected:
auto OnStart(ULONG, PWSTR *) -> NTSTATUS override;

View File

@ -41,20 +41,19 @@ namespace repertory::remote_winfsp {
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]),
: Service(std::wstring{REPERTORY_W}.data()),
config_(config),
lock_(lock),
drive_(drive),
drive_args_(std::move(drive_args)),
host_(drive) {}
host_(drive),
lock_(lock) {}
auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME();
const auto mount_location = utils::string::to_lower(utils::path::absolute(
auto mount_location = utils::string::to_lower(utils::path::absolute(
(drive_args_.size() > 1U) ? drive_args_.at(1U) : ""));
const auto drive_letter =
auto drive_letter =
((mount_location.size() == 2U) ||
((mount_location.size() == 3U) && (mount_location.at(2U) == '\\'))) &&
(mount_location.at(1U) == ':');
@ -137,7 +136,7 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
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);
auto file_path = utils::string::from_utf8(normalized_name);
wcsncpy(ofi->NormalizedName, file_path.data(), wcslen(file_path.c_str()));
ofi->NormalizedNameSize =
static_cast<UINT16>(wcslen(file_path.c_str()) * sizeof(WCHAR));
@ -196,8 +195,7 @@ auto remote_winfsp_drive::GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS {
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));
auto byte_size = static_cast<UINT16>(volume_label.size() * sizeof(WCHAR));
wcscpy_s(&volume_info->VolumeLabel[0U], 32,
utils::string::from_utf8(volume_label).c_str());
volume_info->VolumeLabelLength =
@ -213,20 +211,20 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
&(L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0U, 1U))[0U]);
}
file_system_host->SetFileSystemName(std::wstring{REPERTORY_W}.data());
file_system_host->SetCasePreservedNames(TRUE);
file_system_host->SetCaseSensitiveSearch(FALSE);
file_system_host->SetFileInfoTimeout(1000);
file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
file_system_host->SetNamedStreams(FALSE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetReparsePoints(FALSE);
file_system_host->SetReparsePointsAccessCheck(FALSE);
file_system_host->SetSectorSize(WINFSP_ALLOCATION_UNIT);
file_system_host->SetSectorsPerAllocationUnit(1);
file_system_host->SetFileInfoTimeout(1000);
file_system_host->SetCaseSensitiveSearch(FALSE);
file_system_host->SetCasePreservedNames(TRUE);
file_system_host->SetNamedStreams(FALSE);
file_system_host->SetUnicodeOnDisk(TRUE);
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::time::get_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;
@ -236,10 +234,10 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
-> int {
std::vector<std::string> parsed_drive_args;
const auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false;
for (const auto &arg : drive_args) {
for (auto &&arg : drive_args) {
if (arg == "-f") {
if (not force_no_console) {
enable_console = true;
@ -289,7 +287,7 @@ auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
file_desc, &fi, normalize_name);
if (ret == STATUS_SUCCESS) {
set_file_info(ofi->FileInfo, fi);
const auto file_path = utils::string::from_utf8(normalize_name);
auto file_path = utils::string::from_utf8(normalize_name);
wcsncpy(ofi->NormalizedName, file_path.data(), wcslen(file_path.c_str()));
ofi->NormalizedNameSize =
static_cast<UINT16>(wcslen(file_path.c_str()) * sizeof(WCHAR));
@ -312,7 +310,7 @@ auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
void remote_winfsp_drive::populate_file_info(const json &item,
FSP_FSCTL_FILE_INFO &file_info) {
const auto di = directory_item::from_json(item);
auto di = directory_item::from_json(item);
file_info.FileSize = di.directory ? 0 : di.size;
file_info.AllocationSize =
utils::divide_with_ceiling(file_info.FileSize, WINFSP_ALLOCATION_UNIT) *
@ -353,9 +351,9 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
&ret)) {
auto item_found = false;
for (const auto &item : item_list) {
const auto item_path = item["path"].get<std::string>();
const auto display_name = utils::string::from_utf8(
for (auto &&item : item_list) {
auto item_path = item["path"].get<std::string>();
auto display_name = utils::string::from_utf8(
utils::path::strip_to_file_name(item_path));
if (not marker || (marker && item_found)) {
// if (not utils::path::is_ads_file_path(item_path)) {

View File

@ -61,11 +61,11 @@ winfsp_drive::winfsp_service::winfsp_service(
lock_data &lock, winfsp_drive &drive, std::vector<std::string> drive_args,
app_config &config)
: Service(std::wstring{REPERTORY_W}.data()),
lock_(lock),
config_(config),
drive_(drive),
drive_args_(std::move(drive_args)),
host_(drive),
config_(config) {}
lock_(lock) {}
auto winfsp_drive::handle_error(std::string_view function_name,
const std::string &api_path, api_error error,
@ -554,25 +554,24 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
if (not config_.get_enable_mount_manager()) {
file_system_host->SetPrefix(
(L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0, 1))
.data());
&(L"\\repertory\\" +
std::wstring(file_system_host->FileSystemName()).substr(0U, 1U))[0U]);
}
file_system_host->SetCasePreservedNames(TRUE);
file_system_host->SetCaseSensitiveSearch(TRUE);
file_system_host->SetFileInfoTimeout(1000);
file_system_host->SetFlushAndPurgeOnCleanup(TRUE);
file_system_host->SetMaxComponentLength(255U);
file_system_host->SetNamedStreams(FALSE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetReparsePoints(FALSE);
file_system_host->SetReparsePointsAccessCheck(FALSE);
file_system_host->SetSectorSize(WINFSP_ALLOCATION_UNIT);
file_system_host->SetSectorsPerAllocationUnit(1);
file_system_host->SetFileInfoTimeout(1000);
file_system_host->SetCaseSensitiveSearch(TRUE);
file_system_host->SetCasePreservedNames(TRUE);
file_system_host->SetNamedStreams(FALSE);
file_system_host->SetUnicodeOnDisk(TRUE);
file_system_host->SetMaxComponentLength(255U);
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::time::get_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;