Skip to content

Commit ad5d9aa

Browse files
committed
[SETUPLIB] Add UNICODE_STRING versions of the pOpenDevice helpers (reactos#7310)
+ Use a FILE_SHARE_ALL define. Based on a suggestion from Whindmar Saksit.
1 parent 1d3bce1 commit ad5d9aa

File tree

2 files changed

+79
-12
lines changed

2 files changed

+79
-12
lines changed

base/setup/lib/utils/devutils.c

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
* Specifies the type of share access for the device.
3232
*
3333
* @return An NTSTATUS code indicating success or failure.
34+
*
35+
* @see pOpenDeviceEx()
3436
**/
3537
NTSTATUS
36-
pOpenDeviceEx(
37-
_In_ PCWSTR DevicePath,
38+
pOpenDeviceEx_UStr(
39+
_In_ PCUNICODE_STRING DevicePath,
3840
_Out_ PHANDLE DeviceHandle,
3941
_In_ ACCESS_MASK DesiredAccess,
4042
_In_ ULONG ShareAccess)
4143
{
42-
UNICODE_STRING Name;
4344
OBJECT_ATTRIBUTES ObjectAttributes;
4445
IO_STATUS_BLOCK IoStatusBlock;
4546

46-
RtlInitUnicodeString(&Name, DevicePath);
4747
InitializeObjectAttributes(&ObjectAttributes,
48-
&Name,
48+
(PUNICODE_STRING)DevicePath,
4949
OBJ_CASE_INSENSITIVE,
5050
NULL,
5151
NULL);
@@ -66,22 +66,72 @@ pOpenDeviceEx(
6666
*
6767
* @param[in] DevicePath
6868
* @param[out] DeviceHandle
69-
* See the DevicePath and DeviceHandle parameters of pOpenDeviceEx().
69+
* See the DevicePath and DeviceHandle parameters of pOpenDeviceEx_UStr().
7070
*
7171
* @return An NTSTATUS code indicating success or failure.
7272
*
73-
* @see pOpenDeviceEx()
73+
* @see pOpenDevice(), pOpenDeviceEx(), pOpenDeviceEx_UStr()
74+
**/
75+
NTSTATUS
76+
pOpenDevice_UStr(
77+
_In_ PCUNICODE_STRING DevicePath,
78+
_Out_ PHANDLE DeviceHandle)
79+
{
80+
return pOpenDeviceEx_UStr(DevicePath,
81+
DeviceHandle,
82+
FILE_READ_DATA | FILE_READ_ATTRIBUTES,
83+
FILE_SHARE_ALL);
84+
}
85+
86+
/**
87+
* @brief
88+
* Open an existing device given by its NT-style path, which is assumed to be
89+
* for a disk device or a partition. The open is for synchronous I/O access.
90+
*
91+
* @param[in] DevicePath
92+
* @param[out] DeviceHandle
93+
* @param[in] DesiredAccess
94+
* @param[in] ShareAccess
95+
* See pOpenDeviceEx_UStr() parameters.
96+
*
97+
* @return An NTSTATUS code indicating success or failure.
98+
*
99+
* @see pOpenDeviceEx_UStr()
100+
**/
101+
NTSTATUS
102+
pOpenDeviceEx(
103+
_In_ PCWSTR DevicePath,
104+
_Out_ PHANDLE DeviceHandle,
105+
_In_ ACCESS_MASK DesiredAccess,
106+
_In_ ULONG ShareAccess)
107+
{
108+
UNICODE_STRING Name;
109+
RtlInitUnicodeString(&Name, DevicePath);
110+
return pOpenDeviceEx_UStr(&Name, DeviceHandle, DesiredAccess, ShareAccess);
111+
}
112+
113+
/**
114+
* @brief
115+
* Open an existing device given by its NT-style path, which is assumed to be
116+
* for a disk device or a partition. The open is share read/write/delete, for
117+
* synchronous I/O and read access.
118+
*
119+
* @param[in] DevicePath
120+
* @param[out] DeviceHandle
121+
* See the DevicePath and DeviceHandle parameters of pOpenDeviceEx_UStr().
122+
*
123+
* @return An NTSTATUS code indicating success or failure.
124+
*
125+
* @see pOpenDeviceEx(), pOpenDevice_UStr(), pOpenDeviceEx_UStr()
74126
**/
75127
NTSTATUS
76128
pOpenDevice(
77129
_In_ PCWSTR DevicePath,
78130
_Out_ PHANDLE DeviceHandle)
79131
{
80-
return pOpenDeviceEx(DevicePath,
81-
DeviceHandle,
82-
FILE_READ_DATA | FILE_READ_ATTRIBUTES,
83-
FILE_SHARE_VALID_FLAGS // FILE_SHARE_READ,WRITE,DELETE
84-
);
132+
UNICODE_STRING Name;
133+
RtlInitUnicodeString(&Name, DevicePath);
134+
return pOpenDevice_UStr(&Name, DeviceHandle);
85135
}
86136

87137
/* EOF */

base/setup/lib/utils/devutils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@
77

88
#pragma once
99

10+
/* Flags combination allowing all the read, write and delete share modes.
11+
* Currently similar to FILE_SHARE_VALID_FLAGS. */
12+
#define FILE_SHARE_ALL \
13+
(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
14+
1015
/* FUNCTIONS *****************************************************************/
1116

17+
NTSTATUS
18+
pOpenDeviceEx_UStr(
19+
_In_ PCUNICODE_STRING DevicePath,
20+
_Out_ PHANDLE DeviceHandle,
21+
_In_ ACCESS_MASK DesiredAccess,
22+
_In_ ULONG ShareAccess);
23+
24+
NTSTATUS
25+
pOpenDevice_UStr(
26+
_In_ PCUNICODE_STRING DevicePath,
27+
_Out_ PHANDLE DeviceHandle);
28+
1229
NTSTATUS
1330
pOpenDeviceEx(
1431
_In_ PCWSTR DevicePath,

0 commit comments

Comments
 (0)