Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138/* * PROJECT: ReactOS Setup Library * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) * PURPOSE: Device utility functions * COPYRIGHT: Copyright 2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org> */
#include "precomp.h"#include "devutils.h"
/* FUNCTIONS *****************************************************************/
/** * @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 * Supplies the NT-style path to the device to open. * * @param[out] DeviceHandle * If successful, receives the NT handle of the opened device. * Once the handle is no longer in use, call NtClose() to close it. * * @param[in] DesiredAccess * An ACCESS_MASK value combination that determines the requested access * to the device. Because the open is for synchronous access, SYNCHRONIZE * is automatically added to the access mask. * * @param[in] ShareAccess * Specifies the type of share access for the device. * * @return An NTSTATUS code indicating success or failure. * * @see pOpenDeviceEx() **/NTSTATUSpOpenDeviceEx_UStr( _In_ PCUNICODE_STRING DevicePath, _Out_ PHANDLE DeviceHandle, _In_ ACCESS_MASK DesiredAccess, _In_ ULONG ShareAccess){ OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock;
InitializeObjectAttributes(&ObjectAttributes, (PUNICODE_STRING)DevicePath, OBJ_CASE_INSENSITIVE, NULL, NULL); return NtOpenFile(DeviceHandle, DesiredAccess | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, ShareAccess, /* FILE_NON_DIRECTORY_FILE | */ FILE_SYNCHRONOUS_IO_NONALERT);}
/** * @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 pOpenDevice(), pOpenDeviceEx(), pOpenDeviceEx_UStr() **/NTSTATUSpOpenDevice_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() **/NTSTATUSpOpenDeviceEx( _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() **/NTSTATUSpOpenDevice( _In_ PCWSTR DevicePath, _Out_ PHANDLE DeviceHandle){ UNICODE_STRING Name; RtlInitUnicodeString(&Name, DevicePath); return pOpenDevice_UStr(&Name, DeviceHandle);}
/* EOF */