The Learning API uses the Findfirstvolume series functions to traverse the drive to obtain drive information

Source: Internet
Author: User

#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

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.