怎样用c语言读硬盘引导扇区?(win2000,xp下)
为什么用“absread()“不能读?
[此贴子已经被作者于2005-2-25 16:13:39编辑过]
改后可读软盘扇区 出错信息:应用程序试着直接访问硬盘,但仍无法支持。 据说可用win api函数直接实现,但我不知道是什么函数。 #include<stdio.h> #include<stdlib.h> #include<dos.h> #include<ctype.h> const int num=512; int Maxnum; FILE *fp; unsigned char *buf;
void ReadDisk(int nsects,int isect)/*nsects:要读的扇区数;isect:其实逻辑扇区号。*/ {
unsigned int i,j;
/*absread(drive,number of sects to read,start sect number,buf)*/ /*use INT 25h,Read disk sects! */ absread(2,nsects,isect,buf);
/*将结果写入文件*/ for(i=0;i<Maxnum;i+=16) { /*for(j),print by ascii */ for(j=0;j<16;j++) { fprintf(fp,"%02x",buf[i+j]); fprintf(fp," "); } fprintf(fp," ");
/*for(j),print by char*/ for(j=0;j<16;j++) { if(isprint(buf[i+j])) fprintf(fp,"%c",buf[i+j]); else fprintf(fp,"."); } fprintf(fp,"\n");
}/*End for(i)*/
}/*readdisk()*/
int main() { char p[512],ch; int k;
fp=fopen("out.txt","w+"); /*Creat file "out.txt" and write in.*/ if(fp==0) { printf("File open error!"); exit(0); }
fprintf(fp,"\n/*--------------------------Boot引导纪录----------------------------*/\n\n"); /*Boot引导纪录: One sect!*/ Maxnum=num; buf=malloc(Maxnum); ReadDisk(1,0); return 0; }/*main()*/