Determining volume cluster size without using GetDiskFreeSpace

https://stackoverflow.com/questions/11373603/determining-volume-cluster-size-without-using-getdiskfreespace

You can use DeviceIoControl with IOCTL_STORAGE_QUERY_PROPERTY. On input, set the PropertyId in the STORAGE_PROPERTY_QUERY structure to StorageAccessAlignmentProperty.

That will get you a STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR, which contains members for both BytesPerLogicalSector and BytesPerPhysicalSector. The linked reference page includes demo code to retrieve and display the logical/physical sector sizes for a device.

 
  • Thanks, looks promising. But how to go deeper and retrieve cluster (allocation unit) size for the volume (file system)? Which are built on the top of physical drive and its logical sectors.
    – OnTheFly Jul 8 '12 at 7:56
  • For NTFS you can use FSCTL_GET_NTFS_VOLUME_DATA. I'm not sure how many other file systems you're likely to care about.
    – Jerry Coffin Jul 8 '12 at 8:12
  • well, at least FAT32 too (as i've noticed already f/s driver handles NTFS and FAT32 no in common way)
    – OnTheFly Jul 8 '12 at 12:33
  • For FAT32 just read the first sector. Bytes per sector is a word at 0x0B and sectors per cluster is a byte at 0x0D. See home.teleport.com/~brainy/fat32.htm
    – Harry Johnston Jul 9 '12 at 3:21

posted on 2021-05-20 17:40  liujx2019  阅读(51)  评论(0编辑  收藏  举报

导航