absread, abswirte

基本介紹

  • 中文名:absread, abswirte
  • 功  能:對磁碟扇區讀、寫數據
  • 頭檔案dos.h
  • 返回值:0:成功;-1:失敗。
函式名: absread, abswirte,功能:,參數:,舉一個簡單的例子,

函式名: absread, abswirte

功 能: 絕對磁碟扇區讀、寫數據
用 法: int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
drive=0(A驅動器)、1(B驅動器)、
nsects=要讀、寫的扇區數(最多64K個);
lsect=起始邏輯扇區號;
buffer=要讀、寫入數據的記憶體起始地址。

功能:

讀----從drive指定的驅動器磁碟上,sectnum指定的邏輯扇區號開始讀取(通過DOS中斷0x25讀取)num個(最多64K個)扇區的內容,儲存於buf所指的緩衝區中;寫----將指定內容寫入(調用DOS中斷0x26)磁碟上的指定扇區,即使寫入的地方是磁碟的邏輯結構、檔案、FAT表和目錄結構所在的扇區,也照常進行。

參數:

drive=0對應A盤,drive=1對應B盤。
返回值:0:成功;-1:失敗。
頭檔案:dos.h
用absread讀出的數據是二進制形式的,其內容就是原本在磁碟中存儲的數據的副本,至於表示什麼,就依賴於原先存儲的格式及數據的內容了.
abswrite函式將記憶體中指定的數據寫入磁碟的特定位置,其內容也是二進制形式的,如果想再找到寫入內容,當然可以用absread在原位置讀出.

舉一個簡單的例子

比方說C糟主引導區受損,則可用軟碟或光碟啟動系統,利用abswrite將主引導區的備份重新寫入,覆蓋逐級損的部分,即可達到手工修復的目的.
程式例:
/* absread example */
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
int main(void)
{
int i, strt, ch_out, sector;
char buf[512];
printf("Insert a diskette into drive A and press any key\n");
getch();
sector = 0;
if (absread(0, 1, sector, &buf) != 0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK\n");
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}

相關詞條

熱門詞條

聯絡我們