#include <windows.h>
#include <stdio.h>
/************************************
* BOOL Getdiskspaceinfo (LPSTR pszdrive)
* Function: Get disk information according to input disk drive
* Parameter: LPSTR pszdrive
Drive root path, such as D:
************************************/
BOOL Getdiskspaceinfo (LPSTR pszdrive)
{
DWORD64 Qwfreebytestocaller, Qwtotalbytes, qwfreebytes;
DWORD Dwsectperclust, Dwbtyespersect, Dwfreeclusters, dwtotalclusters;
BOOL Bresult;
Bresult = GetDiskFreeSpaceEx (pszdrive,
(Pularge_integer) &qwfreebytestocaller,
(Pularge_integer) &qwtotalbytes,
(Pularge_integer) &qwfreebytes);
if (bresult)
{
printf ("Use GetDiskFreeSpaceEx to obtain disk information \ n");
printf ("Available free Space (bytes): \t%i64d\n", Qwfreebytestocaller);
printf ("Free Space (bytes): \t\t%i64d\n", qwfreebytes);
printf ("Total disk Capacity (bytes): \t\t%i64d\n", qwtotalbytes);
}
Bresult = GetDiskFreeSpace (pszdrive,
&dwsectperclust,
&dwbtyespersect,
&dwfreeclusters,
&dwtotalclusters);
if (bresult)
{
printf ("\ n use GetDiskFreeSpace to obtain disk space information \ n");
printf ("Number of idle arrowheads: \t\t\t%d\n", dwfreeclusters);
printf ("Total number of arrowheads: \t\t\t%d\n", dwtotalclusters);
printf ("Number of sectors per arrowheads: \t\t\t%d\n", dwsectperclust);
printf ("Capacity per sector (bytes): \t\t\t%d\n", dwbtyespersect);
printf ("Free Space (bytes): \t\t%i64d\n", (DWORD64) dwtotalclusters* (DWORD64) dwsectperclust* (DWORD64) dwbtyespersect);
printf ("Total disk Capacity (bytes): \t\t%i64d", (DWORD64) dwtotalclusters* (DWORD64) dwsectperclust* (DWORD64) dwbtyespersect);
}
return bresult;
}
int main (int argc, PCHAR argv[])
{
Getdiskspaceinfo (argv[1]);
}
Usage examples:
Learn the API to get disk information