Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xamix opened this issue Aug 17, 2018 · 0 comments

Comments

@xamix
Copy link

xamix commented Aug 17, 2018

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant