Skip to content

Windows: GetDeviceNumberFromVolumeHandle should return BOOL otherwise other function may fail #72

@xamix

Description

@xamix

GetDeviceNumberFromVolumeHandle return 0 when it fail. However I have a case where my storageDeviceNumber.DeviceNumber is also 0.

This made other functions using GetDeviceNumberFromVolumeHandle to also fail:
For example EjectDriveLetter at line 353 check for the deviceNumber and so fail even if it's a good device number which is equal to 0

Maybe change function to:

BOOL GetDeviceNumberFromVolumeHandle(HANDLE volume, ULONG* devNumber) {
	STORAGE_DEVICE_NUMBER storageDeviceNumber;
	DWORD bytesReturned;

	BOOL result = DeviceIoControl(volume,
		IOCTL_STORAGE_GET_DEVICE_NUMBER,
		NULL, 0,
		&storageDeviceNumber,
		sizeof(storageDeviceNumber),
		&bytesReturned,
		NULL);

	if (!result) {
		return false;
	}

	*devNumber = storageDeviceNumber.DeviceNumber;

	return true;
}

FIX all function using this for example in EjectDriveLetter:

ULONG deviceNumber;
BOOL result = GetDeviceNumberFromVolumeHandle(volumeHandle, &deviceNumber);
if (!result) {
	MountUtilsLog("Couldn't get device number from volume handle");
	CloseHandle(volumeHandle);
	return MOUNTUTILS_ERROR_GENERAL;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions