如何确定为磁盘设备分配了哪些块?

How to determine what bloks are allocated for the disk device?

许多现代存储类型使用 Thin provisioning to allocate blocks. I need to get Block allocation map for the disk device. There is FSCTL_GET_VOLUME_BITMAP 来获取卷位图,但它是特定于文件系统的,我需要一种不是特定于 FS 的方法。 从 Windows 8 Windows is sending "TRIM and Unmap" hints to storage media to track allocated blocks.

开始

UNMAP is the SCSI command by which an application or the system can communicate to the storage stack and the disk that a certain sector or range of sectors are currently not in use, including sectors that were previously in use by files that were later deleted.

所以这应该是可能的。不幸的是,我无法找到 Disk Management Control Code 或磁盘管理功能来获取它。也许有人知道如何获得它?

就像 gubblebozer 暗示的那样 - GET LBA STATUS SBC-3 中引入的命令是从设备本身检索低级映射的方法。来自 Thin Provisioning

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 结构将包含一个位图 平板分配。