플로피 드라이브 (A :)가 설치된 Windows 7 VM이 있습니다. 플로피 드라이브의 부트 섹터를 구조로 읽으려고합니다. 그러나이 프로그램을 실행할 때마다 플로피 드라이브를 찾지 못합니다. 나는 그것이 접근 가능하다는 것을 확인할 수있다.C 프로그램이 플로피 드라이브에 대한 핸들을 얻지 못합니다.
코드 :
#include "stdafx.h"
#include<Windows.h>
#include<stdio.h>
#include<conio.h>
#include<WinBase.h>
#pragma pack(1)
struct boot
{
BYTE jump[3];
char bsOemName[8];
WORD bytesperSector;
BYTE sectorpercluster;
WORD sectorsreservedarea;
BYTE copiesFAT;
WORD maxrootdirentries;
WORD totalSectors;
BYTE mediaDescriptor;
WORD sectorsperFAT;
WORD sectorsperTrack;
WORD sides;
WORD hiddenSectors;
char reserve[480];
};
void ReadSector(char *src, int ss, int num, void* buff);
void main()
{
struct boot b;
ReadSector("\\\\.\\A:", 0, 1, &b);
printf("\nBoot sector Name: %s\n", b.bsOemName);
printf("Bytes per sector: %d\n", b.bytesperSector);
printf("Sectors per Cluster: %d\n", b.sectorpercluster);
printf("Total Sectors: %d\n", b.totalSectors);
}
void ReadSector(char *src, int ss, int num, void* buff)
{
HANDLE h; //HANDLE is a typedef of void *HANDLE
unsigned int br;
h = CreateFile(src, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
DWORD dw = GetLastError();
printf("\nLast Error: %d", dw);
if (h != NULL)
{
printf("\nError reading floppy disk '%s'", src);
printf("\nReturn value for handle = %d", h);
}
else
{
printf("\nSuccess..");
}
SetFilePointer(h, (ss * 512), NULL,FILE_BEGIN);
ReadFile(h, buff, num, &br, NULL);
CloseHandle(h);
}
출력/오류 :
C:\Users\IEUser\Desktop>Hardware.exe
Last Error: 2
Error reading floppy disk '\\.\A:'
Return value for handle = -1
Boot sector Name:
Bytes per sector: 14336
Sectors per Cluster: 248
Total Sectors: 0
오류 코드가 시스템에서 반환은 2 : 지정한 파일을 찾을 수 없습니다.
플로피 드라이브를 열지 못하기 때문에 구조체 변수에 쓰레기 값이 저장됩니다.
누군가 도와 드릴 수 있습니까?
이 _text_하십시오으로 오류를 붙여 여기
수정 된 코드입니다. –"A :"는 장치 이름이 아닙니다. 장치 관리자에서 드라이브를 찾고 해당 장치에 대해 나열된 다른 "이름"을 시도하십시오. 또한 플로피 디스크에 액세스하기위한 [문서] (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858 (v = vs.85) .aspx)에 나열된 몇 가지 제한 사항이 있습니다. 예를 들어, 현재'FILE_SHARE_WRITE'를 사용하고 있지는 않지만 꼭해야만합니다. –
[documentation] (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858 (v = vs.85) .aspx)는 "볼륨이나 플로피 디스크를 열 때, dwShareMode 매개 변수에는 FILE_SHARE_WRITE 플래그가 있어야합니다. " – nos