如何使用 IOCTL_STORAGE_QUERY_PROPERTY 获得 属性-存在状态

how to get property-exists status with IOCTL_STORAGE_QUERY_PROPERTY

我找不到关于这个调用方式的任何解释:

DeviceIoControl( aHANDLE, 
        IOCTL_STORAGE_QUERY_PROPERTY,
        & aSTORAGE_PROPERTY_QUERY, 
       ... etc.)

应该在 aSTORAGE_PROPERTY_QUERY.QueryType 时工作 设置为 PropertyExistsQuery.

这不知何故应该告诉我 属性, 由 aSTORAGE_PROPERTY_QUERY.PropertyId 指定, 可从 aHANDLE.

寻址的对象中获得

此外,它特别不会 return 输出缓冲区中的任何信息(当 QueryType 时 return 编辑信息 设置为 PropertyStandardQuery).

我通过反复试验发现 DeviceIoControl() 的 return 值仍然表示函数调用的 success/failure,并且不表示 属性 的可用性.

那么,这是如何工作的?

Also, it specifically DOES NOT return any information in the output buffer (where information is returned when QueryType is set to PropertyStandardQuery).

IOCTRL_STORAGE_QUERY_PROPERTY and STORAGE_PROPERTY_QUERY 文档中明确指出:

The optional output buffer returned through the lpOutBuffer parameter can be one of several structures depending on the value of the PropertyId member of the STORAGE_PROPERTY_QUERY structure pointed to by the lpInBuffer parameter. These values are enumerated by the STORAGE_PROPERTY_ID enumeration. If the QueryType member of the STORAGE_PROPERTY_QUERY is set to PropertyExistsQuery then no structure is returned.

The optional output buffer returned through the lpOutBuffer parameter of the IOCTL_STORAGE_QUERY_PROPERTY control code can be one of several structures depending on the value of the PropertyId member. If the QueryType member is set to PropertyExistsQuery, then no structure is returned.

IOCTRL_STORAGE_QUERY_PROPERTY 文档也明确说明如下:

nOutBufferSize

The size of the output buffer, in bytes. It can be zero to determine whether a property exists without retrieving its data. To do that, set this parameter to zero (0) and the QueryType member of the STORAGE_PROPERTY_QUERY input structure to PropertyExistsQuery (1). If the call to DeviceIoControl returns a nonzero value then the property exists.

这与您声称 DeviceIoControl() 的 return 值没有告诉您您在寻找什么相矛盾。

但是,PropertyExistsQuery is not reliable on all systems and devices! It can report incorrect results at times (also, when retrieving a property's STORAGE_DESCRIPTOR_HEADER 似乎有时也会报告不正确的 Size 值。

链接文章的作者继续展示他如何诉诸于不仅请求 属性 的存在,而且查询它的 header 和数据,然后证实结果。

代码在 VB 中,但可以翻译成 C/C++。