Home > Software engineering >  Windows how to obtain the physical disk unallocated space
Windows how to obtain the physical disk unallocated space

Time:09-22

Article 1. In the disk management can see the black box of unallocated disk space, show Windows support this kind of information,
2. Call windowsAPI function only disk for total capacity and the size of each partition, but can not accurately know whether there is unallocated space, unallocated space how much is the specific size,
A great god, help solve,

CodePudding user response:

Don't know much about, but I think the amount minus the amount of each partition and is no unallocated space size?

CodePudding user response:

How to share, windowsAPI function called disk for the total capacity (the total number of bytes) and which API function calls? Just meet this requirement, previously did not contact with this knowledge, thank you

CodePudding user response:

reference 1st floor light bamboo hat reply:
don't understand, but I think the amount minus the amount of each partition and is no unallocated space size?
theory can be like that, but each partition has a few megabytes of reserve capacity, so that calculate the capacity of the round, can only be inaccurate,
Another problem is that the want to lose this number, you can't be sure are reserved partition, or unallocated,

CodePudding user response:

reference 1st floor housecarl response:
don't understand, but I think the amount minus the amount of each partition and is no unallocated space size?

Can be so in theory, but the physical disk capacity has a few megabytes of reservation is used to store each partition information, so that calculate the capacity of the round, can only be inaccurate, another problem is, this want to lose this number, you can't be sure are reserved disk, or unallocated,

CodePudding user response:

GetDiskFreeSpaceEx

CodePudding user response:

Lz can use this a try,
DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, & amp; LayOutInfo, sizeof (DRIVE_LAYOUT_INFORMATION_EX) * 20, & amp; BytesReturned, NULL)
According to the offset of layOutInfo inside each partition layOutInfo [0]. PartitionEntry [I] StartingOffset length and partition layOutInfo [0]. PartitionEntry [I] PartitionLength estimate unallocated space between two partition size,
If no unallocated space between layOutInfo [0]. PartitionEntry [I] StartingOffset + layOutInfo [0]. PartitionEntry [I] PartitionLength=layOutInfo [0]. PartitionEntry [I + 1] StartingOffset,
If there is unallocated space, then the unallocated space of size: size=layOutInfo [0]. PartitionEntry [I + 1] StartingOffset - (layOutInfo [0]. PartitionEntry [I] StartingOffset + layOutInfo [0]. PartitionEntry [I] PartitionLength).

CodePudding user response:

refer to the second floor my_xxh response:
can share, how windowsAPI function called disk for the total capacity (total number of bytes), and what API function calls? Just meet this requirement, previously did not contact with this knowledge, thank you

Disk for total capacity can use the
DISK_GEOMETRY_EX geoStruct;
Memset (& amp; GeoStruct, 0, sizeof (geoStruct));
DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, & amp; GeoStruct, sizeof (geoStruct), & amp; BytesReturned, NULL)
http://www.cppblog.com/dingding/archive/2008/09/23/62570.html

CodePudding user response:

refer to 6th floor light bamboo hat reply:
lz can use this a try,
DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, & amp; LayOutInfo, sizeof (DRIVE_LAYOUT_INFORMATION_EX) * 20, & amp; BytesReturned, NULL)
According to the offset of layOutInfo inside each partition layOutInfo [0]. PartitionEntry [I] StartingOffset length and partition layOutInfo [0]. PartitionEntry [I] PartitionLength estimate unallocated space between two partition size,
If no unallocated space between layOutInfo [0]. PartitionEntry [I] StartingOffset + layOutInfo [0]. PartitionEntry [I] PartitionLength=layOutInfo [0]. PartitionEntry [I + 1] StartingOffset,
If there is unallocated space, then the unallocated space of size: size=layOutInfo [0]. PartitionEntry [I + 1] StartingOffset - (layOutInfo [0]. PartitionEntry [I] StartingOffset + layOutInfo [0]. PartitionEntry [I] PartitionLength).
Good idea. Now, the most headache is unallocated space on the location of the disk sector at the beginning, I can in the past the first partition offsets, but normal disk the first partition will also have a few megabytes of offset, so not Good judgment is the disk itself necessarily normal offset or has not been allocated space, I just want to know how to pick out the undistributed system is? Provide any API to us?

CodePudding user response:

Don't know how the partitioning software implementation of unallocated space of the sun?
O great god teach ah,

CodePudding user response:

references 9 f sinat_33383231 response:
don't know how the partitioning software realizes the unallocated space of the sun?
O great god teach ah,

I also have the same question, many partitioning software can display the unallocated space, we have not found a temporary effective methods, the existing API can only be found already partition information

CodePudding user response:

Feeling is driven interface, the user program can not used directly, but the OS is no problem
  • Related