Author: ekohl
Date: Sun Nov 22 17:55:40 2015
New Revision: 70037
URL:
http://svn.reactos.org/svn/reactos?rev=70037&view=rev
Log:
[KERNEL32]
GetDriveTypeW: Use neither CreateFileW nor InternalOpenDirW to open the drive, because
both functions call SetLastError upon failure. This can cause failing checks in lines 23,
44 and 59 of the kernel32_apitest:GetDriveType test. Use NtOpenFile instead.
Modified:
trunk/reactos/dll/win32/kernel32/client/file/disk.c
Modified: trunk/reactos/dll/win32/kernel32/client/file/disk.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/disk.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/disk.c [iso-8859-1] Sun Nov 22 17:55:40
2015
@@ -377,15 +377,19 @@
GetDriveTypeW(IN LPCWSTR lpRootPathName)
{
FILE_FS_DEVICE_INFORMATION FileFsDevice;
+ OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
- HANDLE hFile;
- NTSTATUS errCode;
+ UNICODE_STRING PathName;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+ PWSTR CurrentDir = NULL;
+ PCWSTR lpRootPath;
if (!lpRootPathName)
{
/* If NULL is passed, use current directory path */
DWORD BufferSize = GetCurrentDirectoryW(0, NULL);
- LPWSTR CurrentDir = HeapAlloc(GetProcessHeap(), 0, BufferSize * sizeof(WCHAR));
+ CurrentDir = HeapAlloc(GetProcessHeap(), 0, BufferSize * sizeof(WCHAR));
if (!CurrentDir)
return DRIVE_UNKNOWN;
if (!GetCurrentDirectoryW(BufferSize, CurrentDir))
@@ -393,31 +397,59 @@
HeapFree(GetProcessHeap(), 0, CurrentDir);
return DRIVE_UNKNOWN;
}
- hFile = InternalOpenDirW(CurrentDir, FALSE);
+
+ if (wcslen(CurrentDir) > 3)
+ CurrentDir[3] = 0;
+
+ lpRootPath = (PCWSTR)CurrentDir;
+ }
+ else
+ {
+ TRACE("lpRootPathName: %S\n", lpRootPathName);
+ lpRootPath = lpRootPathName;
+ }
+
+ TRACE("lpRootPath: %S\n", lpRootPath);
+
+ if (!RtlDosPathNameToNtPathName_U(lpRootPath, &PathName, NULL, NULL))
+ {
+ if (CurrentDir != NULL)
+ HeapFree(GetProcessHeap(), 0, CurrentDir);
+
+ return DRIVE_NO_ROOT_DIR;
+ }
+
+ TRACE("PathName: %S\n", PathName.Buffer);
+
+ if (CurrentDir != NULL)
HeapFree(GetProcessHeap(), 0, CurrentDir);
- }
- else
- {
- hFile = InternalOpenDirW(lpRootPathName, FALSE);
- }
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */
- }
-
- errCode = NtQueryVolumeInformationFile (hFile,
- &IoStatusBlock,
- &FileFsDevice,
- sizeof(FILE_FS_DEVICE_INFORMATION),
- FileFsDeviceInformation);
- if (!NT_SUCCESS(errCode))
- {
- CloseHandle(hFile);
- BaseSetLastNTError (errCode);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &PathName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ RtlFreeHeap(RtlGetProcessHeap(), 0, PathName.Buffer);
+ if (!NT_SUCCESS(Status))
+ return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */
+
+ Status = NtQueryVolumeInformationFile(FileHandle,
+ &IoStatusBlock,
+ &FileFsDevice,
+ sizeof(FILE_FS_DEVICE_INFORMATION),
+ FileFsDeviceInformation);
+ NtClose(FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
return 0;
}
- CloseHandle(hFile);
switch (FileFsDevice.DeviceType)
{