实战DeviceIoControl 之五:列举已安装的存储设备[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 bhw98 的 blog

y_access) // 存储设备的总线类型 typedef enum _storage_bus_type { bustypeunknown = 0x00, bustypescsi, bustypeatapi, bustypeata, bustype1394, bustypessa, bustypefibre, bustypeusb, bustyperaid, bustypemaxreserved = 0x7f } storage_bus_type, *pstorage_bus_type; // 查询存储设备属性的类型 typedef enum _storage_query_type { propertystandardquery = 0, // 读取描述 propertyexistsquery, // 测试是否支持 propertymaskquery, // 读取指定的描述 propertyquerymaxdefined // 验证数据 } storage_query_type, *pstorage_query_type; // 查询存储设备还是适配器属性 typedef enum _storage_property_id { storagedeviceproperty = 0, // 查询设备属性 storageadapterproperty // 查询适配器属性 } storage_property_id, *pstorage_property_id; // 查询属性输入的数据结构 typedef struct _storage_property_query { storage_property_id propertyid; // 设备/适配器 storage_query_type querytype; // 查询类型 uchar additionalparameters[1]; // 额外的数据(仅定义了象征性的1个字节) } storage_property_query, *pstorage_property_query; // 查询属性输出的数据结构 typedef struct _storage_device_descriptor { ulong version; // 版本 ulong size; // 结构大小 uchar devicetype; // 设备类型 uchar devicetypemodifier; // scsi-2额外的设备类型 boolean removablemedia; // 是否可移动 boolean commandqueueing; // 是否支持命令队列 ulong vendoridoffset; // 厂家设定值的偏移 ulong productidoffset; // 产品id的偏移 ulong productrevisionoffset; // 产品版本的偏移 ulong serialnumberoffset; // 序列号的偏移 storage_bus_type bustype; // 总线类型 ulong rawpropertieslength; // 额外的属性数据长度 uchar rawdeviceproperties[1]; // 额外的属性数据(仅定义了象征性的1个字节) } storage_device_descriptor, *pstorage_device_descriptor; // 取设备属性信息 // hdevice -- 设备句柄 // pdevdesc -- 输出的设备描述和属性信息缓冲区指针(包含连接在一起的两部分) bool getdriveproperty(handle hdevice, pstorage_device_descriptor pdevdesc) { storage_property_query query; // 查询输入参数 dword dwoutbytes; // ioctl输出数据长度 bool bresult; // ioctl返回值 // 指定查询方式 query.propertyid = storagedeviceproperty; query.querytype = propertystandardquery; // 用ioctl_storage_query_property取设备属性信息 bresult = ::deviceiocontrol(hdevice, // 设备句柄 ioctl_storage_query_property, // 取设备属性信息 &query, sizeof(storage_property_query), // 输入数据缓冲区 pdevdesc, pdevdesc->size, // 输出数据缓冲区 &dwoutbytes, // 输出数据长度 (lpoverlapped)null); // 用同步i/o return bresult; }

q 我用这个方法从ioctl_storage_query_property返回的数据中,没有得到cdrom和usb接口的外置硬盘的序列号、产品id等信息。但从设备路径上看,明明是有这些信息的,为什么它没有填充到storage_device_descriptor中呢?再就是为什么硬盘序列号本是“d22p7khe            ”,为什么它填充的是“3146563447534558202020202020202020202020”这种形式呢?

a 对这两个问题我也是心存疑惑,但又不敢妄加猜测,正琢磨着向微软请教呢。

[相关资源]

  • 本文demo源码:storageenum.zip (23kb)
  • bhw98的专栏:http://www.csdn.net/develop/author/netauthor/bhw98/

    首次发布:2003-02-28

  • 本文关键:DeviceIoControl,GUID
      相关方案
    Google
     

    本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

    go top