}
-CHAR
-GetDriveLetter(ULONG DriveNumber,
- ULONG PartitionNumber)
-{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING LinkName;
- WCHAR LinkBuffer[8];
- CHAR Letter;
- HANDLE LinkHandle;
- UNICODE_STRING TargetName;
- PWCHAR TargetBuffer;
- PWCHAR DeviceBuffer;
- ULONG Length;
- NTSTATUS Status;
-
- wcscpy(LinkBuffer, L"\\??\\A:");
-
- RtlInitUnicodeString(&LinkName,
- LinkBuffer);
-
- InitializeObjectAttributes(&ObjectAttributes,
- &LinkName,
- OBJ_OPENLINK,
- NULL,
- NULL);
-
- TargetBuffer = RtlAllocateHeap(ProcessHeap, 0, MAX_PATH * sizeof(WCHAR));
- DeviceBuffer = RtlAllocateHeap(ProcessHeap, 0, MAX_PATH * sizeof(WCHAR));
-
- TargetName.Length = 0;
- TargetName.MaximumLength = MAX_PATH * sizeof(WCHAR);
- TargetName.Buffer = TargetBuffer;
-
- swprintf(DeviceBuffer,
- L"\\Device\\Harddisk%lu\\Partition%lu",
- DriveNumber,
- PartitionNumber);
-
- for (Letter = 'C'; Letter <= 'Z'; Letter++)
- {
- LinkBuffer[4] = (WCHAR)Letter;
- TargetName.Length = 0;
-
- Status = NtOpenSymbolicLinkObject(&LinkHandle,
- SYMBOLIC_LINK_ALL_ACCESS,
- &ObjectAttributes);
- if (NT_SUCCESS(Status))
- {
- Status = NtQuerySymbolicLinkObject(LinkHandle,
- &TargetName,
- &Length);
- NtClose(LinkHandle);
- if (NT_SUCCESS(Status))
- {
- if (_wcsicmp(DeviceBuffer, TargetBuffer) == 0)
- {
- RtlFreeHeap(ProcessHeap, 0, DeviceBuffer);
- RtlFreeHeap(ProcessHeap, 0, TargetBuffer);
- return(Letter);
- }
- }
- }
- }
-
- RtlFreeHeap(ProcessHeap, 0, DeviceBuffer);
- RtlFreeHeap(ProcessHeap, 0, TargetBuffer);
-
- return((CHAR)0);
-}
-
/* EOF */