磁盘的数据组织:
盘片上的园环叫磁道(track), 每个磁道分成许多扇形的扇区(sector), 每个扇区是连续的512字节.
磁盘由1个或多个盘片组成, 盘片分单面和双面, 每个面有一个磁头(head)来读写.
这些(1个或多个)盘片, 相同的磁道构成柱面(cylinder).
定位用到的参数:
NS: 逻辑扇区号
ns: 扇区号 (从1开始)
nc: 柱面号 (从0开始)
nh: 磁头号 (从0开始)
spt: 每磁道扇区数(sector per track)
h: 磁头数
由NS计算ns, nc, nh
ns = (NS % spt) + 1
nc = (NS / spt) / h
nh = (NS / spt) % h
对于扇区数和柱面数, 可以通过BIOS中断 0x13h, ah = 0x8来取得, 语法为
INT 13 - DISK - GET DRIVE PARAMETERS (PC,XT286,CONV,PS,ESDI,SCSI)
AH = 08h
DL = drive (bit 7 set for hard disk)
ES:DI = 0000h:0000h to guard against BIOS bugs
Return:
CF set on error
AH = status (07h) (see #00234)
CF clear if successful
AH = 00h
AL = 00h on at least some BIOSes
BL = drive type (AT/PS2 floppies only)
CH = low eight bits of maximum cylinder number
CL = maximum sector number (bits 5-0)
high two bits of maximum cylinder number (bits 7-6)
DH = maximum head number
DL = number of drives
ES:DI -> drive parameter table (floppies only)
在DOS下运行debug
-a 100
-xxxx:xxxx mov ah, 8
-xxxx:xxxx mov dl, 0 (驱动器号, 第一块硬盘用80)
-xxxx:xxxx int 13
-xxxx:xxxx int 3 (软中断, 防止继续执行下去)
-xxxx:xxxx (直接回车)
-g=100
-r
-q(退出)
你会看到各寄存器的内容, 我们注意的是
BX = 0004; CX = 4F12(0100 1111 0001 0010); DX = 0101
其中BL = 04表示1.44M软盘(2磁头, 80柱面, 18扇区)
DH = 01 表示有最大磁头号是1, 从0开始, 所以有2个磁头
DL = 01 有一个驱动器(???期待高人解答...)
CL的高2位(00)和CH(0100 1111)合在一起是04F, 表示最大柱面号79, 同样从0开始, 所以有80个柱面
CL的低6位(01 0010) = 12表示最大磁道号为18, 从1开始