當前位置:編程學習大全網 - 源碼下載 - 確定磁盤上信息的位置需要哪幾個參數?在磁盤機上,這壹尋址過程是怎樣實現的?

確定磁盤上信息的位置需要哪幾個參數?在磁盤機上,這壹尋址過程是怎樣實現的?

1.硬盤參數是:磁頭數、簇面數和扇區數。

2. 給妳壹個讀取硬盤參數的子程序,在下面的程序中,將首先讀取硬盤的主引導區 Master boot record,因為所有的硬盤參數都存放在裏面。程序流程如下:

(1) 將指定的物理硬盤主引導區讀入緩沖區

(2) 在引導區偏移地址1BEh處獲取相應的硬盤參數

(3) 通過計算求得該硬盤的磁頭數、簇面數和扇區數

(4) 由得到的硬盤參數求得其容量大小

Get-FdiskParam 子程序調用方式為:

輸入:AL=硬盤物理ID號(80h 或 81h)

程序:CALL Get-FdiskParam

輸出:CF=0成功

AX= 硬盤容量大小(Hex)

CX= 簇面數

DL=扇區數

DH=磁頭數

CF=1 失敗

1.硬盤分區表參數

在硬盤主引導區的1BEh位置即為硬盤分區表參數區,壹個硬盤最多只能分成四個邏輯分區,每個分區參數表占10 h Bytes長度。本節為方便起見,僅設定硬盤為壹個分區的情況,至於多分區情況,請讀者通過修改本程序亦可獲得。這裏以162MB硬盤主引導區中的分區表參數為例。

@@08A08601.GIF;表2 硬盤分區表參數@@

由參數表可查出:磁頭數=15,簇面數=1010,扇區數=22

2.硬盤容量計算

通過分區表的參數,還可求得硬盤的容量大小。在提供的程序中對硬盤容量的計算均按16進制方式:

硬盤容量(MB)=磁頭數×簇面數×扇區數×512/1024為精簡程序,筆者在計算時舍掉了許多余數(舍掉較多,僅保留整數),故此計算得來的容量與實際容量有些差異,請讀者引用時註意。

3.讀硬盤參數源碼(程序2)

程序2:

;----------------

;Get Hard Cyls,Sector,Head,Size

;Input:AL= Fdisk ID(80h,81h)

;Output: CF= 0 successfully

;AX= Fdisk size(Hex)

;CX= Number of Cylinders

:DL= Number of Sectors

;DH= Number of Heads

;CF= 1 failed

;-------------

Get-Fdiskparamproc near

cmp al,80h ;test Fdisk ID

jb Get-FdiskExit

mov cx,cs

mov ds,cx

mov es,cx ;set DS,ES segment

mov dl,al ;Fdisk ID

mov bx,offset Partition-area

mov cx,1

mov dh,0

mov ax,201h ;read partition sector

int 13h

jb Get-FdiskExit ;failed to exit.

mov bx,offset Partiton-area+1beh

mov al,[bx+8] ;Sector counter

mov ah,[bx+5] ;Head counter

mov dl,[bx+7] ;cylinder lower

mov dh,[bx+6] ;cylinder high

mov cx,6

shr dh,cl

inc dx ;get cylinder

push dx ;save cylinder

push ax ;save head & sector

mul ah ;compute Fdisk size

mul dx

mov cx,11

Loop-shift:

shr dx,1

rcr ax,1

loop Loop-shift ;Get Fdisk size

pop dx ;sectors & heads

pop cx ;cylinder counter

clc ;clear CF flag

Get-FdiskExit:

retn

Get-FdiskParamendp

Partition-area db 512 dup(0) ;read Partition buffer

  • 上一篇:ai原創文章生成器
  • 下一篇:健康應用Android源代碼
  • copyright 2024編程學習大全網