Author: pschweitzer
Date: Tue Sep 26 06:18:07 2017
New Revision: 75969
URL:
http://svn.reactos.org/svn/reactos?rev=75969&view=rev
Log:
[KERNEL32]
W2K3ify GetVolumeInformationA().
Also fix a regression brought by GetVolumeInformationW() rewrite (yay, winetests!).
Modified:
trunk/reactos/dll/win32/kernel32/client/file/volume.c
Modified: trunk/reactos/dll/win32/kernel32/client/file/volume.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/volume.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/volume.c [iso-8859-1] Tue Sep 26 06:18:07
2017
@@ -85,124 +85,113 @@
OUT LPSTR lpFileSystemNameBuffer OPTIONAL,
IN DWORD nFileSystemNameSize)
{
- UNICODE_STRING FileSystemNameU;
- UNICODE_STRING VolumeNameU = { 0, 0, NULL };
- ANSI_STRING VolumeName;
- ANSI_STRING FileSystemName;
- PWCHAR RootPathNameW;
- BOOL Result;
-
- if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
- return FALSE;
-
- if (lpVolumeNameBuffer)
- {
- VolumeNameU.MaximumLength = (USHORT)nVolumeNameSize * sizeof(WCHAR);
- VolumeNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- VolumeNameU.MaximumLength);
- if (VolumeNameU.Buffer == NULL)
- {
- goto FailNoMem;
- }
- }
-
- if (lpFileSystemNameBuffer)
- {
- FileSystemNameU.Length = 0;
- FileSystemNameU.MaximumLength = (USHORT)nFileSystemNameSize * sizeof(WCHAR);
- FileSystemNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- FileSystemNameU.MaximumLength);
- if (FileSystemNameU.Buffer == NULL)
- {
- if (VolumeNameU.Buffer != NULL)
- {
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- VolumeNameU.Buffer);
- }
-
-FailNoMem:
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
- }
- }
-
- Result = GetVolumeInformationW (RootPathNameW,
- lpVolumeNameBuffer ? VolumeNameU.Buffer : NULL,
- nVolumeNameSize,
- lpVolumeSerialNumber,
- lpMaximumComponentLength,
- lpFileSystemFlags,
- lpFileSystemNameBuffer ? FileSystemNameU.Buffer : NULL,
- nFileSystemNameSize);
-
- if (Result)
- {
- if (lpVolumeNameBuffer)
- {
- VolumeNameU.Length = wcslen(VolumeNameU.Buffer) * sizeof(WCHAR);
- VolumeName.Length = 0;
- VolumeName.MaximumLength = (USHORT)nVolumeNameSize;
- VolumeName.Buffer = lpVolumeNameBuffer;
- }
-
- if (lpFileSystemNameBuffer)
- {
- FileSystemNameU.Length = wcslen(FileSystemNameU.Buffer) * sizeof(WCHAR);
- FileSystemName.Length = 0;
- FileSystemName.MaximumLength = (USHORT)nFileSystemNameSize;
- FileSystemName.Buffer = lpFileSystemNameBuffer;
- }
-
- /* convert unicode strings to ansi (or oem) */
- if (bIsFileApiAnsi)
- {
- if (lpVolumeNameBuffer)
- {
- RtlUnicodeStringToAnsiString (&VolumeName,
- &VolumeNameU,
- FALSE);
- }
- if (lpFileSystemNameBuffer)
- {
- RtlUnicodeStringToAnsiString (&FileSystemName,
- &FileSystemNameU,
- FALSE);
- }
- }
- else
- {
- if (lpVolumeNameBuffer)
- {
- RtlUnicodeStringToOemString (&VolumeName,
- &VolumeNameU,
- FALSE);
- }
- if (lpFileSystemNameBuffer)
- {
- RtlUnicodeStringToOemString (&FileSystemName,
- &FileSystemNameU,
- FALSE);
- }
- }
- }
-
- if (lpVolumeNameBuffer)
- {
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- VolumeNameU.Buffer);
- }
- if (lpFileSystemNameBuffer)
- {
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- FileSystemNameU.Buffer);
- }
-
- return Result;
+ BOOL Ret;
+ NTSTATUS Status;
+ PUNICODE_STRING RootPathNameU;
+ ANSI_STRING VolumeName, FileSystemName;
+ UNICODE_STRING VolumeNameU, FileSystemNameU;
+
+ /* If no root path provided, default to \ */
+ if (lpRootPathName == NULL)
+ {
+ lpRootPathName = "\\";
+ }
+
+ /* Convert root path to unicode */
+ RootPathNameU = Basep8BitStringToStaticUnicodeString(lpRootPathName);
+ if (RootPathNameU == NULL)
+ {
+ return FALSE;
+ }
+
+ /* Init all our STRINGS (U/A) */
+ VolumeNameU.Buffer = NULL;
+ VolumeNameU.MaximumLength = 0;
+ FileSystemNameU.Buffer = NULL;
+ FileSystemNameU.MaximumLength = 0;
+
+ VolumeName.Buffer = lpVolumeNameBuffer;
+ VolumeName.MaximumLength = nVolumeNameSize + 1;
+ FileSystemName.Buffer = lpFileSystemNameBuffer;
+ FileSystemName.MaximumLength = nFileSystemNameSize + 1;
+
+ /* Assume failure for now */
+ Ret = FALSE;
+
+ /* If caller wants volume name, allocate a buffer to receive it */
+ if (lpVolumeNameBuffer != NULL)
+ {
+ VolumeNameU.MaximumLength = sizeof(WCHAR) * (nVolumeNameSize + 1);
+ VolumeNameU.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
+ VolumeNameU.MaximumLength);
+ if (VolumeNameU.Buffer == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ goto CleanAndQuit;
+ }
+ }
+
+ /* If caller wants file system name, allocate a buffer to receive it */
+ if (lpFileSystemNameBuffer != NULL)
+ {
+ FileSystemNameU.MaximumLength = sizeof(WCHAR) * (nVolumeNameSize + 1);
+ FileSystemNameU.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
+ FileSystemNameU.MaximumLength);
+ if (FileSystemNameU.Buffer == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ goto CleanAndQuit;
+ }
+ }
+
+ /* Call W */
+ Ret = GetVolumeInformationW(RootPathNameU->Buffer, VolumeNameU.Buffer,
+ nVolumeNameSize, lpVolumeSerialNumber,
+ lpMaximumComponentLength, lpFileSystemFlags,
+ FileSystemNameU.Buffer, nFileSystemNameSize);
+ /* If it succeed, convert back to ANSI */
+ if (Ret)
+ {
+ if (lpVolumeNameBuffer != NULL)
+ {
+ RtlInitUnicodeString(&VolumeNameU, VolumeNameU.Buffer);
+ Status = RtlUnicodeStringToAnsiString(&VolumeName, &VolumeNameU,
FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ Ret = FALSE;
+
+ goto CleanAndQuit;
+ }
+ }
+
+ if (lpFileSystemNameBuffer != NULL)
+ {
+ RtlInitUnicodeString(&FileSystemNameU, FileSystemNameU.Buffer);
+ Status = RtlUnicodeStringToAnsiString(&FileSystemName,
&FileSystemNameU, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ Ret = FALSE;
+
+ goto CleanAndQuit;
+ }
+ }
+ }
+
+ /* Clean and quit */
+CleanAndQuit:
+ if (VolumeNameU.Buffer != NULL)
+ {
+ RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeNameU.Buffer);
+ }
+
+ if (FileSystemNameU.Buffer != NULL)
+ {
+ RtlFreeHeap(RtlGetProcessHeap(), 0, FileSystemNameU.Buffer);
+ }
+
+ return Ret;
}
/*