DWORD dwFlagsAndAttributes,
__in HANDLE hTemplateFile
。;
lpFileName為需要打開(kāi)設(shè)備的名稱(chēng),對(duì)于磁盤(pán)來(lái)說(shuō),可能為以下幾種形式:
對(duì)于物理驅(qū)動(dòng)器x,形式為 \\.\PhysicalDriveX ,編號(hào)從0開(kāi)始,例如
名稱(chēng)
含義
\\.\PhysicalDrive0
打開(kāi)第一個(gè)物理驅(qū)動(dòng)器
\\.\PhysicalDrive2
打開(kāi)第三個(gè)物理驅(qū)動(dòng)器
對(duì)于邏輯分區(qū)(卷),形式為 \\.\X: ,例如
名稱(chēng)
含義
\\.\A:
打開(kāi)A盤(pán)(軟驅(qū))
\\.\C:
打開(kāi)C盤(pán)(磁盤(pán)邏輯分區(qū))
最后復(fù)制一段MSDN上的示例代碼作為本節(jié)的結(jié)束,該示例獲取磁盤(pán)的詳細(xì)信息(包括柱面、磁道、扇區(qū)等統(tǒng)計(jì)信息)并打印出來(lái)。
/* The code of interest is in the subroutine GetDriveGeometry. The
code in main shows how to interpret the results of the call. */
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
hDevice = CreateFile(TEXT("\\\\.\\PhysicalDrive0"), // drive
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
。↙POVERLAPPED) NULL); // synchronous I/O
CloseHandle(hDevice);
return (bResult);
}
int main(int argc, char *argv[])
{
DISK_GEOMETRY pdg; // disk drive geometry structure
BOOL bResult; // generic results flag
ULONGLONG DiskSize; // size of the drive, in bytes
bResult = GetDriveGeometry (&pdg);
if (bResult)
{
printf("Cylinders = %I64d ", pdg.Cylinders);
printf("Tracks/cylinder = %ld ", (ULONG) pdg.TracksPerCylinder);
printf("Sectors/track = %ld ", (ULONG) pdg.SectorsPerTrack);
printf("Bytes/sector = %ld ", (ULONG) pdg.BytesPerSector);
DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
。║LONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Gb) ", DiskSize,
DiskSize / (1024 * 1024 * 1024));
}
else
{
printf ("GetDriveGeometry failed. Error %ld. ", GetLastError ());
}
return ((int)bResult);
}
億恩科技地址(ADD):鄭州市黃河路129號(hào)天一大廈608室 郵編(ZIP):450008 傳真(FAX):0371-60123888
聯(lián)系:億恩小凡
QQ:89317007
電話:0371-63322206 本文出自:億恩科技【mszdt.com】
服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|