Rev 133 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 133 | Rev 384 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | ;; FAT16/32 functions for KolibriOS ;; |
5 | ;; FAT16/32 functions for KolibriOS ;; |
6 | ;; ;; |
6 | ;; ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; See file COPYING for details ;; |
9 | ;; See file COPYING for details ;; |
- | 10 | ;; 04.02.2007 LFN create folder - diamond ;; |
|
- | 11 | ;; 08.10.2006 LFN delete file/folder - diamond ;; |
|
- | 12 | ;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;; |
|
10 | ;; 17.08.2006 LFN write/append to file - diamond ;; |
13 | ;; 17.08.2006 LFN write/append to file - diamond ;; |
11 | ;; 23.06.2006 LFN start application - diamond ;; |
14 | ;; 23.06.2006 LFN start application - diamond ;; |
12 | ;; 15.06.2006 LFN get/set file/folder info - diamond ;; |
15 | ;; 15.06.2006 LFN get/set file/folder info - diamond ;; |
13 | ;; 27.05.2006 LFN create/rewrite file - diamond ;; |
16 | ;; 27.05.2006 LFN create/rewrite file - diamond ;; |
14 | ;; 04.05.2006 LFN read folder - diamond ;; |
17 | ;; 04.05.2006 LFN read folder - diamond ;; |
Line 58... | Line 61... | ||
58 | PUSHAD_EBX equ [esp+16] |
61 | PUSHAD_EBX equ [esp+16] |
59 | PUSHAD_EBP equ [esp+8] |
62 | PUSHAD_EBP equ [esp+8] |
60 | PUSHAD_ESI equ [esp+4] |
63 | PUSHAD_ESI equ [esp+4] |
61 | PUSHAD_EDI equ [esp+0] |
64 | PUSHAD_EDI equ [esp+0] |
Line -... | Line 65... | ||
- | 65 | ||
- | 66 | uglobal |
|
62 | 67 | align 4 |
|
63 | cluster dd 0 ; used by file_write,makedir,append |
68 | cluster dd 0 ; used by file_write,makedir,append |
64 | partition_count dd 0 ; partitions found by set_FAT32_variables |
69 | partition_count dd 0 ; partitions found by set_FAT32_variables |
65 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
70 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
Line 80... | Line 85... | ||
80 | old_filesize dd 0 ; used by append |
85 | old_filesize dd 0 ; used by append |
81 | new_filepos dd 0 ; used by append |
86 | new_filepos dd 0 ; used by append |
82 | bytes2write dd 0 ; used by append |
87 | bytes2write dd 0 ; used by append |
Line 83... | Line 88... | ||
83 | 88 | ||
- | 89 | cache_search_start dd 0 ; used by find_empty_slot |
|
Line -... | Line 90... | ||
- | 90 | endg |
|
84 | cache_search_start dd 0 ; used by find_empty_slot |
91 | |
85 | 92 | iglobal |
|
Line 86... | Line 93... | ||
86 | fat_in_cache dd -1 |
93 | fat_in_cache dd -1 |
- | 94 | endg |
|
- | 95 | ||
87 | fat_cache: times 512 db 0 |
96 | uglobal |
88 | 97 | align 4 |
|
89 | uglobal |
- | |
90 | Sector512: ; label for dev_hdcd.inc |
98 | fat_cache: times 512 db 0 |
91 | buffer: times 512 db 0 |
99 | Sector512: ; label for dev_hdcd.inc |
Line 92... | Line -... | ||
92 | deltree_buffer: times 512 db 0 |
- | |
93 | fsinfo_buffer: times 512 db 0 |
- | |
94 | endg |
- | |
95 | - | ||
96 | iglobal |
- | |
97 | NewDirEntry1 db ". ",0x10 |
- | |
98 | times 20 db 0 |
- | |
99 | NewDirEntry2 db ".. ",0x10 |
100 | buffer: times 512 db 0 |
100 | times 20 db 0 |
101 | fsinfo_buffer: times 512 db 0 |
Line 101... | Line 102... | ||
101 | endg |
102 | endg |
Line 121... | Line 122... | ||
121 | jmp reserve_hd1 |
122 | jmp reserve_hd1 |
Line 122... | Line 123... | ||
122 | 123 | ||
Line 123... | Line 124... | ||
123 | reserve_ok1: |
124 | reserve_ok1: |
124 | 125 | ||
125 | push eax |
126 | push eax |
126 | mov eax,[0x3000] |
127 | mov eax,[CURRENT_TASK] |
127 | shl eax,5 |
128 | shl eax,5 |
128 | mov eax,[eax+0x3000+TASKDATA.pid] |
129 | mov eax,[eax+CURRENT_TASK+TASKDATA.pid] |
129 | mov [hd1_status],eax |
130 | mov [hd1_status],eax |
130 | pop eax |
131 | pop eax |
131 | sti |
132 | sti |
- | 133 | ret |
|
- | 134 | ;******************************************** |
|
- | 135 | ||
- | 136 | uglobal |
|
- | 137 | hd_in_cache db ? |
|
132 | ret |
138 | endg |
133 | ;******************************************** |
139 | |
134 | reserve_hd_channel: |
140 | reserve_hd_channel: |
135 | cmp [hdbase], 0x1F0 |
141 | cmp [hdbase], 0x1F0 |
136 | jne .IDE_Channel_2 |
142 | jne .IDE_Channel_2 |
Line 145... | Line 151... | ||
145 | cli |
151 | cli |
146 | cmp [IDE_Channel_2],0 |
152 | cmp [IDE_Channel_2],0 |
147 | je .reserve_ok_2 |
153 | je .reserve_ok_2 |
148 | sti |
154 | sti |
149 | call change_task |
155 | call change_task |
150 | jmp .IDE_Channel_1 |
156 | jmp .IDE_Channel_2 |
151 | .reserve_ok_1: |
157 | .reserve_ok_1: |
152 | mov [IDE_Channel_1],1 |
158 | mov [IDE_Channel_1], 1 |
153 | ret |
159 | push eax |
- | 160 | mov al, 1 |
|
- | 161 | jmp @f |
|
154 | .reserve_ok_2: |
162 | .reserve_ok_2: |
155 | mov [IDE_Channel_2],1 |
163 | mov [IDE_Channel_2], 1 |
- | 164 | push eax |
|
- | 165 | mov al, 3 |
|
- | 166 | @@: |
|
- | 167 | cmp [hdid], 1 |
|
- | 168 | sbb al, -1 |
|
- | 169 | cmp al, [hd_in_cache] |
|
- | 170 | jz @f |
|
- | 171 | mov [hd_in_cache], al |
|
- | 172 | call clear_hd_cache |
|
- | 173 | @@: |
|
- | 174 | pop eax |
|
156 | ret |
175 | ret |
Line 157... | Line 176... | ||
157 | 176 | ||
158 | free_hd_channel: |
177 | free_hd_channel: |
159 | cmp [hdbase], 0x1F0 |
178 | cmp [hdbase], 0x1F0 |
Line 163... | Line 182... | ||
163 | ret |
182 | ret |
164 | .IDE_Channel_2: |
183 | .IDE_Channel_2: |
165 | mov [IDE_Channel_2],0 |
184 | mov [IDE_Channel_2],0 |
166 | ret |
185 | ret |
167 | ;******************************************** |
186 | ;******************************************** |
168 | clear_hd_cache: |
- | |
169 | - | ||
170 | push eax ecx edi |
- | |
171 | mov edi,0x600000 |
- | |
172 | mov ecx,16384 |
- | |
173 | xor eax,eax |
- | |
174 | cld |
- | |
175 | rep stosd ; clear hd cache with 0 |
- | |
176 | mov [cache_search_start],eax |
- | |
177 | mov [fat_in_cache],-1 |
- | |
178 | mov [fat_change],0 |
- | |
179 | pop edi ecx eax |
- | |
180 | ret |
- | |
181 | - | ||
182 | problem_partition db 0 ; used for partitions search |
187 | problem_partition db 0 ; used for partitions search |
Line 183... | Line 188... | ||
183 | 188 | ||
Line 184... | Line 189... | ||
184 | include 'part_set.inc' |
189 | include 'part_set.inc' |
Line 193... | Line 198... | ||
193 | 198 | ||
194 | cmp eax,2 |
199 | cmp eax,2 |
195 | jb sfc_error |
200 | jb sfc_error |
196 | cmp eax,[LAST_CLUSTER] |
201 | cmp eax,[LAST_CLUSTER] |
197 | ja sfc_error |
202 | ja sfc_error |
198 | cmp [fat_type],16 |
203 | cmp [fs_type],16 |
199 | je sfc_1 |
204 | je sfc_1 |
200 | add eax,eax |
205 | add eax,eax |
201 | sfc_1: |
206 | sfc_1: |
202 | add eax,eax |
207 | add eax,eax |
Line 221... | Line 226... | ||
221 | cmp [hd_error],0 |
226 | cmp [hd_error],0 |
222 | jne sfc_error |
227 | jne sfc_error |
Line 223... | Line 228... | ||
223 | 228 | ||
224 | 229 | ||
225 | sfc_in_cache: |
230 | sfc_in_cache: |
Line 226... | Line 231... | ||
226 | cmp [fat_type],16 |
231 | cmp [fs_type],16 |
227 | jne sfc_test32 |
232 | jne sfc_test32 |
228 | 233 | ||
Line 257... | Line 262... | ||
257 | ; input : EAX = cluster |
262 | ; input : EAX = cluster |
258 | ; output : EAX = next cluster |
263 | ; output : EAX = next cluster |
259 | ;-------------------------------- |
264 | ;-------------------------------- |
260 | push ebx esi |
265 | push ebx esi |
Line 261... | Line 266... | ||
261 | 266 | ||
262 | cmp [fat_type],16 |
267 | cmp [fs_type],16 |
263 | je gfc_1 |
268 | je gfc_1 |
264 | add eax,eax |
269 | add eax,eax |
265 | gfc_1: |
270 | gfc_1: |
266 | add eax,eax |
271 | add eax,eax |
Line 385... | Line 390... | ||
385 | ja adr_not_found ; too big cluster number, something is wrong |
390 | ja adr_not_found ; too big cluster number, something is wrong |
386 | cmp eax,2 |
391 | cmp eax,2 |
387 | jnb adr_data_cluster |
392 | jnb adr_data_cluster |
Line 388... | Line 393... | ||
388 | 393 | ||
389 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
394 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
390 | cmp [fat_type],16 |
395 | cmp [fs_type],16 |
391 | jne adr_data_cluster |
396 | jne adr_data_cluster |
392 | mov eax,[ROOT_START] |
397 | mov eax,[ROOT_START] |
393 | mov edx,[ROOT_SECTORS] |
398 | mov edx,[ROOT_SECTORS] |
394 | mov [fat16_root],1 ; flag for fat16 rootdir |
399 | mov [fat16_root],1 ; flag for fat16 rootdir |
Line 480... | Line 485... | ||
480 | ja adw_not_found ; too big cluster number, something is wrong |
485 | ja adw_not_found ; too big cluster number, something is wrong |
481 | cmp eax,2 |
486 | cmp eax,2 |
482 | jnb adw_data_cluster |
487 | jnb adw_data_cluster |
Line 483... | Line 488... | ||
483 | 488 | ||
484 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
489 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
485 | cmp [fat_type],16 |
490 | cmp [fs_type],16 |
486 | jne adw_data_cluster |
491 | jne adw_data_cluster |
487 | mov eax,[ROOT_START] |
492 | mov eax,[ROOT_START] |
488 | mov edx,[ROOT_SECTORS] |
493 | mov edx,[ROOT_SECTORS] |
489 | mov [fat16_root],1 ; flag for fat16 rootdir |
494 | mov [fat16_root],1 ; flag for fat16 rootdir |
Line 603... | Line 608... | ||
603 | ja gdc_error ; too big cluster number, something is wrong |
608 | ja gdc_error ; too big cluster number, something is wrong |
604 | cmp eax,2 |
609 | cmp eax,2 |
605 | jnb gdc_cluster |
610 | jnb gdc_cluster |
Line 606... | Line 611... | ||
606 | 611 | ||
607 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
612 | mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir |
608 | cmp [fat_type],16 |
613 | cmp [fs_type],16 |
609 | jne gdc_cluster |
614 | jne gdc_cluster |
610 | mov eax,[ROOT_START] |
615 | mov eax,[ROOT_START] |
611 | mov ecx,[ROOT_SECTORS] ; Note: not cluster size |
616 | mov ecx,[ROOT_SECTORS] ; Note: not cluster size |
612 | mov [fat16_root],1 ; flag for fat16 rootdir |
617 | mov [fat16_root],1 ; flag for fat16 rootdir |
Line 810... | Line 815... | ||
810 | mov [ebx+24],ax |
815 | mov [ebx+24],ax |
811 | pop eax |
816 | pop eax |
812 | ret |
817 | ret |
Line 813... | Line -... | ||
813 | - | ||
814 | - | ||
815 | makedir: |
- | |
816 | ;----------------------------------------------------- |
- | |
817 | ; input : eax = directory name |
- | |
818 | ; edx = path |
- | |
819 | ; output : eax = 0 - ok |
- | |
820 | ; 3 - unknown FS |
- | |
821 | ; 5 - file not found |
- | |
822 | ; 8 - disk full |
- | |
823 | ; 10 - access denied |
- | |
824 | ; Note : can only make one directory at time |
- | |
825 | ;----------------------------------------------------- |
- | |
826 | cmp [fat_type],0 |
- | |
827 | jnz make_dir_fat_ok |
- | |
828 | mov eax,ERROR_UNKNOWN_FS |
- | |
829 | ret |
- | |
830 | - | ||
831 | make_dir_fat_ok: |
- | |
832 | ; call reserve_hd1 |
- | |
833 | - | ||
834 | pushad |
- | |
835 | - | ||
836 | mov ebx,edx |
- | |
837 | call get_cluster_of_a_path |
- | |
838 | jnc make_dir_found_path |
- | |
839 | cmp [hd_error],0 |
- | |
840 | jne make_dir_error_1 |
- | |
841 | - | ||
842 | make_dir_path_not_found: |
- | |
843 | popad |
- | |
844 | call update_disk ; write all of cache and fat to hd |
- | |
845 | cmp [hd_error],0 |
- | |
846 | jne make_dir_error_2 |
- | |
847 | - | ||
848 | mov [hd1_status],0 |
- | |
849 | mov eax,ERROR_FILE_NOT_FOUND |
- | |
850 | ret |
- | |
851 | - | ||
852 | make_dir_disk_full: |
- | |
853 | cmp [hd_error],0 |
- | |
854 | jne make_dir_error_1 |
- | |
855 | popad |
- | |
856 | call update_disk ; write all of cache and fat to hd |
- | |
857 | cmp [hd_error],0 |
- | |
858 | jne make_dir_error_2 |
- | |
859 | - | ||
860 | mov [hd1_status],0 |
- | |
861 | mov eax,ERROR_DISK_FULL |
- | |
862 | ret |
- | |
863 | - | ||
864 | make_dir_already_exist: |
- | |
865 | cmp [hd_error],0 |
- | |
866 | jne make_dir_error_1 |
- | |
867 | mov eax,[cluster] ; directory cluster |
- | |
868 | xor edx,edx ; free |
- | |
869 | call set_FAT |
- | |
870 | cmp [hd_error],0 |
- | |
871 | jne make_dir_error_1 |
- | |
872 | - | ||
873 | popad |
- | |
874 | call update_disk ; write all of cache and fat to hd |
- | |
875 | make_dir_error_2: |
- | |
876 | mov [hd1_status],0 |
- | |
877 | mov eax,ERROR_ACCESS_DENIED |
- | |
878 | ret |
- | |
879 | - | ||
880 | make_dir_error_1: |
- | |
881 | popad |
- | |
882 | jmp make_dir_error_2 |
- | |
883 | - | ||
884 | make_dir_error_3: |
- | |
885 | add esp,4 |
- | |
886 | jmp make_dir_error_1 |
- | |
887 | - | ||
888 | make_dir_found_path: |
- | |
889 | cmp eax,[ROOT_CLUSTER] |
- | |
890 | jnz make_dir_not_root |
- | |
891 | xor eax,eax |
- | |
892 | - | ||
893 | make_dir_not_root: |
- | |
894 | mov ecx,eax ; directorys start cluster |
- | |
895 | mov word [NewDirEntry2+26],cx ; 16 bits low of cluster |
- | |
896 | shr ecx,16 |
- | |
897 | mov word [NewDirEntry2+20],cx ; 16 bits high of cluster (=0 fat16) |
- | |
898 | - | ||
899 | push eax ; save parent directory cluster |
- | |
900 | mov eax,2 |
- | |
901 | call get_free_FAT |
- | |
902 | mov [cluster],eax ; first free cluster |
- | |
903 | pop eax |
- | |
904 | jc make_dir_disk_full |
- | |
905 | - | ||
906 | push eax |
- | |
907 | mov eax,[cluster] ; directory cluster |
- | |
908 | mov edx,[fatEND] ; end for directory |
- | |
909 | call set_FAT |
- | |
910 | cmp [hd_error],0 |
- | |
911 | jne make_dir_error_3 |
- | |
912 | pop eax |
- | |
913 | - | ||
914 | mov ebx,PUSHAD_EAX ; dir name |
- | |
915 | push eax |
- | |
916 | call analyze_directory ; check if directory already exist |
- | |
917 | cmp [hd_error],0 |
- | |
918 | jne make_dir_error_1 |
- | |
919 | - | ||
920 | pop eax |
- | |
921 | jnc make_dir_already_exist ; need to free allocated cluster! |
- | |
922 | - | ||
923 | call analyze_directory_to_write |
- | |
924 | jc make_dir_already_exist ; need to free allocated cluster! |
- | |
925 | - | ||
926 | mov esi,PUSHAD_EAX ; dir name |
- | |
927 | mov edi,ebx ; pointer in buffer |
- | |
928 | mov ecx,11 |
- | |
929 | cld |
- | |
930 | rep movsb |
- | |
931 | - | ||
932 | mov dword [ebx+28],0 ; dir size is always 0 |
- | |
933 | mov ecx,[cluster] |
- | |
934 | mov [ebx+26],cx ; 16 bits low of cluster |
- | |
935 | mov word [NewDirEntry1+26],cx |
- | |
936 | shr ecx,16 |
- | |
937 | mov [ebx+20],cx ; 16 bits high of cluster (=0 fat16) |
- | |
938 | mov word [NewDirEntry1+20],cx |
- | |
939 | mov byte [ebx+11],0x10 ; attribute = directory |
- | |
940 | - | ||
941 | call set_current_time_for_entry |
- | |
942 | mov ecx,[ebx+22] |
- | |
943 | mov dword [NewDirEntry1+22],ecx |
- | |
944 | mov dword [NewDirEntry2+22],ecx |
- | |
945 | - | ||
946 | mov ebx,buffer ; save the directory name,length,cluster |
- | |
947 | call hd_write |
- | |
948 | cmp [hd_error],0 |
- | |
949 | jne make_dir_error_1 |
- | |
950 | - | ||
951 | mov ecx,512/4 |
- | |
952 | xor eax,eax |
- | |
953 | mov edi,buffer |
- | |
954 | cld |
- | |
955 | rep stosd ; clear new directory cluster |
- | |
956 | - | ||
957 | mov eax,[cluster] ; new directory cluster |
- | |
958 | sub eax,2 |
- | |
959 | mov edx,[SECTORS_PER_CLUSTER] |
- | |
960 | imul eax,edx |
- | |
961 | add eax,[DATA_START] |
- | |
962 | mov ebx,buffer |
- | |
963 | add eax,edx ; start from last sector |
- | |
964 | - | ||
965 | dir_set_empty_directory: |
- | |
966 | dec eax ; next sector |
- | |
967 | cmp edx,1 ; is first directory sector? |
- | |
968 | jnz not_first_sector ; no. write empty sector |
- | |
969 | mov esi,NewDirEntry1 |
- | |
970 | mov edi,buffer |
- | |
971 | mov ecx,64/4 |
- | |
972 | cld |
- | |
973 | rep movsd ; copy 2 first directory entrys "." and ".." |
- | |
974 | - | ||
975 | not_first_sector: |
- | |
976 | call hd_write |
- | |
977 | cmp [hd_error],0 |
- | |
978 | jne make_dir_error_1 |
- | |
979 | - | ||
980 | dec edx |
- | |
981 | jnz dir_set_empty_directory |
- | |
982 | - | ||
983 | mov ecx,-1 ; remove 1 cluster from free disk space |
- | |
984 | call add_disk_free_space |
- | |
985 | cmp [hd_error],0 |
- | |
986 | jne make_dir_error_1 |
- | |
987 | - | ||
988 | popad |
- | |
989 | call update_disk ; write all of cache and fat to hd |
- | |
990 | cmp [hd_error],0 |
- | |
991 | jne make_dir_error_2 |
- | |
992 | mov [hd1_status],0 |
- | |
993 | xor eax,eax |
- | |
994 | ret |
- | |
995 | - | ||
996 | - | ||
997 | removedir: |
- | |
998 | ;----------------------------------------------------- |
- | |
999 | ; input : eax = file/directory name |
- | |
1000 | ; edx = path |
- | |
1001 | ; output : eax = 0 - ok |
- | |
1002 | ; 3 - unknown FS |
- | |
1003 | ; 5 - file not found |
- | |
1004 | ; 10 - access denied |
- | |
1005 | ;----------------------------------------------------- |
- | |
1006 | cmp [fat_type],0 |
- | |
1007 | jnz remove_dir_fat_ok |
- | |
1008 | mov eax,ERROR_UNKNOWN_FS |
- | |
1009 | ret |
- | |
1010 | - | ||
1011 | remove_dir_fat_ok: |
- | |
1012 | ; call reserve_hd1 |
- | |
1013 | - | ||
1014 | push edi |
- | |
1015 | mov edi,1 ; allow directory remove |
- | |
1016 | call file_delete |
- | |
1017 | cmp [hd_error],0 |
- | |
1018 | jne @f |
- | |
1019 | - | ||
1020 | pop edi |
- | |
1021 | - | ||
1022 | call update_disk ; write all of cache and fat to hd |
- | |
1023 | @@: |
- | |
1024 | mov [hd1_status],0 |
- | |
Line 1025... | Line 818... | ||
1025 | ret |
818 | |
1026 | 819 | ||
1027 | 820 | ||
1028 | add_disk_free_space: |
821 | add_disk_free_space: |
1029 | ;----------------------------------------------------- |
822 | ;----------------------------------------------------- |
1030 | ; input : ecx = cluster count |
823 | ; input : ecx = cluster count |
1031 | ; Note : negative = remove clusters from free space |
824 | ; Note : negative = remove clusters from free space |
1032 | ; positive = add clusters to free space |
825 | ; positive = add clusters to free space |
1033 | ;----------------------------------------------------- |
826 | ;----------------------------------------------------- |
1034 | test ecx,ecx ; no change |
827 | test ecx,ecx ; no change |
Line 1035... | Line 828... | ||
1035 | je add_dfs_no |
828 | je add_dfs_no |
1036 | cmp [fat_type],32 ; free disk space only used by fat32 |
829 | cmp [fs_type],32 ; free disk space only used by fat32 |
1037 | jne add_dfs_no |
830 | jne add_dfs_no |
Line 1072... | Line 865... | ||
1072 | ; 3 - unknown FS |
865 | ; 3 - unknown FS |
1073 | ; 5 - file not found |
866 | ; 5 - file not found |
1074 | ; 8 - disk full |
867 | ; 8 - disk full |
1075 | ; 10 - access denied |
868 | ; 10 - access denied |
1076 | ;-------------------------------------------------------------------------- |
869 | ;-------------------------------------------------------------------------- |
- | 870 | cmp [fs_type], 16 |
|
- | 871 | jz fat_ok_for_writing |
|
1077 | cmp [fat_type],0 |
872 | cmp [fs_type], 32 |
1078 | jnz fat_ok_for_writing |
873 | jz fat_ok_for_writing |
1079 | mov eax,ERROR_UNKNOWN_FS |
874 | push ERROR_UNKNOWN_FS |
- | 875 | pop eax |
|
1080 | ret |
876 | ret |
Line 1081... | Line 877... | ||
1081 | 877 | ||
1082 | fat_ok_for_writing: |
878 | fat_ok_for_writing: |
Line 1258... | Line 1054... | ||
1258 | ; 6 - end of file |
1054 | ; 6 - end of file |
1259 | ; 9 - fat table corrupted |
1055 | ; 9 - fat table corrupted |
1260 | ; 10 - access denied |
1056 | ; 10 - access denied |
1261 | ; ebx = size of file/directory |
1057 | ; ebx = size of file/directory |
1262 | ;-------------------------------------------------------------------------- |
1058 | ;-------------------------------------------------------------------------- |
- | 1059 | cmp [fs_type], 16 |
|
- | 1060 | jz fat_ok_for_reading |
|
1263 | cmp [fat_type],0 |
1061 | cmp [fs_type], 32 |
1264 | jnz fat_ok_for_reading |
1062 | jz fat_ok_for_reading |
1265 | xor ebx,ebx |
1063 | xor ebx,ebx |
1266 | mov eax,ERROR_UNKNOWN_FS |
1064 | mov eax,ERROR_UNKNOWN_FS |
1267 | mov [hd1_status], ebx |
1065 | mov [hd1_status], ebx |
1268 | ret |
1066 | ret |
Line 1380... | Line 1178... | ||
1380 | test eax,eax |
1178 | test eax,eax |
1381 | jnz dir_size_next |
1179 | jnz dir_size_next |
Line 1382... | Line 1180... | ||
1382 | 1180 | ||
1383 | mov eax,[ROOT_SECTORS] |
1181 | mov eax,[ROOT_SECTORS] |
1384 | shl eax,9 ; fat16 rootdir size in bytes |
1182 | shl eax,9 ; fat16 rootdir size in bytes |
1385 | cmp [fat_type],16 |
1183 | cmp [fs_type],16 |
1386 | je dir_size_ret |
1184 | je dir_size_ret |
Line 1387... | Line 1185... | ||
1387 | mov eax,[ROOT_CLUSTER] |
1185 | mov eax,[ROOT_CLUSTER] |
1388 | 1186 | ||
Line 1415... | Line 1213... | ||
1415 | ; output : eax = 0 - ok |
1213 | ; output : eax = 0 - ok |
1416 | ; 3 - unknown FS |
1214 | ; 3 - unknown FS |
1417 | ; 5 - file not found |
1215 | ; 5 - file not found |
1418 | ; 10 - access denied |
1216 | ; 10 - access denied |
1419 | ;----------------------------------------------------- |
1217 | ;----------------------------------------------------- |
1420 | cmp [fat_type],0 |
1218 | cmp [fs_type], 16 |
1421 | jnz file_del_fat_ok |
1219 | jz file_del_fat_ok |
- | 1220 | cmp [fs_type], 32 |
|
- | 1221 | jz file_del_fat_ok |
|
1422 | mov eax,ERROR_UNKNOWN_FS |
1222 | push ERROR_UNKNOWN_FS |
- | 1223 | pop eax |
|
1423 | ret |
1224 | ret |
Line 1424... | Line 1225... | ||
1424 | 1225 | ||
1425 | file_del_fat_ok: |
1226 | file_del_fat_ok: |
Line 1432... | Line 1233... | ||
1432 | mov ebx,PUSHAD_EAX ; file/directory name |
1233 | mov ebx,PUSHAD_EAX ; file/directory name |
1433 | call analyze_directory |
1234 | call analyze_directory |
1434 | jc file_to_delete_not_found |
1235 | jc file_to_delete_not_found |
Line 1435... | Line 1236... | ||
1435 | 1236 | ||
1436 | test byte [ebx+11],0x10 ; is it directory? |
- | |
1437 | jz delete_notdir ; no. it's file |
- | |
1438 | cmp edi,1 ; allow directory remove |
- | |
1439 | jnz delete_no_access ; no |
- | |
1440 | - | ||
1441 | push eax ; save directory sector |
- | |
1442 | mov eax,[ebx+20-2] ; first cluster of file |
- | |
1443 | mov ax,[ebx+26] ; 0 length files start cluster = 0 |
- | |
1444 | and eax,[fatMASK] |
- | |
1445 | xor ebp,ebp ; counter for directory deepnes |
- | |
1446 | call clear_directory |
- | |
1447 | pop eax |
1237 | test byte [ebx+11],0x10 ; is it directory? |
1448 | jc delete_no_access |
- | |
1449 | - | ||
1450 | push ebx ; save directory pointer in buffer |
- | |
1451 | mov ebx,buffer |
- | |
1452 | call hd_read ; read directory sector |
- | |
1453 | cmp [hd_error],0 |
- | |
1454 | jne delete_no_access_1 |
- | |
Line 1455... | Line 1238... | ||
1455 | pop ebx |
1238 | jnz delete_no_access |
1456 | 1239 | ||
1457 | delete_notdir: |
1240 | delete_notdir: |
1458 | call delete_entry_name |
1241 | call delete_entry_name |
Line 1512... | Line 1295... | ||
1512 | access_denied_01: |
1295 | access_denied_01: |
1513 | pop edx ecx eax |
1296 | pop edx ecx eax |
1514 | ret |
1297 | ret |
Line 1515... | Line -... | ||
1515 | - | ||
1516 | - | ||
1517 | clear_directory: |
- | |
1518 | ;----------------------------------------------------- |
- | |
1519 | ; input : eax = directory cluster |
- | |
1520 | ; ebp = directory deepnes |
- | |
1521 | ; Note : use recursive call |
- | |
1522 | ;----------------------------------------------------- |
- | |
1523 | pushad |
- | |
1524 | inc ebp |
- | |
1525 | cmp ebp,64 ; if over 63 directory deep |
- | |
1526 | jnb clear_error ; something must be wrong |
- | |
1527 | - | ||
1528 | clear_new_cluster: |
- | |
1529 | cmp eax,[LAST_CLUSTER] |
- | |
1530 | ja clear_end |
- | |
1531 | cmp eax,[ROOT_CLUSTER] ; don't remove root cluster |
- | |
1532 | jz clear_end |
- | |
1533 | mov esi,eax ; esi = current directory cluster |
- | |
1534 | sub eax,2 |
- | |
1535 | jb clear_end |
- | |
1536 | mov ecx,[SECTORS_PER_CLUSTER] |
- | |
1537 | imul eax,ecx |
- | |
1538 | add eax,[DATA_START] |
- | |
1539 | - | ||
1540 | clear_new_sector: |
- | |
1541 | mov edi,eax ; edi = current directory sector |
- | |
1542 | mov ebx,deltree_buffer |
- | |
1543 | call hd_read |
- | |
1544 | cmp [hd_error],0 |
- | |
1545 | jne clear_error |
- | |
1546 | - | ||
1547 | mov edx,512/32 ; count of dir entrys per sector = 16 |
- | |
1548 | - | ||
1549 | clear_analyze: |
- | |
1550 | mov al,[ebx+11] ; file attribute |
- | |
1551 | and al,0xf |
- | |
1552 | cmp al,0xf |
- | |
1553 | je clear_long_filename |
- | |
1554 | - | ||
1555 | cmp byte [ebx],'.' ; parent or current directory |
- | |
1556 | je clear_next_entry |
- | |
1557 | cmp byte [ebx],0xe5 ; deleted |
- | |
1558 | je clear_next_entry |
- | |
1559 | cmp byte [ebx],0 ; empty |
- | |
1560 | je clear_write_last |
- | |
1561 | ;je clear_next_entry |
- | |
1562 | - | ||
1563 | mov eax,[ebx+20-2] ; first cluster of entry |
- | |
1564 | mov ax,[ebx+26] |
- | |
1565 | and eax,[fatMASK] |
- | |
1566 | - | ||
1567 | test byte [ebx+11],0x10 ; is it directory? |
- | |
1568 | jz clear_file ; no |
- | |
1569 | - | ||
1570 | push eax ebx |
- | |
1571 | mov eax,edi |
- | |
1572 | mov ebx,deltree_buffer ; save buffer over recursive call |
- | |
1573 | call hd_write ; write directory sector to disk |
- | |
1574 | cmp [hd_error],0 |
- | |
1575 | jne clear_error |
- | |
1576 | - | ||
1577 | pop ebx eax |
- | |
1578 | - | ||
1579 | call clear_directory ; recursive call !!! |
- | |
1580 | jc clear_error ; exit if error found |
- | |
1581 | - | ||
1582 | push eax ebx |
- | |
1583 | mov eax,edi |
- | |
1584 | mov ebx,deltree_buffer |
- | |
1585 | call hd_read ; read directory sector again |
- | |
1586 | cmp [hd_error],0 |
- | |
1587 | jne clear_error_1 |
- | |
1588 | - | ||
1589 | pop ebx eax |
- | |
1590 | - | ||
1591 | clear_file: |
- | |
1592 | call clear_cluster_chain |
- | |
1593 | cmp [hd_error],0 |
- | |
1594 | jne clear_error |
- | |
1595 | - | ||
1596 | clear_long_filename: |
- | |
1597 | mov byte [ebx],0xe5 |
- | |
1598 | - | ||
1599 | clear_next_entry: |
- | |
1600 | add ebx,32 ; position of next dir entry |
- | |
1601 | dec edx |
- | |
1602 | jnz clear_analyze |
- | |
1603 | - | ||
1604 | mov eax,edi |
- | |
1605 | mov ebx,deltree_buffer |
- | |
1606 | call hd_write ; write directory sector to disk |
- | |
1607 | cmp [hd_error],0 |
- | |
1608 | jne clear_error |
- | |
1609 | - | ||
1610 | inc eax ; next sector |
- | |
1611 | dec ecx |
- | |
1612 | jnz clear_new_sector |
- | |
1613 | - | ||
1614 | mov eax,esi |
- | |
1615 | call get_FAT ; get next cluster |
- | |
1616 | cmp [hd_error],0 |
- | |
1617 | jne clear_error |
- | |
1618 | - | ||
1619 | jmp clear_new_cluster ; clear it |
- | |
1620 | - | ||
1621 | clear_write_last: |
- | |
1622 | mov eax,edi |
- | |
1623 | mov ebx,deltree_buffer |
- | |
1624 | call hd_write ; write directory sector to disk |
- | |
1625 | cmp [hd_error],0 |
- | |
1626 | jne clear_error |
- | |
1627 | - | ||
1628 | clear_end: |
- | |
1629 | popad |
- | |
1630 | clc |
- | |
1631 | ret |
- | |
1632 | clear_error_1: |
- | |
1633 | add esp,8 |
- | |
1634 | clear_error: |
- | |
1635 | popad |
- | |
1636 | stc |
- | |
1637 | ret |
- | |
1638 | 1298 | ||
1639 | 1299 | ||
1640 | delete_entry_name: |
1300 | delete_entry_name: |
1641 | ;----------------------------------------------------- |
1301 | ;----------------------------------------------------- |
1642 | ; input : eax = directory sector |
1302 | ; input : eax = directory sector |
Line 1689... | Line 1349... | ||
1689 | 1349 | ||
1690 | delete_name_end: |
1350 | delete_name_end: |
Line 1691... | Line -... | ||
1691 | ret |
- | |
1692 | - | ||
1693 | - | ||
1694 | rename: |
- | |
1695 | ;----------------------------------------------------------- |
- | |
1696 | ; input : eax = source directory name |
- | |
1697 | ; edx = source path |
- | |
1698 | ; ebx = dest directory name |
- | |
1699 | ; edi = dest path |
- | |
1700 | ; output : eax = 0 - ok |
- | |
1701 | ; 3 - unknown FS |
- | |
1702 | ; 5 - file not found |
- | |
1703 | ; 8 - disk full |
- | |
1704 | ; 10 - access denied |
- | |
1705 | ;----------------------------------------------------------- |
- | |
1706 | cmp [fat_type],0 |
- | |
1707 | jnz fat_ok_for_rename |
- | |
1708 | mov eax,ERROR_UNKNOWN_FS |
- | |
1709 | ret |
- | |
1710 | - | ||
1711 | fat_ok_for_rename: |
- | |
1712 | ; call reserve_hd1 |
- | |
1713 | - | ||
1714 | pushad |
- | |
1715 | - | ||
1716 | mov ebx,edx ; source path |
- | |
1717 | call get_cluster_of_a_path |
- | |
1718 | jc rename_entry_not_found |
- | |
1719 | - | ||
1720 | mov ebx,PUSHAD_EAX ; source directory name |
- | |
1721 | call analyze_directory |
- | |
1722 | jc rename_entry_not_found |
- | |
1723 | - | ||
1724 | mov [sector_tmp],eax ; save source sector |
- | |
1725 | mov [entry_pos],ebx |
- | |
1726 | mov esi,ebx |
- | |
1727 | mov edi,dir_entry |
- | |
1728 | mov ecx,32/4 |
- | |
1729 | cld |
- | |
1730 | rep movsd ; save entry |
- | |
1731 | - | ||
1732 | mov ebx,PUSHAD_EDI ; dest path |
- | |
1733 | call get_cluster_of_a_path |
- | |
1734 | jc rename_entry_not_found |
- | |
1735 | - | ||
1736 | mov edx,eax ; save dest directory cluster |
- | |
1737 | mov ebx,PUSHAD_EBX ; dest directory name |
- | |
1738 | push [longname_sec1] |
- | |
1739 | push [longname_sec2] |
- | |
1740 | call analyze_directory ; check if entry already exist |
- | |
1741 | cmp [hd_error],0 |
- | |
1742 | jne rename_entry_already_exist_1 |
- | |
1743 | - | ||
1744 | pop [longname_sec2] |
- | |
1745 | pop [longname_sec1] |
- | |
1746 | jnc rename_entry_already_exist |
- | |
1747 | - | ||
1748 | mov eax,edx |
- | |
1749 | call analyze_directory_to_write |
- | |
1750 | jc rename_disk_full |
- | |
1751 | - | ||
1752 | mov esi,dir_entry |
- | |
1753 | mov edi,ebx |
- | |
1754 | mov ecx,32/4 |
- | |
1755 | cld |
- | |
1756 | rep movsd ; copy entry |
- | |
1757 | mov esi,PUSHAD_EBX ; dest directory name |
- | |
1758 | mov edi,ebx |
- | |
1759 | mov ecx,11 |
- | |
1760 | rep movsb ; copy name |
- | |
1761 | - | ||
1762 | mov ebx,buffer ; save the directory name,length,cluster |
- | |
1763 | call hd_write |
- | |
1764 | - | ||
1765 | test byte [dir_entry+11],0x10 ; is it directory? |
- | |
1766 | jz rename_not_dir ; no |
- | |
1767 | mov eax,[dir_entry+20-2] ; FAT entry |
- | |
1768 | mov ax,[dir_entry+26] |
- | |
1769 | and eax,[fatMASK] |
- | |
1770 | call change_2dot_cluster |
- | |
1771 | cmp [hd_error],0 |
- | |
1772 | jne rename_entry_already_exist |
- | |
1773 | - | ||
1774 | rename_not_dir: |
- | |
1775 | cmp [hd_error],0 |
- | |
1776 | jne rename_entry_already_exist |
- | |
1777 | mov eax,[sector_tmp] |
- | |
1778 | mov ebx,buffer |
- | |
1779 | call hd_read ; read source directory sector |
- | |
1780 | cmp [hd_error],0 |
- | |
1781 | jne rename_entry_already_exist |
- | |
1782 | - | ||
1783 | mov ebx,[entry_pos] |
- | |
1784 | call delete_entry_name |
- | |
1785 | cmp [hd_error],0 |
- | |
1786 | jne rename_entry_already_exist |
- | |
1787 | - | ||
1788 | popad |
- | |
1789 | call update_disk ; write all of cache and fat to hd |
- | |
1790 | cmp [hd_error],0 |
- | |
1791 | jne rename_entry_already_exist_2 |
- | |
1792 | mov [hd1_status],0 |
- | |
1793 | xor eax,eax |
- | |
1794 | ret |
- | |
1795 | - | ||
1796 | rename_entry_not_found: |
- | |
1797 | cmp [hd_error],0 |
- | |
1798 | jne rename_entry_already_exist |
- | |
1799 | popad |
- | |
1800 | mov [hd1_status],0 |
- | |
1801 | mov eax,ERROR_FILE_NOT_FOUND |
- | |
1802 | ret |
- | |
1803 | - | ||
1804 | rename_entry_already_exist_1: |
- | |
1805 | add esp,8 |
- | |
1806 | rename_entry_already_exist: |
- | |
1807 | popad |
- | |
1808 | rename_entry_already_exist_2: |
- | |
1809 | mov [hd1_status],0 |
- | |
1810 | mov eax,ERROR_ACCESS_DENIED |
- | |
1811 | ret |
- | |
1812 | - | ||
1813 | rename_disk_full: |
- | |
1814 | cmp [hd_error],0 |
- | |
1815 | jne rename_entry_already_exist |
- | |
1816 | popad |
- | |
1817 | mov [hd1_status],0 |
- | |
1818 | mov eax,ERROR_DISK_FULL |
- | |
1819 | ret |
- | |
1820 | - | ||
1821 | - | ||
1822 | change_2dot_cluster: |
- | |
1823 | ;----------------------------------------------------------- |
- | |
1824 | ; input : eax = directory cluster |
- | |
1825 | ; edx = value to save |
- | |
1826 | ; change : eax,ebx,edx |
- | |
1827 | ;----------------------------------------------------------- |
- | |
1828 | cmp eax,[LAST_CLUSTER] |
- | |
1829 | ja not_2dot ; too big cluster number, something is wrong |
- | |
1830 | sub eax,2 |
- | |
1831 | jb not_2dot |
- | |
1832 | - | ||
1833 | imul eax,[SECTORS_PER_CLUSTER] |
- | |
1834 | add eax,[DATA_START] |
- | |
1835 | mov ebx,buffer |
- | |
1836 | call hd_read |
- | |
1837 | cmp [hd_error],0 |
- | |
1838 | jne not_2dot |
- | |
1839 | - | ||
1840 | cmp dword [ebx+32],'.. ' |
- | |
1841 | jnz not_2dot |
- | |
1842 | - | ||
1843 | cmp edx,[ROOT_CLUSTER] ; is rootdir cluster? |
- | |
1844 | jne not_2dot_root |
- | |
1845 | xor edx,edx ; yes. set it zero |
- | |
1846 | - | ||
1847 | not_2dot_root: |
- | |
1848 | mov [ebx+32+26],dx ; 16 bits low of cluster |
- | |
1849 | shr edx,16 |
- | |
1850 | mov [ebx+32+20],dx ; 16 bits high of cluster (=0 fat16) |
- | |
1851 | call hd_write |
- | |
1852 | - | ||
1853 | not_2dot: |
- | |
1854 | ret |
1351 | ret |
1855 | 1352 | ||
1856 | 1353 | ||
1857 | get_hd_info: |
1354 | get_hd_info: |
1858 | ;----------------------------------------------------------- |
1355 | ;----------------------------------------------------------- |
1859 | ; output : eax = 0 - ok |
1356 | ; output : eax = 0 - ok |
1860 | ; 3 - unknown FS |
1357 | ; 3 - unknown FS |
1861 | ; 10 - access denied |
1358 | ; 10 - access denied |
1862 | ; edx = cluster size in bytes |
1359 | ; edx = cluster size in bytes |
- | 1360 | ; ebx = total clusters on disk |
|
- | 1361 | ; ecx = free clusters on disk |
|
1863 | ; ebx = total clusters on disk |
1362 | ;----------------------------------------------------------- |
1864 | ; ecx = free clusters on disk |
1363 | cmp [fs_type], 16 |
1865 | ;----------------------------------------------------------- |
1364 | jz info_fat_ok |
1866 | cmp [fat_type],0 |
1365 | cmp [fs_type], 32 |
1867 | jnz info_fat_ok |
1366 | jz info_fat_ok |
1868 | xor edx,edx |
1367 | xor edx,edx |
1869 | xor ebx,ebx |
1368 | xor ebx,ebx |
Line 1923... | Line 1422... | ||
1923 | 1422 | ||
1924 | call write_cache |
1423 | call write_cache |
1925 | update_disk_acces_denied: |
1424 | update_disk_acces_denied: |
Line 1926... | Line -... | ||
1926 | ret |
- | |
1927 | - | ||
1928 | - | ||
1929 | ;************************************************************************** |
- | |
1930 | ; |
- | |
1931 | ; 0x600008 - first entry in cache list |
- | |
1932 | ; |
- | |
1933 | ; +0 - lba sector |
- | |
1934 | ; +4 - state of cache sector |
- | |
1935 | ; 0 = empty |
- | |
1936 | ; 1 = used for read ( same as in hd ) |
- | |
1937 | ; 2 = used for write ( differs from hd ) |
- | |
1938 | ; |
- | |
1939 | ; +65536 - cache entries |
- | |
1940 | ; |
- | |
1941 | ;************************************************************************** |
- | |
1942 | - | ||
1943 | - | ||
1944 | hd_read: |
- | |
1945 | ;----------------------------------------------------------- |
- | |
1946 | ; input : eax = block to read |
- | |
1947 | ; ebx = destination |
- | |
1948 | ;----------------------------------------------------------- |
- | |
1949 | push ecx esi edi ; scan cache |
- | |
1950 | - | ||
1951 | mov ecx,cache_max ; entries in cache |
- | |
1952 | mov esi,0x600000+8 |
- | |
1953 | mov edi,1 |
- | |
1954 | - | ||
1955 | hdreadcache: |
- | |
1956 | - | ||
1957 | cmp dword [esi+4],0 ; empty |
- | |
1958 | je nohdcache |
- | |
1959 | - | ||
1960 | cmp [esi],eax ; correct sector |
- | |
1961 | je yeshdcache |
- | |
1962 | - | ||
1963 | nohdcache: |
- | |
1964 | - | ||
1965 | add esi,8 |
- | |
1966 | inc edi |
- | |
1967 | dec ecx |
- | |
1968 | jnz hdreadcache |
- | |
1969 | - | ||
1970 | call find_empty_slot ; ret in edi |
- | |
1971 | cmp [hd_error],0 |
- | |
1972 | jne return_01 |
- | |
1973 | - | ||
1974 | push eax edx |
- | |
1975 | - | ||
1976 | call wait_for_hd_idle |
- | |
1977 | cmp [hd_error],0 |
- | |
1978 | jne hd_read_error |
- | |
1979 | - | ||
1980 | cli |
- | |
1981 | xor eax,eax |
- | |
1982 | mov edx,[hdbase] |
- | |
1983 | inc edx |
- | |
1984 | out dx,al ; ATAFeatures à ¥£¨áâà "®á®¡¥Â®á⥩" |
- | |
1985 | inc edx |
- | |
1986 | inc eax |
- | |
1987 | out dx,al ; ATASectorCount áç¥â稪 ᥪâ®à ®¢ |
- | |
1988 | inc edx |
- | |
1989 | mov eax,[esp+4] |
- | |
1990 | out dx,al ; ATASectorNumber à ¥£¨áâà ®¬¥à  á¥ªâ®à  |
- | |
1991 | shr eax,8 |
- | |
1992 | inc edx |
- | |
1993 | out dx,al ; ATACylinder ®¬¥à 樫¨Â¤à  (¬« ¤è¨© ¡ ©â) |
- | |
1994 | shr eax,8 |
- | |
1995 | inc edx |
- | |
1996 | out dx,al ; ®¬¥à 樫¨Â¤à  (áâ à 訩 ¡ ©â) |
- | |
1997 | shr eax,8 |
- | |
1998 | inc edx |
- | |
1999 | and al,1+2+4+8 |
- | |
2000 | add al,byte [hdid] |
- | |
2001 | add al,128+64+32 |
- | |
2002 | out dx,al ; ®¬¥à £®«®¢ª¨/®¬¥à ¤¨áª |
- | |
2003 | inc edx |
- | |
2004 | mov al,20h |
- | |
2005 | out dx,al ; ATACommand à ¥£¨áâà ª®¬ Â¤ |
- | |
2006 | sti |
- | |
2007 | - | ||
2008 | call wait_for_sector_buffer |
- | |
2009 | - | ||
2010 | cmp [hd_error],0 |
- | |
2011 | jne hd_read_error |
- | |
2012 | - | ||
2013 | cli |
- | |
2014 | push edi |
- | |
2015 | shl edi,9 |
- | |
2016 | add edi,0x600000+65536 |
- | |
2017 | mov ecx,256 |
- | |
2018 | mov edx,[hdbase] |
- | |
2019 | cld |
- | |
2020 | rep insw |
- | |
2021 | pop edi |
- | |
2022 | sti |
- | |
2023 | - | ||
2024 | pop edx eax |
- | |
2025 | blok_read_2: |
- | |
2026 | lea esi,[edi*8+0x600000] |
- | |
2027 | mov [esi],eax ; sector number |
- | |
2028 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
- | |
2029 | - | ||
2030 | yeshdcache: |
- | |
2031 | - | ||
2032 | mov esi,edi |
- | |
2033 | shl esi,9 |
- | |
2034 | add esi,0x600000+65536 |
- | |
2035 | mov edi,ebx |
- | |
2036 | mov ecx,512/4 |
- | |
2037 | cld |
- | |
2038 | rep movsd ; move data |
- | |
2039 | return_01: |
- | |
2040 | pop edi esi ecx |
- | |
2041 | ret |
- | |
2042 | - | ||
2043 | - | ||
2044 | hd_write: |
- | |
2045 | ;----------------------------------------------------------- |
- | |
2046 | ; input : eax = block |
- | |
2047 | ; ebx = pointer to memory |
- | |
2048 | ;----------------------------------------------------------- |
- | |
2049 | push ecx esi edi |
- | |
2050 | - | ||
2051 | ; check if the cache already has the sector and overwrite it |
- | |
2052 | - | ||
2053 | mov ecx,cache_max |
- | |
2054 | mov esi,0x600000+8 |
- | |
2055 | mov edi,1 |
- | |
2056 | - | ||
2057 | hdwritecache: |
- | |
2058 | - | ||
2059 | cmp dword [esi+4],0 ; if cache slot is empty |
- | |
2060 | je not_in_cache_write |
- | |
2061 | - | ||
2062 | cmp [esi],eax ; if the slot has the sector |
- | |
2063 | je yes_in_cache_write |
- | |
2064 | - | ||
2065 | not_in_cache_write: |
- | |
2066 | - | ||
2067 | add esi,8 |
- | |
2068 | inc edi |
- | |
2069 | dec ecx |
- | |
2070 | jnz hdwritecache |
- | |
2071 | - | ||
2072 | ; sector not found in cache |
- | |
2073 | ; write the block to a new location |
- | |
2074 | - | ||
2075 | call find_empty_slot ; ret in edi |
- | |
2076 | cmp [hd_error],0 |
- | |
2077 | jne hd_write_access_denied |
- | |
2078 | - | ||
2079 | lea esi,[edi*8+0x600000] |
- | |
2080 | mov [esi],eax ; sector number |
- | |
2081 | - | ||
2082 | yes_in_cache_write: |
- | |
2083 | - | ||
2084 | mov dword [esi+4],2 ; write - differs from hd |
- | |
2085 | - | ||
2086 | shl edi,9 |
- | |
2087 | add edi,0x600000+65536 |
- | |
2088 | mov esi,ebx |
- | |
2089 | mov ecx,512/4 |
- | |
2090 | cld |
- | |
2091 | rep movsd ; move data |
- | |
2092 | hd_write_access_denied: |
- | |
2093 | pop edi esi ecx |
- | |
2094 | ret |
- | |
2095 | - | ||
2096 | - | ||
2097 | write_cache: |
- | |
2098 | ;----------------------------------------------------------- |
- | |
2099 | ; write all changed sectors to disk |
- | |
2100 | ;----------------------------------------------------------- |
- | |
2101 | push eax ecx edx esi edi |
- | |
2102 | - | ||
2103 | ; write difference ( 2 ) from cache to hd |
- | |
2104 | - | ||
2105 | mov ecx,cache_max |
- | |
2106 | mov esi,0x600000+8 |
- | |
2107 | mov edi,1 |
- | |
2108 | - | ||
2109 | write_cache_more: |
- | |
2110 | - | ||
2111 | cmp dword [esi+4],2 ; if cache slot is not different |
- | |
2112 | jne does_not_need_writing |
- | |
2113 | - | ||
2114 | mov dword [esi+4],1 ; same as in hd |
- | |
2115 | mov eax,[esi] ; eax = sector to write |
- | |
2116 | - | ||
2117 | cmp eax,[PARTITION_START] |
- | |
2118 | jb danger |
- | |
2119 | cmp eax,[PARTITION_END] |
- | |
2120 | ja danger |
- | |
2121 | - | ||
2122 | call wait_for_hd_idle |
- | |
2123 | cmp [hd_error],0 |
- | |
2124 | jne hd_write_error |
- | |
2125 | - | ||
2126 | cli |
- | |
2127 | xor eax,eax |
- | |
2128 | mov edx,[hdbase] |
- | |
2129 | inc edx |
- | |
2130 | out dx,al |
- | |
2131 | inc edx |
- | |
2132 | inc eax |
- | |
2133 | out dx,al |
- | |
2134 | inc edx |
- | |
2135 | mov eax,[esi] ; eax = sector to write |
- | |
2136 | out dx,al |
- | |
2137 | shr eax,8 |
- | |
2138 | inc edx |
- | |
2139 | out dx,al |
- | |
2140 | shr eax,8 |
- | |
2141 | inc edx |
- | |
2142 | out dx,al |
- | |
2143 | shr eax,8 |
- | |
2144 | inc edx |
- | |
2145 | and al,1+2+4+8 |
- | |
2146 | add al,byte [hdid] |
- | |
2147 | add al,128+64+32 |
- | |
2148 | out dx,al |
- | |
2149 | inc edx |
- | |
2150 | mov al,30h |
- | |
2151 | out dx,al |
- | |
2152 | sti |
- | |
2153 | - | ||
2154 | call wait_for_sector_buffer |
- | |
2155 | - | ||
2156 | cmp [hd_error],0 |
- | |
2157 | jne hd_write_error |
- | |
2158 | - | ||
2159 | push ecx esi |
- | |
2160 | - | ||
2161 | cli |
- | |
2162 | mov esi,edi |
- | |
2163 | shl esi,9 |
- | |
2164 | add esi,0x600000+65536 ; esi = from memory position |
- | |
2165 | mov ecx,256 |
- | |
2166 | mov edx,[hdbase] |
- | |
2167 | cld |
- | |
2168 | rep outsw |
- | |
2169 | sti |
- | |
2170 | - | ||
2171 | pop esi ecx |
- | |
2172 | - | ||
2173 | danger: |
- | |
2174 | does_not_need_writing: |
- | |
2175 | - | ||
2176 | add esi,8 |
- | |
2177 | inc edi |
- | |
2178 | dec ecx |
- | |
2179 | jnz write_cache_more |
- | |
2180 | return_02: |
- | |
2181 | pop edi esi edx ecx eax |
- | |
2182 | ret |
- | |
2183 | - | ||
2184 | - | ||
2185 | find_empty_slot: |
- | |
2186 | ;----------------------------------------------------------- |
- | |
2187 | ; find empty or read slot, flush cache if next 10% is used by write |
- | |
2188 | ; output : edi = cache slot |
- | |
2189 | ;----------------------------------------------------------- |
- | |
2190 | push ecx esi |
- | |
2191 | - | ||
2192 | search_again: |
- | |
2193 | - | ||
2194 | mov ecx,cache_max*10/100 |
- | |
2195 | mov edi,[cache_search_start] |
- | |
2196 | - | ||
2197 | search_for_empty: |
- | |
2198 | - | ||
2199 | inc edi |
- | |
2200 | cmp edi,cache_max |
- | |
2201 | jbe inside_cache |
- | |
2202 | mov edi,1 |
- | |
2203 | - | ||
2204 | inside_cache: |
- | |
2205 | - | ||
2206 | cmp dword [edi*8+0x600000+4],2 ; get cache slot info |
- | |
2207 | jb found_slot ; it's empty or read |
- | |
2208 | dec ecx |
- | |
2209 | jnz search_for_empty |
- | |
2210 | - | ||
2211 | call write_cache ; no empty slots found, write all |
- | |
2212 | cmp [hd_error],0 |
- | |
2213 | jne found_slot_access_denied |
- | |
2214 | - | ||
2215 | jmp search_again ; and start again |
- | |
2216 | - | ||
2217 | found_slot: |
- | |
2218 | - | ||
2219 | mov [cache_search_start],edi |
- | |
2220 | found_slot_access_denied: |
- | |
2221 | pop esi ecx |
- | |
2222 | ret |
- | |
2223 | - | ||
2224 | - | ||
2225 | save_hd_wait_timeout: |
- | |
2226 | - | ||
2227 | push eax |
- | |
2228 | mov eax,[timer_ticks];[0xfdf0] |
- | |
2229 | add eax,300 ; 3 sec timeout |
- | |
2230 | mov [hd_wait_timeout],eax |
- | |
2231 | pop eax |
- | |
2232 | ret |
- | |
2233 | - | ||
2234 | - | ||
2235 | check_hd_wait_timeout: |
- | |
2236 | - | ||
2237 | push eax |
- | |
2238 | mov eax,[hd_wait_timeout] |
- | |
2239 | cmp [timer_ticks], eax ;[0xfdf0],eax |
- | |
2240 | jg hd_timeout_error |
- | |
2241 | pop eax |
- | |
2242 | mov [hd_error],0 |
- | |
2243 | ret |
- | |
2244 | - | ||
2245 | iglobal |
- | |
2246 | hd_timeout_str db 'K : FS - HD timeout',13,10,0 |
- | |
2247 | hd_read_str db 'K : FS - HD read error',13,10,0 |
- | |
2248 | hd_write_str db 'K : FS - HD write error',13,10,0 |
- | |
2249 | hd_lba_str db 'K : FS - HD LBA error',13,10,0 |
- | |
2250 | endg |
- | |
2251 | - | ||
2252 | hd_timeout_error: |
- | |
2253 | - | ||
2254 | call clear_hd_cache |
- | |
2255 | call clear_application_table_status |
- | |
2256 | mov esi,hd_timeout_str |
- | |
2257 | call sys_msg_board_str |
- | |
2258 | ; jmp $ |
- | |
2259 | mov [hd_error],1 |
- | |
2260 | pop eax |
- | |
2261 | ret |
- | |
2262 | - | ||
2263 | hd_read_error: |
- | |
2264 | - | ||
2265 | call clear_hd_cache |
- | |
2266 | call clear_application_table_status |
- | |
2267 | mov esi,hd_read_str |
- | |
2268 | call sys_msg_board_str |
- | |
2269 | pop edx eax |
- | |
2270 | jmp return_01 |
- | |
2271 | ; jmp $ |
- | |
2272 | - | ||
2273 | hd_write_error: |
- | |
2274 | - | ||
2275 | call clear_hd_cache |
- | |
2276 | call clear_application_table_status |
- | |
2277 | mov esi,hd_write_str |
- | |
2278 | call sys_msg_board_str |
- | |
2279 | jmp return_02 |
- | |
2280 | ; jmp $ |
- | |
2281 | - | ||
2282 | hd_lba_error: |
- | |
2283 | call clear_hd_cache |
- | |
2284 | call clear_application_table_status |
- | |
2285 | mov esi,hd_lba_str |
- | |
2286 | call sys_msg_board_str |
- | |
2287 | jmp LBA_read_ret |
- | |
2288 | - | ||
2289 | - | ||
2290 | wait_for_hd_idle: |
- | |
2291 | - | ||
2292 | push eax edx |
- | |
2293 | - | ||
2294 | call save_hd_wait_timeout |
- | |
2295 | - | ||
2296 | mov edx,[hdbase] |
- | |
2297 | add edx,0x7 |
- | |
2298 | - | ||
2299 | wfhil1: |
- | |
2300 | - | ||
2301 | call check_hd_wait_timeout |
- | |
2302 | cmp [hd_error],0 |
- | |
2303 | jne @f |
- | |
2304 | - | ||
2305 | in al,dx |
- | |
2306 | test al,128 |
- | |
2307 | jnz wfhil1 |
- | |
2308 | - | ||
2309 | @@: |
- | |
2310 | - | ||
2311 | pop edx eax |
- | |
2312 | ret |
- | |
2313 | - | ||
2314 | - | ||
2315 | - | ||
2316 | wait_for_sector_buffer: |
- | |
2317 | - | ||
2318 | push eax edx |
- | |
2319 | - | ||
2320 | mov edx,[hdbase] |
- | |
2321 | add edx,0x7 |
- | |
2322 | - | ||
2323 | call save_hd_wait_timeout |
- | |
2324 | - | ||
2325 | hdwait_sbuf: ; wait for sector buffer to be ready |
- | |
2326 | - | ||
2327 | call check_hd_wait_timeout |
- | |
2328 | cmp [hd_error],0 |
- | |
2329 | jne @f |
- | |
2330 | - | ||
2331 | in al,dx |
- | |
2332 | test al,8 |
- | |
2333 | jz hdwait_sbuf |
- | |
2334 | - | ||
2335 | mov [hd_error],0 |
- | |
2336 | - | ||
2337 | cmp [hd_setup],1 ; do not mark error for setup request |
- | |
2338 | je buf_wait_ok |
- | |
2339 | - | ||
2340 | test al,1 ; previous command ended up with an error |
- | |
2341 | jz buf_wait_ok |
- | |
2342 | @@: |
- | |
2343 | mov [hd_error],1 |
- | |
2344 | - | ||
2345 | buf_wait_ok: |
- | |
2346 | - | ||
2347 | pop edx eax |
- | |
2348 | ret |
- | |
2349 | - | ||
2350 | 1425 | ret |
|
2351 | 1426 | ||
2352 | read_hd_file: |
1427 | read_hd_file: |
2353 | ;----------------------------------------------------------------- |
1428 | ;----------------------------------------------------------------- |
2354 | ; |
1429 | ; |
Line 2409... | Line 1484... | ||
2409 | push 0 |
1484 | push 0 |
2410 | push 0 |
1485 | push 0 |
2411 | push fat16_root_first |
1486 | push fat16_root_first |
2412 | push fat16_root_next |
1487 | push fat16_root_next |
2413 | mov eax, [ROOT_CLUSTER] |
1488 | mov eax, [ROOT_CLUSTER] |
2414 | cmp [fat_type], 32 |
1489 | cmp [fs_type], 32 |
2415 | jz .fat32 |
1490 | jz .fat32 |
2416 | .loop: |
1491 | .loop: |
2417 | call fat_find_lfn |
1492 | call fat_find_lfn |
2418 | jc .notfound |
1493 | jc .notfound |
2419 | cmp byte [esi], 0 |
1494 | cmp byte [esi], 0 |
Line 2460... | Line 1535... | ||
2460 | ; ret ebx = bytes read or 0xffffffff file not found |
1535 | ; ret ebx = bytes read or 0xffffffff file not found |
2461 | ; eax = 0 ok read or other = errormsg |
1536 | ; eax = 0 ok read or other = errormsg |
2462 | ; |
1537 | ; |
2463 | ;-------------------------------------------------------------- |
1538 | ;-------------------------------------------------------------- |
2464 | fs_HdRead: |
1539 | fs_HdRead: |
2465 | cmp [fat_type], 0 |
1540 | cmp [fs_type], 16 |
2466 | jnz @f |
1541 | jz @f |
- | 1542 | cmp [fs_type], 32 |
|
- | 1543 | jz @f |
|
- | 1544 | cmp [fs_type], 1 |
|
- | 1545 | jz ntfs_HdRead |
|
2467 | or ebx, -1 |
1546 | or ebx, -1 |
2468 | mov eax, ERROR_UNKNOWN_FS |
1547 | mov eax, ERROR_UNKNOWN_FS |
2469 | ret |
1548 | ret |
2470 | @@: |
1549 | @@: |
2471 | push edi |
1550 | push edi |
Line 2615... | Line 1694... | ||
2615 | ; ret ebx = blocks read or 0xffffffff folder not found |
1694 | ; ret ebx = blocks read or 0xffffffff folder not found |
2616 | ; eax = 0 ok read or other = errormsg |
1695 | ; eax = 0 ok read or other = errormsg |
2617 | ; |
1696 | ; |
2618 | ;-------------------------------------------------------------- |
1697 | ;-------------------------------------------------------------- |
2619 | fs_HdReadFolder: |
1698 | fs_HdReadFolder: |
- | 1699 | cmp [fs_type], 1 |
|
- | 1700 | jz ntfs_HdReadFolder |
|
- | 1701 | cmp [fs_type], 16 |
|
- | 1702 | jz @f |
|
- | 1703 | cmp [fs_type], 32 |
|
- | 1704 | jz @f |
|
- | 1705 | push ERROR_UNSUPPORTED_FS |
|
- | 1706 | pop eax |
|
- | 1707 | or ebx, -1 |
|
- | 1708 | ret |
|
- | 1709 | @@: |
|
2620 | mov eax, [ROOT_CLUSTER] |
1710 | mov eax, [ROOT_CLUSTER] |
2621 | push edi |
1711 | push edi |
2622 | cmp byte [esi], 0 |
1712 | cmp byte [esi], 0 |
2623 | jz .doit |
1713 | jz .doit |
2624 | call hd_find_lfn |
1714 | call hd_find_lfn |
Line 2655... | Line 1745... | ||
2655 | mov esi, edi ; esi points to BDFE |
1745 | mov esi, edi ; esi points to BDFE |
2656 | .new_cluster: |
1746 | .new_cluster: |
2657 | mov [cluster_tmp], eax |
1747 | mov [cluster_tmp], eax |
2658 | test eax, eax |
1748 | test eax, eax |
2659 | jnz @f |
1749 | jnz @f |
2660 | cmp [fat_type], 32 |
1750 | cmp [fs_type], 32 |
2661 | jz .notfound |
1751 | jz .notfound |
2662 | mov eax, [ROOT_START] |
1752 | mov eax, [ROOT_START] |
2663 | push [ROOT_SECTORS] |
1753 | push [ROOT_SECTORS] |
2664 | push ebx |
1754 | push ebx |
2665 | jmp .new_sector |
1755 | jmp .new_sector |
Line 2775... | Line 1865... | ||
2775 | jae fat16_root_next_sector |
1865 | jae fat16_root_next_sector |
2776 | add edi, 0x20 |
1866 | add edi, 0x20 |
2777 | ret ; CF=0 |
1867 | ret ; CF=0 |
2778 | fat16_root_next_sector: |
1868 | fat16_root_next_sector: |
2779 | ; read next sector |
1869 | ; read next sector |
- | 1870 | push [longname_sec2] |
|
- | 1871 | pop [longname_sec1] |
|
2780 | push ecx |
1872 | push ecx |
2781 | mov ecx, [eax+4] |
1873 | mov ecx, [eax+4] |
- | 1874 | push ecx |
|
- | 1875 | add ecx, [ROOT_START] |
|
- | 1876 | mov [longname_sec2], ecx |
|
- | 1877 | pop ecx |
|
2782 | inc ecx |
1878 | inc ecx |
2783 | mov [eax+4], ecx |
1879 | mov [eax+4], ecx |
2784 | cmp ecx, [ROOT_SECTORS] |
1880 | cmp ecx, [ROOT_SECTORS] |
2785 | pop ecx |
1881 | pop ecx |
2786 | jae fat16_root_first.readerr |
1882 | jae fat16_root_first.readerr |
Line 2826... | Line 1922... | ||
2826 | cmp edi, buffer+0x200-0x20 |
1922 | cmp edi, buffer+0x200-0x20 |
2827 | jae fat_notroot_next_sector |
1923 | jae fat_notroot_next_sector |
2828 | add edi, 0x20 |
1924 | add edi, 0x20 |
2829 | ret ; CF=0 |
1925 | ret ; CF=0 |
2830 | fat_notroot_next_sector: |
1926 | fat_notroot_next_sector: |
- | 1927 | push [longname_sec2] |
|
- | 1928 | pop [longname_sec1] |
|
- | 1929 | push eax |
|
- | 1930 | call fat_get_sector |
|
- | 1931 | mov [longname_sec2], eax |
|
- | 1932 | pop eax |
|
2831 | push ecx |
1933 | push ecx |
2832 | mov ecx, [eax+4] |
1934 | mov ecx, [eax+4] |
2833 | inc ecx |
1935 | inc ecx |
2834 | cmp ecx, [SECTORS_PER_CLUSTER] |
1936 | cmp ecx, [SECTORS_PER_CLUSTER] |
2835 | jae fat_notroot_next_cluster |
1937 | jae fat_notroot_next_cluster |
Line 2972... | Line 2074... | ||
2972 | fshrfs: |
2074 | fshrfs: |
2973 | mov eax, ERROR_UNKNOWN_FS |
2075 | mov eax, ERROR_UNKNOWN_FS |
2974 | xor ebx, ebx |
2076 | xor ebx, ebx |
2975 | ret |
2077 | ret |
Line -... | Line 2078... | ||
- | 2078 | ||
- | 2079 | fs_HdCreateFolder: |
|
- | 2080 | mov al, 1 |
|
- | 2081 | jmp fs_HdRewrite.common |
|
2976 | 2082 | ||
- | 2083 | fs_HdRewrite: |
|
- | 2084 | xor eax, eax |
|
2977 | fs_HdRewrite: |
2085 | .common: |
- | 2086 | cmp [fs_type], 1 |
|
- | 2087 | jz ntfs_HdRewrite |
|
- | 2088 | cmp [fs_type], 16 |
|
- | 2089 | jz @f |
|
2978 | cmp [fat_type], 0 |
2090 | cmp [fs_type], 32 |
- | 2091 | jnz fshrfs |
|
2979 | jz fshrfs |
2092 | @@: |
2980 | cmp byte [esi], 0 |
2093 | cmp byte [esi], 0 |
2981 | jz fshrad |
2094 | jz fshrad |
2982 | pushad |
2095 | pushad |
2983 | xor ebp, ebp |
2096 | xor ebp, ebp |
Line 2993... | Line 2106... | ||
2993 | @@: |
2106 | @@: |
2994 | pop esi |
2107 | pop esi |
2995 | test ebp, ebp |
2108 | test ebp, ebp |
2996 | jnz .noroot |
2109 | jnz .noroot |
2997 | mov ebp, [ROOT_CLUSTER] |
2110 | mov ebp, [ROOT_CLUSTER] |
2998 | cmp [fat_type], 32 |
2111 | cmp [fs_type], 32 |
2999 | jz .pushnotroot |
2112 | jz .pushnotroot |
3000 | push fat16_root_extend_dir |
2113 | push fat16_root_extend_dir |
3001 | push fat16_root_end_write |
2114 | push fat16_root_end_write |
3002 | push fat16_root_next_write |
2115 | push fat16_root_next_write |
3003 | push fat16_root_begin_write |
2116 | push fat16_root_begin_write |
Line 3006... | Line 2119... | ||
3006 | push ebp |
2119 | push ebp |
3007 | push fat16_root_first |
2120 | push fat16_root_first |
3008 | push fat16_root_next |
2121 | push fat16_root_next |
3009 | jmp .common1 |
2122 | jmp .common1 |
3010 | .noroot: |
2123 | .noroot: |
- | 2124 | mov eax, ERROR_ACCESS_DENIED |
|
- | 2125 | cmp byte [ebp+1], 0 |
|
- | 2126 | jz .ret1 |
|
3011 | ; check existence |
2127 | ; check existence |
3012 | mov byte [ebp], 0 |
2128 | mov byte [ebp], 0 |
3013 | call hd_find_lfn |
2129 | call hd_find_lfn |
3014 | mov byte [ebp], '/' |
2130 | mov byte [ebp], '/' |
3015 | lea esi, [ebp+1] |
2131 | lea esi, [ebp+1] |
Line 3039... | Line 2155... | ||
3039 | push fat_notroot_first |
2155 | push fat_notroot_first |
3040 | push fat_notroot_next |
2156 | push fat_notroot_next |
3041 | .common1: |
2157 | .common1: |
3042 | call fat_find_lfn |
2158 | call fat_find_lfn |
3043 | jc .notfound |
2159 | jc .notfound |
3044 | ; found; must not be directory |
2160 | ; found |
3045 | test byte [edi+11], 10h |
2161 | test byte [edi+11], 10h |
- | 2162 | jz .exists_file |
|
- | 2163 | ; found directory; if we are creating directory, return OK, |
|
- | 2164 | ; if we are creating file, say "access denied" |
|
- | 2165 | add esp, 32 |
|
- | 2166 | popad |
|
- | 2167 | test al, al |
|
- | 2168 | mov eax, ERROR_ACCESS_DENIED |
|
- | 2169 | jz @f |
|
- | 2170 | mov al, 0 |
|
- | 2171 | @@: |
|
- | 2172 | xor ebx, ebx |
|
- | 2173 | ret |
|
- | 2174 | .exists_file: |
|
- | 2175 | ; found file; if we are creating directory, return "access denied", |
|
- | 2176 | ; if we are creating file, delete existing file and continue |
|
- | 2177 | cmp byte [esp+32+28], 0 |
|
3046 | jz @f |
2178 | jz @f |
3047 | add esp, 32 |
2179 | add esp, 32 |
3048 | popad |
2180 | popad |
3049 | mov eax, ERROR_ACCESS_DENIED |
2181 | mov eax, ERROR_ACCESS_DENIED |
3050 | xor ebx, ebx |
2182 | xor ebx, ebx |
Line 3277... | Line 2409... | ||
3277 | mov [edi+18], ax ; last access date |
2409 | mov [edi+18], ax ; last access date |
3278 | xor ecx, ecx |
2410 | xor ecx, ecx |
3279 | mov word [edi+20], cx ; high word of cluster |
2411 | mov word [edi+20], cx ; high word of cluster |
3280 | mov word [edi+26], cx ; low word of cluster - to be filled |
2412 | mov word [edi+26], cx ; low word of cluster - to be filled |
3281 | mov dword [edi+28], ecx ; file size - to be filled |
2413 | mov dword [edi+28], ecx ; file size - to be filled |
- | 2414 | cmp byte [esp+32+28], cl |
|
- | 2415 | jz .doit |
|
- | 2416 | ; create directory |
|
- | 2417 | mov byte [edi+11], 10h ; attributes: folder |
|
- | 2418 | mov edx, edi |
|
- | 2419 | lea eax, [esp+8] |
|
- | 2420 | call dword [eax+16] ; flush directory |
|
- | 2421 | push ecx |
|
- | 2422 | mov ecx, [SECTORS_PER_CLUSTER] |
|
- | 2423 | shl ecx, 9 |
|
- | 2424 | jmp .doit2 |
|
3282 | .doit: |
2425 | .doit: |
3283 | lea eax, [esp+8] |
2426 | lea eax, [esp+8] |
3284 | call dword [eax+16] ; flush directory |
2427 | call dword [eax+16] ; flush directory |
3285 | push ecx |
2428 | push ecx |
3286 | mov ecx, [esp+4+32+24] |
2429 | mov ecx, [esp+4+32+24] |
- | 2430 | .doit2: |
|
3287 | push ecx |
2431 | push ecx |
3288 | push edi |
2432 | push edi |
3289 | mov esi, edx |
2433 | mov esi, edx |
3290 | test ecx, ecx |
2434 | test ecx, ecx |
3291 | jz .done |
2435 | jz .done |
Line 3310... | Line 2454... | ||
3310 | mov ebp, [SECTORS_PER_CLUSTER] |
2454 | mov ebp, [SECTORS_PER_CLUSTER] |
3311 | imul eax, ebp |
2455 | imul eax, ebp |
3312 | add eax, [DATA_START] |
2456 | add eax, [DATA_START] |
3313 | ; write data |
2457 | ; write data |
3314 | .write_sector: |
2458 | .write_sector: |
- | 2459 | cmp byte [esp+16+32+28], 0 |
|
- | 2460 | jnz .writedir |
|
3315 | mov ecx, 512 |
2461 | mov ecx, 512 |
3316 | cmp dword [esp+8], ecx |
2462 | cmp dword [esp+8], ecx |
3317 | jb .writeshort |
2463 | jb .writeshort |
3318 | ; we can write directly from given buffer |
2464 | ; we can write directly from given buffer |
3319 | mov ebx, esi |
2465 | mov ebx, esi |
Line 3323... | Line 2469... | ||
3323 | mov ecx, [esp+8] |
2469 | mov ecx, [esp+8] |
3324 | push ecx |
2470 | push ecx |
3325 | mov edi, buffer |
2471 | mov edi, buffer |
3326 | mov ebx, edi |
2472 | mov ebx, edi |
3327 | rep movsb |
2473 | rep movsb |
- | 2474 | .writedircont: |
|
3328 | mov ecx, buffer+0x200 |
2475 | mov ecx, buffer+0x200 |
3329 | sub ecx, edi |
2476 | sub ecx, edi |
3330 | push eax |
2477 | push eax |
3331 | xor eax, eax |
2478 | xor eax, eax |
3332 | rep stosb |
2479 | rep stosb |
Line 3389... | Line 2536... | ||
3389 | call add_disk_free_space |
2536 | call add_disk_free_space |
3390 | add esp, 32 |
2537 | add esp, 32 |
3391 | call update_disk |
2538 | call update_disk |
3392 | popad |
2539 | popad |
3393 | ret |
2540 | ret |
- | 2541 | .writedir: |
|
- | 2542 | push 512 |
|
- | 2543 | mov edi, buffer |
|
- | 2544 | mov ebx, edi |
|
- | 2545 | mov ecx, [SECTORS_PER_CLUSTER] |
|
- | 2546 | shl ecx, 9 |
|
- | 2547 | cmp ecx, [esp+12] |
|
- | 2548 | jnz .writedircont |
|
- | 2549 | dec dword [esp+16] |
|
- | 2550 | push esi |
|
- | 2551 | mov ecx, 32/4 |
|
- | 2552 | rep movsd |
|
- | 2553 | pop esi |
|
- | 2554 | mov dword [edi-32], '. ' |
|
- | 2555 | mov dword [edi-32+4], ' ' |
|
- | 2556 | mov dword [edi-32+8], ' ' |
|
- | 2557 | mov byte [edi-32+11], 10h |
|
- | 2558 | push esi |
|
- | 2559 | mov ecx, 32/4 |
|
- | 2560 | rep movsd |
|
- | 2561 | pop esi |
|
- | 2562 | mov dword [edi-32], '.. ' |
|
- | 2563 | mov dword [edi-32+4], ' ' |
|
- | 2564 | mov dword [edi-32+8], ' ' |
|
- | 2565 | mov byte [edi-32+11], 10h |
|
- | 2566 | mov ecx, [esp+20+8] |
|
- | 2567 | cmp ecx, [ROOT_CLUSTER] |
|
- | 2568 | jnz @f |
|
- | 2569 | xor ecx, ecx |
|
- | 2570 | @@: |
|
- | 2571 | mov word [edi-32+26], cx |
|
- | 2572 | shr ecx, 16 |
|
- | 2573 | mov [edi-32+20], cx |
|
- | 2574 | jmp .writedircont |
|
Line 3394... | Line 2575... | ||
3394 | 2575 | ||
3395 | ;---------------------------------------------------------------- |
2576 | ;---------------------------------------------------------------- |
3396 | ; |
2577 | ; |
3397 | ; fs_HdWrite - LFN variant for writing to floppy |
2578 | ; fs_HdWrite - LFN variant for writing to hard disk |
3398 | ; |
2579 | ; |
3399 | ; esi points to filename |
2580 | ; esi points to filename |
3400 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
2581 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
3401 | ; may be ebx=0 - start from first byte |
2582 | ; may be ebx=0 - start from first byte |
Line 3416... | Line 2597... | ||
3416 | fs_HdWrite.ret11: |
2597 | fs_HdWrite.ret11: |
3417 | push 11 |
2598 | push 11 |
3418 | jmp fs_HdWrite.ret0 |
2599 | jmp fs_HdWrite.ret0 |
Line 3419... | Line 2600... | ||
3419 | 2600 | ||
3420 | fs_HdWrite: |
2601 | fs_HdWrite: |
- | 2602 | cmp [fs_type], 1 |
|
- | 2603 | jz ntfs_HdWrite |
|
- | 2604 | cmp [fs_type], 16 |
|
- | 2605 | jz @f |
|
3421 | cmp [fat_type], 0 |
2606 | cmp [fs_type], 32 |
3422 | jnz @f |
2607 | jz @f |
3423 | push ERROR_UNKNOWN_FS |
2608 | push ERROR_UNKNOWN_FS |
3424 | jmp .ret0 |
2609 | jmp .ret0 |
3425 | @@: |
2610 | @@: |
3426 | cmp byte [esi], 0 |
2611 | cmp byte [esi], 0 |
Line 3527... | Line 2712... | ||
3527 | 2712 | ||
3528 | ; now ebx=start pos, ecx=end pos, both lie inside file |
2713 | ; now ebx=start pos, ecx=end pos, both lie inside file |
3529 | sub ecx, ebx |
2714 | sub ecx, ebx |
3530 | jz .ret |
2715 | jz .ret |
- | 2716 | .write_loop: |
|
- | 2717 | ; skip unmodified sectors |
|
- | 2718 | cmp dword [esp], 0x200 |
|
- | 2719 | jb .modify |
|
- | 2720 | sub ebx, 0x200 |
|
- | 2721 | jae .skip |
|
- | 2722 | add ebx, 0x200 |
|
3531 | .write_loop: |
2723 | .modify: |
3532 | ; get length of data in current sector |
2724 | ; get length of data in current sector |
3533 | push ecx |
2725 | push ecx |
3534 | sub ebx, 0x200 |
2726 | sub ebx, 0x200 |
3535 | jb .hasdata |
2727 | jb .hasdata |
Line 3583... | Line 2775... | ||
3583 | jbe @f |
2775 | jbe @f |
3584 | mov edi, buffer |
2776 | mov edi, buffer |
3585 | add edi, esi |
2777 | add edi, esi |
3586 | rep stosb |
2778 | rep stosb |
3587 | @@: |
2779 | @@: |
3588 | pop edi ecx eax |
2780 | pop edi ecx |
3589 | ; copy new data |
2781 | ; copy new data |
3590 | push eax |
- | |
3591 | mov eax, edx |
2782 | mov eax, edx |
3592 | neg ebx |
2783 | neg ebx |
3593 | jecxz @f |
2784 | jecxz @f |
3594 | add ebx, buffer+0x200 |
2785 | add ebx, buffer+0x200 |
3595 | call memmove |
2786 | call memmove |
Line 3605... | Line 2796... | ||
3605 | jnz .device_err2 |
2796 | jnz .device_err2 |
3606 | add edx, ecx |
2797 | add edx, ecx |
3607 | sub [esp], ecx |
2798 | sub [esp], ecx |
3608 | pop ecx |
2799 | pop ecx |
3609 | jz .ret |
2800 | jz .ret |
- | 2801 | .skip: |
|
3610 | ; next sector |
2802 | ; next sector |
3611 | inc ebp |
2803 | inc ebp |
3612 | cmp ebp, [SECTORS_PER_CLUSTER] |
2804 | cmp ebp, [SECTORS_PER_CLUSTER] |
3613 | jb @f |
2805 | jb @f |
3614 | xor ebp, ebp |
2806 | xor ebp, ebp |
Line 3749... | Line 2941... | ||
3749 | ; |
2941 | ; |
3750 | ; ret eax = 0 ok or other = errormsg |
2942 | ; ret eax = 0 ok or other = errormsg |
3751 | ; |
2943 | ; |
3752 | ;-------------------------------------------------------------- |
2944 | ;-------------------------------------------------------------- |
3753 | fs_HdSetFileEnd: |
2945 | fs_HdSetFileEnd: |
3754 | cmp [fat_type], 0 |
2946 | cmp [fs_type], 1 |
- | 2947 | jz ntfs_HdSetFileEnd |
|
- | 2948 | cmp [fs_type], 16 |
|
- | 2949 | jz @f |
|
- | 2950 | cmp [fs_type], 32 |
|
3755 | jnz @f |
2951 | jz @f |
3756 | push ERROR_UNKNOWN_FS |
2952 | push ERROR_UNKNOWN_FS |
3757 | .ret: |
2953 | .ret: |
3758 | pop eax |
2954 | pop eax |
3759 | ret |
2955 | ret |
3760 | @@: |
2956 | @@: |
Line 3977... | Line 3173... | ||
3977 | mov al, 11 |
3173 | mov al, 11 |
3978 | @@: |
3174 | @@: |
3979 | ret |
3175 | ret |
Line 3980... | Line 3176... | ||
3980 | 3176 | ||
3981 | fs_HdGetFileInfo: |
3177 | fs_HdGetFileInfo: |
- | 3178 | cmp [fs_type], 1 |
|
- | 3179 | jz ntfs_HdGetFileInfo |
|
- | 3180 | cmp [fs_type], 16 |
|
- | 3181 | jz @f |
|
3982 | cmp [fat_type], 0 |
3182 | cmp [fs_type], 32 |
3983 | jnz @f |
3183 | jz @f |
3984 | mov eax, ERROR_UNKNOWN_FS |
3184 | mov eax, ERROR_UNKNOWN_FS |
3985 | ret |
3185 | ret |
3986 | @@: |
3186 | @@: |
3987 | cmp byte [esi], 0 |
3187 | cmp byte [esi], 0 |
Line 4001... | Line 3201... | ||
4001 | @@: |
3201 | @@: |
4002 | popfd |
3202 | popfd |
4003 | jmp fs_GetFileInfo_finish |
3203 | jmp fs_GetFileInfo_finish |
Line 4004... | Line 3204... | ||
4004 | 3204 | ||
4005 | fs_HdSetFileInfo: |
3205 | fs_HdSetFileInfo: |
- | 3206 | cmp [fs_type], 1 |
|
- | 3207 | jz ntfs_HdSetFileInfo |
|
- | 3208 | cmp [fs_type], 16 |
|
- | 3209 | jz @f |
|
4006 | cmp [fat_type], 0 |
3210 | cmp [fs_type], 32 |
4007 | jnz @f |
3211 | jz @f |
4008 | mov eax, ERROR_UNKNOWN_FS |
3212 | mov eax, ERROR_UNKNOWN_FS |
4009 | ret |
3213 | ret |
4010 | @@: |
3214 | @@: |
4011 | cmp byte [esi], 0 |
3215 | cmp byte [esi], 0 |
Line 4037... | Line 3241... | ||
4037 | call update_disk |
3241 | call update_disk |
4038 | pop edi |
3242 | pop edi |
4039 | xor eax, eax |
3243 | xor eax, eax |
4040 | ret |
3244 | ret |
Line -... | Line 3245... | ||
- | 3245 | ||
- | 3246 | if 0 ; starting from revision 237 execute is implemented in taskman.inc |
|
4041 | 3247 | ; through fs_XxxGetFileInfo and fs_XxxRead |
|
4042 | ;---------------------------------------------------------------- |
3248 | ;---------------------------------------------------------------- |
4043 | ; |
3249 | ; |
4044 | ; fs_HdExecute - LFN variant for executing from harddisk |
3250 | ; fs_HdExecute - LFN variant for executing from harddisk |
4045 | ; |
3251 | ; |
Line 4074... | Line 3280... | ||
4074 | ;-------------------------------------------------------------- |
3280 | ;-------------------------------------------------------------- |
Line 4075... | Line 3281... | ||
4075 | 3281 | ||
4076 | .flags: |
3282 | .flags: |
4077 | cmp [fat_type], 0 |
3283 | cmp [fat_type], 0 |
4078 | jnz @f |
3284 | jnz @f |
4079 | mov eax, ERROR_UNKNOWN_FS |
3285 | mov eax, -ERROR_UNKNOWN_FS |
4080 | ret |
3286 | ret |
4081 | @@: |
3287 | @@: |
4082 | cmp byte [esi], 0 |
3288 | cmp byte [esi], 0 |
4083 | jnz @f |
3289 | jnz @f |
Line 4156... | Line 3362... | ||
4156 | ret |
3362 | ret |
4157 | .err: |
3363 | .err: |
4158 | popad |
3364 | popad |
4159 | mov eax, 11 |
3365 | mov eax, 11 |
4160 | ret |
3366 | ret |
- | 3367 | end if |
|
- | 3368 | ||
- | 3369 | ;---------------------------------------------------------------- |
|
- | 3370 | ; |
|
- | 3371 | ; fs_HdDelete - delete file or empty folder from hard disk |
|
- | 3372 | ; |
|
- | 3373 | ; esi points to filename |
|
- | 3374 | ; |
|
- | 3375 | ; ret eax = 0 ok or other = errormsg |
|
- | 3376 | ; |
|
- | 3377 | ;-------------------------------------------------------------- |
|
- | 3378 | fs_HdDelete: |
|
- | 3379 | cmp [fs_type], 1 |
|
- | 3380 | jz ntfs_HdDelete |
|
- | 3381 | cmp [fs_type], 16 |
|
- | 3382 | jz @f |
|
- | 3383 | cmp [fs_type], 32 |
|
- | 3384 | jz @f |
|
- | 3385 | push ERROR_UNKNOWN_FS |
|
- | 3386 | .pop_ret: |
|
- | 3387 | pop eax |
|
- | 3388 | ret |
|
- | 3389 | @@: |
|
- | 3390 | cmp byte [esi], 0 |
|
- | 3391 | jnz @f |
|
- | 3392 | ; cannot delete root! |
|
- | 3393 | .access_denied: |
|
- | 3394 | push ERROR_ACCESS_DENIED |
|
- | 3395 | jmp .pop_ret |
|
- | 3396 | @@: |
|
- | 3397 | and [longname_sec1], 0 |
|
- | 3398 | and [longname_sec2], 0 |
|
- | 3399 | push edi |
|
- | 3400 | call hd_find_lfn |
|
- | 3401 | jnc .found |
|
- | 3402 | pop edi |
|
- | 3403 | push ERROR_FILE_NOT_FOUND |
|
- | 3404 | jmp .pop_ret |
|
- | 3405 | .found: |
|
- | 3406 | cmp dword [edi], '. ' |
|
- | 3407 | jz .access_denied2 |
|
- | 3408 | cmp dword [edi], '.. ' |
|
- | 3409 | jz .access_denied2 |
|
- | 3410 | test byte [edi+11], 10h |
|
- | 3411 | jz .dodel |
|
- | 3412 | ; we can delete only empty folders! |
|
- | 3413 | pushad |
|
- | 3414 | mov ebp, [edi+20-2] |
|
- | 3415 | mov bp, [edi+26] |
|
- | 3416 | xor ecx, ecx |
|
- | 3417 | lea eax, [ebp-2] |
|
- | 3418 | imul eax, [SECTORS_PER_CLUSTER] |
|
- | 3419 | add eax, [DATA_START] |
|
- | 3420 | mov ebx, buffer |
|
- | 3421 | call hd_read |
|
- | 3422 | cmp [hd_error], 0 |
|
- | 3423 | jnz .err1 |
|
- | 3424 | add ebx, 2*0x20 |
|
- | 3425 | .checkempty: |
|
- | 3426 | cmp byte [ebx], 0 |
|
- | 3427 | jz .empty |
|
- | 3428 | cmp byte [ebx], 0xE5 |
|
- | 3429 | jnz .notempty |
|
- | 3430 | add ebx, 0x20 |
|
- | 3431 | cmp ebx, buffer+0x200 |
|
- | 3432 | jb .checkempty |
|
- | 3433 | inc ecx |
|
- | 3434 | cmp ecx, [SECTORS_PER_CLUSTER] |
|
- | 3435 | jb @f |
|
- | 3436 | mov eax, ebp |
|
- | 3437 | call get_FAT |
|
- | 3438 | cmp [hd_error], 0 |
|
- | 3439 | jnz .err1 |
|
- | 3440 | mov ebp, eax |
|
- | 3441 | xor ecx, ecx |
|
- | 3442 | @@: |
|
- | 3443 | lea eax, [ebp-2] |
|
- | 3444 | imul eax, [SECTORS_PER_CLUSTER] |
|
- | 3445 | add eax, [DATA_START] |
|
- | 3446 | add eax, ecx |
|
- | 3447 | mov ebx, buffer |
|
- | 3448 | call hd_read |
|
- | 3449 | cmp [hd_error], 0 |
|
- | 3450 | jz .checkempty |
|
- | 3451 | .err1: |
|
- | 3452 | popad |
|
- | 3453 | .err2: |
|
- | 3454 | pop edi |
|
- | 3455 | push 11 |
|
- | 3456 | pop eax |
|
- | 3457 | ret |
|
- | 3458 | .notempty: |
|
- | 3459 | popad |
|
- | 3460 | .access_denied2: |
|
- | 3461 | pop edi |
|
- | 3462 | push ERROR_ACCESS_DENIED |
|
- | 3463 | pop eax |
|
- | 3464 | ret |
|
- | 3465 | .empty: |
|
- | 3466 | popad |
|
- | 3467 | push ebx |
|
- | 3468 | mov ebx, buffer |
|
- | 3469 | call hd_read |
|
- | 3470 | pop ebx |
|
- | 3471 | cmp [hd_error], 0 |
|
- | 3472 | jnz .err2 |
|
- | 3473 | .dodel: |
|
- | 3474 | push eax |
|
- | 3475 | mov eax, [edi+20-2] |
|
- | 3476 | mov ax, [edi+26] |
|
- | 3477 | xchg eax, [esp] |
|
- | 3478 | ; delete folder entry |
|
- | 3479 | mov byte [edi], 0xE5 |
|
- | 3480 | ; delete LFN (if present) |
|
- | 3481 | .lfndel: |
|
- | 3482 | cmp edi, buffer |
|
- | 3483 | ja @f |
|
- | 3484 | cmp [longname_sec2], 0 |
|
- | 3485 | jz .lfndone |
|
- | 3486 | push [longname_sec2] |
|
- | 3487 | push [longname_sec1] |
|
- | 3488 | pop [longname_sec2] |
|
- | 3489 | and [longname_sec1], 0 |
|
- | 3490 | push ebx |
|
- | 3491 | mov ebx, buffer |
|
- | 3492 | call hd_write |
|
- | 3493 | mov eax, [esp+4] |
|
- | 3494 | call hd_read |
|
- | 3495 | pop ebx |
|
- | 3496 | pop eax |
|
- | 3497 | mov edi, buffer+0x200 |
|
- | 3498 | @@: |
|
- | 3499 | sub edi, 0x20 |
|
- | 3500 | cmp byte [edi], 0xE5 |
|
- | 3501 | jz .lfndone |
|
- | 3502 | cmp byte [edi+11], 0xF |
|
- | 3503 | jnz .lfndone |
|
- | 3504 | mov byte [edi], 0xE5 |
|
- | 3505 | jmp .lfndel |
|
- | 3506 | .lfndone: |
|
- | 3507 | push ebx |
|
- | 3508 | mov ebx, buffer |
|
- | 3509 | call hd_write |
|
- | 3510 | pop ebx |
|
- | 3511 | ; delete FAT chain |
|
- | 3512 | pop eax |
|
- | 3513 | call clear_cluster_chain |
|
- | 3514 | call update_disk |
|
- | 3515 | pop edi |
|
- | 3516 | xor eax, eax |
|
- | 3517 | cmp [hd_error], 0 |
|
- | 3518 | jz @f |
|
- | 3519 | mov al, 11 |
|
- | 3520 | @@: |
|
- | 3521 | ret |
|
Line 4161... | Line 3522... | ||
4161 | 3522 |