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
Comments
Please share your structure and I'll add it when I apply the fixes to the enum. |
Please find attached my implementation of 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. |
I've incorporated your structures with some minor changes and would appreciate your unit test to validate my changes. |
UnitTest_WinIOCtl.zip
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. |
Thanks for the unit test. It helped me uncover a big bug. I'm working through a solution now. |
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)); |
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.The text was updated successfully, but these errors were encountered: