mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[FMIFS][FORMAT][SDK] Improve/Fix QueryDeviceInformation() and related code (#7475)
- FMIFS: QueryDeviceInformation(): Use more specific types and improve documentation. Follow-up to commit4838d7bd56. - FORMAT: wmain(): * Zero the correct variable. Addendum to commitc5a9f22d4e. * No need to zero the whole volumeName array. Follow-up to commit358fecdcf0.
This commit is contained in:
@@ -352,11 +352,11 @@ static VOID Usage(LPWSTR ProgramName)
|
||||
int wmain(int argc, WCHAR *argv[])
|
||||
{
|
||||
int badArg;
|
||||
DEVICE_INFORMATION DeviceInformation = {0};
|
||||
DEVICE_INFORMATION DeviceInformation;
|
||||
FMIFS_MEDIA_FLAG media = FMIFS_HARDDISK;
|
||||
DWORD driveType;
|
||||
WCHAR fileSystem[1024];
|
||||
WCHAR volumeName[1024] = {0};
|
||||
WCHAR volumeName[1024];
|
||||
WCHAR input[1024];
|
||||
DWORD serialNumber;
|
||||
ULARGE_INTEGER totalNumberOfBytes, totalNumberOfFreeBytes;
|
||||
@@ -465,6 +465,8 @@ int wmain(int argc, WCHAR *argv[])
|
||||
dwError = GetLastError();
|
||||
if (dwError == ERROR_UNRECOGNIZED_VOLUME)
|
||||
{
|
||||
// Unformatted volume
|
||||
volumeName[0] = UNICODE_NULL;
|
||||
wcscpy(fileSystem, L"RAW");
|
||||
}
|
||||
else
|
||||
@@ -477,9 +479,11 @@ int wmain(int argc, WCHAR *argv[])
|
||||
|
||||
ConResPrintf(StdOut, STRING_FILESYSTEM, fileSystem);
|
||||
|
||||
if (QueryDeviceInformation(RootDirectory,
|
||||
&DeviceInformation,
|
||||
sizeof(DeviceInformation)))
|
||||
if (!QueryDeviceInformation(RootDirectory, &DeviceInformation, sizeof(DeviceInformation)))
|
||||
{
|
||||
totalNumberOfBytes.QuadPart = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
totalNumberOfBytes.QuadPart = DeviceInformation.SectorSize *
|
||||
DeviceInformation.SectorCount.QuadPart;
|
||||
|
||||
+12
-12
@@ -57,27 +57,27 @@ QueryAvailableFileSystemFormat(
|
||||
* @param[in] DriveRoot
|
||||
* String which contains a DOS device name,
|
||||
*
|
||||
* @param[in,out] DeviceInformation
|
||||
* Pointer to buffer with DEVICE_INFORMATION structure which will receive data.
|
||||
* @param[out] DeviceInformation
|
||||
* Pointer to buffer which will receive DEVICE_INFORMATION data.
|
||||
*
|
||||
* @param[in] BufferSize
|
||||
* Size of buffer in bytes.
|
||||
* Size of DeviceInformation buffer, in bytes.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the buffer was large enough and was filled with
|
||||
* TRUE if the buffer was large enough (pre-Vista at least, Vista+ if possible) and was filled with
|
||||
* the requested information, FALSE otherwise.
|
||||
*
|
||||
* @remarks
|
||||
* The returned information is mostly related to Sony Memory Stick devices.
|
||||
* On Vista+ the returned information is disk sector size and volume length in sectors,
|
||||
* The returned flags are mostly related to Sony Memory Stick devices.
|
||||
* On Vista+, the returned information is disk sector size and volume length in sectors,
|
||||
* regardless of the type of disk.
|
||||
* ReactOS implementation returns DEVICE_HOTPLUG flag if inspected device is a hotplug device
|
||||
* ReactOS returns DEVICE_HOTPLUG flag if inspected device is a hotplug device,
|
||||
* as well as sector size and volume length of disk device.
|
||||
*/
|
||||
BOOL
|
||||
NTAPI
|
||||
QueryDeviceInformation(
|
||||
_In_ PWCHAR DriveRoot,
|
||||
_In_ PCWSTR DriveRoot,
|
||||
_Out_ PVOID DeviceInformation,
|
||||
_In_ ULONG BufferSize)
|
||||
{
|
||||
@@ -94,7 +94,7 @@ QueryDeviceInformation(
|
||||
WCHAR DriveName[MAX_PATH];
|
||||
|
||||
/* Buffer should be able to at least hold DeviceFlags */
|
||||
if (BufferSize < sizeof(ULONG) ||
|
||||
if (BufferSize < RTL_SIZEOF_THROUGH_FIELD(DEVICE_INFORMATION, DeviceFlags) ||
|
||||
!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
|
||||
{
|
||||
return FALSE;
|
||||
@@ -157,10 +157,10 @@ QueryDeviceInformation(
|
||||
DeviceInfo->DeviceFlags |= DEVICE_HOTPLUG;
|
||||
}
|
||||
|
||||
/* Other flags that would be set here are related to Sony "Memory Stick"
|
||||
* type of devices which we do not have any special support for */
|
||||
/* UNIMPLEMENTED: Other flags that would be set here are related to Sony "Memory Stick"
|
||||
* type of devices, which we do not have any special support for */
|
||||
|
||||
if (BufferSize >= sizeof(DEVICE_INFORMATION))
|
||||
if (BufferSize >= RTL_SIZEOF_THROUGH_FIELD(DEVICE_INFORMATION, SectorCount))
|
||||
{
|
||||
/* This is the Vista+ version of the structure.
|
||||
* We need to also provide disk sector size and volume length in sectors. */
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef struct
|
||||
typedef struct _DEVICE_INFORMATION
|
||||
{
|
||||
ULONG DeviceFlags;
|
||||
// Vista+ fields.
|
||||
ULONG SectorSize;
|
||||
LARGE_INTEGER SectorCount;
|
||||
} DEVICE_INFORMATION, *PDEVICE_INFORMATION;
|
||||
@@ -180,7 +181,7 @@ QueryAvailableFileSystemFormat(
|
||||
BOOL
|
||||
NTAPI
|
||||
QueryDeviceInformation(
|
||||
_In_ PWCHAR DriveRoot,
|
||||
_In_ PCWSTR DriveRoot,
|
||||
_Out_ PVOID DeviceInformation,
|
||||
_In_ ULONG BufferSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user