Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 74 → Rev 73

/kernel/trunk/fs/fs.inc
2,8 → 2,7
;; ;;
;; 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 ;;
32,7 → 31,6
endg
 
file_system:
 
; IN:
;
; eax = 0 ; read file /RamDisk/First 6 /HardDisk/First 30
938,8 → 936,6
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)
976,8 → 972,6
sti
 
call wait_for_sector_buffer
cmp [hd_error],0
jne hd_lba_error
 
cli
 
993,7 → 987,7
xor ebx,ebx
 
LBA_read_ret:
mov [hd_error],0
 
mov [hd1_status],0
add esp,2*4
 
/kernel/trunk/fs/fat32.inc
7,8 → 7,7
;; 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 ;;
174,16 → 173,11
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
253,19 → 247,14
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
 
289,9 → 278,6
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
299,8 → 285,6
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
327,9 → 311,6
 
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
380,9 → 361,6
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:
419,9 → 397,6
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?
475,9 → 450,6
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:
497,9 → 469,6
 
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?
511,8 → 480,6
 
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
519,15 → 486,10
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
545,9 → 507,6
 
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
558,8 → 517,7
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
606,9 → 564,6
 
gdcl1:
call hd_read
cmp [hd_error],0
jne gdc_error
 
add ebx,512 ; update pointer
dec edx
 
651,9 → 606,6
 
sdc_write:
call hd_write
cmp [hd_error],0
jne sdc_error
 
add ebx,512 ; update pointer
inc eax
dec edx
816,58 → 768,34
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
890,16 → 818,11
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!
 
928,8 → 851,6
 
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
957,21 → 878,14
 
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
997,13 → 911,9
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
1023,16 → 933,11
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
1114,23 → 1019,16
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
1141,8 → 1039,6
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
1156,8 → 1052,6
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
1169,9 → 1063,6
 
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
1181,9 → 1072,6
 
mov eax,[cluster]
call get_FAT
cmp [hd_error],0
jne append_access
 
cmp eax,2
jb append_fat
cmp eax,[LAST_CLUSTER]
1196,16 → 1084,10
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
1222,8 → 1104,6
jmp append_ret_code
append_disk_full:
cmp [hd_error],0
jne append_access
mov eax,ERROR_DISK_FULL
jmp append_ret_code
 
1236,9 → 1116,6
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?
1249,16 → 1126,11
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
 
1270,18 → 1142,14
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
1301,9 → 1169,6
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
1318,9 → 1183,6
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:
1327,23 → 1189,15
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
1378,9 → 1232,6
 
sub edi,esi
call get_FAT ; get next cluster
cmp [hd_error],0
jne filepos_eof
 
jmp filepos_new_cluster
 
filepos_cluster_ok:
1435,9 → 1286,6
 
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
1447,34 → 1295,21
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]
1481,12 → 1316,8
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
1498,13 → 1329,6
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
1536,8 → 1360,6
 
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
1547,8 → 1369,6
 
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
1561,9 → 1381,6
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
 
1571,19 → 1388,12
 
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
1606,7 → 1416,6
; 5 - file not found
; 6 - end of file
; 9 - fat table corrupted
; 10 - access denied
; ebx = size of file/directory
;--------------------------------------------------------------------------
cmp [fat_type],0
1630,9 → 1439,6
 
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
1650,8 → 1456,6
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
1673,9 → 1477,6
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
1688,8 → 1489,6
ret
 
file_read_eof:
cmp [hd_error],0
jne file_access_denied
popad
mov [hd1_status],0
mov ebx,[file_size]
1704,8 → 1503,6
ret
 
file_to_read_not_found:
cmp [hd_error],0
jne file_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
1712,12 → 1509,6
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:
;-----------------------------------------------------
1741,9 → 1532,6
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
 
1799,26 → 1587,16
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
1825,8 → 1603,6
ret
 
file_to_delete_not_found:
cmp [hd_error],0
jne delete_no_access
popad
mov eax,ERROR_FILE_NOT_FOUND
ret
1850,9 → 1626,6
 
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
1859,7 → 1632,6
 
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
1892,9 → 1664,6
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:
1922,9 → 1691,6
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 !!!
1934,15 → 1700,10
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
1955,8 → 1716,6
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
1964,9 → 1723,6
 
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:
1973,15 → 1729,12
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
2008,9 → 1761,6
 
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]
2019,9 → 1769,6
 
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:
2089,9 → 1836,6
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
2119,51 → 1863,34
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
2185,8 → 1912,6
add eax,[DATA_START]
mov ebx,buffer
call hd_read
cmp [hd_error],0
jne not_2dot
 
cmp dword [ebx+32],'.. '
jnz not_2dot
2213,7 → 1938,6
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
; ebx = file size
;-----------------------------------------------------------
cmp [fat_type],0
2249,8 → 1973,6
 
get_filesize_dirsize:
call get_dir_size
cmp [hd_error],0
jne get_filesize_access_denied
 
get_filesize_set_size:
mov PUSHAD_EBX,eax
2260,8 → 1982,6
ret
 
get_filesize_not_found:
cmp [hd_error],0
jne get_filesize_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
2268,12 → 1988,6
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:
;-----------------------------------------------------------
2282,7 → 1996,6
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
; ebx = file attribute
;-----------------------------------------------------------
cmp [fat_type],0
2311,8 → 2024,6
ret
 
get_fileattr_not_found:
cmp [hd_error],0
jne get_fileattr_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
2319,12 → 2030,6
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:
;-----------------------------------------------------------
2333,7 → 2038,6
; 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
2368,8 → 2072,6
ret
 
get_filedate_not_found:
cmp [hd_error],0
jne get_filedate_access_denied
popad
mov [hd1_status],0
xor ebx,ebx
2376,18 → 2078,11
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
2410,9 → 2105,6
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
2429,13 → 2121,6
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:
;-----------------------------------------------------------
2445,13 → 2130,10
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
 
 
2497,41 → 2179,36
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
2565,7 → 2242,7
mov ecx,512/4
cld
rep movsd ; move data
return_01:
; blok_read_2:
pop edi esi ecx
ret
2602,8 → 2279,6
; 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
2618,7 → 2293,7
mov ecx,512/4
cld
rep movsd ; move data
hd_write_access_denied:
 
pop edi esi ecx
ret
 
2649,8 → 2324,6
ja danger
 
call wait_for_hd_idle
cmp [hd_error],0
jne hd_write_error
 
cli
xor eax,eax
2706,7 → 2379,7
inc edi
dec ecx
jnz write_cache_more
return_02:
 
pop edi esi edx ecx eax
ret
 
2738,15 → 2411,12
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
 
2768,7 → 2438,6
cmp [timer_ticks], eax ;[0xfdf0],eax
jg hd_timeout_error
pop eax
mov [hd_error],0
ret
 
iglobal
2775,7 → 2444,6
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:
2784,11 → 2452,9
call clear_application_table_status
mov esi,hd_timeout_str
call sys_msg_board_str
; jmp $
mov [hd_error],1
pop eax
ret
jmp $
 
 
hd_read_error:
 
call clear_hd_cache
2795,9 → 2461,7
call clear_application_table_status
mov esi,hd_read_str
call sys_msg_board_str
pop edx eax
jmp return_01
; jmp $
jmp $
 
hd_write_error:
 
2805,17 → 2469,11
call clear_application_table_status
mov esi,hd_write_str
call sys_msg_board_str
jmp return_02
; jmp $
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
2828,20 → 2486,15
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
2854,8 → 2507,6
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
2868,7 → 2519,6
 
test al,1 ; previous command ended up with an error
jz buf_wait_ok
@@:
mov [hd_error],1
 
buf_wait_ok:
2960,9 → 2610,6
.new_sector:
mov ebx, buffer
call hd_read
cmp [hd_error],0
jne .notfound
 
mov edi, ebx
add ebx, 512
push eax
2982,9 → 2629,6
jnz .notfound
mov eax, [cluster_tmp]
call get_FAT
cmp [hd_error],0
jne .notfound
 
cmp eax, 2
jb .notfound
cmp eax, [fatRESERVED]
3009,9 → 2653,6
jnz .notfound
mov eax, [cluster_tmp]
call get_FAT
cmp [hd_error],0
jne .notfound
 
cmp eax, 2
jb .notfound
cmp eax, [fatRESERVED]
3023,9 → 2664,6
.read_entry:
mov ebx, [buffer]
call hd_read
cmp [hd_error],0
jne .notfound
 
mov edi, ebx
.entryfound:
cmp byte [esi], 0
3067,29 → 2705,16
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
3138,9 → 2763,6
push ebx
mov ebx, edx
call hd_read
cmp [hd_error],0
jne .noaccess_1
 
pop ebx
add edx, 512
sub ecx, 512
3151,9 → 2773,6
push eax ebx
mov ebx, buffer
call hd_read
cmp [hd_error],0
jne .noaccess_3
 
mov eax, ebx
pop ebx
add eax, ebx
3186,9 → 2805,6
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/part_set.inc
1,6 → 1,4
;*************************************************************
;* 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 *
;*************************************************************
102,8 → 100,6
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
253,9 → 249,6
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?