From 2da5db933cc0510f1e80c873b33c79d0bd2a9e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 6 Jan 2025 21:51:57 +0100 Subject: [PATCH] [MOUNTMGR_APITEST] Add utils.c for some utility functions (#6990) And update the precompiled header. --- .../rostests/apitests/mountmgr/CMakeLists.txt | 6 +-- modules/rostests/apitests/mountmgr/precomp.h | 30 +++++++++--- modules/rostests/apitests/mountmgr/utils.c | 49 +++++++++++++++++++ 3 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 modules/rostests/apitests/mountmgr/utils.c diff --git a/modules/rostests/apitests/mountmgr/CMakeLists.txt b/modules/rostests/apitests/mountmgr/CMakeLists.txt index 4c499c26a98..dbba2775f56 100644 --- a/modules/rostests/apitests/mountmgr/CMakeLists.txt +++ b/modules/rostests/apitests/mountmgr/CMakeLists.txt @@ -1,6 +1,7 @@ list(APPEND SOURCE - QueryPoints.c) + QueryPoints.c + utils.c) list(APPEND PCH_SKIP_SOURCE testlist.c) @@ -9,9 +10,8 @@ add_executable(mountmgr_apitest ${SOURCE} ${PCH_SKIP_SOURCE}) +add_pch(mountmgr_apitest precomp.h "${PCH_SKIP_SOURCE}") target_link_libraries(mountmgr_apitest wine ${PSEH_LIB}) set_module_type(mountmgr_apitest win32cui) add_importlibs(mountmgr_apitest msvcrt kernel32 ntdll) -# TODO: Enable this when we get more than one source file to justify its use -#add_pch(mountmgr_apitest precomp.h "${PCH_SKIP_SOURCE}") add_rostests_file(TARGET mountmgr_apitest) diff --git a/modules/rostests/apitests/mountmgr/precomp.h b/modules/rostests/apitests/mountmgr/precomp.h index 33509fb8083..462f62e1a38 100644 --- a/modules/rostests/apitests/mountmgr/precomp.h +++ b/modules/rostests/apitests/mountmgr/precomp.h @@ -1,12 +1,28 @@ -#ifndef _MOUNTMGR_APITEST_PRECOMP_H_ -#define _MOUNTMGR_APITEST_PRECOMP_H_ +/* + * PROJECT: ReactOS API Tests + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Precompiled header + * COPYRIGHT: Copyright 2019 Pierre Schweitzer + * Copyright 2025 Hermès Bélusca-Maïto + */ + +#pragma once #define WIN32_NO_STATUS - #include -#include -#include -#include + +#define NTOS_MODE_USER +#include #include -#endif /* _MOUNTMGR_APITEST_PRECOMP_H_ */ +#include +#include + +/* utils.c */ + +LPCSTR wine_dbgstr_us(const UNICODE_STRING *us); + +HANDLE +GetMountMgrHandle(VOID); + +/* EOF */ diff --git a/modules/rostests/apitests/mountmgr/utils.c b/modules/rostests/apitests/mountmgr/utils.c new file mode 100644 index 00000000000..50755581f04 --- /dev/null +++ b/modules/rostests/apitests/mountmgr/utils.c @@ -0,0 +1,49 @@ +/* + * PROJECT: ReactOS API Tests + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Utility functions + * COPYRIGHT: Copyright 2025 Hermès Bélusca-Maïto + */ + +#include "precomp.h" + +LPCSTR wine_dbgstr_us(const UNICODE_STRING *us) +{ + if (!us) return "(null)"; + return wine_dbgstr_wn(us->Buffer, us->Length / sizeof(WCHAR)); +} + +/** + * @brief + * Retrieves a handle to the MountMgr controlling device. + * The handle should be closed with NtClose() once it is no longer in use. + **/ +HANDLE +GetMountMgrHandle(VOID) +{ + NTSTATUS Status; + UNICODE_STRING MountMgrDevice; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE MountMgrHandle = NULL; + + RtlInitUnicodeString(&MountMgrDevice, MOUNTMGR_DEVICE_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &MountMgrDevice, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtOpenFile(&MountMgrHandle, + FILE_READ_ATTRIBUTES | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SYNCHRONOUS_IO_NONALERT); + if (!NT_SUCCESS(Status)) + { + winetest_print("NtOpenFile(%s) failed, Status 0x%08lx\n", + wine_dbgstr_us(&MountMgrDevice), Status); + } + + return MountMgrHandle; +}