Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 73 → Rev 74

/kernel/trunk/fs/fat32.inc
7,7 → 7,8
;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;;
;; ;;
;; See file COPYING for details ;;
;; ;;
;; 29.04.2006 Elimination of hangup after the ;;
;; expiration hd_wait_timeout - Mario79 ;;
;; 23.04.2006 LFN read - diamond ;;
;; 28.01.2006 find all Fat16/32 partition in all input point ;;
;; to MBR, see file part_set.inc - Mario79 ;;
173,11 → 174,16
cmp [fat_change],0 ; is fat changed?
je sfc_no_change ; no
call write_fat_sector ; yes. write it into disk
cmp [hd_error],0
jne sfc_error
 
sfc_no_change:
mov [fat_in_cache],eax ; save fat sector
call hd_read
cmp [hd_error],0
jne sfc_error
 
 
sfc_in_cache:
cmp [fat_type],16
jne sfc_test32
247,14 → 253,19
cmp [fat_change],0 ; is fat changed?
je gfc_no_change ; no
call write_fat_sector ; yes. write it into disk
cmp [hd_error],0
jne hd_error_01
 
gfc_no_change:
mov [fat_in_cache],eax
call hd_read
cmp [hd_error],0
jne hd_error_01
 
gfc_in_cache:
mov eax,[ebx+esi]
and eax,[fatMASK]
hd_error_01:
pop esi ebx
ret
 
278,6 → 289,9
gff_in_range:
push eax
call get_FAT ; get cluster state
cmp [hd_error],0
jne gff_not_found_1
 
test eax,eax ; is it free?
pop eax
je gff_found ; yes
285,6 → 299,8
dec ecx ; is all checked?
jns gff_test ; no
 
gff_not_found_1:
add esp,4
gff_not_found:
pop ecx ; yes. disk is full
stc
311,6 → 327,9
 
write_next_fat:
call hd_write
cmp [hd_error],0
jne write_fat_not_used
 
add eax,[SECTORS_PER_FAT]
dec ecx
jnz write_next_fat
361,6 → 380,9
adr_new_sector:
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne adr_not_found
 
mov ecx,512/32 ; count of dir entrys per sector = 16
 
adr_analyze:
397,6 → 419,9
adr_next_cluster:
mov eax,[cluster_tmp]
call get_FAT ; get next cluster
cmp [hd_error],0
jne adr_not_found
 
cmp eax,2 ; incorrect fat chain?
jb adr_not_found ; yes
cmp eax,[fatRESERVED] ; is it end of directory?
450,6 → 475,9
adw_new_sector:
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne adw_not_found
 
mov ecx,512/32 ; count of dir entrys per sector = 16
 
adw_analyze:
469,6 → 497,9
 
mov eax,[cluster_tmp]
call get_FAT ; get next cluster
cmp [hd_error],0
jne adw_not_found
 
cmp eax,2 ; incorrect fat chain?
jb adw_not_found ; yes
cmp eax,[fatRESERVED] ; is it end of directory?
480,6 → 511,8
 
mov edx,[fatEND] ; new end for directory
call set_FAT
cmp [hd_error],0
jne adw_not_found
 
push eax ; save new cluster
mov edx,eax
486,10 → 519,15
mov eax,[cluster_tmp] ; change last cluster to point new cluster
mov [f_del],1
call set_FAT
cmp [hd_error],0
jne adw_not_found_1
 
mov [f_del],0
 
mov ecx,-1 ; remove 1 cluster from free disk space
call add_disk_free_space
cmp [hd_error],0
jne adw_not_found_1
 
mov ecx,512/4
xor eax,eax
507,6 → 545,9
 
adw_set_empty_directory:
call hd_write
cmp [hd_error],0
jne adw_not_found_1
 
inc eax ; next sector
dec ecx
jnz adw_set_empty_directory
517,7 → 558,8
pop edi edx ecx
clc ; free space found
ret
 
adw_not_found_1:
add esp,4
adw_not_found:
pop edi edx ecx
stc ; free space not found
564,6 → 606,9
 
gdcl1:
call hd_read
cmp [hd_error],0
jne gdc_error
 
add ebx,512 ; update pointer
dec edx
 
606,6 → 651,9
 
sdc_write:
call hd_write
cmp [hd_error],0
jne sdc_error
 
add ebx,512 ; update pointer
inc eax
dec edx
768,34 → 816,58
mov ebx,edx
call get_cluster_of_a_path
jnc make_dir_found_path
cmp [hd_error],0
jne make_dir_error_1
 
make_dir_path_not_found:
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne make_dir_error_2
 
mov [hd1_status],0
mov eax,ERROR_FILE_NOT_FOUND
ret
 
make_dir_disk_full:
cmp [hd_error],0
jne make_dir_error_1
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne make_dir_error_2
 
mov [hd1_status],0
mov eax,ERROR_DISK_FULL
ret
 
make_dir_already_exist:
cmp [hd_error],0
jne make_dir_error_1
mov eax,[cluster] ; directory cluster
xor edx,edx ; free
mov [f_del],1
call set_FAT
cmp [hd_error],0
jne make_dir_error_1
 
mov [f_del],0
 
popad
call update_disk ; write all of cache and fat to hd
make_dir_error_2:
mov [hd1_status],0
mov eax,ERROR_ACCESS_DENIED
ret
 
make_dir_error_1:
popad
jmp make_dir_error_2
 
make_dir_error_3:
add esp,4
jmp make_dir_error_1
 
make_dir_found_path:
cmp eax,[ROOT_CLUSTER]
jnz make_dir_not_root
818,11 → 890,16
mov eax,[cluster] ; directory cluster
mov edx,[fatEND] ; end for directory
call set_FAT
cmp [hd_error],0
jne make_dir_error_3
pop eax
 
mov ebx,PUSHAD_EAX ; dir name
push eax
call analyze_directory ; check if directory already exist
cmp [hd_error],0
jne make_dir_error_1
 
pop eax
jnc make_dir_already_exist ; need to free allocated cluster!
 
851,6 → 928,8
 
mov ebx,buffer ; save the directory name,length,cluster
call hd_write
cmp [hd_error],0
jne make_dir_error_1
 
mov ecx,512/4
xor eax,eax
878,14 → 957,21
 
not_first_sector:
call hd_write
cmp [hd_error],0
jne make_dir_error_1
dec edx
jnz dir_set_empty_directory
 
mov ecx,-1 ; remove 1 cluster from free disk space
call add_disk_free_space
cmp [hd_error],0
jne make_dir_error_1
 
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne make_dir_error_2
mov [hd1_status],0
xor eax,eax
ret
911,9 → 997,13
push edi
mov edi,1 ; allow directory remove
call file_delete
cmp [hd_error],0
jne @f
 
pop edi
 
call update_disk ; write all of cache and fat to hd
@@:
mov [hd1_status],0
ret
 
933,11 → 1023,16
mov eax,[ADR_FSINFO]
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne add_not_fs
 
cmp dword [ebx+0x1fc],0xaa550000 ; check sector id
jne add_not_fs
 
add [ebx+0x1e8],ecx
call hd_write
cmp [hd_error],0
jne add_not_fs
 
add_not_fs:
pop ebx eax
1019,16 → 1114,23
mov [ebx+20],cx ; 16 bits high of cluster (=0 fat16)
mov edx,[fatEND] ; new end for cluster chain
call set_FAT
cmp [hd_error],0
jne append_access
 
push eax ; save first cluster
mov eax,[sector_tmp]
mov ebx,buffer
call hd_write ; write new file entry back to disk
cmp [hd_error],0
jne append_access_1
 
pop eax
 
append_remove_free:
mov ecx,-1 ; remove 1 cluster from free disk space
call add_disk_free_space ; Note: uses buffer
cmp [hd_error],0
jne append_access
 
append_found_cluster:
mov [cluster],eax
1039,6 → 1141,8
xor edi,edi
 
append_new_sector:
cmp [hd_error],0
jne append_access
push ecx
mov ecx,[bytes2write] ; bytes left in buffer
mov ebx,512
1052,6 → 1156,8
jz append_full_sector ; yes
mov ebx,buffer ; overwrite part of sector
call hd_read ; read old sector
cmp [hd_error],0
jne append_access_1
 
append_full_sector:
sub [bytes2write],ecx
1063,6 → 1169,9
 
mov ebx,buffer
call hd_write
cmp [hd_error],0
jne append_access
 
cmp [bytes2write],0 ; is all done?
jz append_done
xor edi,edi
1072,6 → 1181,9
 
mov eax,[cluster]
call get_FAT
cmp [hd_error],0
jne append_access
 
cmp eax,2
jb append_fat
cmp eax,[LAST_CLUSTER]
1084,10 → 1196,16
push eax ; save new cluster
mov edx,[fatEND] ; new end for cluster chain
call set_FAT
cmp [hd_error],0
jne append_access_1
mov edx,eax
mov eax,[cluster]
mov [f_del],1
call set_FAT ; update previous cluster
cmp [hd_error],0
jne append_access_1
 
mov [f_del],0
pop eax
jmp append_remove_free
1104,6 → 1222,8
jmp append_ret_code
 
append_disk_full:
cmp [hd_error],0
jne append_access
mov eax,ERROR_DISK_FULL
jmp append_ret_code
 
1116,6 → 1236,9
mov eax,[sector_tmp] ; update directory entry
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne append_access
mov ebx,[entry_pos]
mov ecx,[new_filepos]
cmp ecx,[old_filesize] ; is file pos above old size?
1126,11 → 1249,16
call set_current_time_for_entry
mov ebx,buffer
call hd_write ; write new file entry back to disk
cmp [hd_error],0
jne append_access
 
sub ecx,PUSHAD_ESI ; start position
mov PUSHAD_EBX,ecx ; bytes written
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne append_access_2
 
mov [hd1_status],0
ret
 
1142,14 → 1270,18
ret
 
append_not_found:
cmp [hd_error],0
jne append_access
popad
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_FILE_NOT_FOUND
ret
 
append_access_1:
add esp,4
append_access:
popad
append_access_2:
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_ACCESS_DENIED
1169,6 → 1301,9
call set_current_time_for_entry
mov ebx,buffer
call hd_write
cmp [hd_error],0
jne append_access
 
mov eax,edx ; first cluster
test edi,edi ; 0 length file?
jz truncate_clear_chain
1183,6 → 1318,9
sub edi,esi
jbe truncate_pos_found
call get_FAT ; get next cluster
cmp [hd_error],0
jne append_access
 
jmp truncate_new_cluster
 
truncate_pos_found:
1189,15 → 1327,23
mov edx,[fatEND] ; new end for cluster chain
mov [f_del],1
call set_FAT
cmp [hd_error],0
jne append_access
 
mov [f_del],0
mov eax,edx ; clear rest of chain
 
truncate_clear_chain:
call clear_cluster_chain
cmp [hd_error],0
jne append_access
 
truncate_eof:
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne append_access_2
 
mov [hd1_status],0
xor ebx,ebx
xor eax,eax
1232,6 → 1378,9
 
sub edi,esi
call get_FAT ; get next cluster
cmp [hd_error],0
jne filepos_eof
 
jmp filepos_new_cluster
 
filepos_cluster_ok:
1286,6 → 1435,9
 
xor edi,edi ; don't allow directory remove
call file_delete ; try to delete the file first
cmp [hd_error],0
jne exit_write_access_1
 
test eax,eax
jz old_deleted ; deleted ok
cmp eax,ERROR_FILE_NOT_FOUND
1295,21 → 1447,34
mov ebx,PUSHAD_EDX
call get_cluster_of_a_path
jnc found_directory_for_writing
cmp [hd_error],0
jne exit_write_access
 
exit_writing_with_error:
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne exit_write_access_2
 
mov [hd1_status],0
mov eax,ERROR_FILE_NOT_FOUND
ret
 
exit_writing_disk_full_clear:
cmp [hd_error],0
jne exit_write_access_1
mov eax,[sector_tmp]
mov ebx,buffer
call hd_read ; read directory sector
cmp [hd_error],0
jne exit_write_access_1
 
mov edx,[entry_pos]
mov byte [edx],0xe5 ; mark as deleted
call hd_write
cmp [hd_error],0
jne exit_write_access_1
 
mov eax,[edx+20-2] ; FAT entry
mov ax,[edx+26]
and eax,[fatMASK]
1316,8 → 1481,12
call clear_cluster_chain
 
exit_writing_disk_full:
cmp [hd_error],0
jne exit_write_access_1
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne exit_write_access_2
mov [hd1_status],0
mov eax,ERROR_DISK_FULL
ret
1329,6 → 1498,13
mov eax,ERROR_ACCESS_DENIED
ret
 
exit_write_access_1:
popad
exit_write_access_2:
mov [hd1_status],0
mov eax,ERROR_ACCESS_DENIED
ret
 
found_directory_for_writing:
call analyze_directory_to_write
jc exit_writing_disk_full
1360,6 → 1536,8
 
mov ebx,buffer ; save the directory name,length,cluster
call hd_write
cmp [hd_error],0
jne exit_write_access_1
 
imul edi,[SECTORS_PER_CLUSTER],512 ; edi = cluster size in bytes
xor ecx,ecx ; cluster count
1369,6 → 1547,8
 
mov eax,[cluster] ; eax = block
call set_data_cluster
cmp [hd_error],0
jne exit_write_access_1
 
sub esi,edi ; sub wrote bytes
jbe file_saved_OK ; end if all done
1381,6 → 1561,9
mov edx,eax
xchg eax,[cluster] ; get old cluster and save new cluster
call set_FAT ; add it in cluster chain
cmp [hd_error],0
jne exit_write_access_1
 
dec ecx ; update cluster count
jmp hd_new_block_write
 
1388,12 → 1571,19
 
mov edx,[fatEND] ; new end for cluster chain
call set_FAT
cmp [hd_error],0
jne exit_write_access_1
 
dec ecx ; update cluster count
 
call add_disk_free_space ; remove clusters from free disk space
cmp [hd_error],0
jne exit_write_access_1
 
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne exit_write_access_2
mov [hd1_status],0
xor eax,eax
ret
1416,6 → 1606,7
; 5 - file not found
; 6 - end of file
; 9 - fat table corrupted
; 10 - access denied
; ebx = size of file/directory
;--------------------------------------------------------------------------
cmp [fat_type],0
1439,6 → 1630,9
 
xor eax,eax
call get_dir_size ; return rootdir size
cmp [hd_error],0
jne file_access_denied
 
mov [file_size],eax
mov eax,[ROOT_CLUSTER]
jmp file_read_start
1456,6 → 1650,8
mov ax,[ebx+26]
and eax,[fatMASK]
call get_dir_size
cmp [hd_error],0
jne file_access_denied
 
read_set_size:
mov [file_size],eax
1477,6 → 1673,9
je file_read_OK ; yes
 
call get_FAT ; get next cluster
cmp [hd_error],0
jne file_access_denied
 
cmp eax,[fatRESERVED] ; end of file
jnb file_read_eof
cmp eax,2 ; incorrect fat chain
1489,6 → 1688,8
ret
 
file_read_eof:
cmp [hd_error],0
jne file_access_denied
popad
mov [hd1_status],0
mov ebx,[file_size]
1503,6 → 1704,8
ret
 
file_to_read_not_found:
cmp [hd_error],0
jne file_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
1509,6 → 1712,12
mov eax,ERROR_FILE_NOT_FOUND
ret
 
file_access_denied:
popad
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_ACCESS_DENIED
ret
 
get_dir_size:
;-----------------------------------------------------
1532,6 → 1741,9
cmp eax,[fatRESERVED] ; end of directory
ja dir_size_end
call get_FAT ; get next cluster
cmp [hd_error],0
jne dir_size_ret
 
inc edx
jmp dir_size_next
 
1587,16 → 1799,26
push ebx ; save directory pointer in buffer
mov ebx,buffer
call hd_read ; read directory sector
cmp [hd_error],0
jne delete_no_access_1
pop ebx
 
delete_notdir:
call delete_entry_name
cmp [hd_error],0
jne delete_no_access
 
mov eax,ecx ; first cluster of file
call clear_cluster_chain
cmp [hd_error],0
jne delete_no_access
 
popad
xor eax,eax
ret
 
delete_no_access_1:
add esp,4
delete_no_access:
popad
mov eax,ERROR_ACCESS_DENIED
1603,6 → 1825,8
ret
 
file_to_delete_not_found:
cmp [hd_error],0
jne delete_no_access
popad
mov eax,ERROR_FILE_NOT_FOUND
ret
1626,6 → 1850,9
 
xor edx,edx
call set_FAT ; clear fat entry
cmp [hd_error],0
jne access_denied_01
 
inc ecx ; update cluster count
mov eax,edx ; old cluster
jmp clean_new_chain
1632,6 → 1859,7
 
delete_OK:
call add_disk_free_space ; add clusters to free disk space
access_denied_01:
mov [f_del],0
pop edx ecx eax
ret
1664,6 → 1892,9
mov edi,eax ; edi = current directory sector
mov ebx,deltree_buffer
call hd_read
cmp [hd_error],0
jne clear_error
 
mov edx,512/32 ; count of dir entrys per sector = 16
 
clear_analyze:
1691,6 → 1922,9
mov eax,edi
mov ebx,deltree_buffer ; save buffer over recursive call
call hd_write ; write directory sector to disk
cmp [hd_error],0
jne clear_error
 
pop ebx eax
 
call clear_directory ; recursive call !!!
1700,10 → 1934,15
mov eax,edi
mov ebx,deltree_buffer
call hd_read ; read directory sector again
cmp [hd_error],0
jne clear_error_1
 
pop ebx eax
 
clear_file:
call clear_cluster_chain
cmp [hd_error],0
jne clear_error
 
clear_long_filename:
mov byte [ebx],0xe5
1716,6 → 1955,8
mov eax,edi
mov ebx,deltree_buffer
call hd_write ; write directory sector to disk
cmp [hd_error],0
jne clear_error
 
inc eax ; next sector
dec ecx
1723,6 → 1964,9
 
mov eax,esi
call get_FAT ; get next cluster
cmp [hd_error],0
jne clear_error
 
jmp clear_new_cluster ; clear it
 
clear_write_last:
1729,12 → 1973,15
mov eax,edi
mov ebx,deltree_buffer
call hd_write ; write directory sector to disk
cmp [hd_error],0
jne clear_error
 
clear_end:
popad
clc
ret
 
clear_error_1:
add esp,8
clear_error:
popad
stc
1761,6 → 2008,9
 
mov ebx,buffer
call hd_write ; write directory sector back
cmp [hd_error],0
jne delete_name_end
 
xor eax,eax
xchg eax,[longname_sec2]
xchg eax,[longname_sec1]
1769,6 → 2019,9
 
mov ebx,buffer
call hd_read ; read previous sector
cmp [hd_error],0
jne delete_name_end
 
mov ebx,buffer+0x1e0 ; start from last entry
 
delete_test_long:
1836,6 → 2089,9
push [longname_sec1]
push [longname_sec2]
call analyze_directory ; check if entry already exist
cmp [hd_error],0
jne rename_entry_already_exist_1
 
pop [longname_sec2]
pop [longname_sec1]
jnc rename_entry_already_exist
1863,34 → 2119,51
mov ax,[dir_entry+26]
and eax,[fatMASK]
call change_2dot_cluster
cmp [hd_error],0
jne rename_entry_already_exist
 
rename_not_dir:
cmp [hd_error],0
jne rename_entry_already_exist
mov eax,[sector_tmp]
mov ebx,buffer
call hd_read ; read source directory sector
cmp [hd_error],0
jne rename_entry_already_exist
 
mov ebx,[entry_pos]
call delete_entry_name
cmp [hd_error],0
jne rename_entry_already_exist
 
popad
call update_disk ; write all of cache and fat to hd
cmp [hd_error],0
jne rename_entry_already_exist_2
mov [hd1_status],0
xor eax,eax
ret
 
rename_entry_not_found:
cmp [hd_error],0
jne rename_entry_already_exist
popad
mov [hd1_status],0
mov eax,ERROR_FILE_NOT_FOUND
ret
 
rename_entry_already_exist_1:
add esp,8
rename_entry_already_exist:
popad
rename_entry_already_exist_2:
mov [hd1_status],0
mov eax,ERROR_ACCESS_DENIED
ret
 
rename_disk_full:
cmp [hd_error],0
jne rename_entry_already_exist
popad
mov [hd1_status],0
mov eax,ERROR_DISK_FULL
1912,6 → 2185,8
add eax,[DATA_START]
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne not_2dot
 
cmp dword [ebx+32],'.. '
jnz not_2dot
1938,6 → 2213,7
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
; ebx = file size
;-----------------------------------------------------------
cmp [fat_type],0
1973,6 → 2249,8
 
get_filesize_dirsize:
call get_dir_size
cmp [hd_error],0
jne get_filesize_access_denied
 
get_filesize_set_size:
mov PUSHAD_EBX,eax
1982,6 → 2260,8
ret
 
get_filesize_not_found:
cmp [hd_error],0
jne get_filesize_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
1988,6 → 2268,12
mov eax,ERROR_FILE_NOT_FOUND
ret
 
get_filesize_access_denied:
popad
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_ACCESS_DENIED
ret
 
get_fileattr:
;-----------------------------------------------------------
1996,6 → 2282,7
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
; ebx = file attribute
;-----------------------------------------------------------
cmp [fat_type],0
2024,6 → 2311,8
ret
 
get_fileattr_not_found:
cmp [hd_error],0
jne get_fileattr_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
2030,6 → 2319,12
mov eax,ERROR_FILE_NOT_FOUND
ret
 
get_fileattr_access_denied:
popad
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_ACCESS_DENIED
ret
 
get_filedate:
;-----------------------------------------------------------
2038,6 → 2333,7
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
; ebx = file date/time
; bits 31..25 = year-1980
; bits 24..21 = month
2072,6 → 2368,8
ret
 
get_filedate_not_found:
cmp [hd_error],0
jne get_filedate_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
2078,11 → 2376,18
mov eax,ERROR_FILE_NOT_FOUND
ret
 
get_filedate_access_denied:
popad
mov [hd1_status],0
xor ebx,ebx
mov eax,ERROR_ACCESS_DENIED
ret
 
get_hd_info:
;-----------------------------------------------------------
; output : eax = 0 - ok
; 3 - unknown FS
; 10 - access denied
; edx = cluster size in bytes
; ebx = total clusters on disk
; ecx = free clusters on disk
2105,6 → 2410,9
info_cluster:
push eax
call get_FAT ; get cluster info
cmp [hd_error],0
jne info_access_denied
 
test eax,eax ; is it free?
jnz info_used ; no
inc ecx
2121,6 → 2429,13
xor eax,eax
ret
 
info_access_denied:
add esp,4
xor edx,edx
xor ebx,ebx
xor ecx,ecx
mov eax,ERROR_ACCESS_DENIED
ret
 
update_disk:
;-----------------------------------------------------------
2130,10 → 2445,13
je upd_no_change
 
call write_fat_sector
cmp [hd_error],0
jne update_disk_acces_denied
 
upd_no_change:
 
call write_cache
update_disk_acces_denied:
ret
 
 
2179,36 → 2497,41
jnz hdreadcache
 
call find_empty_slot ; ret in edi
cmp [hd_error],0
jne return_01
 
call wait_for_hd_idle
push eax edx
 
call wait_for_hd_idle
cmp [hd_error],0
jne hd_read_error
 
cli
xor eax,eax
mov edx,[hdbase]
inc edx
out dx,al ; ATAFeatures ðåãèñòð "îñîáåííîñòåé"
out dx,al ; ATAFeatures  ¥£ð¡¢  "®¡®¡¥­­®¡¢¥©"
inc edx
inc eax
out dx,al ; ATASectorCount ñ÷åò÷èê ñåêòîðîâ
out dx,al ; ATASectorCount ¡§¥¢§ðª ¡¥ª¢® ®¢
inc edx
mov eax,[esp+4]
out dx,al ; ATASectorNumber ðåãèñòð íîìåðà ñåêòîðà
out dx,al ; ATASectorNumber  ¥£ð¡¢  ­®¬¥   ¡¥ª¢®  
shr eax,8
inc edx
out dx,al ; ATACylinder íîìåð öèëèíäðà (ìëàäøèé áàéò)
out dx,al ; ATACylinder ­®¬¥  ¦ð«ð­¤   (¬« ¤¨ð© ¡ ©¢)
shr eax,8
inc edx
out dx,al ; íîìåð öèëèíäðà (ñòàðøèé áàéò)
out dx,al ; ­®¬¥  ¦ð«ð­¤   (¡¢  ¨ð© ¡ ©¢)
shr eax,8
inc edx
and al,1+2+4+8
add al,byte [hdid]
add al,128+64+32
out dx,al ; íîìåð ãîëîâêè/íîìåð äèñêà
out dx,al ; ­®¬¥  £®«®¢ªð/­®¬¥  ¤ð¡ª 
inc edx
mov al,20h
out dx,al ; ATACommand ðåãèñòð êîìàíä
out dx,al ; ATACommand  ¥£ð¡¢  ª®¬ ­¤
sti
 
call wait_for_sector_buffer
2242,7 → 2565,7
mov ecx,512/4
cld
rep movsd ; move data
; blok_read_2:
return_01:
pop edi esi ecx
ret
2279,6 → 2602,8
; write the block to a new location
 
call find_empty_slot ; ret in edi
cmp [hd_error],0
jne hd_write_access_denied
 
lea esi,[edi*8+0x600000]
mov [esi],eax ; sector number
2293,7 → 2618,7
mov ecx,512/4
cld
rep movsd ; move data
 
hd_write_access_denied:
pop edi esi ecx
ret
 
2324,6 → 2649,8
ja danger
 
call wait_for_hd_idle
cmp [hd_error],0
jne hd_write_error
 
cli
xor eax,eax
2379,7 → 2706,7
inc edi
dec ecx
jnz write_cache_more
 
return_02:
pop edi esi edx ecx eax
ret
 
2411,12 → 2738,15
jnz search_for_empty
 
call write_cache ; no empty slots found, write all
cmp [hd_error],0
jne found_slot_access_denied
 
jmp search_again ; and start again
 
found_slot:
 
mov [cache_search_start],edi
 
found_slot_access_denied:
pop esi ecx
ret
 
2438,6 → 2768,7
cmp [timer_ticks], eax ;[0xfdf0],eax
jg hd_timeout_error
pop eax
mov [hd_error],0
ret
 
iglobal
2444,6 → 2775,7
hd_timeout_str db 'K : FS - HD timeout',13,10,0
hd_read_str db 'K : FS - HD read error',13,10,0
hd_write_str db 'K : FS - HD write error',13,10,0
hd_lba_str db 'K : FS - HD LBA error',13,10,0
endg
 
hd_timeout_error:
2452,9 → 2784,11
call clear_application_table_status
mov esi,hd_timeout_str
call sys_msg_board_str
jmp $
; jmp $
mov [hd_error],1
pop eax
ret
 
 
hd_read_error:
 
call clear_hd_cache
2461,7 → 2795,9
call clear_application_table_status
mov esi,hd_read_str
call sys_msg_board_str
jmp $
pop edx eax
jmp return_01
; jmp $
 
hd_write_error:
 
2469,11 → 2805,17
call clear_application_table_status
mov esi,hd_write_str
call sys_msg_board_str
jmp $
jmp return_02
; jmp $
 
hd_lba_error:
call clear_hd_cache
call clear_application_table_status
mov esi,hd_lba_str
call sys_msg_board_str
jmp LBA_read_ret
 
 
 
wait_for_hd_idle:
 
push eax edx
2486,15 → 2828,20
wfhil1:
 
call check_hd_wait_timeout
cmp [hd_error],0
jne @f
 
in al,dx
test al,128
jnz wfhil1
 
@@:
 
pop edx eax
ret
 
 
 
wait_for_sector_buffer:
 
push eax edx
2507,6 → 2854,8
hdwait_sbuf: ; wait for sector buffer to be ready
 
call check_hd_wait_timeout
cmp [hd_error],0
jne @f
 
in al,dx
test al,8
2519,6 → 2868,7
 
test al,1 ; previous command ended up with an error
jz buf_wait_ok
@@:
mov [hd_error],1
 
buf_wait_ok:
2610,6 → 2960,9
.new_sector:
mov ebx, buffer
call hd_read
cmp [hd_error],0
jne .notfound
 
mov edi, ebx
add ebx, 512
push eax
2629,6 → 2982,9
jnz .notfound
mov eax, [cluster_tmp]
call get_FAT
cmp [hd_error],0
jne .notfound
 
cmp eax, 2
jb .notfound
cmp eax, [fatRESERVED]
2653,6 → 3009,9
jnz .notfound
mov eax, [cluster_tmp]
call get_FAT
cmp [hd_error],0
jne .notfound
 
cmp eax, 2
jb .notfound
cmp eax, [fatRESERVED]
2664,6 → 3023,9
.read_entry:
mov ebx, [buffer]
call hd_read
cmp [hd_error],0
jne .notfound
 
mov edi, ebx
.entryfound:
cmp byte [esi], 0
2705,16 → 3067,29
jnz @f
.noaccess:
pop edi
.noaccess_2:
or ebx, -1
mov eax, ERROR_ACCESS_DENIED
ret
.noaccess_3:
add esp,4
.noaccess_1:
add esp,4
.noaccess_4:
add esp,4*5
jmp .noaccess_2
 
@@:
call hd_find_lfn
jnc .found
pop edi
cmp [hd_error],0
jne .noaccess_2
or ebx, -1
mov eax, ERROR_FILE_NOT_FOUND
ret
 
.found:
test byte [edi+11], 0x10 ; do not allow read directories
jnz .noaccess
2763,6 → 3138,9
push ebx
mov ebx, edx
call hd_read
cmp [hd_error],0
jne .noaccess_1
 
pop ebx
add edx, 512
sub ecx, 512
2773,6 → 3151,9
push eax ebx
mov ebx, buffer
call hd_read
cmp [hd_error],0
jne .noaccess_3
 
mov eax, ebx
pop ebx
add eax, ebx
2805,6 → 3186,9
jnz .new_sector
mov eax, [cluster_tmp]
call get_FAT
cmp [hd_error],0
jne .noaccess_4
 
jmp .new_cluster
.done:
pop ebx edx ecx ebx edi
/kernel/trunk/fs/fs.inc
2,7 → 2,8
;; ;;
;; System service for filesystem call ;;
;; (C) 2004 Ville Turjanmaa, License: GPL ;;
;; ;;
;; 29.04.2006 Elimination of hangup after the ;;
;; expiration hd_wait_timeout (for LBA) - Mario79 ;;
;; xx.04.2006 LFN support - diamond ;;
;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV ;;
;; 23.11.2004 test if hd/partition is set - ATV ;;
31,6 → 32,7
endg
 
file_system:
 
; IN:
;
; eax = 0 ; read file /RamDisk/First 6 /HardDisk/First 30
936,6 → 938,8
mov [hdid],ebx
 
call wait_for_hd_idle
cmp [hd_error],0
jne hd_lba_error
 
; eax = hd port
; ebx = set for primary (0x00) or slave (0x10)
972,6 → 976,8
sti
 
call wait_for_sector_buffer
cmp [hd_error],0
jne hd_lba_error
 
cli
 
987,7 → 993,7
xor ebx,ebx
 
LBA_read_ret:
 
mov [hd_error],0
mov [hd1_status],0
add esp,2*4
 
/kernel/trunk/fs/part_set.inc
1,4 → 1,6
;*************************************************************
;* 29.04.2006 Elimination of hangup after the *
;* expiration hd_wait_timeout - Mario79 *
;* 28.01.2006 find all Fat16/32 partition in all input point *
;* to MBR - Mario79 *
;*************************************************************
100,6 → 102,8
add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne problem_hd
 
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
jnz end_partition_chain
249,6 → 253,9
mov [hd_setup],1
mov ebx,buffer
call hd_read ; read boot sector of partition
cmp [hd_error],0
jne problem_fat_dec_count
 
mov [hd_setup],0
 
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?