Learn the API to get disk information

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.