?? findbad.asm
字號(hào):
;版本 V1.3 增加使用說(shuō)明
;版本 V1.2 需手動(dòng)修改NO_F中參數(shù)值,并采用
;運(yùn)行提示輸入NO_F中參數(shù)值=》初始化=》測(cè)試=》復(fù)制數(shù)據(jù)區(qū)testhd至testhd_bak=》
;寫(xiě)壞柱連續(xù)扇區(qū)標(biāo)識(shí)到FAT1表=》初始化=》復(fù)制數(shù)據(jù)區(qū)testhd_bak至testhd
;=》復(fù)制begin_FAT1_rs至begin_FAT2_rs寫(xiě)壞柱連續(xù)扇區(qū)標(biāo)識(shí)到FAT2表
;針對(duì)FAT32分區(qū)格式 ,且FAT區(qū)+DBR區(qū)所在柱面不可有壞扇區(qū)
;C:盤(pán)(chs最大8G)尋找壞扇區(qū)并在FAT 記錄表中標(biāo)識(shí)0FFFFFF7H,以1柱為標(biāo)識(shí)單位。
;我的筆記本硬盤(pán)分區(qū)參數(shù) FBR_1beH:80 01 01 00 0B 7F BF 0C 3F 00 00 00 41 99 40 00
; DBR: bn_A=00020h bn_B=101fh bn_C=02h bn_E=08h sector=0200H nh=80h ns=3fh
;-------------------------------
;常量定義區(qū)
;color8 equ 1fh ;'LiGuohui'
;-------------------------------
;------------------------------
;數(shù)據(jù)定義區(qū)
data segment para 'data'
file db 100h dup(88h)
NO_F db 02h ;確認(rèn)檢查分區(qū)表中第幾分區(qū)檢查,默認(rèn)第1分區(qū)
NO_F_DAT db 16 dup(0h) ;指定分區(qū)分區(qū)表數(shù)據(jù)
sector dw 200h ;每扇區(qū)字節(jié)512=200h,DBR偏移量0B-0CH
nc dw 20dh ;本硬盤(pán)柱面總數(shù),柱面0~524=525=20dh
nh db 80h ;本硬盤(pán)磁頭總數(shù),磁頭0~127=128=80h,DBR偏移量1A-1BH
ns db 3fh ;本硬盤(pán)單一磁道扇區(qū)總數(shù),扇區(qū)1~63=63=3FH,DBR偏移量18-19H
int13_c db 00h ;中斷13H格式訪問(wèn)硬盤(pán)時(shí)柱面參數(shù)值,注真實(shí)柱面由int13_s高2bit和int13_c組成
int13_h db 00h ;中斷13H格式訪問(wèn)硬盤(pán)時(shí)磁頭參數(shù)值
int13_s db 01h ;中斷13H格式訪問(wèn)硬盤(pán)時(shí)扇區(qū)參數(shù)值
phy_c dw 00h ;硬盤(pán)物理真實(shí)柱面值
phy_h db 01h ;硬盤(pán)物理真實(shí)磁頭值
phy_s db 01h ;硬盤(pán)物理真實(shí)扇區(qū)值
phy_1c_ns dw 00h;硬盤(pán)物理真實(shí)1柱面值扇區(qū)總數(shù)
dos_start_c dw 00h ;DOS分區(qū)開(kāi)始柱面值
dos_start_h db 01h ;DOS分區(qū)開(kāi)始磁頭值
dos_start_s db 01h ;DOS分區(qū)開(kāi)始扇區(qū)值
dos_end_c dw 20dh ;DOS分區(qū)結(jié)束柱面值
dos_end_h db 7fh ;DOS分區(qū)結(jié)束磁頭值
dos_end_s db 3fh ;DOS分區(qū)結(jié)束扇區(qū)值
dos_rs_L16 dw 00h ;DOS分區(qū)邏輯扇區(qū)值,0-***雙字
dos_rs_H16 dw 00h
dos_CH_L16 dw 00h ;DOS分區(qū)簇號(hào),0-***雙字
dos_CH_H16 dw 00h
bn_A dw 20h ;DOS分區(qū)保留扇區(qū),DBR偏移量0E-0FH
bn_B dw 04b3h ;DOS分區(qū)中1個(gè)FAT表占用扇區(qū)數(shù),DBR偏移量24-25H
bn_C db 02h ;DOS分區(qū)中FAT表個(gè)數(shù),DBR偏移量10H
bn_E db 08h ;DOS分區(qū)中每簇扇區(qū)數(shù),DBR偏移量0DH
testhd db 1024 dup(30h) ;硬盤(pán)物理真實(shí)柱面值壞柱記錄區(qū)0-1023=1024=200H
testhd_bak db 1024 dup(30h)
;testhd db 0fh dup(30h),31h,1f0h dup(30h)
err_FAT32 db 'Disk isn`t FAT32!',0dh,0ah,'$'
temp_DAT db 512 dup(0h) ;讀寫(xiě)扇區(qū)緩沖區(qū)
err_NH db 'Head must small than 100h!',0dh,0ah,'$'
err_ns db 'sector must small than 40h!',0dh,0ah,'$'
err_nc db 'Cyli must small than 400h !',0dh,0ah,'$'
err_dos_start_c db 'start cy is bad !',0dh,0ah,'$'
test_c db 00h ;測(cè)試壞扇區(qū)時(shí)柱面變量ch
test_h db 00h ;dh
test_s db 01h ;cl
begin_FAT1_rs_L16 dw 00h ;FAT1區(qū)開(kāi)始邏輯扇區(qū)-雙字
begin_FAT1_rs_H16 dw 00h
begin_FAT2_rs_L16 dw 00h ;FAT2區(qū)開(kāi)始邏輯扇區(qū)-雙字
begin_FAT2_rs_H16 dw 00h
BAD_C dw 01h ;壞柱面號(hào)
dos_CH_bg_L16 dw 00h ;壞柱開(kāi)始簇號(hào)值-雙字
dos_CH_bg_H16 dw 00h
dos_CH_ED_L16 dw 00h ;壞柱終止簇號(hào)值-雙字
dos_CH_ED_H16 dw 00h
FAT1_BAD_CH_rs1_L16 DW 00H ;壞簇在FAT1表中開(kāi)始相對(duì)邏輯扇區(qū)-雙字
FAT1_BAD_CH_rs1_H16 DW 00H
FAT1_BAD_CH_rs2_L16 DW 00H ;壞簇在FAT1表中終止相對(duì)邏輯扇區(qū)-雙字
FAT1_BAD_CH_rs2_H16 DW 00H
FAT2_BAD_CH_rs1_L16 DW 00H ;壞簇在FAT2表中開(kāi)始相對(duì)邏輯扇區(qū)-雙字
FAT2_BAD_CH_rs1_H16 DW 00H
FAT2_BAD_CH_rs2_L16 DW 00H ;壞簇在FAT2表中終止相對(duì)邏輯扇區(qū)-雙字
FAT2_BAD_CH_rs2_H16 DW 00H
WRITE_SECTOR_BG_NO DW 00H
WRITE_SECTOR_ED_NO DW 00H
Bad_DAT DD 80H DUP(0FFFFFF7H) ;在相對(duì)fat表中的某扇區(qū)全填寫(xiě)壞簇標(biāo)志
dsp_test_c_DAT db 'Testing '
dsp_test_c_DAt1 db 20h,20h,20h,20h,'H of '
dsp_test_c_DAT2 db 20h,20h,20h,20h,'H',0dh,0ah,'$'
cpy_FAT1_FAT2_1_L16 dw 00h
cpy_FAT1_FAT2_1_H16 dw 00h
cpy_FAT1_FAT2_2_L16 dw 00h
cpy_FAT1_FAT2_2_H16 dw 00h
dsp_cpy_FAT1_FAT2_DAT db 'Writting '
dsp_cpy_FAT1_FAT2_DAT1 db 20h,20h,20h,20h,'H of '
dsp_cpy_FAT1_FAT2_DAT2 db 20h,20h,20h,20h,'H',0dh,0ah,'$'
write_FAT1_dat db 'Writting FAT1.....',0dh,0ah,'$'
write_FAT2_dat db 'Writting FAT2.....',0dh,0ah,'$'
select_No_DPT db 'Select Disk Partition Table:',0dh,0ah
db ' 0: No.1 DPT',0dh,0ah
db ' 1: No.2 DPT',0dh,0ah
db ' 2: No.3 DPT',0dh,0ah
db ' 3: No.4 DPT',0dh,0ah
db 'Input Number: $'
select_hc db 0dh,0ah,'$'
VGA11H_DAT db 38400 dup(0ffh),'程序設(shè)計(jì):江蘇新科李國(guó)輝'
;FAT32公式說(shuō)明: dos_rs=nh*ns*(phy_c - dos_strat_c)
; + ns*(phy_h - dos_start_h) + (phy_s - dos_start_s)
; phy_s=(dos_rs MOD ns) + dos_start_s
; phy_h=((dos_rs DIV ns) MOD nh) + dos_start_h
; phy_c=((dos_rs DIV ns) DIV nh) + dos_start_c
; dos_CH=((dos_rs - bn_A - bn_C*bn_B) DIV bn_E)+2
; dos_rs=bn_A + bn_C*bn_B + (dos_CH - 2)* bn_E
data ends
;------------------------------
;------------------------------
;代碼區(qū)
code segment para 'code'
assume cs:code; ds:data;ss:stack
beg: mov ax,data
mov ds,ax
push ax
pop es
call DSP_VGA11H ;顯示使用說(shuō)明圖像 按數(shù)字8繼續(xù)
beg_0: mov ah,09h ;initial No_F
mov dx,offset select_No_DPT
int 21h
mov ah,1h
int 21h
sub al,30h
cmp al,4h
jnc beg_0
mov no_F,al
mov ah,09h
mov dx,offset select_hc
int 21h
call ini_bn
call tests
mov si,offset testhd
mov di,offset testhd_bak
mov cx,200h
beg1: mov al,[si]
mov [di],al
inc di
inc si
dec cx
jnz beg1
mov ah,09h
mov dx,offset write_fat1_dat
int 21h
call write_bad
mov di,offset testhd
mov si,offset testhd_bak
mov cx,200h
beg2: mov al,[si]
mov [di],al
inc di
inc si
dec cx
jnz beg2
call ini_bn
mov ax,begin_fat2_rs_L16
mov dx,begin_fat2_rs_H16
mov begin_fat1_rs_L16,ax
mov begin_fat1_rs_H16,dx
mov ah,09h
mov dx,offset write_fat2_dat
int 21h
call write_bad
; call copy_fat1_fat2
mov ax,4c00h
int 21h
ret
READ_NO_F proc near
;將由no_f選定檢查盤(pán)分區(qū)表中16字節(jié)信息讀出至no_f_dat區(qū)
push ax
push bx
push cx
push dx
pushf
push si
push di
mov ah,00h
mov dl,80h
int 13h
mov ax,0201h
mov bx,offset temp_dat
mov cx,0001h
mov dx,0080h
int 13h
mov si,bx
add si,1beh
mov cl,no_f
mov al,10h
mul cl
add si,ax
mov di,offset no_f_dat
mov cl,10h
read_no_f1:mov al,[si]
mov [di],al
inc si
inc di
dec cl
jnz read_no_f1
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
READ_NO_F endp
int13chs_phy proc near
;將int13柱磁扇轉(zhuǎn)換成物理真實(shí)柱磁扇
;輸入:int13_c/h/s 輸出:phy_c/h/s
push ax
push bx
push cx
push dx
pushf
push si
push di
mov ah,int13_h
mov phy_h,ah
mov ah,int13_s
mov al,ah
and ah,0c0h
and al,3fh
mov phy_s,al
mov al,int13_c
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,03h
mov phy_c,ax
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
int13chs_phy endp
phychs_int13 proc near
;將物理真實(shí)柱<=1023磁扇轉(zhuǎn)換成int13柱磁扇
;輸入:phy_c/h/s 輸出:int13_c/h/s
push ax
push bx
push cx
push dx
pushf
push si
push di
mov ah,phy_h
mov int13_h,ah
mov ax,phy_c
mov int13_c,al
shl ah,1h
shl ah,1h
shl ah,1h
shl ah,1h
shl ah,1h
shl ah,1h
and ah,0c0h
mov al,phy_s
or ah,al
mov int13_s,ah
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
phychs_int13 endp
ini_bn proc near
;初始化變量區(qū)子程序
push ax
push bx
push cx
push dx
pushf
push si
push di
call read_no_f
mov si,offset no_f_dat
mov ah,[si+4h]
cmp ah,0bh
jz ini_bn_1
mov dx,offset err_fat32
mov ah,09h
int 21h
mov ax,4c00h
int 21h
ret
ini_bn_1:mov al,[si+1h]
mov int13_h,al
mov al,[si+2h]
mov int13_s,al
mov al,[si+3h]
mov int13_c,al
call int13chs_phy
mov ax,phy_c
mov dos_start_c,ax
mov al,phy_h
mov dos_start_h,al
mov al,phy_s
mov dos_start_s,al
;-------------------------
mov al,[si+5h]
mov int13_h,al
mov al,[si+6h]
mov int13_s,al
mov al,[si+7h]
mov int13_c,al
call int13chs_phy
mov ax,phy_c
mov dos_end_c,ax
mov al,phy_h
mov dos_end_h,al
mov al,phy_s
mov dos_end_s,al
;--------------------------
mov ax,0201h ;讀入選定分區(qū)DBR至temp_dat
mov bx,offset temp_dat
mov dl,80h
mov dh,[si+1h]
mov cl,[si+2h]
mov ch,[si+3h]
int 13h
;--------------------------
mov si,offset temp_dat
mov ax,[si+0bh] ;讀入sector
mov sector,ax
mov ax,[si+1ah] ;讀入nh
cmp ax,100h
jb ini_bn_2
mov dx,offset err_nh
exit: mov ah,09h
int 21h
mov ax,4c00h
int 21h
ret
ini_bn_2:mov nh,al
;--------------------------
mov ax,[si+18h] ;讀入NS
cmp ax,40h
jb ini_bn_3
mov dx,offset err_ns
jmp exit
ini_bn_3:mov ns,al
;--------------------------
mov cl,ns ;計(jì)算phy_1c_ns
mov al,nh
mul cl
mov phy_1c_ns,ax
;--------------------------
mov ax,[si+0eh] ;讀入bn_A bn_B bn_C bn_E
mov bn_A,ax
mov ax,[si+24h]
mov bn_B,ax
mov al,[si+10h]
mov bn_C,al
mov al,[si+0dh]
mov bn_E,al
;--------------------------
;計(jì)算要測(cè)試的總柱面數(shù)nc
mov si,offset no_f_dat
mov bx,[si+0ah]
mov dx,[si+0eh]
add dx,bx
mov ax,[si+08h]
mov cx,[si+0ch]
add ax,cx
jnc ini_bn_4
inc dx
ini_bn_4:mov bx,phy_1c_ns
div bx
cmp dx,00h
jz ini_bn_5
inc ax
ini_bn_5:cmp ax,400h
jb ini_bn_6
mov dx,offset err_nc
jmp exit
ini_bn_6:mov nc,ax
;-------------------------
mov ax,bn_A ;初始化begin_Fat1_rs begin_Fat2_rs
mov begin_fat1_rs_l16,ax
mov ax,00h
mov begin_fat1_rs_h16,ax
mov dx,00h
mov ax,bn_B
add ax,bn_A
jnc ini_bn_7
inc dx
ini_bn_7:mov begin_FAT2_rs_L16,ax
mov begin_FAT2_rs_H16,dx
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
ini_bn endp
dsp_test_c_nc proc near
push ax
push bx
push cx
push dx
pushf
push si
push di
mov al,test_c
mov ah,test_s
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,03h
mov si,offset dsp_test_C_dat1
push ax
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,0fh
cmp ah,0ah
jb dsp_t1
add ah,7h
dsp_t1:add ah,30h
mov [si+0],ah
pop ax
push ax
and ah,0fh
cmp ah,0ah
jb dsp_t2
add ah,7h
dsp_t2:add ah,30h
mov [si+1h],ah
pop ax
push ax
shr al,1h
shr al,1h
shr al,1h
shr al,1h
and al,0fh
cmp al,0ah
jb dsp_t3
add al,7h
dsp_t3:add al,30h
mov [si+2h],al
pop ax
push ax
and al,0fh
cmp al,0ah
jb dsp_t4
add al,7h
dsp_t4:add al,30h
mov [si+3h],al
pop ax
;--------------------
mov ax,nc
mov si,offset dsp_test_C_dat2
push ax
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,0fh
cmp ah,0ah
jb dsp_t5
add ah,7h
dsp_t5:add ah,30h
mov [si+0],ah
pop ax
push ax
and ah,0fh
cmp ah,0ah
jb dsp_t6
add ah,7h
dsp_t6:add ah,30h
mov [si+1h],ah
pop ax
push ax
shr al,1h
shr al,1h
shr al,1h
shr al,1h
and al,0fh
cmp al,0ah
jb dsp_t7
add al,7h
dsp_t7:add al,30h
mov [si+2h],al
pop ax
push ax
and al,0fh
cmp al,0ah
jb dsp_t8
add al,7h
dsp_t8:add al,30h
mov [si+3h],al
pop ax
;--------------
mov dx,offset dsp_test_c_dat
mov ah,09h
int 21h
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
dsp_test_c_nc endp
dsp_cpy_fat1_fat2 proc near
push ax
push bx
push cx
push dx
pushf
push si
push di
mov ax,cpy_FAT1_FAT2_1_L16
mov si,offset dsp_cpy_fat1_fat2_dat1
push ax
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,0fh
cmp ah,0ah
jb dsp_c1
add ah,7h
dsp_c1:add ah,30h
mov [si+0],ah
pop ax
push ax
and ah,0fh
cmp ah,0ah
jb dsp_c2
add ah,7h
dsp_c2:add ah,30h
mov [si+1h],ah
pop ax
push ax
shr al,1h
shr al,1h
shr al,1h
shr al,1h
and al,0fh
cmp al,0ah
jb dsp_c3
add al,7h
dsp_c3:add al,30h
mov [si+2h],al
pop ax
push ax
and al,0fh
cmp al,0ah
jb dsp_c4
add al,7h
dsp_c4:add al,30h
mov [si+3h],al
pop ax
;--------------------
mov ax,cpy_fat1_fat2_2_L16
mov si,offset dsp_cpy_fat1_fat2_dat2
push ax
shr ah,1h
shr ah,1h
shr ah,1h
shr ah,1h
and ah,0fh
cmp ah,0ah
jb dsp_c5
add ah,7h
dsp_c5:add ah,30h
mov [si+0],ah
pop ax
push ax
and ah,0fh
cmp ah,0ah
jb dsp_c6
add ah,7h
dsp_c6:add ah,30h
mov [si+1h],ah
pop ax
push ax
shr al,1h
shr al,1h
shr al,1h
shr al,1h
and al,0fh
cmp al,0ah
jb dsp_c7
add al,7h
dsp_c7:add al,30h
mov [si+2h],al
pop ax
push ax
and al,0fh
cmp al,0ah
jb dsp_c8
add al,7h
dsp_c8:add al,30h
mov [si+3h],al
pop ax
;--------------
mov dx,offset dsp_cpy_fat1_fat2_dat
mov ah,09h
int 21h
pop di
pop si
popf
pop dx
pop cx
pop bx
pop ax
ret
dsp_cpy_fat1_fat2 endp
tests proc near
;測(cè)試dos_start_c~nc-1柱面壞道,并將結(jié)果記錄在testhd中
;每個(gè)字節(jié)對(duì)一個(gè)柱面,"31H"表示壞柱
push ax
push bx
push cx
push dx
pushf
push si
push di
mov ah,00h ;硬盤(pán)復(fù)位
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -