#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE MAX_PATH
BOOL Getdirverinfo (LPSTR szdrive);
int main (void)
{
TCHAR Buf[bufsize];
HANDLE Hvol;
BOOL Bflag;
/**********************************
* Findfirstvolume (Buf,bufsize)
* Function: Find the first drive in the host
* Parameter: Buf,bufsize
*buf memory buffers pointing to the drive name
*bufsize parameter buf The buffer size pointed to
* Return value HANDLE: Drive device Name
**********************************/
Hvol = Findfirstvolume (buf,bufsize);
if (Hvol = = INVALID_HANDLE_VALUE)
{
printf (TEXT ("No volmes found!\n"));
Return (-1);
}
Getdirverinfo (BUF);
while (Findnextvolume (hvol,buf,bufsize))
{
Getdirverinfo (BUF);
}
Bflag = Findvolumeclose (Hvol);
Char ch;
ch = getchar ();
return (Bflag);
}
Getdirverinfo function
BOOL Getdirverinfo (LPSTR szdrive)
{
UINT Udivetype;
DWORD Dwvolumeserialnumber;
DWORD dwmaximumcomponentlength;
DWORD Dwfilesystemflags;
CHAR Szfilesystemnamebuffer[bufsize];
CHAR Szdirvername[max_path];
printf ("\n%s\n", szdrive);
/*********************
* UINT WINAPI GetDriveType (LPSTR szdrive);
* Function: Determine the type of a disk drive
* Parameter: LPSTR szdrive
* Indicates the root of the drive to get the property, such as C \
* Return value UINT: Indicates disk type
**********************/
Udivetype = GetDriveType (szdrive);
Switch (udivetype)
{
Case drive_unknown://Unknown disk type
printf ("The drive type cannot is determined.");
Break
Case drive_no_root_dir://Description parameter is invalid
printf ("The root Path is invalid,for Example,no volume are mounted at the path.");
Break
Case drive_removable://Removable Disk
printf ("The drive was a type that had removable media,for example,\
A floppy drive or removable hard disk. ");
Break
Case drive_fixed://Fixed Disk
printf ("The drive was a type that cannot be removed,for example,a fixed\
Hard drive. ");
Break
Case drive_remote://Network Disk
printf ("The drive was a remote (network) drive");
Break
Case drive_cdrom://Optical Drive
printf ("The drive is a CD-ROM drive.");
Break
Case Drive_ramdisk://ram
printf ("The drive is a RAM disk.");
Break
Default
Break
}
/***********************************
*getvolumeinformation (Szdrive,szdirvername,max_path,
&dwvolumeserialnumber,&dwmaximumcomponentlength,
&dwfilesystemflags,szfilesystemnamebuffer,bufsize)
* Function: Get information of disk drive
* Parameters: as follows
* Return value: Nonzero is successful
***********************************/
if (! GetVolumeInformation (szdrive,
szdirvername,//volume label (string)
Length of Max_path,//szdirvename
&dwvolumeserialnumber,//variables used to load serial numbers of a disk volume
&dwmaximumcomponentlength,//to load the length of each part of the file name
&dwfilesystemflags,//variable for loading one or more bits flags
szfilesystemnamebuffer,//System Type
BUFSIZE))
{
return FALSE;
}
if (0!=lstrlen (szdirvername))
{
printf ("\ndrive Name is%s\n", szdirvername);
}
printf ("\nvolume Serial number is%u", dwvolumeserialnumber);
printf ("\nmaximun Component Length is%u", dwmaximumcomponentlength);
printf ("\nsystem Type is%s\n", szfilesystemnamebuffer);
if (Dwfilesystemflags & file_supports_reparse_points)
{
printf ("The file system does not a support volume Mount points.\n");
}
if (Dwfilesystemflags & File_volume_quotas)
{
printf ("The file system supports disk quotas.\n");
}
if (Dwfilesystemflags & File_case_sensitive_search)
{
printf ("The file system supports case-sensitive file names.\n");
}
printf ("... \ n");
return TRUE;
}
The Learning API uses the Findfirstvolume series functions to traverse the drive to obtain drive information