许多现代存储types使用精简configuration来分配块。 我需要获取磁盘设备的块分配映射 。 有FSCTL_GET_VOLUME_BITMAP获取卷位图,但它是文件系统特定的,我需要一个不是特定于FS的方法。 从Windows 8开始,Windows 正在向存储介质发送“TRIM和Unmap”提示以跟踪分配的块 。
UNMAP是应用程序或系统可以与存储堆栈通信的SCSI命令,以及当前未使用某个扇区或扇区范围的磁盘,包括之前由之前被删除的文件使用的扇区。
所以这应该是可能的。 不幸的是,我无法find磁盘pipe理控制代码或磁盘pipe理function来获取它。 也许有人知道如何得到它?
就像gubblebozer提出的一样 – SBC-3中引入的GET LBA STATUS命令是从设备本身检索低级映射的方法。 从精简配置
The application can call the IOCTL DSM allocation routine to send the SCSI command and retrieve the mapped or unmapped state of each slab in a particular range. If the LBA provisioning status returned does not describe the entire allocation range, the application sends another SCSI command to retrieve the provisioning status of the remaining LBA range.
看起来这可以在IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES的帮助下完成,那么DEVICE_DATA_SET_LB_PROVISIONING_STATE结构将包含一个slab分配的位图。