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

Wrong STORAGE_PROPERTY_ID enumeration values #403

Closed
elf2k00 opened this issue May 29, 2023 · 6 comments
Closed

Wrong STORAGE_PROPERTY_ID enumeration values #403

elf2k00 opened this issue May 29, 2023 · 6 comments

Comments

@elf2k00
Copy link

elf2k00 commented May 29, 2023

The enum values for STORAGE_PROPERTY_ID defined in winioctl.h are incorrectly enumerated as described in Microsoft documentation

The enum values for some of the items are fixed and it re-defines the subsequent values:
StorageDeviceIoCapabilityProperty = 48,
StorageDeviceSelfEncryptionProperty = 64,

As in Vanara these fixed values are not set, the next values in the enumeration are wrongly set provoking and undefined behavior while querying the system with DeviceIoControl.

For example, the STORAGE_PROPERTY_ID.StorageDeviceManagementStatus should have the value 56, but in Vanara it has the value 21.

Vanara.PInvoke.Kernel32.WinIOCtl.Enums.cs should be modified with the STORAGE_PROPERTY_ID fixed values.

I'm also implementing the STORAGE_DEVICE_MANAGEMENT_STATUS structure from winioctl.h, it's missing in Vanara, please let me know if you want me to share the code.

@dahall
Copy link
Owner

dahall commented May 31, 2023

Please share your structure and I'll add it when I apply the fixes to the enum.

@elf2k00
Copy link
Author

elf2k00 commented May 31, 2023

Please find attached my implementation of STORAGE_DEVICE_MANAGEMENT_STATUS;

For these are structures I couldn't find documentation in winioctl.h documentation in the web, they were directly ported from C++ winioctl.h 10.0.22000 build 0032

I can give you some simple code to test the struct using Vanara with a call to DeviceIOControl, they give you the Health Operational and Disk details of a disk.

STORAGE_DEVICE_MANAGEMENT_STATUS.zip

@dahall
Copy link
Owner

dahall commented Jun 1, 2023

I've incorporated your structures with some minor changes and would appreciate your unit test to validate my changes.

dahall added a commit that referenced this issue Jun 2, 2023
@dahall dahall closed this as completed in 91490dc Jun 2, 2023
@elf2k00
Copy link
Author

elf2k00 commented Jun 2, 2023

UnitTest_WinIOCtl.zip
Please find attached the unit test, for all volumes in the system queries the device for some properties:

  • BusType
  • Health and Operational Status

I'm working right now in querying the drive for its form factor with STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR and STORAGE_PHYSICAL_DEVICE_DATA, but finding some problems, let you know if I get it right.

@dahall
Copy link
Owner

dahall commented Jun 8, 2023

Thanks for the unit test. It helped me uncover a big bug. I'm working through a solution now.

@dahall dahall reopened this Jun 8, 2023
@dahall
Copy link
Owner

dahall commented Jun 9, 2023

Whew. I had to create custom marshalers for a couple of structures, but it is all done now.

Just for your reference, there is an easier way to write the code you gave me:

using SafeHFILE hdisk = CreateFile(vol.TrimEnd('\\'), 0, FileShare.ReadWrite, null, FileMode.Open, 0);
Win32Error.ThrowLastErrorIfInvalid(hdisk);

STORAGE_PROPERTY_QUERY query = new(STORAGE_PROPERTY_ID.StorageDeviceProperty);
Win32Error.ThrowLastErrorIfFalse(DeviceIoControl(hdisk, IOControlCode.IOCTL_STORAGE_QUERY_PROPERTY, query, out STORAGE_DESCRIPTOR_HEADER sdh));
Win32Error.ThrowLastErrorIfFalse(DeviceIoControl(hdisk, IOControlCode.IOCTL_STORAGE_QUERY_PROPERTY, query, out STORAGE_DEVICE_DESCRIPTOR_MGD sdd, sdh.Size));

query.PropertyId = STORAGE_PROPERTY_ID.StorageDeviceManagementStatus;
Win32Error.ThrowLastErrorIfFalse(DeviceIoControl(hdisk, IOControlCode.IOCTL_STORAGE_QUERY_PROPERTY, query, out STORAGE_DEVICE_MANAGEMENT_STATUS outVar));

@dahall dahall closed this as completed Jun 9, 2023
dahall added a commit that referenced this issue Jun 9, 2023
dahall added a commit that referenced this issue Jun 9, 2023
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

2 participants