?? fat32.inc
字號:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.10 *
;***********************
pop edi
pop esi
pop edx
pop ecx
add esp,4
stc ;file not found
ret
found_file_analyze:
pop edi
pop esi
pop edx
pop ecx
add esp,4
clc ;file found
ret
cluster_tmp: dd 0 ; common variable used by
; analyze_directory and analyze_directory_to_write
cluster_tmp2: dd 0
cluster_tmp3: dd 0
analyze_directory_to_write:
;--------------------------------
; input : EAX = first cluster of the directory
; output : IF CARRY=0 EAX = sector where the file is found
; EBX = pointer in buffer
; [buffer .. buffer+511]
; ECX,EDX,EDI,EDI not changed
; IF CARRY=1
;--------------------------------
push ecx
push edx
push esi
push edi
adr561:
mov [cluster_tmp],eax
mov [cluster_tmp2],eax
mov ecx,[FAT32_SIZE]
imul ecx,[NUMBER_OF_FATS]
add ecx,[RESERVED_SECTOR]
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.10 *
;***********************
cmp [fs_type],2
je correct2_14
sub eax,2
correct2_14:
imul eax,[SECTOR_PER_CLUSTER]
cmp [fs_type],1
je correct2_16
cmp [file_or_directory],0
je correct2_16
cmp [analyze_f16],0
je correct2_16
add eax,[correct_fat16]
correct2_16:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.10 *
;***********************
add eax,[PARTITION_START]
add eax,ecx
mov edx,[SECTOR_PER_CLUSTER]
new_sector_in_cluster1:
mov ebx,buffer
call hd_read ;_new
mov ecx,512/32
adr1_analyze1:
cmp byte [ebx],0x00
je found_file_analyze1
cmp byte [ebx],0xe5
je found_file_analyze1
avanti:
add ebx,32
loop adr1_analyze1
inc eax
dec edx
jne new_sector_in_cluster1
mov eax,[cluster_tmp]
mov [cluster_tmp3],eax
call get_FAT
mov [cluster_tmp],eax
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.11 *
;***********************
cmp [fs_type],2
je correct5_1
cmp eax,0x0f000000
jb adr561
correct6_1:
xor eax,eax
cmp [fs_type],2
je correct3_15_3
mov eax,2 ;this block of code add a new cluster
correct3_15_3:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.11 *
;***********************
call get_free_FAT ;for the directory because the directory
;is full
push eax
mov edx,0x0fffffff ; new end for directory
call set_FAT
pop eax
mov edx,eax
mov eax,[cluster_tmp3]
mov [f_del],1
call set_FAT
mov [f_del],0
; mov edx,eax
; mov eax,[cluster_tmp2]
; call set_FAT
mov ecx,512/4
xor eax,eax
mov edi,buffer
cld
rep stosd
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.12 *
;***********************
cmp [fs_type],2
je correct2_17
sub edx,2
correct2_17:
mov eax,[SECTOR_PER_CLUSTER]
imul eax,edx
cmp [fs_type],1
je correct2_19
cmp [file_or_directory],0
je correct2_19
cmp [analyze_f16],0
je correct2_19
add eax,[correct_fat16]
correct2_19:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.12 *
;***********************
add eax,[PARTITION_START]
add eax,[RESERVED_SECTOR]
mov ecx,[FAT32_SIZE]
imul ecx,[NUMBER_OF_FATS]
add eax,ecx
mov ebx,buffer
mov ecx,[SECTOR_PER_CLUSTER]
set_empty_directory:
call hd_write_new
inc eax
loop set_empty_directory
sub eax,[SECTOR_PER_CLUSTER]
found_file_analyze1:
pop edi
pop esi
pop edx
pop ecx
clc ;file found
ret
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.13 *
;***********************
correct5_1:
cmp eax,0xFFFF
jb adr561
jmp correct6_1
correct5_2:
cmp eax,0xfff8 ;0xFFFF
jb adr56
jmp correct6_2
correct5_3:
cmp eax,0xFFFF
jge delete_OK
jmp correct6_3
correct5_4:
cmp [file_or_directory],0
je file_read_eof
cmp eax,0xFFFF
jge file_read_eof
jmp correct6_4
correct3_15_5:
check_new_1:
cmp word [buffer+edx],0
jne no_found_1
cmp word [buffer+edx+2],0
jne no_found_1
jmp found
no_found_1:
add edx,2
inc ecx
cmp edx,512-2
jb check_new_1
inc ecx
inc eax
call hd_read ;_new
xor edx,edx
jmp check_new_1
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.13 *
;***********************
data_read dd 0x0
blocks_to_read dd 0x0
return_data_pointer dd 0x0
file_size dd 0x0
get_data_cluster:
;--------------------------------
; input : EAX = # block
; ( EBX = pointer to buffer )
; ( ECX = # bytes to read in buffer )
; output: nothing
;--------------------------------
ORG_EAX equ [esp+20]
ORG_EBX equ [esp+16]
ORG_ECX equ [esp+12]
ORG_EDX equ [esp+8]
ORG_ESI equ [esp+4]
ORG_EDI equ [esp]
push eax ; ORG_EAX
push ebx ; ORG_EBX
push ecx ; ORG_ECX
push edx ; ORG_EDX
push esi ; ORG_ESI
push edi ; ORG_EDI
; mov edi,ebx
;
; xor edx,edx
; mov eax,ecx
; mov ebx,512
; div ebx
mov ecx,[FAT32_SIZE]
imul ecx,[NUMBER_OF_FATS]
add ecx,[RESERVED_SECTOR]
mov ebx,ORG_EAX
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.14 *
;***********************
cmp [fs_type],2
je correct2_20
sub ebx,2
correct2_20:
imul ebx,[SECTOR_PER_CLUSTER]
cmp [fs_type],1
je correct2_22
cmp [file_or_directory],0
je correct2_22
add ebx,[correct_fat16]
correct2_22:
add ebx,[PARTITION_START]
add ebx,ecx
mov ecx,[SECTOR_PER_CLUSTER]
cmp [fs_type],1
je correct7_1
cmp [file_or_directory],1
je correct7_1
mov ecx,32
correct7_1:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.14 *
;***********************
mov eax,ebx
mov ebx,buffer
read:
cmp [data_read],0 ; first wanted block
je gdcl1
dec [data_read]
jmp gdcl2
gdcl1:
mov ebx,[return_data_pointer]
call hd_read ;_new
; push ecx
; mov esi,buffer
; mov edi,[return_data_pointer]
; mov ecx,512
; cld
; rep movsb
; pop ecx
add [return_data_pointer],512
dec [blocks_to_read]
gdcl2:
cmp [blocks_to_read],0
je out_of_read
inc eax
loop read
out_of_read:
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
set_data_cluster:
;--------------------------------
; input : EAX = # block
; EBX = pointer to buffer
; ECX = # bytes to write in buffer
; output: nothing
;--------------------------------
push eax ; ORG_EAX
push ebx ; ORG_EBX
push ecx ; ORG_ECX
push edx ; ORG_EDX
push esi ; ORG_ESI
push edi ; ORG_EDI
mov esi,ebx
xor edx,edx
mov eax,ecx
mov ebx,512
div ebx
mov ecx,[FAT32_SIZE]
imul ecx,[NUMBER_OF_FATS]
add ecx,[RESERVED_SECTOR]
mov ebx,ORG_EAX
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.15 *
;***********************
cmp [fs_type],2
je correct2_23
sub ebx,2
correct2_23:
imul ebx,[SECTOR_PER_CLUSTER]
cmp [fs_type],1
je correct2_25
cmp [file_or_directory],0
je correct2_25
add ebx,[correct_fat16]
correct2_25:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.15 *
;***********************
add ebx,[PARTITION_START]
add ebx,ecx
mov ecx,[SECTOR_PER_CLUSTER] ; vt
mov eax,ebx
mov ebx,buffer
write:
push ecx
mov edi,buffer
mov ecx,512
cld
rep movsb
call hd_write_new
inc eax
pop ecx
loop write
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
get_free_FAT:
;------------------------------------------
; input : EAX = # cluster for start the searching
; output : EAX = # first cluster found free
;-------------------------------------------
push ebx
push ecx
push edx
mov ecx,eax
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.16 *
;***********************
cmp [fs_type],1
je correct3_15
shl eax,1
jmp correct3_16
correct3_15:
shl eax,2
correct3_16:
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.16 *
;***********************
xor edx,edx
mov ebx,512
div ebx
add eax,[RESERVED_SECTOR]
add eax,[PARTITION_START]
mov ebx,buffer
call hd_read ;_new
check_new:
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.17 *
;***********************
cmp [fs_type],2
je correct3_15_5
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.17 *
;***********************
cmp dword [buffer+edx],0
jne no_found
cmp dword [buffer+edx+4],0
jne no_found
jmp found
no_found:
add edx,4
inc ecx
cmp edx,512-4
jb check_new
inc ecx
inc eax
call hd_read ;_new
xor edx,edx
jmp check_new
found:
mov eax,ecx
pop edx
pop ecx
pop ebx
ret
;EXPERIMENTAL !!!!!!!!!!!!!
get_cluster_of_a_path:
;---------------------------------------------------------
; input: EBX = pointer to a path string
; (example: the path "/files/data/document" become
; "files......data.......document...0"
; '.' = space char
; '0' = char(0) (ASCII=0) !!! )
; output: if (CARRY=1) -> ERROR in the PATH
; if (CARRY=0) -> EAX=cluster
;---------------------------------------------------------
push ebx
push edx
mov eax,[ROOT_CLUSTER]
mov edx,ebx
;***********************
;* Start *
;* Mario79 edited code *
;* Fat16 *
;* change 1.18 *
;***********************
mov [analyze_f16],0
search_end_of_path:
cmp byte [edx],0
je found_end_of_path
inc edx ; '/'
mov ebx,edx
call analyze_directory
mov [analyze_f16],1
;***********************
;* End *
;* Mario79 edited code *
;* Fat16 *
;* change 1.18 *
;***********************
jc directory_not_found
mov ax,[ebx+20] ;read the HIGH 16bit cluster field
shl eax,16
mov ax,[ebx+26] ;read the LOW 16bit cluster field
add edx,11 ;8+3 (name+extension)
jmp search_end_of_path
found_end_of_path:
pop edx
pop ebx
clc ;no errors
ret
directory_not_found:
pop edx
pop ebx
stc ;errors occour
ret
bcd2bin:
;----------------------------------
; input : AL=BCD number (eg. 0x11)
; output : AH=0
; AL=decimal number (eg. 11)
;----------------------------------
push cx
mov cl,al
shr cl,4
mov ch,cl
shl cl,3
add cl,ch
add cl,ch
and al,0xf
add al,cl
mov ah,0
pop cx
ret
get_data_for_file:
;-----------------------------------------------------
; Get data from CMOS and pack day,month,year in AX
; DATE bits 0..4 : day of month 0..31
; 5..8 : month of year 1..12
; 9..15 : count of years from 1980
;-----------------------------------------------------
push dx
xor dx,dx
mov al,0x7 ;day
out 0x70,al
in al,0x71
call bcd2bin
or dx,ax
mov al,0x8 ;month
out 0x70,al
in al,0x71
call bcd2bin
shl ax,5
or dx,ax
mov al,0x9 ;year
out 0x70,al
in al,0x71
call bcd2bin
add ax,20 ;because CMOS return only the
;two last digit (eg. 2000 -> 00 , 2001 -> 01) and we
shl ax,9 ;need the difference with
;1980 (eg. 2001-1980)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -