我是使用 C 学习 windows 编程的初学者。我读取引导扇区的程序为每个驱动器(即软盘或硬盘)显示相同的输出。该程序不应该为每个驱动器生成相同的输出。
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#pragma pack(1)
struct boot
{
BYTE JUMP[3];
char bsOemName[8];
WORD bytesperSector;
BYTE sectorspercluster;
WORD sectorsreservedarea;
BYTE copiesFAT;
WORD maxrootdirentries;
WORD totalSectors;
BYTE mediaDescripter;
WORD sectorsperFAT;
WORD sectorsperTrack;
WORD sides;
WORD hiddenSectors;
char reserve[480];
WORD volumelabel;
};
void ReadSector(char *src,int ss,int num,void *buff);
void main()
{
struct boot b;
ReadSector("\\\\dell-PC\\c:",0,1,&b);
printf("Boot Sector name: %d\n",b.bsOemName);
printf("Bytes per Sector: %d\n",b.bytesperSector);
printf("Sectors per Cluster: %d\n",b.sectorspercluster);
printf("Total sectors: %d\n",b.totalSectors);
printf("copies FAT: %d\n",b.copiesFAT);
printf("hidden sectors: %d\n",b.hiddenSectors);
printf("volume label: %d\n",b.volumelabel);
}
void ReadSector(char *src,int ss,int num,void *buff)
{
HANDLE h;
unsigned int br;
h=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
SetFilePointer(h,(ss*512),NULL,FILE_BEGIN);
ReadFile(h,buff,512*num,&br,NULL);
CloseHandle(h);
}
它为我传递给 ReadSector() 函数的每个参数生成相同的输出。也就是说,如果我通过d:
or e:
,输出总是相同的。我是否将垃圾值作为输出?
Boot Sector name: 1637707
Bytes per Sector: 52428
Sectors per Cluster: 204
Total sectors: 52428
copies FAT: 204
hidden sectors: 52428
volume label: 52428