開発環境 Microsoft Visual Studio Express 2013 for Windows Desktop
実行環境 Microsoft Windows 8.1 (64bit)
プロジェクトの種類 Visual C++/Win32 コンソール アプリケーション
プロジェクト名 GetFdInfo
アプリケーションの種類 コンソール アプリケーション
追加のオプション 空のプロジェクト、SDLチェック

GetFdInfo.cpp
#include <stdio.h>
#include <Windows.h>
 
int main()
{
	HANDLE hDevice = CreateFile(L"\\\\.\\A:", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hDevice == INVALID_HANDLE_VALUE) {
		return 1;
	}
 
	DISK_GEOMETRY dg;
	BOOL b;
	b = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof dg, NULL, NULL);
	printf("(C)シリンダ数:%lld\n", dg.Cylinders.QuadPart);
	printf("(H)ヘッド数:%u\n", dg.TracksPerCylinder);
	printf("(S)セクタ数:%u\n", dg.SectorsPerTrack);
	printf("セクタサイズ:%u\n", dg.BytesPerSector);
	printf("フォーマット容量:%lld\n",
		dg.Cylinders.QuadPart * dg.TracksPerCylinder * dg.SectorsPerTrack * dg.BytesPerSector);
 
	b = CloseHandle(hDevice);
	return 0;
}
 

実行例
C:\Projects\VC++\GetFdInfo\Debug>GetFdInfo.exe
(C)シリンダ数:77
(H)ヘッド数:2
(S)セクタ数:8
セクタサイズ:1024
フォーマット容量:1261568

C:\Projects\VC++\GetFdInfo\Debug>GetFdInfo.exe
(C)シリンダ数:80
(H)ヘッド数:2
(S)セクタ数:18
セクタサイズ:512
フォーマット容量:1474560
最終更新:2014年12月27日 21:29