阅读:1845回复:8
请问怎样读引导扇区?
各位能告诉一下怎样在linux下读写引导扇区吗?
需要用到是么函数或者调用是么中断? Thanks |
|
沙发#
发布于:2002-08-06 15:27
取得内核级权限后,用汇编都啊,我也没试过?
|
|
|
板凳#
发布于:2002-08-06 18:50
给你一段程序是保存mbr用的!你自己参看参看吧,很简单!
#include <stdio.h> #include <stdlib.h> #include <dos.h> #include <bios.h> #include <string.h> #include <alloc.h> #include <ctype.h> int main(int argc,char *argv[]) { unsigned char Buffer1[512]; char ByteStr1[3],ByteStr2[5]; FILE *Stream1; int Chg1; printf(\"Convert HD MBR to C/C++ Language Variable Tool\\n\"); printf(\"Copyright(C) by Zhao Shi-ping\\n\"); printf(\"TBsoft Software Studio 1997/10\\n\\n\"); if(argc!=2) { printf(\"Usage: MBR2C <Variable Name>\\n\"); exit(1); } if(biosdisk(2,0x80,0,0,1,1,Buffer1)!=0) { printf(\"Read HD MBR Error !\\n\"); exit(1); } memset(Buffer1+0x00da,0,294); Buffer1[0x01fe]=0x55; Buffer1[0x01ff]=0xaa; printf(\"Save HD MBR Data to file MBR_DATA.H ...\"); if((Stream1=fopen(\"MBR_DATA.H\",\"wb\"))==NULL) { printf(\"\\nCannot create the file MBR_DATA.H !\\n\"); exit(1); } fprintf(Stream1,\"unsigned char %s[512]={\\r\\n\\t\",argv[1]); for(Chg1=0;Chg1<512;Chg1++) { itoa(Buffer1[Chg1],ByteStr1,16); strcpy(ByteStr2,\"0x00\"); if(strlen(ByteStr1)==1) strcpy(ByteStr2+3,ByteStr1); else strcpy(ByteStr2+2,ByteStr1); fprintf(Stream1,\"%s\",ByteStr2); if(Chg1!=511) fprintf(Stream1,\",\"); if((Chg1+1)%16==0) fprintf(Stream1,\"\\r\\n\\t\"); } fprintf(Stream1,\"};\\r\\n\"); fclose(Stream1); printf(\" OK !\\n\"); return 0; } |
|
|
地板#
发布于:2002-08-09 22:00
我是新手,我觉得应该这样:
你写一个系统调用,系统调用代码中直接用i/o操作硬盘 别见笑,我还没读到驱动 |
|
地下室#
发布于:2002-08-10 02:12
请问biosdisk在是么头文件中定义的
thank you |
|
5楼#
发布于:2002-08-10 12:25
请问biosdisk在是么头文件中定义的 怎么这么麻烦?用dd /dev/hdx不就可以读出hdx的mbr了么? |
|
|
6楼#
发布于:2002-08-13 18:44
能告诉以下怎么写吗?
thanks |
|
7楼#
发布于:2002-08-17 18:02
serach the source code of dd, then use the code.
Perhaps open /dev/hda then read it will do. 能告诉以下怎么写吗? |
|
|
8楼#
发布于:2002-08-21 15:28
dd if=/dev/hdx of=XXX bs=512 count=1
man dd先 而后看看source... |
|