Subversion Repositories Kolibri OS

Rev

Rev 465 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 465 Rev 495
Line 1... Line 1...
1
$Revision: 465 $
1
$Revision: 495 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                                      ;;
3
;;                                                                      ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
Line 41... Line 41...
41
    mov   [flp_status],eax
41
    mov   [flp_status],eax
42
    pop   eax
42
    pop   eax
43
    sti
43
    sti
44
    ret
44
    ret
Line 45... Line -...
45
 
-
 
46
floppy_free_space:
-
 
47
;---------------------------------------------
-
 
48
;
-
 
49
; returns free space in edi
-
 
50
;
-
 
51
;---------------------------------------------
-
 
52
    push   eax ebx ecx
-
 
53
    call   read_flp_fat
-
 
54
    cmp    [FDC_Status],0
-
 
55
    jne    fdc_status_error_2
-
 
56
    mov    eax,0x282004
-
 
57
    xor    edi,edi
-
 
58
    mov    ecx,2847   ;1448000/512
-
 
59
rdfs1_1:
-
 
60
    mov    ebx,[eax]
-
 
61
    and    ebx,4095
-
 
62
    jne    rdfs2_1
-
 
63
    add    edi,512
-
 
64
rdfs2_1:
-
 
65
    add    eax,2
-
 
66
    loop   rdfs1_1
-
 
67
fdc_status_error_2:
-
 
68
    pop    ecx ebx eax
-
 
69
    ret
-
 
70
 
-
 
71
 
-
 
Line 72... Line 45...
72
 
45
 
73
 
46
 
74
floppy_fileread:
47
floppy_fileread:
75
;----------------------------------------------------------------
48
;----------------------------------------------------------------
Line 504... Line 477...
504
 
477
 
505
   popad
478
   popad
Line 506... Line -...
506
   ret
-
 
507
 
-
 
508
 
-
 
509
floppy_filedelete:
-
 
510
;--------------------------------------------
-
 
511
;
-
 
512
; filedelete - sys floppy
-
 
513
; in:
-
 
514
; eax - filename 11 chars - for root directory
-
 
515
; edi  pointer to path   /fd/1/...... - for all files in nested directories
-
 
516
;
-
 
517
; out:
-
 
518
; eax - 0 = successful, 1 = file not found, 10 = access denied
-
 
519
;
-
 
520
;--------------------------------------------
-
 
521
    mov    [path_pointer_flp],edi
-
 
522
    mov    [save_flag],0
-
 
523
    mov    ebp,1  ; file not found as default
-
 
524
filedelete_newtry_1:
-
 
525
    sub    esp,32
-
 
526
    call   expand_filename
-
 
527
    push   eax ebx ecx edx esi edi
-
 
528
    call   read_flp_fat
-
 
529
    cmp    [FDC_Status],0
-
 
530
    jne    frnoreadd_1
-
 
531
    mov    [FDD_Track],0      ; Öèëèíäð
-
 
532
    mov    [FDD_Head],1      ; Ñòîðîíà
-
 
533
    mov    [FDD_Sector],2      ; Ñåêòîð
-
 
534
    call    SeekTrack
-
 
535
    mov     dh,14
-
 
536
l.20_2:
-
 
537
    call    ReadSectWithRetr
-
 
538
    cmp    [FDC_Status],0
-
 
539
    jne    fdc_status_error_4
-
 
540
    mov     dl,16
-
 
541
    mov     edi,FDD_BUFF
-
 
542
    inc     [FDD_Sector]
-
 
543
l.21_2:
-
 
544
    mov    esi,eax            ;Name of file we want
-
 
545
    mov    ecx,11
-
 
546
    cld
-
 
547
    rep    cmpsb            ;Found the file?
-
 
548
    je     fifoundd_1          ;Yes
-
 
549
    add    ecx,21
-
 
550
    add    edi, ecx         ;Advance to next entry
-
 
551
    dec    dl
-
 
552
    jne    l.21_2
-
 
553
    dec    dh
-
 
554
    jne    l.20_2
-
 
555
    jmp    frnoreadd_1
-
 
556
 
-
 
557
fdc_status_error_4:
-
 
558
    pop    edi esi edx ecx ebx eax
-
 
559
    add    esp,32
-
 
560
    jmp    fdc_status_error_1
-
 
561
 
-
 
562
fifoundd_1:
-
 
563
    mov    eax,[path_pointer_flp]
-
 
564
    cmp    [eax+36],byte 0
-
 
565
    je    fifoundd_2
-
 
566
    movzx  eax, word [edi+0xf]
-
 
567
    mov    ebx,[path_pointer_flp]
-
 
568
    add    ebx,36
-
 
569
    call   get_cluster_of_a_path_flp
-
 
570
    jc     frnoreadd_1_1
-
 
571
    mov    edi,ebx
-
 
572
    add    edi,11
-
 
573
    jmp    fifoundd_2_1
-
 
574
fifoundd_2:
-
 
575
    dec    [FDD_Sector]
-
 
576
fifoundd_2_1:
-
 
577
    mov    [edi-11],byte 0xE5    ;mark filename deleted
-
 
578
        movzx   edi, word [edi+0xf] ;edi = cluster
-
 
579
frnewd_1:
-
 
580
    shl    edi,1            ;find next cluster from FAT
-
 
581
    add    edi,FLOPPY_FAT
-
 
582
    mov    eax,[edi]
-
 
583
    mov    [edi],word 0x0        ;clear fat chain cluster
-
 
584
    and    eax,4095
-
 
585
    mov    edi,eax
-
 
586
    cmp    edi,dword 4095        ;last cluster ?
-
 
587
    jz     frnoreadd2_1
-
 
588
    jmp    frnewd_1
-
 
589
 
-
 
590
frnoreadd2_1:
-
 
591
    call   WriteSectWithRetr
-
 
592
    cmp    [FDC_Status],0
-
 
593
    jne    fdc_status_error_4
-
 
594
    call   save_flp_fat
-
 
595
    cmp    [FDC_Status],0
-
 
596
    jne    fdc_status_error_4
-
 
597
;    pop    edi esi edx ecx ebx eax
-
 
598
;    add    esp,32
-
 
599
    mov    ebp,0       ; file found
-
 
600
;    jmp    filedelete_newtry_1
-
 
601
    jmp    frnoreadd_1
-
 
602
 
-
 
603
frnoreadd_1_1:
-
 
604
    cmp    [FDC_Status],0
-
 
605
    jne    fdc_status_error_4
-
 
606
frnoreadd_1:
-
 
607
    pop    edi esi edx ecx ebx eax
-
 
608
    add    esp,32
-
 
609
    mov    eax,ebp
-
 
610
    ret
-
 
611
 
-
 
612
floppy_filesave:
-
 
613
;----------------------------------------------------------
-
 
614
;
-
 
615
; filesave - sys floppy
-
 
616
;
-
 
617
; eax      ; pointer to file name 11 chars - for root directory
-
 
618
; ebx      ; buffer
-
 
619
; ecx      ; count to write in bytes
-
 
620
; edx      ; 0 create new , 1 append
-
 
621
; edi  pointer to path   /fd/1/......  - for all files in nested directories
-
 
622
;
-
 
623
; output : eax = 0 - ok
-
 
624
;                5 - file not found / directory not found
-
 
625
;                8 - disk full
-
 
626
;               10 - access denied
-
 
627
;-----------------------------------------------------------
-
 
628
    mov    [path_pointer_flp],edi
-
 
629
    sub  esp,32
-
 
630
    call expand_filename
-
 
631
    cmp  edx,0
-
 
632
    jnz  fsdel_1
-
 
633
    pusha
-
 
634
    call floppy_filedelete
-
 
635
    cmp    [FDC_Status],0
-
 
636
    jne    fdc_status_error_6
-
 
637
    popa
-
 
638
    mov    [save_flag],1
-
 
639
fsdel_1:
-
 
640
    call   floppy_free_space
-
 
641
    cmp    [FDC_Status],0
-
 
642
    jne    fdc_status_error_6
-
 
643
    cmp    ecx,edi
-
 
644
    jb     rd_do_save_1
-
 
645
    add    esp,32
-
 
646
    mov    eax,8    ; not enough free space
-
 
647
    mov   [flp_status],0
-
 
648
    ret
-
 
649
 
-
 
650
fdc_status_error_6:
-
 
651
    popa
-
 
652
    add    esp,32
-
 
653
    jmp    fdc_status_error_1
-
 
654
 
