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

fdread.cpp
#include <stdio.h>
#include <Windows.h>
 
int main()
{
	// FDデバイス
	HANDLE hDev = CreateFile(L"\\\\.\\A:", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hDev == INVALID_HANDLE_VALUE) {
		fprintf(stderr, "FDデバイス取得に失敗\n");
		return 1;
	}
 
	// 諸元
	DISK_GEOMETRY dg;
	DeviceIoControl(hDev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof dg, NULL, NULL);
	LONGLONG llVol = dg.Cylinders.QuadPart * dg.TracksPerCylinder * dg.SectorsPerTrack * dg.BytesPerSector;
 
	printf("Cylinders:%lld\n", dg.Cylinders.QuadPart);
	printf("TracksPerCylinder:%u\n", dg.TracksPerCylinder);
	printf("SectorsPerTrack:%u\n", dg.SectorsPerTrack);
	printf("BytesPerSector:%u\n", dg.BytesPerSector);
	printf("Vol:%lld\n", llVol);
 
	static BYTE buf[80 * 2 * 18 * 512];
	DWORD dwRead = (DWORD)llVol;
	BOOL b;
	b = ReadFile(hDev, buf, dwRead, &dwRead, NULL);
	if (b == FALSE) {
		fprintf(stderr, "FD読み込みに失敗\n");
		goto Exit;
	}
	printf("NumberOfBytesRead=%u\n", dwRead);
 
	// ファイル出力
	FILE *pFile;
	fopen_s(&pFile, "fdread.dup", "wb");
	if (pFile == NULL) {
		fprintf(stderr, "出力ファイルのオープンに失敗\n");
		goto Exit;
	}
	fwrite(buf, 1, dwRead, pFile);
	fclose(pFile);
 
Exit:
	CloseHandle(hDev);
	return 0;
}
 
最終更新:2015年12月30日 11:34