https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ad5d9aa28acc256a7b3a3550433e9dd884842308

commit ad5d9aa28acc256a7b3a3550433e9dd884842308
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Sat Aug 31 20:20:38 2024 +0200
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Sun Oct 20 16:51:16 2024 +0200

    [SETUPLIB] Add UNICODE_STRING versions of the pOpenDevice helpers (#7310)
    
    + Use a FILE_SHARE_ALL define. Based on a suggestion from Whindmar Saksit.
---
 base/setup/lib/utils/devutils.c | 74 ++++++++++++++++++++++++++++++++++-------
 base/setup/lib/utils/devutils.h | 17 ++++++++++
 2 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/base/setup/lib/utils/devutils.c b/base/setup/lib/utils/devutils.c
index f8bc8a83daf..fd20a98ae32 100644
--- a/base/setup/lib/utils/devutils.c
+++ b/base/setup/lib/utils/devutils.c
@@ -31,21 +31,21 @@
  * Specifies the type of share access for the device.
  *
  * @return  An NTSTATUS code indicating success or failure.
+ *
+ * @see pOpenDeviceEx()
  **/
 NTSTATUS
-pOpenDeviceEx(
-    _In_ PCWSTR DevicePath,
+pOpenDeviceEx_UStr(
+    _In_ PCUNICODE_STRING DevicePath,
     _Out_ PHANDLE DeviceHandle,
     _In_ ACCESS_MASK DesiredAccess,
     _In_ ULONG ShareAccess)
 {
-    UNICODE_STRING Name;
     OBJECT_ATTRIBUTES ObjectAttributes;
     IO_STATUS_BLOCK IoStatusBlock;
 
-    RtlInitUnicodeString(&Name, DevicePath);
     InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
+                               (PUNICODE_STRING)DevicePath,
                                OBJ_CASE_INSENSITIVE,
                                NULL,
                                NULL);
@@ -66,22 +66,72 @@ pOpenDeviceEx(
  *
  * @param[in]   DevicePath
  * @param[out]  DeviceHandle
- * See the DevicePath and DeviceHandle parameters of pOpenDeviceEx().
+ * See the DevicePath and DeviceHandle parameters of pOpenDeviceEx_UStr().
  *
  * @return  An NTSTATUS code indicating success or failure.
  *
- * @see pOpenDeviceEx()
+ * @see pOpenDevice(), pOpenDeviceEx(), pOpenDeviceEx_UStr()
+ **/
+NTSTATUS
+pOpenDevice_UStr(
+    _In_ PCUNICODE_STRING DevicePath,
+    _Out_ PHANDLE DeviceHandle)
+{
+    return pOpenDeviceEx_UStr(DevicePath,
+                              DeviceHandle,
+                              FILE_READ_DATA | FILE_READ_ATTRIBUTES,
+                              FILE_SHARE_ALL);
+}
+
+/**
+ * @brief
+ * Open an existing device given by its NT-style path, which is assumed to be
+ * for a disk device or a partition. The open is for synchronous I/O access.
+ *
+ * @param[in]   DevicePath
+ * @param[out]  DeviceHandle
+ * @param[in]   DesiredAccess
+ * @param[in]   ShareAccess
+ * See pOpenDeviceEx_UStr() parameters.
+ *
+ * @return  An NTSTATUS code indicating success or failure.
+ *
+ * @see pOpenDeviceEx_UStr()
+ **/
+NTSTATUS
+pOpenDeviceEx(
+    _In_ PCWSTR DevicePath,
+    _Out_ PHANDLE DeviceHandle,
+    _In_ ACCESS_MASK DesiredAccess,
+    _In_ ULONG ShareAccess)
+{
+    UNICODE_STRING Name;
+    RtlInitUnicodeString(&Name, DevicePath);
+    return pOpenDeviceEx_UStr(&Name, DeviceHandle, DesiredAccess, ShareAccess);
+}
+
+/**
+ * @brief
+ * Open an existing device given by its NT-style path, which is assumed to be
+ * for a disk device or a partition. The open is share read/write/delete, for
+ * synchronous I/O and read access.
+ *
+ * @param[in]   DevicePath
+ * @param[out]  DeviceHandle
+ * See the DevicePath and DeviceHandle parameters of pOpenDeviceEx_UStr().
+ *
+ * @return  An NTSTATUS code indicating success or failure.
+ *
+ * @see pOpenDeviceEx(), pOpenDevice_UStr(), pOpenDeviceEx_UStr()
  **/
 NTSTATUS
 pOpenDevice(
     _In_ PCWSTR DevicePath,
     _Out_ PHANDLE DeviceHandle)
 {
-    return pOpenDeviceEx(DevicePath,
-                         DeviceHandle,
-                         FILE_READ_DATA | FILE_READ_ATTRIBUTES,
-                         FILE_SHARE_VALID_FLAGS // FILE_SHARE_READ,WRITE,DELETE
-                         );
+    UNICODE_STRING Name;
+    RtlInitUnicodeString(&Name, DevicePath);
+    return pOpenDevice_UStr(&Name, DeviceHandle);
 }
 
 /* EOF */
diff --git a/base/setup/lib/utils/devutils.h b/base/setup/lib/utils/devutils.h
index 63bbb624d66..028e2d983c4 100644
--- a/base/setup/lib/utils/devutils.h
+++ b/base/setup/lib/utils/devutils.h
@@ -7,8 +7,25 @@
 
 #pragma once
 
+/* Flags combination allowing all the read, write and delete share modes.
+ * Currently similar to FILE_SHARE_VALID_FLAGS. */
+#define FILE_SHARE_ALL \
+    (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
+
 /* FUNCTIONS *****************************************************************/
 
+NTSTATUS
+pOpenDeviceEx_UStr(
+    _In_ PCUNICODE_STRING DevicePath,
+    _Out_ PHANDLE DeviceHandle,
+    _In_ ACCESS_MASK DesiredAccess,
+    _In_ ULONG ShareAccess);
+
+NTSTATUS
+pOpenDevice_UStr(
+    _In_ PCUNICODE_STRING DevicePath,
+    _Out_ PHANDLE DeviceHandle);
+
 NTSTATUS
 pOpenDeviceEx(
     _In_ PCWSTR DevicePath,

Reply via email to