-
 
655
rd_do_save_1:
-
 
656
    push   eax ebx ecx edx esi edi
-
 
657
    call   read_flp_fat
-
 
658
    cmp    [FDC_Status],0
-
 
659
    jne    fdc_status_error_7
-
 
660
    push   eax
-
 
661
    mov    eax,[path_pointer_flp]
-
 
662
    cmp    [eax+36],byte 0
-
 
663
    jne    fifoundds_2
-
 
664
    pop    eax
-
 
665
    mov    [save_root_flag],1
-
 
666
    call   read_flp_root
-
 
667
    cmp    [FDC_Status],0
-
 
668
    jne    fdc_status_error_7
-
 
669
    mov    edi,FLOPPY_BUFF   ;Point at directory
-
 
670
    mov    edx,224 +1
-
 
671
    ; find an empty spot for filename in the root dir
-
 
672
l20ds_1:
-
 
673
    sub    edx,1
-
 
674
    jz     frnoreadds_1
-
 
675
l21ds_1:
-
 
676
    cmp    [edi],byte 0xE5
-
 
677
    jz     fifoundds_1
-
 
678
    cmp    [edi],byte 0x0
-
 
679
    jz     fifoundds_1
-
 
680
    add    edi,32            ; Advance to next entry
-
 
681
    jmp    l20ds_1
-
 
682
 
-
 
683
fifoundds_2:
-
 
684
    pop    eax
-
 
685
    mov    [save_root_flag],0
-
 
686
    mov    [FDD_Track],0      ; Öèëèíäð
-
 
687
    mov    [FDD_Head],1       ; Ñòîðîíà
-
 
688
    mov    [FDD_Sector],2      ; Ñåêòîð
-
 
689
    call   SeekTrack
-
 
690
    mov    dh,14
-
 
691
l.20_3:
-
 
692
    call    ReadSectWithRetr
-
 
693
    cmp    [FDC_Status],0
-
 
694
    jne    fdc_status_error_7
-
 
695
    mov    dl,16
-
 
696
    mov    edi,FDD_BUFF
-
 
697
    inc     [FDD_Sector]
-
 
698
l.21_3:
-
 
699
    mov    esi,eax            ;Name of file we want
-
 
700
    mov    ecx,11
-
 
701
    cld
-
 
702
    rep    cmpsb            ;Found the file?
-
 
703
    je     fifoundds_3          ;Yes
-
 
704
    add    ecx,21
-
 
705
    add    edi, ecx         ;Advance to next entry
-
 
706
    dec    dl
-
 
707
    jne    l.21_3
-
 
708
    dec    dh
-
 
709
    jne    l.20_3
-
 
710
fdc_status_error_8:
-
 
711
    pop     edi esi edx ecx ebx eax
-
 
712
    mov    eax,5            ; file not found ?
-
 
713
    mov    ebx,-1
-
 
714
    add    esp,32
-
 
715
    mov    [flp_status],0
-
 
716
    ret
-
 
717
 
-
 
718
fifoundds_3:
-
 
719
    add    edi,0xf
-
 
720
    mov    eax,[edi]
-
 
721
    and    eax,65535
-
 
722
    mov    ebx,[path_pointer_flp]
-
 
723
    add    ebx,36
-
 
724
    call   get_cluster_of_a_path_flp
-
 
725
    jc     fdc_status_error_7_1
-
 
726
found_directory_for_writing_flp:
-
 
727
    call   analyze_directory_to_write_flp
-
 
728
    jc     fdc_status_error_7_1
-
 
729
    mov    edi,ebx
-
 
730
fifoundds_1:
-
 
731
    push   edi            ; move the filename to root dir
-
 
732
    mov    esi,[esp+4+20]
-
 
733
    cmp    [save_root_flag],0
-
 
734
    jne    fifoundds_4
-
 
735
    mov    esi,[pointer_file_name_flp]
-
 
736
fifoundds_4:
-
 
737
    mov    ecx,11
-
 
738
    cld
-
 
739
    rep    movsb
-
 
740
    pop    edi
-
 
741
    mov    edx,edi
-
 
742
    add    edx,11+0xf        ; edx <- cluster save position
-
 
743
    mov    ebx,[esp+12]        ; save file size
-
 
744
    mov    [edi+28],ebx
-
 
745
    mov    [edi+11],byte 0x20    ; attribute
-
 
746
    call   get_date_for_file     ; from FAT32.INC
-
 
747
    mov    [edi+24],ax      ; date
-
 
748
    mov    [edi+18],ax      ; date
-
 
749
    call   get_time_for_file     ; from FAT32.INC
-
 
750
    mov    [edi+22],ax      ; time
-
 
751
    xor    ax,ax
-
 
752
    mov    [edi+20],ax
-
 
753
    mov    ebx,1            ; first cluster
-
 
754
    cmp    [save_root_flag],0
-
 
755
    jne    frnewds_1
-
 
756
    call   frnewds_2
-
 
757
    pusha
-
 
758
    call   WriteSectWithRetr
-
 
759
    popa
-
 
760
    cmp    [FDC_Status],0
-
 
761
    jne    fdc_status_error_7
-
 
762
    jmp    frnewds_3
-
 
763
 
-
 
764
frnewds_1:
-
 
765
    call   frnewds_2
-
 
766
frnewds_3:
-
 
767
    pusha                ; move save to floppy cluster
-
 
768
    add    ebx,31
-
 
769
    mov    eax,ebx
-
 
770
    mov    esi,[esp+32+16]
-
 
771
    call   take_data_from_application_1
-
 
772
    call   save_chs_sector
-
 
773
    cmp    [FDC_Status],0
-
 
774
    jne    fdc_status_error_7
-
 
775
    popa
-
 
776
    mov    eax,[esp+12]
-
 
777
    cmp    eax,512
-
 
778
    jb     flnsa_1
-
 
779
    sub    eax,512
-
 
780
    mov    [esp+12],eax
-
 
781
    mov    eax,[esp+16]
-
 
782
    add    eax,512
-
 
783
    mov    [esp+16],eax
-
 
784
    jmp    frnewds_1
-
 
785
 
-
 
786
frnewds_2:
-
 
787
    add    ebx,1
-
 
788
    mov    edi,ebx            ; find free cluster in FAT
-
 
789
    shl    edi,1
-
 
790
    add    edi,FLOPPY_FAT
-
 
791
    mov    eax,[edi]
-
 
792
    and    eax,4095
-
 
793
    jnz    frnewds_2
-
 
794
    mov    [edx],bx         ; save next cluster pos. to prev cl.
-
 
795
    mov    edx,edi            ; next save pos abs mem add
-
 
796
    ret
-
 
797
 
-
 
798
flnsa_1:
-
 
799
    mov    [edi],word 4095        ; mark end of file - last cluster
-
 
800
    cmp    [save_root_flag],1
-
 
801
    jne    flnsa_2
-
 
802
    call   save_flp_root
-
 
803
    cmp    [FDC_Status],0
-
 
804
    jne    fdc_status_error_7
-
 
805
flnsa_2:
-
 
806
    call   save_flp_fat
-
 
807
    cmp    [FDC_Status],0
-
 
808
    jne    fdc_status_error_7
-
 
809
frnoreadds_1:
-
 
810
    pop    edi esi edx ecx ebx eax
-
 
811
    add    esp,32
-
 
812
    mov    eax,0
-
 
813
    mov   [flp_status],0
-
 
814
    ret
-
 
815
 
-
 
816
fdc_status_error_7_1:
-
 
817
    cmp    [FDC_Status],0
-
 
818
    je    fdc_status_error_8
-
 
819
fdc_status_error_7:
-
 
820
    pop    edi esi edx ecx ebx eax
-
 
821
    add    esp,32
479
   ret
822
    jmp    fdc_status_error_1
480
 
823
 
481
 
824
save_chs_sector:
482
save_chs_sector:
Line 963... Line 621...
963
   add esp,4
621
   add esp,4
964
   clc        ;file found
622
   clc        ;file found
965
   ret
623
   ret
Line 966... Line -...
966
 
-
 
967
 
-
 
968
analyze_directory_to_write_flp:
-
 
969
;--------------------------------
-
 
970
; input  : EAX = first cluster of the directory
-
 
971
; output : IF CARRY=0 EAX = sector where the file is found
-
 
972
;                     EBX = pointer in buffer
-
 
973
;                     [buffer .. buffer+511]
-
 
974
;                     ECX,EDX,EDI,EDI not changed
-
 
975
;          IF CARRY=1
-
 
976
;--------------------------------
-
 
977
 
-
 
978
   push ecx
-
 
979
   push edx
-
 
980
   push esi
-
 
981
 
-
 
982
adr561:
-
 
983
   mov [clust_tmp_flp],eax
-
 
984
   add    eax,31
-
 
985
   pusha
-
 
986
   call   read_chs_sector
-
 
987
   popa
-
 
988
   cmp    [FDC_Status],0
-
 
989
   jne    error_found_file_analyze1
-
 
990
 
-
 
991
   mov ecx,512/32
-
 
992
   mov ebx,FDD_BUFF
-
 
993
 
-
 
994
adr1_analyze1:
-
 
995
   cmp byte [ebx],0x00
-
 
996
   je  found_file_analyze1
-
 
997
   cmp byte [ebx],0xe5
-
 
998
   je  found_file_analyze1
-
 
999
 
-
 
1000
avanti:
-
 
1001
   add ebx,32
-
 
1002
   loop adr1_analyze1
-
 
1003
 
-
 
1004
   mov eax,[clust_tmp_flp]
-
 
1005
   shl    eax,1            ;find next cluster from FAT
-
 
1006
   add    eax,FLOPPY_FAT
-
 
1007
   mov    eax,[eax]
-
 
1008
   and    eax,4095
-
 
1009
   cmp eax,0x0ff8
-
 
1010
   jb  adr561
-
 
1011
 
-
 
1012
   call get_free_FAT               ;this block of code add a new cluster
-
 
1013
                                   ;for the directory because the directory
-
 
1014
                                   ;is full
-
 
1015
 
-
 
1016
   mov [edi],word 0x0fff
-
 
1017
 
-
 
1018
   mov eax,[clust_tmp_flp]
-
 
1019
   shl    eax,1            ;find next cluster from FAT
-
 
1020
   add    eax,FLOPPY_FAT
-
 
1021
   sub    edi,FLOPPY_FAT
-
 
1022
   mov    [eax],di
-
 
1023
 
-
 
1024
   pusha
-
 
1025
   mov ecx,512/4
-
 
1026
   xor eax,eax
-
 
1027
   mov edi,FDD_BUFF
-
 
1028
   cld
-
 
1029
   rep stosd
-
 
1030
   popa
-
 
1031
 
-
 
1032
   mov    eax,edi
-
 
1033
   add    eax,31
-
 
1034
   pusha
-
 
1035
   call   save_chs_sector
-
 
1036
   popa
-
 
1037
   cmp    [FDC_Status],0
-
 
1038
   jne    error_found_file_analyze1
-
 
1039
   mov    ebx,FDD_BUFF
-
 
1040
 
-
 
1041
found_file_analyze1:
-
 
1042
 
-
 
1043
   pop esi
-
 
1044
   pop edx
-
 
1045
   pop ecx
-
 
1046
   clc        ;file found
-
 
1047
   ret
-
 
1048
 
-
 
1049
error_found_file_analyze1:
-
 
1050
   pop esi
-
 
1051
   pop edx
-
 
1052
   pop ecx
-
 
1053
   stc
-
 
1054
   ret
-
 
1055
 
-
 
1056
get_free_FAT_flp:
-
 
1057
;------------------------------------------
-
 
1058
; input  :  EAX = # cluster for start the searching
-
 
1059
; output :  EAX = # first cluster found free
-
 
1060
;-------------------------------------------
-
 
1061
   push ebx
-
 
1062
 
-
 
1063
    mov    ebx,1
-
 
1064
check_new_flp:
-
 
1065
    add    ebx,1
-
 
1066
    mov    edi,ebx            ; find free cluster in FAT
-
 
1067
    shl    edi,1
-
 
1068
    add    edi,FLOPPY_FAT
-
 
1069
    mov    eax,[edi]
-
 
1070
    and    eax,4095
-
 
1071
    cmp    eax,0x0
-
 
1072
    jnz    check_new_flp
-
 
1073
 
-
 
1074
   pop ebx
-
 
1075
   ret
624
 
1076
 
625
 
1077
; \begin{diamond}
626
; \begin{diamond}
1078
fat_find_lfn:
627
fat_find_lfn:
1079
; in: esi->name
628
; in: esi->name