From: Eric Kohl Date: Sun, 22 Nov 2015 17:55:40 +0000 (+0000) Subject: [KERNEL32] X-Git-Tag: ReactOS-0.4.0~60^2~70 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=317a71e165bae6b7814903380bdf38a31d20ca06 [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. svn path=/trunk/; revision=70037 --- diff --git a/reactos/dll/win32/kernel32/client/file/disk.c b/reactos/dll/win32/kernel32/client/file/disk.c index 5d35637c87f..5c45181bfda 100644 --- a/reactos/dll/win32/kernel32/client/file/disk.c +++ b/reactos/dll/win32/kernel32/client/file/disk.c @@ -377,15 +377,19 @@ WINAPI 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 @@ GetDriveTypeW(IN LPCWSTR lpRootPathName) HeapFree(GetProcessHeap(), 0, CurrentDir); return DRIVE_UNKNOWN; } - hFile = InternalOpenDirW(CurrentDir, FALSE); - HeapFree(GetProcessHeap(), 0, CurrentDir); + + if (wcslen(CurrentDir) > 3) + CurrentDir[3] = 0; + + lpRootPath = (PCWSTR)CurrentDir; } else { - hFile = InternalOpenDirW(lpRootPathName, FALSE); + TRACE("lpRootPathName: %S\n", lpRootPathName); + lpRootPath = lpRootPathName; } - if (hFile == INVALID_HANDLE_VALUE) + TRACE("lpRootPath: %S\n", lpRootPath); + + if (!RtlDosPathNameToNtPathName_U(lpRootPath, &PathName, NULL, NULL)) { - return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */ + if (CurrentDir != NULL) + HeapFree(GetProcessHeap(), 0, CurrentDir); + + return DRIVE_NO_ROOT_DIR; } - errCode = NtQueryVolumeInformationFile (hFile, - &IoStatusBlock, - &FileFsDevice, - sizeof(FILE_FS_DEVICE_INFORMATION), - FileFsDeviceInformation); - if (!NT_SUCCESS(errCode)) + TRACE("PathName: %S\n", PathName.Buffer); + + if (CurrentDir != NULL) + HeapFree(GetProcessHeap(), 0, CurrentDir); + + 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)) { - CloseHandle(hFile); - BaseSetLastNTError (errCode); return 0; } - CloseHandle(hFile); switch (FileFsDevice.DeviceType) {