Rev 71 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 71 | Rev 74 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | ;; FAT16/32 functions for MenuetOS ;; |
5 | ;; FAT16/32 functions for MenuetOS ;; |
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 | ;; 29.04.2006 Elimination of hangup after the ;; |
|
10 | ;; ;; |
11 | ;; expiration hd_wait_timeout - Mario79 ;; |
11 | ;; 23.04.2006 LFN read - diamond ;; |
12 | ;; 23.04.2006 LFN read - diamond ;; |
12 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
13 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
13 | ;; to MBR, see file part_set.inc - Mario79 ;; |
14 | ;; to MBR, see file part_set.inc - Mario79 ;; |
14 | ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; |
15 | ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; |
15 | ;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;; |
16 | ;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;; |
Line 171... | Line 172... | ||
171 | je sfc_in_cache ; yes |
172 | je sfc_in_cache ; yes |
Line 172... | Line 173... | ||
172 | 173 | ||
173 | cmp [fat_change],0 ; is fat changed? |
174 | cmp [fat_change],0 ; is fat changed? |
174 | je sfc_no_change ; no |
175 | je sfc_no_change ; no |
- | 176 | call write_fat_sector ; yes. write it into disk |
|
- | 177 | cmp [hd_error],0 |
|
Line 175... | Line 178... | ||
175 | call write_fat_sector ; yes. write it into disk |
178 | jne sfc_error |
176 | 179 | ||
177 | sfc_no_change: |
180 | sfc_no_change: |
- | 181 | mov [fat_in_cache],eax ; save fat sector |
|
- | 182 | call hd_read |
|
- | 183 | cmp [hd_error],0 |
|
Line 178... | Line 184... | ||
178 | mov [fat_in_cache],eax ; save fat sector |
184 | jne sfc_error |
179 | call hd_read |
185 | |
180 | 186 | ||
Line 245... | Line 251... | ||
245 | je gfc_in_cache |
251 | je gfc_in_cache |
Line 246... | Line 252... | ||
246 | 252 | ||
247 | cmp [fat_change],0 ; is fat changed? |
253 | cmp [fat_change],0 ; is fat changed? |
248 | je gfc_no_change ; no |
254 | je gfc_no_change ; no |
- | 255 | call write_fat_sector ; yes. write it into disk |
|
- | 256 | cmp [hd_error],0 |
|
Line 249... | Line 257... | ||
249 | call write_fat_sector ; yes. write it into disk |
257 | jne hd_error_01 |
250 | 258 | ||
251 | gfc_no_change: |
259 | gfc_no_change: |
- | 260 | mov [fat_in_cache],eax |
|
- | 261 | call hd_read |
|
Line 252... | Line 262... | ||
252 | mov [fat_in_cache],eax |
262 | cmp [hd_error],0 |
253 | call hd_read |
263 | jne hd_error_01 |
254 | 264 | ||
- | 265 | gfc_in_cache: |
|
255 | gfc_in_cache: |
266 | mov eax,[ebx+esi] |
256 | mov eax,[ebx+esi] |
267 | and eax,[fatMASK] |
Line 257... | Line 268... | ||
257 | and eax,[fatMASK] |
268 | hd_error_01: |
Line 276... | Line 287... | ||
276 | mov eax,2 |
287 | mov eax,2 |
Line 277... | Line 288... | ||
277 | 288 | ||
278 | gff_in_range: |
289 | gff_in_range: |
279 | push eax |
290 | push eax |
- | 291 | call get_FAT ; get cluster state |
|
- | 292 | cmp [hd_error],0 |
|
- | 293 | jne gff_not_found_1 |
|
280 | call get_FAT ; get cluster state |
294 | |
281 | test eax,eax ; is it free? |
295 | test eax,eax ; is it free? |
282 | pop eax |
296 | pop eax |
283 | je gff_found ; yes |
297 | je gff_found ; yes |
284 | inc eax ; next cluster |
298 | inc eax ; next cluster |
285 | dec ecx ; is all checked? |
299 | dec ecx ; is all checked? |
Line -... | Line 300... | ||
- | 300 | jns gff_test ; no |
|
- | 301 | ||
286 | jns gff_test ; no |
302 | gff_not_found_1: |
287 | 303 | add esp,4 |
|
288 | gff_not_found: |
304 | gff_not_found: |
289 | pop ecx ; yes. disk is full |
305 | pop ecx ; yes. disk is full |
Line 309... | Line 325... | ||
309 | mov ebx,fat_cache |
325 | mov ebx,fat_cache |
310 | mov ecx,[NUMBER_OF_FATS] |
326 | mov ecx,[NUMBER_OF_FATS] |
Line 311... | Line 327... | ||
311 | 327 | ||
312 | write_next_fat: |
328 | write_next_fat: |
- | 329 | call hd_write |
|
- | 330 | cmp [hd_error],0 |
|
- | 331 | jne write_fat_not_used |
|
313 | call hd_write |
332 | |
314 | add eax,[SECTORS_PER_FAT] |
333 | add eax,[SECTORS_PER_FAT] |
315 | dec ecx |
334 | dec ecx |
Line 316... | Line 335... | ||
316 | jnz write_next_fat |
335 | jnz write_next_fat |
Line 359... | Line 378... | ||
359 | add eax,[DATA_START] |
378 | add eax,[DATA_START] |
Line 360... | Line 379... | ||
360 | 379 | ||
361 | adr_new_sector: |
380 | adr_new_sector: |
362 | mov ebx,buffer |
381 | mov ebx,buffer |
- | 382 | call hd_read |
|
- | 383 | cmp [hd_error],0 |
|
- | 384 | jne adr_not_found |
|
363 | call hd_read |
385 | |
Line 364... | Line 386... | ||
364 | mov ecx,512/32 ; count of dir entrys per sector = 16 |
386 | mov ecx,512/32 ; count of dir entrys per sector = 16 |
365 | 387 | ||
366 | adr_analyze: |
388 | adr_analyze: |
Line 395... | Line 417... | ||
395 | je adr_not_found |
417 | je adr_not_found |
Line 396... | Line 418... | ||
396 | 418 | ||
397 | adr_next_cluster: |
419 | adr_next_cluster: |
398 | mov eax,[cluster_tmp] |
420 | mov eax,[cluster_tmp] |
- | 421 | call get_FAT ; get next cluster |
|
- | 422 | cmp [hd_error],0 |
|
- | 423 | jne adr_not_found |
|
399 | call get_FAT ; get next cluster |
424 | |
400 | cmp eax,2 ; incorrect fat chain? |
425 | cmp eax,2 ; incorrect fat chain? |
401 | jb adr_not_found ; yes |
426 | jb adr_not_found ; yes |
402 | cmp eax,[fatRESERVED] ; is it end of directory? |
427 | cmp eax,[fatRESERVED] ; is it end of directory? |
Line 448... | Line 473... | ||
448 | add eax,[DATA_START] |
473 | add eax,[DATA_START] |
Line 449... | Line 474... | ||
449 | 474 | ||
450 | adw_new_sector: |
475 | adw_new_sector: |
451 | mov ebx,buffer |
476 | mov ebx,buffer |
- | 477 | call hd_read |
|
- | 478 | cmp [hd_error],0 |
|
- | 479 | jne adw_not_found |
|
452 | call hd_read |
480 | |
Line 453... | Line 481... | ||
453 | mov ecx,512/32 ; count of dir entrys per sector = 16 |
481 | mov ecx,512/32 ; count of dir entrys per sector = 16 |
454 | 482 | ||
455 | adw_analyze: |
483 | adw_analyze: |
Line 467... | Line 495... | ||
467 | cmp [fat16_root],1 ; end of fat16 rootdir |
495 | cmp [fat16_root],1 ; end of fat16 rootdir |
468 | je adw_not_found |
496 | je adw_not_found |
Line 469... | Line 497... | ||
469 | 497 | ||
470 | mov eax,[cluster_tmp] |
498 | mov eax,[cluster_tmp] |
- | 499 | call get_FAT ; get next cluster |
|
- | 500 | cmp [hd_error],0 |
|
- | 501 | jne adw_not_found |
|
471 | call get_FAT ; get next cluster |
502 | |
472 | cmp eax,2 ; incorrect fat chain? |
503 | cmp eax,2 ; incorrect fat chain? |
473 | jb adw_not_found ; yes |
504 | jb adw_not_found ; yes |
474 | cmp eax,[fatRESERVED] ; is it end of directory? |
505 | cmp eax,[fatRESERVED] ; is it end of directory? |
Line 478... | Line 509... | ||
478 | call get_free_FAT ; for the directory because the directory |
509 | call get_free_FAT ; for the directory because the directory |
479 | jc adw_not_found ; is full |
510 | jc adw_not_found ; is full |
Line 480... | Line 511... | ||
480 | 511 | ||
481 | mov edx,[fatEND] ; new end for directory |
512 | mov edx,[fatEND] ; new end for directory |
- | 513 | call set_FAT |
|
- | 514 | cmp [hd_error],0 |
|
Line 482... | Line 515... | ||
482 | call set_FAT |
515 | jne adw_not_found |
483 | 516 | ||
484 | push eax ; save new cluster |
517 | push eax ; save new cluster |
485 | mov edx,eax |
518 | mov edx,eax |
486 | mov eax,[cluster_tmp] ; change last cluster to point new cluster |
519 | mov eax,[cluster_tmp] ; change last cluster to point new cluster |
- | 520 | mov [f_del],1 |
|
- | 521 | call set_FAT |
|
- | 522 | cmp [hd_error],0 |
|
487 | mov [f_del],1 |
523 | jne adw_not_found_1 |
Line 488... | Line 524... | ||
488 | call set_FAT |
524 | |
489 | mov [f_del],0 |
525 | mov [f_del],0 |
- | 526 | ||
- | 527 | mov ecx,-1 ; remove 1 cluster from free disk space |
|
Line 490... | Line 528... | ||
490 | 528 | call add_disk_free_space |
|
491 | mov ecx,-1 ; remove 1 cluster from free disk space |
529 | cmp [hd_error],0 |
492 | call add_disk_free_space |
530 | jne adw_not_found_1 |
493 | 531 | ||
Line 505... | Line 543... | ||
505 | mov ebx,buffer |
543 | mov ebx,buffer |
506 | push eax ; save sector number |
544 | push eax ; save sector number |
Line 507... | Line 545... | ||
507 | 545 | ||
508 | adw_set_empty_directory: |
546 | adw_set_empty_directory: |
- | 547 | call hd_write |
|
- | 548 | cmp [hd_error],0 |
|
- | 549 | jne adw_not_found_1 |
|
509 | call hd_write |
550 | |
510 | inc eax ; next sector |
551 | inc eax ; next sector |
511 | dec ecx |
552 | dec ecx |
Line 512... | Line 553... | ||
512 | jnz adw_set_empty_directory |
553 | jnz adw_set_empty_directory |
Line 513... | Line 554... | ||
513 | 554 | ||
514 | pop eax |
555 | pop eax |
515 | 556 | ||
516 | adw_found: |
557 | adw_found: |
- | 558 | pop edi edx ecx |
|
517 | pop edi edx ecx |
559 | clc ; free space found |
518 | clc ; free space found |
560 | ret |
519 | ret |
561 | adw_not_found_1: |
520 | 562 | add esp,4 |
|
521 | adw_not_found: |
563 | adw_not_found: |
Line 562... | Line 604... | ||
562 | dec esi |
604 | dec esi |
563 | jmp gdcl2 |
605 | jmp gdcl2 |
Line 564... | Line 606... | ||
564 | 606 | ||
565 | gdcl1: |
607 | gdcl1: |
- | 608 | call hd_read |
|
- | 609 | cmp [hd_error],0 |
|
- | 610 | jne gdc_error |
|
566 | call hd_read |
611 | |
567 | add ebx,512 ; update pointer |
612 | add ebx,512 ; update pointer |
Line 568... | Line 613... | ||
568 | dec edx |
613 | dec edx |
569 | 614 | ||
Line 604... | Line 649... | ||
604 | imul eax,edx |
649 | imul eax,edx |
605 | add eax,[DATA_START] |
650 | add eax,[DATA_START] |
Line 606... | Line 651... | ||
606 | 651 | ||
607 | sdc_write: |
652 | sdc_write: |
- | 653 | call hd_write |
|
- | 654 | cmp [hd_error],0 |
|
- | 655 | jne sdc_error |
|
608 | call hd_write |
656 | |
609 | add ebx,512 ; update pointer |
657 | add ebx,512 ; update pointer |
610 | inc eax |
658 | inc eax |
611 | dec edx |
659 | dec edx |
612 | jnz sdc_write |
660 | jnz sdc_write |
Line 766... | Line 814... | ||
766 | pushad |
814 | pushad |
Line 767... | Line 815... | ||
767 | 815 | ||
768 | mov ebx,edx |
816 | mov ebx,edx |
769 | call get_cluster_of_a_path |
817 | call get_cluster_of_a_path |
- | 818 | jnc make_dir_found_path |
|
- | 819 | cmp [hd_error],0 |
|
Line 770... | Line 820... | ||
770 | jnc make_dir_found_path |
820 | jne make_dir_error_1 |
771 | 821 | ||
772 | make_dir_path_not_found: |
822 | make_dir_path_not_found: |
- | 823 | popad |
|
- | 824 | call update_disk ; write all of cache and fat to hd |
|
- | 825 | cmp [hd_error],0 |
|
773 | popad |
826 | jne make_dir_error_2 |
774 | call update_disk ; write all of cache and fat to hd |
827 | |
775 | mov [hd1_status],0 |
828 | mov [hd1_status],0 |
Line 776... | Line 829... | ||
776 | mov eax,ERROR_FILE_NOT_FOUND |
829 | mov eax,ERROR_FILE_NOT_FOUND |
- | 830 | ret |
|
- | 831 | ||
777 | ret |
832 | make_dir_disk_full: |
778 | 833 | cmp [hd_error],0 |
|
- | 834 | jne make_dir_error_1 |
|
- | 835 | popad |
|
- | 836 | call update_disk ; write all of cache and fat to hd |
|
779 | make_dir_disk_full: |
837 | cmp [hd_error],0 |
780 | popad |
838 | jne make_dir_error_2 |
781 | call update_disk ; write all of cache and fat to hd |
839 | |
Line 782... | Line 840... | ||
782 | mov [hd1_status],0 |
840 | mov [hd1_status],0 |
- | 841 | mov eax,ERROR_DISK_FULL |
|
- | 842 | ret |
|
783 | mov eax,ERROR_DISK_FULL |
843 | |
784 | ret |
844 | make_dir_already_exist: |
785 | 845 | cmp [hd_error],0 |
|
786 | make_dir_already_exist: |
846 | jne make_dir_error_1 |
- | 847 | mov eax,[cluster] ; directory cluster |
|
- | 848 | xor edx,edx ; free |
|
- | 849 | mov [f_del],1 |
|
787 | mov eax,[cluster] ; directory cluster |
850 | call set_FAT |
Line 788... | Line 851... | ||
788 | xor edx,edx ; free |
851 | cmp [hd_error],0 |
789 | mov [f_del],1 |
852 | jne make_dir_error_1 |
- | 853 | ||
790 | call set_FAT |
854 | mov [f_del],0 |
791 | mov [f_del],0 |
855 | |
792 | 856 | popad |
|
Line -... | Line 857... | ||
- | 857 | call update_disk ; write all of cache and fat to hd |
|
- | 858 | make_dir_error_2: |
|
- | 859 | mov [hd1_status],0 |
|
- | 860 | mov eax,ERROR_ACCESS_DENIED |
|
- | 861 | ret |
|
- | 862 | ||
- | 863 | make_dir_error_1: |
|
- | 864 | popad |
|
793 | popad |
865 | jmp make_dir_error_2 |
794 | call update_disk ; write all of cache and fat to hd |
866 | |
795 | mov [hd1_status],0 |
867 | make_dir_error_3: |
796 | mov eax,ERROR_ACCESS_DENIED |
868 | add esp,4 |
Line 816... | Line 888... | ||
816 | 888 | ||
817 | push eax |
889 | push eax |
818 | mov eax,[cluster] ; directory cluster |
890 | mov eax,[cluster] ; directory cluster |
819 | mov edx,[fatEND] ; end for directory |
891 | mov edx,[fatEND] ; end for directory |
- | 892 | call set_FAT |
|
- | 893 | cmp [hd_error],0 |
|
820 | call set_FAT |
894 | jne make_dir_error_3 |
Line 821... | Line 895... | ||
821 | pop eax |
895 | pop eax |
822 | 896 | ||
823 | mov ebx,PUSHAD_EAX ; dir name |
897 | mov ebx,PUSHAD_EAX ; dir name |
- | 898 | push eax |
|
- | 899 | call analyze_directory ; check if directory already exist |
|
- | 900 | cmp [hd_error],0 |
|
824 | push eax |
901 | jne make_dir_error_1 |
825 | call analyze_directory ; check if directory already exist |
902 | |
Line 826... | Line 903... | ||
826 | pop eax |
903 | pop eax |
827 | jnc make_dir_already_exist ; need to free allocated cluster! |
904 | jnc make_dir_already_exist ; need to free allocated cluster! |
Line 849... | Line 926... | ||
849 | mov dword [NewDirEntry1+22],ecx |
926 | mov dword [NewDirEntry1+22],ecx |
850 | mov dword [NewDirEntry2+22],ecx |
927 | mov dword [NewDirEntry2+22],ecx |
Line 851... | Line 928... | ||
851 | 928 | ||
852 | mov ebx,buffer ; save the directory name,length,cluster |
929 | mov ebx,buffer ; save the directory name,length,cluster |
- | 930 | call hd_write |
|
- | 931 | cmp [hd_error],0 |
|
Line 853... | Line 932... | ||
853 | call hd_write |
932 | jne make_dir_error_1 |
854 | 933 | ||
855 | mov ecx,512/4 |
934 | mov ecx,512/4 |
856 | xor eax,eax |
935 | xor eax,eax |
Line 876... | Line 955... | ||
876 | cld |
955 | cld |
877 | rep movsd ; copy 2 first directory entrys "." and ".." |
956 | rep movsd ; copy 2 first directory entrys "." and ".." |
Line 878... | Line 957... | ||
878 | 957 | ||
879 | not_first_sector: |
958 | not_first_sector: |
- | 959 | call hd_write |
|
- | 960 | cmp [hd_error],0 |
|
- | 961 | jne make_dir_error_1 |
|
880 | call hd_write |
962 | |
881 | dec edx |
963 | dec edx |
Line 882... | Line 964... | ||
882 | jnz dir_set_empty_directory |
964 | jnz dir_set_empty_directory |
883 | 965 | ||
- | 966 | mov ecx,-1 ; remove 1 cluster from free disk space |
|
- | 967 | call add_disk_free_space |
|
Line 884... | Line 968... | ||
884 | mov ecx,-1 ; remove 1 cluster from free disk space |
968 | cmp [hd_error],0 |
885 | call add_disk_free_space |
969 | jne make_dir_error_1 |
- | 970 | ||
- | 971 | popad |
|
886 | 972 | call update_disk ; write all of cache and fat to hd |
|
887 | popad |
973 | cmp [hd_error],0 |
888 | call update_disk ; write all of cache and fat to hd |
974 | jne make_dir_error_2 |
Line 909... | Line 995... | ||
909 | ; call reserve_hd1 |
995 | ; call reserve_hd1 |
Line 910... | Line 996... | ||
910 | 996 | ||
911 | push edi |
997 | push edi |
912 | mov edi,1 ; allow directory remove |
998 | mov edi,1 ; allow directory remove |
- | 999 | call file_delete |
|
- | 1000 | cmp [hd_error],0 |
|
- | 1001 | jne @f |
|
913 | call file_delete |
1002 | |
Line 914... | Line 1003... | ||
914 | pop edi |
1003 | pop edi |
- | 1004 | ||
915 | 1005 | call update_disk ; write all of cache and fat to hd |
|
916 | call update_disk ; write all of cache and fat to hd |
1006 | @@: |
Line 917... | Line 1007... | ||
917 | mov [hd1_status],0 |
1007 | mov [hd1_status],0 |
Line 931... | Line 1021... | ||
931 | 1021 | ||
932 | push eax ebx |
1022 | push eax ebx |
933 | mov eax,[ADR_FSINFO] |
1023 | mov eax,[ADR_FSINFO] |
934 | mov ebx,buffer |
1024 | mov ebx,buffer |
- | 1025 | call hd_read |
|
- | 1026 | cmp [hd_error],0 |
|
- | 1027 | jne add_not_fs |
|
935 | call hd_read |
1028 | |
936 | cmp dword [ebx+0x1fc],0xaa550000 ; check sector id |
1029 | cmp dword [ebx+0x1fc],0xaa550000 ; check sector id |
Line 937... | Line 1030... | ||
937 | jne add_not_fs |
1030 | jne add_not_fs |
938 | 1031 | ||
- | 1032 | add [ebx+0x1e8],ecx |
|
- | 1033 | call hd_write |
|
Line 939... | Line 1034... | ||
939 | add [ebx+0x1e8],ecx |
1034 | cmp [hd_error],0 |
940 | call hd_write |
1035 | jne add_not_fs |
Line 941... | Line 1036... | ||
941 | 1036 | ||
Line 1017... | Line 1112... | ||
1017 | mov [ebx+26],cx ; 16 bits low of cluster |
1112 | mov [ebx+26],cx ; 16 bits low of cluster |
1018 | shr ecx,16 |
1113 | shr ecx,16 |
1019 | mov [ebx+20],cx ; 16 bits high of cluster (=0 fat16) |
1114 | mov [ebx+20],cx ; 16 bits high of cluster (=0 fat16) |
1020 | mov edx,[fatEND] ; new end for cluster chain |
1115 | mov edx,[fatEND] ; new end for cluster chain |
1021 | call set_FAT |
1116 | call set_FAT |
- | 1117 | cmp [hd_error],0 |
|
- | 1118 | jne append_access |
|
Line 1022... | Line 1119... | ||
1022 | 1119 | ||
1023 | push eax ; save first cluster |
1120 | push eax ; save first cluster |
1024 | mov eax,[sector_tmp] |
1121 | mov eax,[sector_tmp] |
1025 | mov ebx,buffer |
1122 | mov ebx,buffer |
- | 1123 | call hd_write ; write new file entry back to disk |
|
- | 1124 | cmp [hd_error],0 |
|
- | 1125 | jne append_access_1 |
|
1026 | call hd_write ; write new file entry back to disk |
1126 | |
Line 1027... | Line 1127... | ||
1027 | pop eax |
1127 | pop eax |
1028 | 1128 | ||
1029 | append_remove_free: |
1129 | append_remove_free: |
- | 1130 | mov ecx,-1 ; remove 1 cluster from free disk space |
|
- | 1131 | call add_disk_free_space ; Note: uses buffer |
|
Line 1030... | Line 1132... | ||
1030 | mov ecx,-1 ; remove 1 cluster from free disk space |
1132 | cmp [hd_error],0 |
1031 | call add_disk_free_space ; Note: uses buffer |
1133 | jne append_access |
1032 | 1134 | ||
1033 | append_found_cluster: |
1135 | append_found_cluster: |
1034 | mov [cluster],eax |
1136 | mov [cluster],eax |
1035 | sub eax,2 |
1137 | sub eax,2 |
1036 | mov ecx,[SECTORS_PER_CLUSTER] |
1138 | mov ecx,[SECTORS_PER_CLUSTER] |
Line 1037... | Line 1139... | ||
1037 | imul eax,ecx |
1139 | imul eax,ecx |
- | 1140 | add eax,[DATA_START] |
|
- | 1141 | xor edi,edi |
|
1038 | add eax,[DATA_START] |
1142 | |
1039 | xor edi,edi |
1143 | append_new_sector: |
1040 | 1144 | cmp [hd_error],0 |
|
1041 | append_new_sector: |
1145 | jne append_access |
1042 | push ecx |
1146 | push ecx |
Line 1050... | Line 1154... | ||
1050 | append_bytes_ok: |
1154 | append_bytes_ok: |
1051 | cmp ecx,512 ; overwrite full sector? |
1155 | cmp ecx,512 ; overwrite full sector? |
1052 | jz append_full_sector ; yes |
1156 | jz append_full_sector ; yes |
1053 | mov ebx,buffer ; overwrite part of sector |
1157 | mov ebx,buffer ; overwrite part of sector |
1054 | call hd_read ; read old sector |
1158 | call hd_read ; read old sector |
- | 1159 | cmp [hd_error],0 |
|
- | 1160 | jne append_access_1 |
|
Line 1055... | Line 1161... | ||
1055 | 1161 | ||
1056 | append_full_sector: |
1162 | append_full_sector: |
1057 | sub [bytes2write],ecx |
1163 | sub [bytes2write],ecx |
1058 | add [new_filepos],ecx |
1164 | add [new_filepos],ecx |
Line 1061... | Line 1167... | ||
1061 | rep movsb |
1167 | rep movsb |
1062 | pop ecx |
1168 | pop ecx |
Line 1063... | Line 1169... | ||
1063 | 1169 | ||
1064 | mov ebx,buffer |
1170 | mov ebx,buffer |
- | 1171 | call hd_write |
|
- | 1172 | cmp [hd_error],0 |
|
- | 1173 | jne append_access |
|
1065 | call hd_write |
1174 | |
1066 | cmp [bytes2write],0 ; is all done? |
1175 | cmp [bytes2write],0 ; is all done? |
1067 | jz append_done |
1176 | jz append_done |
1068 | xor edi,edi |
1177 | xor edi,edi |
1069 | inc eax |
1178 | inc eax |
1070 | dec ecx |
1179 | dec ecx |
Line 1071... | Line 1180... | ||
1071 | jnz append_new_sector |
1180 | jnz append_new_sector |
1072 | 1181 | ||
- | 1182 | mov eax,[cluster] |
|
- | 1183 | call get_FAT |
|
- | 1184 | cmp [hd_error],0 |
|
1073 | mov eax,[cluster] |
1185 | jne append_access |
1074 | call get_FAT |
1186 | |
1075 | cmp eax,2 |
1187 | cmp eax,2 |
1076 | jb append_fat |
1188 | jb append_fat |
Line 1082... | Line 1194... | ||
1082 | call get_free_FAT ; of last free cluster |
1194 | call get_free_FAT ; of last free cluster |
1083 | jc append_disk_full |
1195 | jc append_disk_full |
1084 | push eax ; save new cluster |
1196 | push eax ; save new cluster |
1085 | mov edx,[fatEND] ; new end for cluster chain |
1197 | mov edx,[fatEND] ; new end for cluster chain |
1086 | call set_FAT |
1198 | call set_FAT |
- | 1199 | cmp [hd_error],0 |
|
- | 1200 | jne append_access_1 |
|
- | 1201 | ||
1087 | mov edx,eax |
1202 | mov edx,eax |
1088 | mov eax,[cluster] |
1203 | mov eax,[cluster] |
1089 | mov [f_del],1 |
1204 | mov [f_del],1 |
1090 | call set_FAT ; update previous cluster |
1205 | call set_FAT ; update previous cluster |
- | 1206 | cmp [hd_error],0 |
|
- | 1207 | jne append_access_1 |
|
- | 1208 | ||
1091 | mov [f_del],0 |
1209 | mov [f_del],0 |
1092 | pop eax |
1210 | pop eax |
1093 | jmp append_remove_free |
1211 | jmp append_remove_free |
Line 1094... | Line 1212... | ||
1094 | 1212 | ||
Line 1102... | Line 1220... | ||
1102 | append_fat: |
1220 | append_fat: |
1103 | mov eax,ERROR_FAT_TABLE |
1221 | mov eax,ERROR_FAT_TABLE |
1104 | jmp append_ret_code |
1222 | jmp append_ret_code |
Line 1105... | Line 1223... | ||
1105 | 1223 | ||
- | 1224 | append_disk_full: |
|
- | 1225 | cmp [hd_error],0 |
|
1106 | append_disk_full: |
1226 | jne append_access |
1107 | mov eax,ERROR_DISK_FULL |
1227 | mov eax,ERROR_DISK_FULL |
Line 1108... | Line 1228... | ||
1108 | jmp append_ret_code |
1228 | jmp append_ret_code |
1109 | 1229 | ||
Line 1114... | Line 1234... | ||
1114 | mov PUSHAD_EAX,eax ; return code |
1234 | mov PUSHAD_EAX,eax ; return code |
Line 1115... | Line 1235... | ||
1115 | 1235 | ||
1116 | mov eax,[sector_tmp] ; update directory entry |
1236 | mov eax,[sector_tmp] ; update directory entry |
1117 | mov ebx,buffer |
1237 | mov ebx,buffer |
- | 1238 | call hd_read |
|
- | 1239 | cmp [hd_error],0 |
|
- | 1240 | jne append_access |
|
1118 | call hd_read |
1241 | |
1119 | mov ebx,[entry_pos] |
1242 | mov ebx,[entry_pos] |
1120 | mov ecx,[new_filepos] |
1243 | mov ecx,[new_filepos] |
1121 | cmp ecx,[old_filesize] ; is file pos above old size? |
1244 | cmp ecx,[old_filesize] ; is file pos above old size? |
1122 | jbe append_size_ok ; no |
1245 | jbe append_size_ok ; no |
Line 1123... | Line 1246... | ||
1123 | mov [ebx+28],ecx ; new file size |
1246 | mov [ebx+28],ecx ; new file size |
1124 | 1247 | ||
1125 | append_size_ok: |
1248 | append_size_ok: |
1126 | call set_current_time_for_entry |
1249 | call set_current_time_for_entry |
- | 1250 | mov ebx,buffer |
|
- | 1251 | call hd_write ; write new file entry back to disk |
|
Line 1127... | Line 1252... | ||
1127 | mov ebx,buffer |
1252 | cmp [hd_error],0 |
1128 | call hd_write ; write new file entry back to disk |
1253 | jne append_access |
1129 | 1254 | ||
1130 | sub ecx,PUSHAD_ESI ; start position |
1255 | sub ecx,PUSHAD_ESI ; start position |
- | 1256 | mov PUSHAD_EBX,ecx ; bytes written |
|
- | 1257 | popad |
|
- | 1258 | call update_disk ; write all of cache and fat to hd |
|
1131 | mov PUSHAD_EBX,ecx ; bytes written |
1259 | cmp [hd_error],0 |
1132 | popad |
1260 | jne append_access_2 |
Line 1133... | Line 1261... | ||
1133 | call update_disk ; write all of cache and fat to hd |
1261 | |
1134 | mov [hd1_status],0 |
1262 | mov [hd1_status],0 |
Line 1140... | Line 1268... | ||
1140 | xor ebx,ebx |
1268 | xor ebx,ebx |
1141 | mov eax,ERROR_END_OF_FILE |
1269 | mov eax,ERROR_END_OF_FILE |
1142 | ret |
1270 | ret |
Line 1143... | Line 1271... | ||
1143 | 1271 | ||
- | 1272 | append_not_found: |
|
- | 1273 | cmp [hd_error],0 |
|
1144 | append_not_found: |
1274 | jne append_access |
1145 | popad |
1275 | popad |
1146 | mov [hd1_status],0 |
1276 | mov [hd1_status],0 |
1147 | xor ebx,ebx |
1277 | xor ebx,ebx |
1148 | mov eax,ERROR_FILE_NOT_FOUND |
1278 | mov eax,ERROR_FILE_NOT_FOUND |
- | 1279 | ret |
|
1149 | ret |
1280 | append_access_1: |
1150 | 1281 | add esp,4 |
|
1151 | append_access: |
1282 | append_access: |
- | 1283 | popad |
|
1152 | popad |
1284 | append_access_2: |
1153 | mov [hd1_status],0 |
1285 | mov [hd1_status],0 |
1154 | xor ebx,ebx |
1286 | xor ebx,ebx |
1155 | mov eax,ERROR_ACCESS_DENIED |
1287 | mov eax,ERROR_ACCESS_DENIED |
Line 1167... | Line 1299... | ||
1167 | 1299 | ||
1168 | truncate_save_size: |
1300 | truncate_save_size: |
1169 | call set_current_time_for_entry |
1301 | call set_current_time_for_entry |
1170 | mov ebx,buffer |
1302 | mov ebx,buffer |
- | 1303 | call hd_write |
|
- | 1304 | cmp [hd_error],0 |
|
- | 1305 | jne append_access |
|
1171 | call hd_write |
1306 | |
1172 | mov eax,edx ; first cluster |
1307 | mov eax,edx ; first cluster |
1173 | test edi,edi ; 0 length file? |
1308 | test edi,edi ; 0 length file? |
Line 1174... | Line 1309... | ||
1174 | jz truncate_clear_chain |
1309 | jz truncate_clear_chain |
Line 1181... | Line 1316... | ||
1181 | cmp eax,[fatRESERVED] ; is it end of file? |
1316 | cmp eax,[fatRESERVED] ; is it end of file? |
1182 | jnb truncate_eof ; yes |
1317 | jnb truncate_eof ; yes |
1183 | sub edi,esi |
1318 | sub edi,esi |
1184 | jbe truncate_pos_found |
1319 | jbe truncate_pos_found |
1185 | call get_FAT ; get next cluster |
1320 | call get_FAT ; get next cluster |
- | 1321 | cmp [hd_error],0 |
|
- | 1322 | jne append_access |
|
- | 1323 | ||
1186 | jmp truncate_new_cluster |
1324 | jmp truncate_new_cluster |
Line 1187... | Line 1325... | ||
1187 | 1325 | ||
1188 | truncate_pos_found: |
1326 | truncate_pos_found: |
1189 | mov edx,[fatEND] ; new end for cluster chain |
1327 | mov edx,[fatEND] ; new end for cluster chain |
1190 | mov [f_del],1 |
1328 | mov [f_del],1 |
- | 1329 | call set_FAT |
|
- | 1330 | cmp [hd_error],0 |
|
- | 1331 | jne append_access |
|
1191 | call set_FAT |
1332 | |
1192 | mov [f_del],0 |
1333 | mov [f_del],0 |
Line 1193... | Line 1334... | ||
1193 | mov eax,edx ; clear rest of chain |
1334 | mov eax,edx ; clear rest of chain |
1194 | 1335 | ||
- | 1336 | truncate_clear_chain: |
|
- | 1337 | call clear_cluster_chain |
|
Line 1195... | Line 1338... | ||
1195 | truncate_clear_chain: |
1338 | cmp [hd_error],0 |
1196 | call clear_cluster_chain |
1339 | jne append_access |
1197 | 1340 | ||
- | 1341 | truncate_eof: |
|
- | 1342 | popad |
|
- | 1343 | call update_disk ; write all of cache and fat to hd |
|
1198 | truncate_eof: |
1344 | cmp [hd_error],0 |
1199 | popad |
1345 | jne append_access_2 |
1200 | call update_disk ; write all of cache and fat to hd |
1346 | |
1201 | mov [hd1_status],0 |
1347 | mov [hd1_status],0 |
Line 1230... | Line 1376... | ||
1230 | cmp edi,esi ; skip over full cluster? |
1376 | cmp edi,esi ; skip over full cluster? |
1231 | jb filepos_cluster_ok ; no |
1377 | jb filepos_cluster_ok ; no |
Line 1232... | Line 1378... | ||
1232 | 1378 | ||
1233 | sub edi,esi |
1379 | sub edi,esi |
- | 1380 | call get_FAT ; get next cluster |
|
- | 1381 | cmp [hd_error],0 |
|
- | 1382 | jne filepos_eof |
|
1234 | call get_FAT ; get next cluster |
1383 | |
Line 1235... | Line 1384... | ||
1235 | jmp filepos_new_cluster |
1384 | jmp filepos_new_cluster |
1236 | 1385 | ||
1237 | filepos_cluster_ok: |
1386 | filepos_cluster_ok: |
Line 1284... | Line 1433... | ||
1284 | 1433 | ||
Line 1285... | Line 1434... | ||
1285 | pushad |
1434 | pushad |
1286 | 1435 | ||
- | 1436 | xor edi,edi ; don't allow directory remove |
|
- | 1437 | call file_delete ; try to delete the file first |
|
- | 1438 | cmp [hd_error],0 |
|
1287 | xor edi,edi ; don't allow directory remove |
1439 | jne exit_write_access_1 |
1288 | call file_delete ; try to delete the file first |
1440 | |
1289 | test eax,eax |
1441 | test eax,eax |
1290 | jz old_deleted ; deleted ok |
1442 | jz old_deleted ; deleted ok |
Line 1291... | Line 1443... | ||
1291 | cmp eax,ERROR_FILE_NOT_FOUND |
1443 | cmp eax,ERROR_FILE_NOT_FOUND |
1292 | jnz exit_write_access ; it exist but can't delete |
1444 | jnz exit_write_access ; it exist but can't delete |
1293 | 1445 | ||
1294 | old_deleted: |
1446 | old_deleted: |
- | 1447 | mov ebx,PUSHAD_EDX |
|
- | 1448 | call get_cluster_of_a_path |
|
Line 1295... | Line 1449... | ||
1295 | mov ebx,PUSHAD_EDX |
1449 | jnc found_directory_for_writing |
1296 | call get_cluster_of_a_path |
1450 | cmp [hd_error],0 |
1297 | jnc found_directory_for_writing |
1451 | jne exit_write_access |
- | 1452 | ||
- | 1453 | exit_writing_with_error: |
|
- | 1454 | popad |
|
1298 | 1455 | call update_disk ; write all of cache and fat to hd |
|
1299 | exit_writing_with_error: |
1456 | cmp [hd_error],0 |
1300 | popad |
1457 | jne exit_write_access_2 |
Line 1301... | Line 1458... | ||
1301 | call update_disk ; write all of cache and fat to hd |
1458 | |
- | 1459 | mov [hd1_status],0 |
|
- | 1460 | mov eax,ERROR_FILE_NOT_FOUND |
|
1302 | mov [hd1_status],0 |
1461 | ret |
1303 | mov eax,ERROR_FILE_NOT_FOUND |
1462 | |
1304 | ret |
1463 | exit_writing_disk_full_clear: |
- | 1464 | cmp [hd_error],0 |
|
- | 1465 | jne exit_write_access_1 |
|
- | 1466 | mov eax,[sector_tmp] |
|
1305 | 1467 | mov ebx,buffer |
|
1306 | exit_writing_disk_full_clear: |
1468 | call hd_read ; read directory sector |
1307 | mov eax,[sector_tmp] |
1469 | cmp [hd_error],0 |
- | 1470 | jne exit_write_access_1 |
|
- | 1471 | ||
- | 1472 | mov edx,[entry_pos] |
|
1308 | mov ebx,buffer |
1473 | mov byte [edx],0xe5 ; mark as deleted |
1309 | call hd_read ; read directory sector |
1474 | call hd_write |
1310 | mov edx,[entry_pos] |
1475 | cmp [hd_error],0 |
1311 | mov byte [edx],0xe5 ; mark as deleted |
1476 | jne exit_write_access_1 |
Line 1312... | Line 1477... | ||
1312 | call hd_write |
1477 | |
- | 1478 | mov eax,[edx+20-2] ; FAT entry |
|
- | 1479 | mov ax,[edx+26] |
|
1313 | mov eax,[edx+20-2] ; FAT entry |
1480 | and eax,[fatMASK] |
1314 | mov ax,[edx+26] |
1481 | call clear_cluster_chain |
- | 1482 | ||
- | 1483 | exit_writing_disk_full: |
|
1315 | and eax,[fatMASK] |
1484 | cmp [hd_error],0 |
1316 | call clear_cluster_chain |
1485 | jne exit_write_access_1 |
1317 | 1486 | popad |
|
Line 1318... | Line 1487... | ||
1318 | exit_writing_disk_full: |
1487 | call update_disk ; write all of cache and fat to hd |
Line 1327... | Line 1496... | ||
1327 | call update_disk ; write all of cache and fat to hd |
1496 | call update_disk ; write all of cache and fat to hd |
1328 | mov [hd1_status],0 |
1497 | mov [hd1_status],0 |
1329 | mov eax,ERROR_ACCESS_DENIED |
1498 | mov eax,ERROR_ACCESS_DENIED |
1330 | ret |
1499 | ret |
Line -... | Line 1500... | ||
- | 1500 | ||
- | 1501 | exit_write_access_1: |
|
- | 1502 | popad |
|
- | 1503 | exit_write_access_2: |
|
- | 1504 | mov [hd1_status],0 |
|
- | 1505 | mov eax,ERROR_ACCESS_DENIED |
|
- | 1506 | ret |
|
1331 | 1507 | ||
1332 | found_directory_for_writing: |
1508 | found_directory_for_writing: |
1333 | call analyze_directory_to_write |
1509 | call analyze_directory_to_write |
Line 1334... | Line 1510... | ||
1334 | jc exit_writing_disk_full |
1510 | jc exit_writing_disk_full |
Line 1358... | Line 1534... | ||
1358 | 1534 | ||
Line 1359... | Line 1535... | ||
1359 | call set_current_time_for_entry |
1535 | call set_current_time_for_entry |
1360 | 1536 | ||
- | 1537 | mov ebx,buffer ; save the directory name,length,cluster |
|
- | 1538 | call hd_write |
|
Line 1361... | Line 1539... | ||
1361 | mov ebx,buffer ; save the directory name,length,cluster |
1539 | cmp [hd_error],0 |
1362 | call hd_write |
1540 | jne exit_write_access_1 |
1363 | 1541 | ||
Line 1364... | Line 1542... | ||
1364 | imul edi,[SECTORS_PER_CLUSTER],512 ; edi = cluster size in bytes |
1542 | imul edi,[SECTORS_PER_CLUSTER],512 ; edi = cluster size in bytes |
Line 1365... | Line 1543... | ||
1365 | xor ecx,ecx ; cluster count |
1543 | xor ecx,ecx ; cluster count |
1366 | mov ebx,PUSHAD_ECX ; ebx = buffer |
1544 | mov ebx,PUSHAD_ECX ; ebx = buffer |
- | 1545 | ||
- | 1546 | hd_new_block_write: |
|
Line 1367... | Line 1547... | ||
1367 | 1547 | ||
1368 | hd_new_block_write: |
1548 | mov eax,[cluster] ; eax = block |
1369 | 1549 | call set_data_cluster |
|
Line 1379... | Line 1559... | ||
1379 | jc exit_writing_disk_full_clear |
1559 | jc exit_writing_disk_full_clear |
Line 1380... | Line 1560... | ||
1380 | 1560 | ||
1381 | mov edx,eax |
1561 | mov edx,eax |
1382 | xchg eax,[cluster] ; get old cluster and save new cluster |
1562 | xchg eax,[cluster] ; get old cluster and save new cluster |
- | 1563 | call set_FAT ; add it in cluster chain |
|
- | 1564 | cmp [hd_error],0 |
|
- | 1565 | jne exit_write_access_1 |
|
1383 | call set_FAT ; add it in cluster chain |
1566 | |
1384 | dec ecx ; update cluster count |
1567 | dec ecx ; update cluster count |
Line 1385... | Line 1568... | ||
1385 | jmp hd_new_block_write |
1568 | jmp hd_new_block_write |
Line 1386... | Line 1569... | ||
1386 | 1569 | ||
1387 | file_saved_OK: |
1570 | file_saved_OK: |
- | 1571 | ||
- | 1572 | mov edx,[fatEND] ; new end for cluster chain |
|
- | 1573 | call set_FAT |
|
1388 | 1574 | cmp [hd_error],0 |
|
Line 1389... | Line 1575... | ||
1389 | mov edx,[fatEND] ; new end for cluster chain |
1575 | jne exit_write_access_1 |
- | 1576 | ||
- | 1577 | dec ecx ; update cluster count |
|
Line 1390... | Line 1578... | ||
1390 | call set_FAT |
1578 | |
1391 | dec ecx ; update cluster count |
1579 | call add_disk_free_space ; remove clusters from free disk space |
- | 1580 | cmp [hd_error],0 |
|
- | 1581 | jne exit_write_access_1 |
|
1392 | 1582 | ||
1393 | call add_disk_free_space ; remove clusters from free disk space |
1583 | popad |
1394 | 1584 | call update_disk ; write all of cache and fat to hd |
|
Line 1414... | Line 1604... | ||
1414 | ; output : eax = 0 - ok |
1604 | ; output : eax = 0 - ok |
1415 | ; 3 - unknown FS |
1605 | ; 3 - unknown FS |
1416 | ; 5 - file not found |
1606 | ; 5 - file not found |
1417 | ; 6 - end of file |
1607 | ; 6 - end of file |
1418 | ; 9 - fat table corrupted |
1608 | ; 9 - fat table corrupted |
- | 1609 | ; 10 - access denied |
|
1419 | ; ebx = size of file/directory |
1610 | ; ebx = size of file/directory |
1420 | ;-------------------------------------------------------------------------- |
1611 | ;-------------------------------------------------------------------------- |
1421 | cmp [fat_type],0 |
1612 | cmp [fat_type],0 |
1422 | jnz fat_ok_for_reading |
1613 | jnz fat_ok_for_reading |
1423 | xor ebx,ebx |
1614 | xor ebx,ebx |
Line 1437... | Line 1628... | ||
1437 | test edi,edi ; read rootdir |
1628 | test edi,edi ; read rootdir |
1438 | jne no_read_root |
1629 | jne no_read_root |
Line 1439... | Line 1630... | ||
1439 | 1630 | ||
1440 | xor eax,eax |
1631 | xor eax,eax |
- | 1632 | call get_dir_size ; return rootdir size |
|
- | 1633 | cmp [hd_error],0 |
|
- | 1634 | jne file_access_denied |
|
1441 | call get_dir_size ; return rootdir size |
1635 | |
1442 | mov [file_size],eax |
1636 | mov [file_size],eax |
1443 | mov eax,[ROOT_CLUSTER] |
1637 | mov eax,[ROOT_CLUSTER] |
Line 1444... | Line 1638... | ||
1444 | jmp file_read_start |
1638 | jmp file_read_start |
Line 1454... | Line 1648... | ||
1454 | 1648 | ||
1455 | mov eax,[ebx+20-2] ; FAT entry |
1649 | mov eax,[ebx+20-2] ; FAT entry |
1456 | mov ax,[ebx+26] |
1650 | mov ax,[ebx+26] |
1457 | and eax,[fatMASK] |
1651 | and eax,[fatMASK] |
- | 1652 | call get_dir_size |
|
- | 1653 | cmp [hd_error],0 |
|
Line 1458... | Line 1654... | ||
1458 | call get_dir_size |
1654 | jne file_access_denied |
1459 | 1655 | ||
Line 1460... | Line 1656... | ||
1460 | read_set_size: |
1656 | read_set_size: |
Line 1475... | Line 1671... | ||
1475 | 1671 | ||
1476 | test edx,edx ; is all read? |
1672 | test edx,edx ; is all read? |
Line 1477... | Line 1673... | ||
1477 | je file_read_OK ; yes |
1673 | je file_read_OK ; yes |
- | 1674 | ||
- | 1675 | call get_FAT ; get next cluster |
|
- | 1676 | cmp [hd_error],0 |
|
1478 | 1677 | jne file_access_denied |
|
1479 | call get_FAT ; get next cluster |
1678 | |
1480 | cmp eax,[fatRESERVED] ; end of file |
1679 | cmp eax,[fatRESERVED] ; end of file |
1481 | jnb file_read_eof |
1680 | jnb file_read_eof |
Line 1487... | Line 1686... | ||
1487 | mov ebx,[file_size] |
1686 | mov ebx,[file_size] |
1488 | mov eax,ERROR_FAT_TABLE |
1687 | mov eax,ERROR_FAT_TABLE |
1489 | ret |
1688 | ret |
Line 1490... | Line 1689... | ||
1490 | 1689 | ||
- | 1690 | file_read_eof: |
|
- | 1691 | cmp [hd_error],0 |
|
1491 | file_read_eof: |
1692 | jne file_access_denied |
1492 | popad |
1693 | popad |
1493 | mov [hd1_status],0 |
1694 | mov [hd1_status],0 |
1494 | mov ebx,[file_size] |
1695 | mov ebx,[file_size] |
1495 | mov eax,ERROR_END_OF_FILE |
1696 | mov eax,ERROR_END_OF_FILE |
Line 1501... | Line 1702... | ||
1501 | mov ebx,[file_size] |
1702 | mov ebx,[file_size] |
1502 | xor eax,eax |
1703 | xor eax,eax |
1503 | ret |
1704 | ret |
Line 1504... | Line 1705... | ||
1504 | 1705 | ||
- | 1706 | file_to_read_not_found: |
|
- | 1707 | cmp [hd_error],0 |
|
1505 | file_to_read_not_found: |
1708 | jne file_access_denied |
1506 | popad |
1709 | popad |
1507 | mov [hd1_status],0 |
1710 | mov [hd1_status],0 |
1508 | xor ebx,ebx |
1711 | xor ebx,ebx |
1509 | mov eax,ERROR_FILE_NOT_FOUND |
1712 | mov eax,ERROR_FILE_NOT_FOUND |
Line -... | Line 1713... | ||
- | 1713 | ret |
|
- | 1714 | ||
- | 1715 | file_access_denied: |
|
- | 1716 | popad |
|
- | 1717 | mov [hd1_status],0 |
|
- | 1718 | xor ebx,ebx |
|
Line 1510... | Line 1719... | ||
1510 | ret |
1719 | mov eax,ERROR_ACCESS_DENIED |
1511 | 1720 | ret |
|
1512 | 1721 | ||
1513 | get_dir_size: |
1722 | get_dir_size: |
Line 1530... | Line 1739... | ||
1530 | cmp eax,2 ; incorrect fat chain |
1739 | cmp eax,2 ; incorrect fat chain |
1531 | jb dir_size_end |
1740 | jb dir_size_end |
1532 | cmp eax,[fatRESERVED] ; end of directory |
1741 | cmp eax,[fatRESERVED] ; end of directory |
1533 | ja dir_size_end |
1742 | ja dir_size_end |
1534 | call get_FAT ; get next cluster |
1743 | call get_FAT ; get next cluster |
- | 1744 | cmp [hd_error],0 |
|
- | 1745 | jne dir_size_ret |
|
- | 1746 | ||
1535 | inc edx |
1747 | inc edx |
1536 | jmp dir_size_next |
1748 | jmp dir_size_next |
Line 1537... | Line 1749... | ||
1537 | 1749 | ||
1538 | dir_size_end: |
1750 | dir_size_end: |
Line 1585... | Line 1797... | ||
1585 | jc delete_no_access |
1797 | jc delete_no_access |
Line 1586... | Line 1798... | ||
1586 | 1798 | ||
1587 | push ebx ; save directory pointer in buffer |
1799 | push ebx ; save directory pointer in buffer |
1588 | mov ebx,buffer |
1800 | mov ebx,buffer |
- | 1801 | call hd_read ; read directory sector |
|
- | 1802 | cmp [hd_error],0 |
|
1589 | call hd_read ; read directory sector |
1803 | jne delete_no_access_1 |
Line 1590... | Line 1804... | ||
1590 | pop ebx |
1804 | pop ebx |
1591 | 1805 | ||
- | 1806 | delete_notdir: |
|
- | 1807 | call delete_entry_name |
|
- | 1808 | cmp [hd_error],0 |
|
1592 | delete_notdir: |
1809 | jne delete_no_access |
1593 | call delete_entry_name |
1810 | |
- | 1811 | mov eax,ecx ; first cluster of file |
|
- | 1812 | call clear_cluster_chain |
|
- | 1813 | cmp [hd_error],0 |
|
1594 | mov eax,ecx ; first cluster of file |
1814 | jne delete_no_access |
1595 | call clear_cluster_chain |
1815 | |
1596 | popad |
1816 | popad |
Line -... | Line 1817... | ||
- | 1817 | xor eax,eax |
|
- | 1818 | ret |
|
1597 | xor eax,eax |
1819 | |
1598 | ret |
1820 | delete_no_access_1: |
1599 | 1821 | add esp,4 |
|
1600 | delete_no_access: |
1822 | delete_no_access: |
Line 1601... | Line 1823... | ||
1601 | popad |
1823 | popad |
- | 1824 | mov eax,ERROR_ACCESS_DENIED |
|
- | 1825 | ret |
|
1602 | mov eax,ERROR_ACCESS_DENIED |
1826 | |
1603 | ret |
1827 | file_to_delete_not_found: |
1604 | 1828 | cmp [hd_error],0 |
|
Line 1624... | Line 1848... | ||
1624 | cmp eax,[ROOT_CLUSTER] ; don't remove root cluster |
1848 | cmp eax,[ROOT_CLUSTER] ; don't remove root cluster |
1625 | jz delete_OK |
1849 | jz delete_OK |
Line 1626... | Line 1850... | ||
1626 | 1850 | ||
1627 | xor edx,edx |
1851 | xor edx,edx |
- | 1852 | call set_FAT ; clear fat entry |
|
- | 1853 | cmp [hd_error],0 |
|
- | 1854 | jne access_denied_01 |
|
1628 | call set_FAT ; clear fat entry |
1855 | |
1629 | inc ecx ; update cluster count |
1856 | inc ecx ; update cluster count |
1630 | mov eax,edx ; old cluster |
1857 | mov eax,edx ; old cluster |
Line 1631... | Line 1858... | ||
1631 | jmp clean_new_chain |
1858 | jmp clean_new_chain |
1632 | 1859 | ||
- | 1860 | delete_OK: |
|
1633 | delete_OK: |
1861 | call add_disk_free_space ; add clusters to free disk space |
1634 | call add_disk_free_space ; add clusters to free disk space |
1862 | access_denied_01: |
1635 | mov [f_del],0 |
1863 | mov [f_del],0 |
Line 1662... | Line 1890... | ||
1662 | 1890 | ||
1663 | clear_new_sector: |
1891 | clear_new_sector: |
1664 | mov edi,eax ; edi = current directory sector |
1892 | mov edi,eax ; edi = current directory sector |
1665 | mov ebx,deltree_buffer |
1893 | mov ebx,deltree_buffer |
- | 1894 | call hd_read |
|
- | 1895 | cmp [hd_error],0 |
|
- | 1896 | jne clear_error |
|
1666 | call hd_read |
1897 | |
Line 1667... | Line 1898... | ||
1667 | mov edx,512/32 ; count of dir entrys per sector = 16 |
1898 | mov edx,512/32 ; count of dir entrys per sector = 16 |
1668 | 1899 | ||
1669 | clear_analyze: |
1900 | clear_analyze: |
Line 1689... | Line 1920... | ||
1689 | 1920 | ||
1690 | push eax ebx |
1921 | push eax ebx |
1691 | mov eax,edi |
1922 | mov eax,edi |
1692 | mov ebx,deltree_buffer ; save buffer over recursive call |
1923 | mov ebx,deltree_buffer ; save buffer over recursive call |
- | 1924 | call hd_write ; write directory sector to disk |
|
- | 1925 | cmp [hd_error],0 |
|
- | 1926 | jne clear_error |
|
1693 | call hd_write ; write directory sector to disk |
1927 | |
Line 1694... | Line 1928... | ||
1694 | pop ebx eax |
1928 | pop ebx eax |
1695 | 1929 | ||
Line 1696... | Line 1930... | ||
1696 | call clear_directory ; recursive call !!! |
1930 | call clear_directory ; recursive call !!! |
1697 | jc clear_error ; exit if error found |
1931 | jc clear_error ; exit if error found |
1698 | 1932 | ||
1699 | push eax ebx |
1933 | push eax ebx |
- | 1934 | mov eax,edi |
|
- | 1935 | mov ebx,deltree_buffer |
|
- | 1936 | call hd_read ; read directory sector again |
|
1700 | mov eax,edi |
1937 | cmp [hd_error],0 |
Line 1701... | Line 1938... | ||
1701 | mov ebx,deltree_buffer |
1938 | jne clear_error_1 |
1702 | call hd_read ; read directory sector again |
1939 | |
- | 1940 | pop ebx eax |
|
- | 1941 | ||
Line 1703... | Line 1942... | ||
1703 | pop ebx eax |
1942 | clear_file: |
1704 | 1943 | call clear_cluster_chain |
|
Line 1705... | Line 1944... | ||
1705 | clear_file: |
1944 | cmp [hd_error],0 |
Line 1714... | Line 1953... | ||
1714 | jnz clear_analyze |
1953 | jnz clear_analyze |
Line 1715... | Line 1954... | ||
1715 | 1954 | ||
1716 | mov eax,edi |
1955 | mov eax,edi |
1717 | mov ebx,deltree_buffer |
1956 | mov ebx,deltree_buffer |
- | 1957 | call hd_write ; write directory sector to disk |
|
- | 1958 | cmp [hd_error],0 |
|
Line 1718... | Line 1959... | ||
1718 | call hd_write ; write directory sector to disk |
1959 | jne clear_error |
1719 | 1960 | ||
1720 | inc eax ; next sector |
1961 | inc eax ; next sector |
Line 1721... | Line 1962... | ||
1721 | dec ecx |
1962 | dec ecx |
1722 | jnz clear_new_sector |
1963 | jnz clear_new_sector |
- | 1964 | ||
- | 1965 | mov eax,esi |
|
- | 1966 | call get_FAT ; get next cluster |
|
1723 | 1967 | cmp [hd_error],0 |
|
Line 1724... | Line 1968... | ||
1724 | mov eax,esi |
1968 | jne clear_error |
1725 | call get_FAT ; get next cluster |
1969 | |
1726 | jmp clear_new_cluster ; clear it |
1970 | jmp clear_new_cluster ; clear it |
1727 | 1971 | ||
- | 1972 | clear_write_last: |
|
- | 1973 | mov eax,edi |
|
Line 1728... | Line 1974... | ||
1728 | clear_write_last: |
1974 | mov ebx,deltree_buffer |
1729 | mov eax,edi |
1975 | call hd_write ; write directory sector to disk |
1730 | mov ebx,deltree_buffer |
1976 | cmp [hd_error],0 |
1731 | call hd_write ; write directory sector to disk |
1977 | jne clear_error |
- | 1978 | ||
1732 | 1979 | clear_end: |
|
1733 | clear_end: |
1980 | popad |
1734 | popad |
1981 | clc |
1735 | clc |
1982 | ret |
1736 | ret |
1983 | clear_error_1: |
Line 1759... | Line 2006... | ||
1759 | cmp ebx,buffer |
2006 | cmp ebx,buffer |
1760 | jnb delete_test_long |
2007 | jnb delete_test_long |
Line 1761... | Line 2008... | ||
1761 | 2008 | ||
1762 | mov ebx,buffer |
2009 | mov ebx,buffer |
- | 2010 | call hd_write ; write directory sector back |
|
- | 2011 | cmp [hd_error],0 |
|
- | 2012 | jne delete_name_end |
|
1763 | call hd_write ; write directory sector back |
2013 | |
1764 | xor eax,eax |
2014 | xor eax,eax |
1765 | xchg eax,[longname_sec2] |
2015 | xchg eax,[longname_sec2] |
1766 | xchg eax,[longname_sec1] |
2016 | xchg eax,[longname_sec1] |
1767 | test eax,eax ; is there previous directory sector? |
2017 | test eax,eax ; is there previous directory sector? |
Line 1768... | Line 2018... | ||
1768 | jz delete_name_end ; no |
2018 | jz delete_name_end ; no |
1769 | 2019 | ||
- | 2020 | mov ebx,buffer |
|
- | 2021 | call hd_read ; read previous sector |
|
- | 2022 | cmp [hd_error],0 |
|
1770 | mov ebx,buffer |
2023 | jne delete_name_end |
Line 1771... | Line 2024... | ||
1771 | call hd_read ; read previous sector |
2024 | |
1772 | mov ebx,buffer+0x1e0 ; start from last entry |
2025 | mov ebx,buffer+0x1e0 ; start from last entry |
1773 | 2026 | ||
Line 1834... | Line 2087... | ||
1834 | mov edx,eax ; save dest directory cluster |
2087 | mov edx,eax ; save dest directory cluster |
1835 | mov ebx,PUSHAD_EBX ; dest directory name |
2088 | mov ebx,PUSHAD_EBX ; dest directory name |
1836 | push [longname_sec1] |
2089 | push [longname_sec1] |
1837 | push [longname_sec2] |
2090 | push [longname_sec2] |
1838 | call analyze_directory ; check if entry already exist |
2091 | call analyze_directory ; check if entry already exist |
- | 2092 | cmp [hd_error],0 |
|
- | 2093 | jne rename_entry_already_exist_1 |
|
- | 2094 | ||
1839 | pop [longname_sec2] |
2095 | pop [longname_sec2] |
1840 | pop [longname_sec1] |
2096 | pop [longname_sec1] |
1841 | jnc rename_entry_already_exist |
2097 | jnc rename_entry_already_exist |
Line 1842... | Line 2098... | ||
1842 | 2098 | ||
Line 1861... | Line 2117... | ||
1861 | jz rename_not_dir ; no |
2117 | jz rename_not_dir ; no |
1862 | mov eax,[dir_entry+20-2] ; FAT entry |
2118 | mov eax,[dir_entry+20-2] ; FAT entry |
1863 | mov ax,[dir_entry+26] |
2119 | mov ax,[dir_entry+26] |
1864 | and eax,[fatMASK] |
2120 | and eax,[fatMASK] |
1865 | call change_2dot_cluster |
2121 | call change_2dot_cluster |
- | 2122 | cmp [hd_error],0 |
|
- | 2123 | jne rename_entry_already_exist |
|
Line 1866... | Line 2124... | ||
1866 | 2124 | ||
- | 2125 | rename_not_dir: |
|
- | 2126 | cmp [hd_error],0 |
|
1867 | rename_not_dir: |
2127 | jne rename_entry_already_exist |
1868 | mov eax,[sector_tmp] |
2128 | mov eax,[sector_tmp] |
1869 | mov ebx,buffer |
2129 | mov ebx,buffer |
- | 2130 | call hd_read ; read source directory sector |
|
- | 2131 | cmp [hd_error],0 |
|
Line 1870... | Line 2132... | ||
1870 | call hd_read ; read source directory sector |
2132 | jne rename_entry_already_exist |
1871 | 2133 | ||
- | 2134 | mov ebx,[entry_pos] |
|
- | 2135 | call delete_entry_name |
|
Line 1872... | Line 2136... | ||
1872 | mov ebx,[entry_pos] |
2136 | cmp [hd_error],0 |
1873 | call delete_entry_name |
2137 | jne rename_entry_already_exist |
- | 2138 | ||
- | 2139 | popad |
|
1874 | 2140 | call update_disk ; write all of cache and fat to hd |
|
1875 | popad |
2141 | cmp [hd_error],0 |
1876 | call update_disk ; write all of cache and fat to hd |
2142 | jne rename_entry_already_exist_2 |
Line 1877... | Line 2143... | ||
1877 | mov [hd1_status],0 |
2143 | mov [hd1_status],0 |
- | 2144 | xor eax,eax |
|
- | 2145 | ret |
|
1878 | xor eax,eax |
2146 | |
1879 | ret |
2147 | rename_entry_not_found: |
1880 | 2148 | cmp [hd_error],0 |
|
1881 | rename_entry_not_found: |
2149 | jne rename_entry_already_exist |
Line -... | Line 2150... | ||
- | 2150 | popad |
|
- | 2151 | mov [hd1_status],0 |
|
1882 | popad |
2152 | mov eax,ERROR_FILE_NOT_FOUND |
1883 | mov [hd1_status],0 |
2153 | ret |
- | 2154 | ||
1884 | mov eax,ERROR_FILE_NOT_FOUND |
2155 | rename_entry_already_exist_1: |
1885 | ret |
2156 | add esp,8 |
1886 | 2157 | rename_entry_already_exist: |
|
Line 1887... | Line 2158... | ||
1887 | rename_entry_already_exist: |
2158 | popad |
- | 2159 | rename_entry_already_exist_2: |
|
- | 2160 | mov [hd1_status],0 |
|
1888 | popad |
2161 | mov eax,ERROR_ACCESS_DENIED |
1889 | mov [hd1_status],0 |
2162 | ret |
1890 | mov eax,ERROR_ACCESS_DENIED |
2163 | |
1891 | ret |
2164 | rename_disk_full: |
Line 1910... | Line 2183... | ||
1910 | 2183 | ||
1911 | imul eax,[SECTORS_PER_CLUSTER] |
2184 | imul eax,[SECTORS_PER_CLUSTER] |
1912 | add eax,[DATA_START] |
2185 | add eax,[DATA_START] |
1913 | mov ebx,buffer |
2186 | mov ebx,buffer |
- | 2187 | call hd_read |
|
- | 2188 | cmp [hd_error],0 |
|
Line 1914... | Line 2189... | ||
1914 | call hd_read |
2189 | jne not_2dot |
1915 | 2190 | ||
Line 1916... | Line 2191... | ||
1916 | cmp dword [ebx+32],'.. ' |
2191 | cmp dword [ebx+32],'.. ' |
Line 1936... | Line 2211... | ||
1936 | ; edx = path |
2211 | ; edx = path |
1937 | ; edi = if 0 - read rootdir else normal dir/file size |
2212 | ; edi = if 0 - read rootdir else normal dir/file size |
1938 | ; output : eax = 0 - ok |
2213 | ; output : eax = 0 - ok |
1939 | ; 3 - unknown FS |
2214 | ; 3 - unknown FS |
1940 | ; 5 - file not found |
2215 | ; 5 - file not found |
- | 2216 | ; 10 - access denied |
|
1941 | ; ebx = file size |
2217 | ; ebx = file size |
1942 | ;----------------------------------------------------------- |
2218 | ;----------------------------------------------------------- |
1943 | cmp [fat_type],0 |
2219 | cmp [fat_type],0 |
1944 | jnz get_filesize_fat_ok |
2220 | jnz get_filesize_fat_ok |
1945 | xor ebx,ebx |
2221 | xor ebx,ebx |
Line 1971... | Line 2247... | ||
1971 | mov ax,[ebx+26] |
2247 | mov ax,[ebx+26] |
1972 | and eax,[fatMASK] |
2248 | and eax,[fatMASK] |
Line 1973... | Line 2249... | ||
1973 | 2249 | ||
1974 | get_filesize_dirsize: |
2250 | get_filesize_dirsize: |
- | 2251 | call get_dir_size |
|
- | 2252 | cmp [hd_error],0 |
|
Line 1975... | Line 2253... | ||
1975 | call get_dir_size |
2253 | jne get_filesize_access_denied |
1976 | 2254 | ||
1977 | get_filesize_set_size: |
2255 | get_filesize_set_size: |
1978 | mov PUSHAD_EBX,eax |
2256 | mov PUSHAD_EBX,eax |
1979 | popad |
2257 | popad |
1980 | mov [hd1_status],0 |
2258 | mov [hd1_status],0 |
Line 1981... | Line 2259... | ||
1981 | xor eax,eax |
2259 | xor eax,eax |
- | 2260 | ret |
|
- | 2261 | ||
1982 | ret |
2262 | get_filesize_not_found: |
1983 | 2263 | cmp [hd_error],0 |
|
1984 | get_filesize_not_found: |
2264 | jne get_filesize_access_denied |
1985 | popad |
2265 | popad |
1986 | mov [hd1_status],0 |
2266 | mov [hd1_status],0 |
Line -... | Line 2267... | ||
- | 2267 | xor ebx,ebx |
|
- | 2268 | mov eax,ERROR_FILE_NOT_FOUND |
|
- | 2269 | ret |
|
- | 2270 | ||
- | 2271 | get_filesize_access_denied: |
|
- | 2272 | popad |
|
Line 1987... | Line 2273... | ||
1987 | xor ebx,ebx |
2273 | mov [hd1_status],0 |
1988 | mov eax,ERROR_FILE_NOT_FOUND |
2274 | xor ebx,ebx |
1989 | ret |
2275 | mov eax,ERROR_ACCESS_DENIED |
1990 | 2276 | ret |
|
1991 | 2277 | ||
1992 | get_fileattr: |
2278 | get_fileattr: |
1993 | ;----------------------------------------------------------- |
2279 | ;----------------------------------------------------------- |
- | 2280 | ; input : eax = file name |
|
1994 | ; input : eax = file name |
2281 | ; edx = path |
1995 | ; edx = path |
2282 | ; output : eax = 0 - ok |
1996 | ; output : eax = 0 - ok |
2283 | ; 3 - unknown FS |
1997 | ; 3 - unknown FS |
2284 | ; 5 - file not found |
1998 | ; 5 - file not found |
2285 | ; 10 - access denied |
Line 2022... | Line 2309... | ||
2022 | mov [hd1_status],0 |
2309 | mov [hd1_status],0 |
2023 | xor eax,eax |
2310 | xor eax,eax |
2024 | ret |
2311 | ret |
Line 2025... | Line 2312... | ||
2025 | 2312 | ||
- | 2313 | get_fileattr_not_found: |
|
- | 2314 | cmp [hd_error],0 |
|
2026 | get_fileattr_not_found: |
2315 | jne get_fileattr_access_denied |
2027 | popad |
2316 | popad |
2028 | mov [hd1_status],0 |
2317 | mov [hd1_status],0 |
2029 | xor ebx,ebx |
2318 | xor ebx,ebx |
2030 | mov eax,ERROR_FILE_NOT_FOUND |
2319 | mov eax,ERROR_FILE_NOT_FOUND |
Line -... | Line 2320... | ||
- | 2320 | ret |
|
- | 2321 | ||
- | 2322 | get_fileattr_access_denied: |
|
- | 2323 | popad |
|
- | 2324 | mov [hd1_status],0 |
|
- | 2325 | xor ebx,ebx |
|
Line 2031... | Line 2326... | ||
2031 | ret |
2326 | mov eax,ERROR_ACCESS_DENIED |
2032 | 2327 | ret |
|
2033 | 2328 | ||
2034 | get_filedate: |
2329 | get_filedate: |
2035 | ;----------------------------------------------------------- |
2330 | ;----------------------------------------------------------- |
2036 | ; input : eax = file name |
2331 | ; input : eax = file name |
2037 | ; edx = path |
2332 | ; edx = path |
- | 2333 | ; output : eax = 0 - ok |
|
2038 | ; output : eax = 0 - ok |
2334 | ; 3 - unknown FS |
2039 | ; 3 - unknown FS |
2335 | ; 5 - file not found |
2040 | ; 5 - file not found |
2336 | ; 10 - access denied |
2041 | ; ebx = file date/time |
2337 | ; ebx = file date/time |
2042 | ; bits 31..25 = year-1980 |
2338 | ; bits 31..25 = year-1980 |
Line 2070... | Line 2366... | ||
2070 | mov [hd1_status],0 |
2366 | mov [hd1_status],0 |
2071 | xor eax,eax |
2367 | xor eax,eax |
2072 | ret |
2368 | ret |
Line 2073... | Line 2369... | ||
2073 | 2369 | ||
- | 2370 | get_filedate_not_found: |
|
- | 2371 | cmp [hd_error],0 |
|
2074 | get_filedate_not_found: |
2372 | jne get_filedate_access_denied |
2075 | popad |
2373 | popad |
2076 | mov [hd1_status],0 |
2374 | mov [hd1_status],0 |
2077 | xor ebx,ebx |
2375 | xor ebx,ebx |
2078 | mov eax,ERROR_FILE_NOT_FOUND |
2376 | mov eax,ERROR_FILE_NOT_FOUND |
Line -... | Line 2377... | ||
- | 2377 | ret |
|
- | 2378 | ||
- | 2379 | get_filedate_access_denied: |
|
- | 2380 | popad |
|
- | 2381 | mov [hd1_status],0 |
|
- | 2382 | xor ebx,ebx |
|
Line 2079... | Line 2383... | ||
2079 | ret |
2383 | mov eax,ERROR_ACCESS_DENIED |
2080 | 2384 | ret |
|
2081 | 2385 | ||
2082 | get_hd_info: |
2386 | get_hd_info: |
- | 2387 | ;----------------------------------------------------------- |
|
2083 | ;----------------------------------------------------------- |
2388 | ; output : eax = 0 - ok |
2084 | ; output : eax = 0 - ok |
2389 | ; 3 - unknown FS |
2085 | ; 3 - unknown FS |
2390 | ; 10 - access denied |
2086 | ; edx = cluster size in bytes |
2391 | ; edx = cluster size in bytes |
2087 | ; ebx = total clusters on disk |
2392 | ; ebx = total clusters on disk |
Line 2103... | Line 2408... | ||
2103 | mov ebx,[LAST_CLUSTER] |
2408 | mov ebx,[LAST_CLUSTER] |
Line 2104... | Line 2409... | ||
2104 | 2409 | ||
2105 | info_cluster: |
2410 | info_cluster: |
2106 | push eax |
2411 | push eax |
- | 2412 | call get_FAT ; get cluster info |
|
- | 2413 | cmp [hd_error],0 |
|
- | 2414 | jne info_access_denied |
|
2107 | call get_FAT ; get cluster info |
2415 | |
2108 | test eax,eax ; is it free? |
2416 | test eax,eax ; is it free? |
2109 | jnz info_used ; no |
2417 | jnz info_used ; no |
Line 2110... | Line 2418... | ||
2110 | inc ecx |
2418 | inc ecx |
Line 2119... | Line 2427... | ||
2119 | imul edx,[SECTORS_PER_CLUSTER],512 ; cluster size in bytes |
2427 | imul edx,[SECTORS_PER_CLUSTER],512 ; cluster size in bytes |
2120 | mov [hd1_status],0 |
2428 | mov [hd1_status],0 |
2121 | xor eax,eax |
2429 | xor eax,eax |
2122 | ret |
2430 | ret |
Line -... | Line 2431... | ||
- | 2431 | ||
- | 2432 | info_access_denied: |
|
- | 2433 | add esp,4 |
|
- | 2434 | xor edx,edx |
|
- | 2435 | xor ebx,ebx |
|
- | 2436 | xor ecx,ecx |
|
- | 2437 | mov eax,ERROR_ACCESS_DENIED |
|
Line 2123... | Line 2438... | ||
2123 | 2438 | ret |
|
2124 | 2439 | ||
2125 | update_disk: |
2440 | update_disk: |
2126 | ;----------------------------------------------------------- |
2441 | ;----------------------------------------------------------- |
2127 | ; write changed fat and cache to disk |
2442 | ; write changed fat and cache to disk |
2128 | ;----------------------------------------------------------- |
2443 | ;----------------------------------------------------------- |
Line 2129... | Line 2444... | ||
2129 | cmp [fat_change],0 ; is fat changed? |
2444 | cmp [fat_change],0 ; is fat changed? |
- | 2445 | je upd_no_change |
|
- | 2446 | ||
Line 2130... | Line 2447... | ||
2130 | je upd_no_change |
2447 | call write_fat_sector |
Line 2131... | Line 2448... | ||
2131 | 2448 | cmp [hd_error],0 |
|
- | 2449 | jne update_disk_acces_denied |
|
2132 | call write_fat_sector |
2450 | |
Line 2133... | Line 2451... | ||
2133 | 2451 | upd_no_change: |
|
2134 | upd_no_change: |
2452 | |
Line 2177... | Line 2495... | ||
2177 | inc edi |
2495 | inc edi |
2178 | dec ecx |
2496 | dec ecx |
2179 | jnz hdreadcache |
2497 | jnz hdreadcache |
Line 2180... | Line 2498... | ||
2180 | 2498 | ||
- | 2499 | call find_empty_slot ; ret in edi |
|
- | 2500 | cmp [hd_error],0 |
|
Line 2181... | Line -... | ||
2181 | call find_empty_slot ; ret in edi |
- | |
2182 | 2501 | jne return_01 |
|
Line -... | Line 2502... | ||
- | 2502 | ||
- | 2503 | push eax edx |
|
- | 2504 | ||
- | 2505 | call wait_for_hd_idle |
|
2183 | call wait_for_hd_idle |
2506 | cmp [hd_error],0 |
2184 | push eax edx |
2507 | jne hd_read_error |
2185 | 2508 | ||
2186 | cli |
2509 | cli |
2187 | xor eax,eax |
2510 | xor eax,eax |
2188 | mov edx,[hdbase] |
2511 | mov edx,[hdbase] |
2189 | inc edx |
2512 | inc edx |
2190 | out dx,al ; ATAFeatures ðåãèñòð "îñîáåÃÃîñòåé" |
2513 | out dx,al ; ATAFeatures  ¥£ð¡¢ "®¡®¡¥Â®¡¢¥©" |
2191 | inc edx |
2514 | inc edx |
2192 | inc eax |
2515 | inc eax |
2193 | out dx,al ; ATASectorCount ñ÷åò÷èê ñåêòîðîâ |
2516 | out dx,al ; ATASectorCount ¡§¥¢§ðª ¡¥ª¢® ®¢ |
2194 | inc edx |
2517 | inc edx |
2195 | mov eax,[esp+4] |
2518 | mov eax,[esp+4] |
2196 | out dx,al ; ATASectorNumber ðåãèñòð Ãîìåðà ñåêòîðà |
2519 | out dx,al ; ATASectorNumber  ¥£ð¡¢ Â®¬¥  ¡¥ª¢®  |
2197 | shr eax,8 |
2520 | shr eax,8 |
2198 | inc edx |
2521 | inc edx |
2199 | out dx,al ; ATACylinder Ãîìåð öèëèÃäðà (ìëà äøèé áà éò) |
2522 | out dx,al ; ATACylinder ®¬¥ ¦ð«ð¤  (¬« ¤¨ð© ¡ ©¢) |
2200 | shr eax,8 |
2523 | shr eax,8 |
2201 | inc edx |
2524 | inc edx |
2202 | out dx,al ; Ãîìåð öèëèÃäðà (ñòà ðøèé áà éò) |
2525 | out dx,al ; ®¬¥ ¦ð«ð¤  (¡¢  ¨ð© ¡ ©¢) |
2203 | shr eax,8 |
2526 | shr eax,8 |
2204 | inc edx |
2527 | inc edx |
2205 | and al,1+2+4+8 |
2528 | and al,1+2+4+8 |
2206 | add al,byte [hdid] |
2529 | add al,byte [hdid] |
2207 | add al,128+64+32 |
2530 | add al,128+64+32 |
2208 | out dx,al ; Ãîìåð ãîëîâêè/Ãîìåð äèñêà |
2531 | out dx,al ; ®¬¥ £®«®¢ªð/®¬¥ ¤ð¡ª |
2209 | inc edx |
2532 | inc edx |
Line 2210... | Line 2533... | ||
2210 | mov al,20h |
2533 | mov al,20h |
Line 2211... | Line 2534... | ||
2211 | out dx,al ; ATACommand ðåãèñòð êîìà Ãä |
2534 | out dx,al ; ATACommand  ¥£ð¡¢ ª®¬ Â¤ |
Line 2240... | Line 2563... | ||
2240 | add esi,0x600000+65536 |
2563 | add esi,0x600000+65536 |
2241 | mov edi,ebx |
2564 | mov edi,ebx |
2242 | mov ecx,512/4 |
2565 | mov ecx,512/4 |
2243 | cld |
2566 | cld |
2244 | rep movsd ; move data |
2567 | rep movsd ; move data |
2245 | ; blok_read_2: |
2568 | return_01: |
2246 | pop edi esi ecx |
2569 | pop edi esi ecx |
2247 | ret |
2570 | ret |
Line 2248... | Line 2571... | ||
2248 | 2571 | ||
Line 2277... | Line 2600... | ||
2277 | 2600 | ||
2278 | ; sector not found in cache |
2601 | ; sector not found in cache |
Line 2279... | Line 2602... | ||
2279 | ; write the block to a new location |
2602 | ; write the block to a new location |
- | 2603 | ||
- | 2604 | call find_empty_slot ; ret in edi |
|
Line 2280... | Line 2605... | ||
2280 | 2605 | cmp [hd_error],0 |
|
2281 | call find_empty_slot ; ret in edi |
2606 | jne hd_write_access_denied |
Line 2282... | Line 2607... | ||
2282 | 2607 | ||
Line 2291... | Line 2616... | ||
2291 | add edi,0x600000+65536 |
2616 | add edi,0x600000+65536 |
2292 | mov esi,ebx |
2617 | mov esi,ebx |
2293 | mov ecx,512/4 |
2618 | mov ecx,512/4 |
2294 | cld |
2619 | cld |
2295 | rep movsd ; move data |
2620 | rep movsd ; move data |
2296 | - | ||
- | 2621 | hd_write_access_denied: |
|
2297 | pop edi esi ecx |
2622 | pop edi esi ecx |
2298 | ret |
2623 | ret |
Line 2299... | Line 2624... | ||
2299 | 2624 | ||
Line 2322... | Line 2647... | ||
2322 | jb danger |
2647 | jb danger |
2323 | cmp eax,[PARTITION_END] |
2648 | cmp eax,[PARTITION_END] |
2324 | ja danger |
2649 | ja danger |
Line 2325... | Line 2650... | ||
2325 | 2650 | ||
- | 2651 | call wait_for_hd_idle |
|
- | 2652 | cmp [hd_error],0 |
|
Line 2326... | Line 2653... | ||
2326 | call wait_for_hd_idle |
2653 | jne hd_write_error |
2327 | 2654 | ||
2328 | cli |
2655 | cli |
2329 | xor eax,eax |
2656 | xor eax,eax |
Line 2377... | Line 2704... | ||
2377 | 2704 | ||
2378 | add esi,8 |
2705 | add esi,8 |
2379 | inc edi |
2706 | inc edi |
2380 | dec ecx |
2707 | dec ecx |
2381 | jnz write_cache_more |
2708 | jnz write_cache_more |
2382 | 2709 | return_02: |
|
2383 | pop edi esi edx ecx eax |
2710 | pop edi esi edx ecx eax |
Line 2384... | Line 2711... | ||
2384 | ret |
2711 | ret |
Line 2409... | Line 2736... | ||
2409 | jb found_slot ; it's empty or read |
2736 | jb found_slot ; it's empty or read |
2410 | dec ecx |
2737 | dec ecx |
2411 | jnz search_for_empty |
2738 | jnz search_for_empty |
Line 2412... | Line 2739... | ||
2412 | 2739 | ||
- | 2740 | call write_cache ; no empty slots found, write all |
|
- | 2741 | cmp [hd_error],0 |
|
- | 2742 | jne found_slot_access_denied |
|
2413 | call write_cache ; no empty slots found, write all |
2743 | |
Line 2414... | Line 2744... | ||
2414 | jmp search_again ; and start again |
2744 | jmp search_again ; and start again |
Line 2415... | Line 2745... | ||
2415 | 2745 | ||
2416 | found_slot: |
- | |
- | 2746 | found_slot: |
|
2417 | 2747 | ||
2418 | mov [cache_search_start],edi |
2748 | mov [cache_search_start],edi |
Line 2419... | Line 2749... | ||
2419 | 2749 | found_slot_access_denied: |
|
Line 2436... | Line 2766... | ||
2436 | push eax |
2766 | push eax |
2437 | mov eax,[hd_wait_timeout] |
2767 | mov eax,[hd_wait_timeout] |
2438 | cmp [timer_ticks], eax ;[0xfdf0],eax |
2768 | cmp [timer_ticks], eax ;[0xfdf0],eax |
2439 | jg hd_timeout_error |
2769 | jg hd_timeout_error |
2440 | pop eax |
2770 | pop eax |
- | 2771 | mov [hd_error],0 |
|
2441 | ret |
2772 | ret |
Line 2442... | Line 2773... | ||
2442 | 2773 | ||
2443 | iglobal |
2774 | iglobal |
2444 | hd_timeout_str db 'K : FS - HD timeout',13,10,0 |
2775 | hd_timeout_str db 'K : FS - HD timeout',13,10,0 |
2445 | hd_read_str db 'K : FS - HD read error',13,10,0 |
2776 | hd_read_str db 'K : FS - HD read error',13,10,0 |
- | 2777 | hd_write_str db 'K : FS - HD write error',13,10,0 |
|
2446 | hd_write_str db 'K : FS - HD write error',13,10,0 |
2778 | hd_lba_str db 'K : FS - HD LBA error',13,10,0 |
Line 2447... | Line 2779... | ||
2447 | endg |
2779 | endg |
Line 2448... | Line 2780... | ||
2448 | 2780 | ||
2449 | hd_timeout_error: |
2781 | hd_timeout_error: |
2450 | 2782 | ||
2451 | call clear_hd_cache |
2783 | call clear_hd_cache |
2452 | call clear_application_table_status |
2784 | call clear_application_table_status |
- | 2785 | mov esi,hd_timeout_str |
|
- | 2786 | call sys_msg_board_str |
|
2453 | mov esi,hd_timeout_str |
2787 | ; jmp $ |
Line 2454... | Line 2788... | ||
2454 | call sys_msg_board_str |
2788 | mov [hd_error],1 |
Line 2455... | Line 2789... | ||
2455 | jmp $ |
2789 | pop eax |
2456 | 2790 | ret |
|
2457 | 2791 | ||
2458 | hd_read_error: |
2792 | hd_read_error: |
- | 2793 | ||
- | 2794 | call clear_hd_cache |
|
2459 | 2795 | call clear_application_table_status |
|
Line 2460... | Line 2796... | ||
2460 | call clear_hd_cache |
2796 | mov esi,hd_read_str |
Line 2461... | Line 2797... | ||
2461 | call clear_application_table_status |
2797 | call sys_msg_board_str |
2462 | mov esi,hd_read_str |
2798 | pop edx eax |
2463 | call sys_msg_board_str |
2799 | jmp return_01 |
2464 | jmp $ |
2800 | ; jmp $ |
- | 2801 | ||
2465 | 2802 | hd_write_error: |
|
2466 | hd_write_error: |
- | |
Line -... | Line 2803... | ||
- | 2803 | ||
- | 2804 | call clear_hd_cache |
|
- | 2805 | call clear_application_table_status |
|
- | 2806 | mov esi,hd_write_str |
|
- | 2807 | call sys_msg_board_str |
|
- | 2808 | jmp return_02 |
|
Line 2467... | Line 2809... | ||
2467 | 2809 | ; jmp $ |
|
Line 2468... | Line 2810... | ||
2468 | call clear_hd_cache |
2810 | |
Line 2484... | Line 2826... | ||
2484 | add edx,0x7 |
2826 | add edx,0x7 |
Line 2485... | Line 2827... | ||
2485 | 2827 | ||
Line 2486... | Line 2828... | ||
2486 | wfhil1: |
2828 | wfhil1: |
- | 2829 | ||
- | 2830 | call check_hd_wait_timeout |
|
Line 2487... | Line 2831... | ||
2487 | 2831 | cmp [hd_error],0 |
|
2488 | call check_hd_wait_timeout |
2832 | jne @f |
2489 | 2833 | ||
Line -... | Line 2834... | ||
- | 2834 | in al,dx |
|
- | 2835 | test al,128 |
|
2490 | in al,dx |
2836 | jnz wfhil1 |
2491 | test al,128 |
2837 | |
Line -... | Line 2838... | ||
- | 2838 | @@: |
|
2492 | jnz wfhil1 |
2839 | |
Line 2493... | Line 2840... | ||
2493 | 2840 | pop edx eax |
|
Line 2494... | Line 2841... | ||
2494 | pop edx eax |
2841 | ret |
Line 2505... | Line 2852... | ||
2505 | call save_hd_wait_timeout |
2852 | call save_hd_wait_timeout |
Line 2506... | Line 2853... | ||
2506 | 2853 | ||
Line 2507... | Line 2854... | ||
2507 | hdwait_sbuf: ; wait for sector buffer to be ready |
2854 | hdwait_sbuf: ; wait for sector buffer to be ready |
- | 2855 | ||
- | 2856 | call check_hd_wait_timeout |
|
Line 2508... | Line 2857... | ||
2508 | 2857 | cmp [hd_error],0 |
|
2509 | call check_hd_wait_timeout |
2858 | jne @f |
2510 | 2859 | ||
Line 2517... | Line 2866... | ||
2517 | cmp [hd_setup],1 ; do not mark error for setup request |
2866 | cmp [hd_setup],1 ; do not mark error for setup request |
2518 | je buf_wait_ok |
2867 | je buf_wait_ok |
Line 2519... | Line 2868... | ||
2519 | 2868 | ||
2520 | test al,1 ; previous command ended up with an error |
2869 | test al,1 ; previous command ended up with an error |
- | 2870 | jz buf_wait_ok |
|
2521 | jz buf_wait_ok |
2871 | @@: |
Line 2522... | Line 2872... | ||
2522 | mov [hd_error],1 |
2872 | mov [hd_error],1 |
Line 2523... | Line 2873... | ||
2523 | 2873 | ||
Line 2608... | Line 2958... | ||
2608 | mul ecx |
2958 | mul ecx |
2609 | add eax, [DATA_START] |
2959 | add eax, [DATA_START] |
2610 | .new_sector: |
2960 | .new_sector: |
2611 | mov ebx, buffer |
2961 | mov ebx, buffer |
2612 | call hd_read |
2962 | call hd_read |
- | 2963 | cmp [hd_error],0 |
|
- | 2964 | jne .notfound |
|
- | 2965 | ||
2613 | mov edi, ebx |
2966 | mov edi, ebx |
2614 | add ebx, 512 |
2967 | add ebx, 512 |
2615 | push eax |
2968 | push eax |
2616 | .l1: |
2969 | .l1: |
2617 | call fat_get_name |
2970 | call fat_get_name |
Line 2627... | Line 2980... | ||
2627 | loop .new_sector |
2980 | loop .new_sector |
2628 | cmp [fat16_root], 0 |
2981 | cmp [fat16_root], 0 |
2629 | jnz .notfound |
2982 | jnz .notfound |
2630 | mov eax, [cluster_tmp] |
2983 | mov eax, [cluster_tmp] |
2631 | call get_FAT |
2984 | call get_FAT |
- | 2985 | cmp [hd_error],0 |
|
- | 2986 | jne .notfound |
|
- | 2987 | ||
2632 | cmp eax, 2 |
2988 | cmp eax, 2 |
2633 | jb .notfound |
2989 | jb .notfound |
2634 | cmp eax, [fatRESERVED] |
2990 | cmp eax, [fatRESERVED] |
2635 | jb .new_cluster |
2991 | jb .new_cluster |
2636 | .notfound: |
2992 | .notfound: |
Line 2651... | Line 3007... | ||
2651 | jnz .read_entry |
3007 | jnz .read_entry |
2652 | cmp [fat16_root], 0 |
3008 | cmp [fat16_root], 0 |
2653 | jnz .notfound |
3009 | jnz .notfound |
2654 | mov eax, [cluster_tmp] |
3010 | mov eax, [cluster_tmp] |
2655 | call get_FAT |
3011 | call get_FAT |
- | 3012 | cmp [hd_error],0 |
|
- | 3013 | jne .notfound |
|
- | 3014 | ||
2656 | cmp eax, 2 |
3015 | cmp eax, 2 |
2657 | jb .notfound |
3016 | jb .notfound |
2658 | cmp eax, [fatRESERVED] |
3017 | cmp eax, [fatRESERVED] |
2659 | jae .notfound |
3018 | jae .notfound |
2660 | dec eax |
3019 | dec eax |
Line 2662... | Line 3021... | ||
2662 | mul [SECTORS_PER_CLUSTER] |
3021 | mul [SECTORS_PER_CLUSTER] |
2663 | add eax, [DATA_START] |
3022 | add eax, [DATA_START] |
2664 | .read_entry: |
3023 | .read_entry: |
2665 | mov ebx, [buffer] |
3024 | mov ebx, [buffer] |
2666 | call hd_read |
3025 | call hd_read |
- | 3026 | cmp [hd_error],0 |
|
- | 3027 | jne .notfound |
|
- | 3028 | ||
2667 | mov edi, ebx |
3029 | mov edi, ebx |
2668 | .entryfound: |
3030 | .entryfound: |
2669 | cmp byte [esi], 0 |
3031 | cmp byte [esi], 0 |
2670 | jz .done |
3032 | jz .done |
2671 | test byte [edi+11], 10h ; is a directory? |
3033 | test byte [edi+11], 10h ; is a directory? |
Line 2703... | Line 3065... | ||
2703 | push edi |
3065 | push edi |
2704 | cmp byte [esi], 0 |
3066 | cmp byte [esi], 0 |
2705 | jnz @f |
3067 | jnz @f |
2706 | .noaccess: |
3068 | .noaccess: |
2707 | pop edi |
3069 | pop edi |
- | 3070 | .noaccess_2: |
|
2708 | or ebx, -1 |
3071 | or ebx, -1 |
2709 | mov eax, ERROR_ACCESS_DENIED |
3072 | mov eax, ERROR_ACCESS_DENIED |
2710 | ret |
3073 | ret |
- | 3074 | ||
- | 3075 | .noaccess_3: |
|
- | 3076 | add esp,4 |
|
- | 3077 | .noaccess_1: |
|
- | 3078 | add esp,4 |
|
- | 3079 | .noaccess_4: |
|
- | 3080 | add esp,4*5 |
|
- | 3081 | jmp .noaccess_2 |
|
- | 3082 | ||
2711 | @@: |
3083 | @@: |
2712 | call hd_find_lfn |
3084 | call hd_find_lfn |
2713 | jnc .found |
3085 | jnc .found |
2714 | pop edi |
3086 | pop edi |
- | 3087 | cmp [hd_error],0 |
|
- | 3088 | jne .noaccess_2 |
|
2715 | or ebx, -1 |
3089 | or ebx, -1 |
2716 | mov eax, ERROR_FILE_NOT_FOUND |
3090 | mov eax, ERROR_FILE_NOT_FOUND |
2717 | ret |
3091 | ret |
- | 3092 | ||
2718 | .found: |
3093 | .found: |
2719 | test byte [edi+11], 0x10 ; do not allow read directories |
3094 | test byte [edi+11], 0x10 ; do not allow read directories |
2720 | jnz .noaccess |
3095 | jnz .noaccess |
2721 | test ebx, ebx |
3096 | test ebx, ebx |
2722 | jz .l1 |
3097 | jz .l1 |
Line 2761... | Line 3136... | ||
2761 | jb .force_buf |
3136 | jb .force_buf |
2762 | ; we may read directly to given buffer |
3137 | ; we may read directly to given buffer |
2763 | push ebx |
3138 | push ebx |
2764 | mov ebx, edx |
3139 | mov ebx, edx |
2765 | call hd_read |
3140 | call hd_read |
- | 3141 | cmp [hd_error],0 |
|
- | 3142 | jne .noaccess_1 |
|
- | 3143 | ||
2766 | pop ebx |
3144 | pop ebx |
2767 | add edx, 512 |
3145 | add edx, 512 |
2768 | sub ecx, 512 |
3146 | sub ecx, 512 |
2769 | sub dword [esp], 512 |
3147 | sub dword [esp], 512 |
2770 | jmp .skip |
3148 | jmp .skip |
2771 | .force_buf: |
3149 | .force_buf: |
2772 | ; we must read sector to temporary buffer and then copy it to destination |
3150 | ; we must read sector to temporary buffer and then copy it to destination |
2773 | push eax ebx |
3151 | push eax ebx |
2774 | mov ebx, buffer |
3152 | mov ebx, buffer |
2775 | call hd_read |
3153 | call hd_read |
- | 3154 | cmp [hd_error],0 |
|
- | 3155 | jne .noaccess_3 |
|
- | 3156 | ||
2776 | mov eax, ebx |
3157 | mov eax, ebx |
2777 | pop ebx |
3158 | pop ebx |
2778 | add eax, ebx |
3159 | add eax, ebx |
2779 | push ecx |
3160 | push ecx |
2780 | add ecx, ebx |
3161 | add ecx, ebx |
Line 2803... | Line 3184... | ||
2803 | inc eax |
3184 | inc eax |
2804 | dec edi |
3185 | dec edi |
2805 | jnz .new_sector |
3186 | jnz .new_sector |
2806 | mov eax, [cluster_tmp] |
3187 | mov eax, [cluster_tmp] |
2807 | call get_FAT |
3188 | call get_FAT |
- | 3189 | cmp [hd_error],0 |
|
- | 3190 | jne .noaccess_4 |
|
- | 3191 | ||
2808 | jmp .new_cluster |
3192 | jmp .new_cluster |
2809 | .done: |
3193 | .done: |
2810 | pop ebx edx ecx ebx edi |
3194 | pop ebx edx ecx ebx edi |
2811 | xor eax, eax |
3195 | xor eax, eax |
2812 | ret |
3196 | ret |