mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 17:05:45 +00:00
Minor cleanup of GetVolumeNameForVolumeMountPointW and fix some incorrect return codes (spotted by w3seek).
svn path=/trunk/; revision=20219
This commit is contained in:
parent
4ef6abb3a2
commit
e4556f6060
1 changed files with 42 additions and 36 deletions
|
@ -811,7 +811,6 @@ GetVolumeNameForVolumeMountPointW(
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
HANDLE FileHandle;
|
HANDLE FileHandle;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
PVOID Buffer;
|
|
||||||
ULONG BufferLength;
|
ULONG BufferLength;
|
||||||
PMOUNTDEV_NAME MountDevName;
|
PMOUNTDEV_NAME MountDevName;
|
||||||
PMOUNTMGR_MOUNT_POINT MountPoint;
|
PMOUNTMGR_MOUNT_POINT MountPoint;
|
||||||
|
@ -819,6 +818,7 @@ GetVolumeNameForVolumeMountPointW(
|
||||||
PMOUNTMGR_MOUNT_POINTS MountPoints;
|
PMOUNTMGR_MOUNT_POINTS MountPoints;
|
||||||
ULONG Index;
|
ULONG Index;
|
||||||
PUCHAR SymbolicLinkName;
|
PUCHAR SymbolicLinkName;
|
||||||
|
BOOL Result;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -858,29 +858,31 @@ GetVolumeNameForVolumeMountPointW(
|
||||||
BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR);
|
BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
MountDevName = Buffer = RtlAllocateHeap(GetProcessHeap(), 0, BufferLength);
|
MountDevName = RtlAllocateHeap(GetProcessHeap(), 0, BufferLength);
|
||||||
if (Buffer == NULL)
|
if (MountDevName == NULL)
|
||||||
{
|
{
|
||||||
NtClose(FileHandle);
|
NtClose(FileHandle);
|
||||||
SetLastErrorByStatus(Status);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
|
Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
|
||||||
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
|
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
|
||||||
NULL, 0, Buffer, BufferLength);
|
NULL, 0, MountDevName, BufferLength);
|
||||||
if (Status == STATUS_BUFFER_OVERFLOW)
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength;
|
RtlFreeHeap(GetProcessHeap(), 0, MountDevName);
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, Buffer);
|
if (Status == STATUS_BUFFER_OVERFLOW)
|
||||||
continue;
|
{
|
||||||
}
|
BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength;
|
||||||
else if (!NT_SUCCESS(Status))
|
continue;
|
||||||
{
|
}
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, Buffer);
|
else
|
||||||
NtClose(FileHandle);
|
{
|
||||||
SetLastErrorByStatus(Status);
|
NtClose(FileHandle);
|
||||||
return FALSE;
|
SetLastErrorByStatus(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!NT_SUCCESS(Status));
|
while (!NT_SUCCESS(Status));
|
||||||
|
@ -920,31 +922,33 @@ GetVolumeNameForVolumeMountPointW(
|
||||||
BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS);
|
BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
MountPoints = Buffer = RtlAllocateHeap(GetProcessHeap(), 0, BufferLength);
|
MountPoints = RtlAllocateHeap(GetProcessHeap(), 0, BufferLength);
|
||||||
if (Buffer == NULL)
|
if (MountPoints == NULL)
|
||||||
{
|
{
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, MountPoint);
|
RtlFreeHeap(GetProcessHeap(), 0, MountPoint);
|
||||||
NtClose(FileHandle);
|
NtClose(FileHandle);
|
||||||
SetLastErrorByStatus(Status);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
|
Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
|
||||||
IOCTL_MOUNTMGR_QUERY_POINTS,
|
IOCTL_MOUNTMGR_QUERY_POINTS,
|
||||||
MountPoint, MountPointSize,
|
MountPoint, MountPointSize,
|
||||||
Buffer, BufferLength);
|
MountPoints, BufferLength);
|
||||||
if (Status == STATUS_BUFFER_OVERFLOW)
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
BufferLength = MountPoints->Size;
|
RtlFreeHeap(GetProcessHeap(), 0, MountPoints);
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, Buffer);
|
if (Status == STATUS_BUFFER_OVERFLOW)
|
||||||
continue;
|
{
|
||||||
}
|
BufferLength = MountPoints->Size;
|
||||||
else if (!NT_SUCCESS(Status))
|
continue;
|
||||||
{
|
}
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, MountPoint);
|
else if (!NT_SUCCESS(Status))
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, Buffer);
|
{
|
||||||
SetLastErrorByStatus(Status);
|
RtlFreeHeap(GetProcessHeap(), 0, MountPoint);
|
||||||
return FALSE;
|
SetLastErrorByStatus(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!NT_SUCCESS(Status));
|
while (!NT_SUCCESS(Status));
|
||||||
|
@ -983,14 +987,16 @@ GetVolumeNameForVolumeMountPointW(
|
||||||
(PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset,
|
(PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset,
|
||||||
MountPoint->SymbolicLinkNameLength);
|
MountPoint->SymbolicLinkNameLength);
|
||||||
VolumeName[1] = L'\\';
|
VolumeName[1] = L'\\';
|
||||||
|
Result = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, MountPoints);
|
RtlFreeHeap(GetProcessHeap(), 0, MountPoints);
|
||||||
return TRUE;
|
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
||||||
|
Result = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, MountPoints);
|
return Result;
|
||||||
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue