Open source Ext2read code-How can I tell how many hard disk devices are in Windows?

Source: Internet
Author: User


int Get_ndisks ()
{
HANDLE Hdevice; Handle to examined
int ndisks = 0;
Char path[20] = {"\\\\.\\physicaldrive0"};

do {
TRACE ("ndisks%s", path);
Hdevice = Createfilea (path,//drive to open
Generic_read,//access mode
File_share_read,//SHARE mode
NULL,//default security attributes
Open_existing,//disposition
0,//file attributes
NULL); Don ' t copy any file ' s attributes
if (hdevice! = INVALID_HANDLE_VALUE)
CloseHandle (Hdevice);
ndisks++;
PATH[17] = (char) (' 0 ' + ndisks);
}while (Hdevice! = INVALID_HANDLE_VALUE);

return ndisks-1;
}

Where path is the device name of the first hard disk, and the value of Ndisks indicates that there are currently several hard disks;

Do{}while (), Createfilea in the device is opened, if the return value is not Invalid_handle_value is open, then the ndisks+1, and path[17] is the number of the hard disk device 18th characters in the value, The corresponding character in "\\\\.\\physicaldrive0" is 0 because "\\\\.\\physicaldrive0" is "\\.\physicaldrive0" by escaping the actual string. The first hard disk has a sequence number of 0, the second is 1, and then it accumulates.

CreateFile This function can create or open a handle to an object that can be controlled by this handle:
Console object, communication resource object, directory object (only open), disk device object, file object, mail slot object, pipe object.

A more specific description of the CreateFile function is available for the MS MSDN query.
Chinese Introduction Rec:
Http://www.cnblogs.com/transcom/articles/1384946.html

Open source Ext2read code-How can I tell how many hard disk devices are in Windows?

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.