From 982cf2be5e94aef2415d42f81f988ed4b0ca973d Mon Sep 17 00:00:00 2001 From: Serge Gautherie Date: Thu, 17 Oct 2024 00:45:29 +0200 Subject: [PATCH] [FORMAT] wmain(): Clean GetVolumeInformationW() calls up and immediately print file system out --- base/system/format/format.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/base/system/format/format.c b/base/system/format/format.c index 29b22f9a27d..f51d15aa199 100644 --- a/base/system/format/format.c +++ b/base/system/format/format.c @@ -367,7 +367,6 @@ int wmain(int argc, WCHAR *argv[]) WCHAR volumeName[1024] = {0}; WCHAR input[1024]; DWORD serialNumber; - DWORD flags, maxComponent; ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes; WCHAR szMsg[RC_STRING_MAX_SIZE]; @@ -468,11 +467,11 @@ int wmain(int argc, WCHAR *argv[]) } // - // Determine the drive's file system format + // Get the existing name and file system, and print out the latter // if (!GetVolumeInformationW(RootDirectory, volumeName, ARRAYSIZE(volumeName), - &serialNumber, &maxComponent, &flags, + NULL, NULL, NULL, fileSystem, ARRAYSIZE(fileSystem))) { if (GetLastError() == ERROR_UNRECOGNIZED_VOLUME) @@ -487,6 +486,8 @@ int wmain(int argc, WCHAR *argv[]) } } + ConResPrintf(StdOut, STRING_FILESYSTEM, fileSystem); + if (QueryDeviceInformation(RootDirectory, &DeviceInformation, sizeof(DeviceInformation))) @@ -508,7 +509,6 @@ int wmain(int argc, WCHAR *argv[]) PrintWin32Error(szMsg, GetLastError()); return -1; } - ConResPrintf(StdOut, STRING_FILESYSTEM, fileSystem); // // Make sure they want to do this @@ -611,16 +611,6 @@ int wmain(int argc, WCHAR *argv[]) } } - if (!GetVolumeInformationW(RootDirectory, - volumeName, ARRAYSIZE(volumeName), - &serialNumber, &maxComponent, &flags, - fileSystem, ARRAYSIZE(fileSystem))) - { - K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); - PrintWin32Error(szMsg, GetLastError()); - return -1; - } - // // Print out some stuff including the formatted size // @@ -638,17 +628,18 @@ int wmain(int argc, WCHAR *argv[]) totalNumberOfFreeBytes.QuadPart); // - // Get the drive's serial number + // Get and print out the new serial number // if (!GetVolumeInformationW(RootDirectory, - volumeName, ARRAYSIZE(volumeName), - &serialNumber, &maxComponent, &flags, - fileSystem, ARRAYSIZE(fileSystem))) + NULL, 0, + &serialNumber, NULL, NULL, + NULL, 0)) { K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } + ConResPrintf(StdOut, STRING_SERIAL_NUMBER, (unsigned int)(serialNumber >> 16), (unsigned int)(serialNumber & 0xFFFF));