Skip to content

Commit d1b1292

Browse files
[FMIFS][FORMAT][SDK] Improve/Fix QueryDeviceInformation() and related code (reactos#7475)
- FMIFS: QueryDeviceInformation(): Use more specific types and improve documentation. Follow-up to commit 4838d7b. - FORMAT: wmain(): * Zero the correct variable. Addendum to commit c5a9f22. * No need to zero the whole volumeName array. Follow-up to commit 358fecd.
1 parent 59afe4b commit d1b1292

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

base/system/format/format.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ static VOID Usage(LPWSTR ProgramName)
352352
int wmain(int argc, WCHAR *argv[])
353353
{
354354
int badArg;
355-
DEVICE_INFORMATION DeviceInformation = {0};
355+
DEVICE_INFORMATION DeviceInformation;
356356
FMIFS_MEDIA_FLAG media = FMIFS_HARDDISK;
357357
DWORD driveType;
358358
WCHAR fileSystem[1024];
359-
WCHAR volumeName[1024] = {0};
359+
WCHAR volumeName[1024];
360360
WCHAR input[1024];
361361
DWORD serialNumber;
362362
ULARGE_INTEGER totalNumberOfBytes, totalNumberOfFreeBytes;
@@ -465,6 +465,8 @@ int wmain(int argc, WCHAR *argv[])
465465
dwError = GetLastError();
466466
if (dwError == ERROR_UNRECOGNIZED_VOLUME)
467467
{
468+
// Unformatted volume
469+
volumeName[0] = UNICODE_NULL;
468470
wcscpy(fileSystem, L"RAW");
469471
}
470472
else
@@ -477,9 +479,11 @@ int wmain(int argc, WCHAR *argv[])
477479

478480
ConResPrintf(StdOut, STRING_FILESYSTEM, fileSystem);
479481

480-
if (QueryDeviceInformation(RootDirectory,
481-
&DeviceInformation,
482-
sizeof(DeviceInformation)))
482+
if (!QueryDeviceInformation(RootDirectory, &DeviceInformation, sizeof(DeviceInformation)))
483+
{
484+
totalNumberOfBytes.QuadPart = 0;
485+
}
486+
else
483487
{
484488
totalNumberOfBytes.QuadPart = DeviceInformation.SectorSize *
485489
DeviceInformation.SectorCount.QuadPart;

dll/win32/fmifs/query.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ QueryAvailableFileSystemFormat(
5757
* @param[in] DriveRoot
5858
* String which contains a DOS device name,
5959
*
60-
* @param[in,out] DeviceInformation
61-
* Pointer to buffer with DEVICE_INFORMATION structure which will receive data.
60+
* @param[out] DeviceInformation
61+
* Pointer to buffer which will receive DEVICE_INFORMATION data.
6262
*
6363
* @param[in] BufferSize
64-
* Size of buffer in bytes.
64+
* Size of DeviceInformation buffer, in bytes.
6565
*
6666
* @return
67-
* TRUE if the buffer was large enough and was filled with
67+
* TRUE if the buffer was large enough (pre-Vista at least, Vista+ if possible) and was filled with
6868
* the requested information, FALSE otherwise.
6969
*
7070
* @remarks
71-
* The returned information is mostly related to Sony Memory Stick devices.
72-
* On Vista+ the returned information is disk sector size and volume length in sectors,
71+
* The returned flags are mostly related to Sony Memory Stick devices.
72+
* On Vista+, the returned information is disk sector size and volume length in sectors,
7373
* regardless of the type of disk.
74-
* ReactOS implementation returns DEVICE_HOTPLUG flag if inspected device is a hotplug device
74+
* ReactOS returns DEVICE_HOTPLUG flag if inspected device is a hotplug device,
7575
* as well as sector size and volume length of disk device.
7676
*/
7777
BOOL
7878
NTAPI
7979
QueryDeviceInformation(
80-
_In_ PWCHAR DriveRoot,
80+
_In_ PCWSTR DriveRoot,
8181
_Out_ PVOID DeviceInformation,
8282
_In_ ULONG BufferSize)
8383
{
@@ -94,7 +94,7 @@ QueryDeviceInformation(
9494
WCHAR DriveName[MAX_PATH];
9595

9696
/* Buffer should be able to at least hold DeviceFlags */
97-
if (BufferSize < sizeof(ULONG) ||
97+
if (BufferSize < RTL_SIZEOF_THROUGH_FIELD(DEVICE_INFORMATION, DeviceFlags) ||
9898
!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
9999
{
100100
return FALSE;
@@ -157,10 +157,10 @@ QueryDeviceInformation(
157157
DeviceInfo->DeviceFlags |= DEVICE_HOTPLUG;
158158
}
159159

160-
/* Other flags that would be set here are related to Sony "Memory Stick"
161-
* type of devices which we do not have any special support for */
160+
/* UNIMPLEMENTED: Other flags that would be set here are related to Sony "Memory Stick"
161+
* type of devices, which we do not have any special support for */
162162

163-
if (BufferSize >= sizeof(DEVICE_INFORMATION))
163+
if (BufferSize >= RTL_SIZEOF_THROUGH_FIELD(DEVICE_INFORMATION, SectorCount))
164164
{
165165
/* This is the Vista+ version of the structure.
166166
* We need to also provide disk sector size and volume length in sectors. */

sdk/include/reactos/libs/fmifs/fmifs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct
3737
typedef struct _DEVICE_INFORMATION
3838
{
3939
ULONG DeviceFlags;
40+
// Vista+ fields.
4041
ULONG SectorSize;
4142
LARGE_INTEGER SectorCount;
4243
} DEVICE_INFORMATION, *PDEVICE_INFORMATION;
@@ -180,7 +181,7 @@ QueryAvailableFileSystemFormat(
180181
BOOL
181182
NTAPI
182183
QueryDeviceInformation(
183-
_In_ PWCHAR DriveRoot,
184+
_In_ PCWSTR DriveRoot,
184185
_Out_ PVOID DeviceInformation,
185186
_In_ ULONG BufferSize);
186187

0 commit comments

Comments
 (0)