Subversion Repositories Kolibri OS

Rev

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

Rev 256 Rev 321
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                         ;;
10
;;  08.10.2006 LFN delete file/folder - diamond                    ;;
11
;;  08.10.2006 LFN delete file/folder - diamond                    ;;
11
;;  20.08.2006 LFN set file size (truncate/extend) - diamond       ;;
12
;;  20.08.2006 LFN set file size (truncate/extend) - diamond       ;;
12
;;  17.08.2006 LFN write/append to file - diamond                  ;;
13
;;  17.08.2006 LFN write/append to file - diamond                  ;;
13
;;  23.06.2006 LFN start application - diamond                     ;;
14
;;  23.06.2006 LFN start application - diamond                     ;;
14
;;  15.06.2006 LFN get/set file/folder info - diamond              ;;
15
;;  15.06.2006 LFN get/set file/folder info - diamond              ;;
Line 99... Line 100...
99
  buffer:              times 512 db 0
100
  buffer:              times 512 db 0
100
  deltree_buffer:      times 512 db 0
101
  deltree_buffer:      times 512 db 0
101
  fsinfo_buffer:       times 512 db 0
102
  fsinfo_buffer:       times 512 db 0
102
endg
103
endg
Line 103... Line -...
103
 
-
 
104
iglobal
-
 
105
  NewDirEntry1         db ".          ",0x10
-
 
106
                     times 20 db 0
-
 
107
  NewDirEntry2         db "..         ",0x10
-
 
108
                     times 20 db 0
-
 
109
endg
-
 
110
 
104
 
111
uglobal
105
uglobal
Line 112... Line 106...
112
  dir_entry:           times 32 db 0
106
  dir_entry:           times 32 db 0
Line 137... Line 131...
137
    mov   [hd1_status],eax
131
    mov   [hd1_status],eax
138
    pop   eax
132
    pop   eax
139
    sti
133
    sti
140
    ret
134
    ret
141
;********************************************
135
;********************************************
-
 
136
 
-
 
137
uglobal
-
 
138
hd_in_cache db ?
-
 
139
endg
-
 
140
 
142
reserve_hd_channel:
141
reserve_hd_channel:
143
    cmp   [hdbase], 0x1F0
142
    cmp   [hdbase], 0x1F0
144
    jne   .IDE_Channel_2
143
    jne   .IDE_Channel_2
145
.IDE_Channel_1:
144
.IDE_Channel_1:
146
    cli
145
    cli
Line 153... Line 152...
153
    cli
152
    cli
154
    cmp   [IDE_Channel_2],0
153
    cmp   [IDE_Channel_2],0
155
    je    .reserve_ok_2
154
    je    .reserve_ok_2
156
    sti
155
    sti
157
    call  change_task
156
    call  change_task
158
    jmp   .IDE_Channel_1
157
    jmp   .IDE_Channel_2
159
.reserve_ok_1:
158
.reserve_ok_1:
160
    mov [IDE_Channel_1],1
159
        mov     [IDE_Channel_1], 1
161
    ret
160
        push    eax
-
 
161
        mov     al, 1
-
 
162
        jmp     @f
162
.reserve_ok_2:
163
.reserve_ok_2:
163
    mov [IDE_Channel_2],1
164
        mov     [IDE_Channel_2], 1
-
 
165
        push    eax
-
 
166
        mov     al, 3
-
 
167
@@:
-
 
168
        cmp     [hdid], 1
-
 
169
        sbb     al, -1
-
 
170
        cmp     al, [hd_in_cache]
-
 
171
        jz      @f
-
 
172
        mov     [hd_in_cache], al
-
 
173
        call    clear_hd_cache
-
 
174
@@:
-
 
175
	pop     eax
164
    ret
176
        ret
Line 165... Line 177...
165
    
177
 
166
free_hd_channel:
178
free_hd_channel:
167
    cmp   [hdbase], 0x1F0
179
    cmp   [hdbase], 0x1F0
Line 804... Line 816...
804
    mov   [ebx+24],ax
816
    mov   [ebx+24],ax
805
    pop   eax
817
    pop   eax
806
    ret
818
    ret
Line 807... Line -...
807
 
-
 
808
 
-
 
809
makedir:
-
 
810
;-----------------------------------------------------
-
 
811
; input  : eax = directory name
-
 
812
;          edx = path
-
 
813
; output : eax = 0 - ok
-
 
814
;                3 - unknown FS
-
 
815
;                5 - file not found
-
 
816
;                8 - disk full
-
 
817
;               10 - access denied
-
 
818
; Note   : can only make one directory at time
-
 
819
;-----------------------------------------------------
-
 
820
        cmp     [fs_type], 16
-
 
821
        jz      make_dir_fat_ok
-
 
822
        cmp     [fs_type], 32
-
 
823
        jz      make_dir_fat_ok
-
 
824
        push    ERROR_UNKNOWN_FS
-
 
825
        pop     eax
-
 
826
        ret
-
 
827
 
-
 
828
  make_dir_fat_ok:
-
 
829
;    call  reserve_hd1
-
 
830
 
-
 
831
    pushad
-
 
832
 
-
 
833
    mov   ebx,edx
-
 
834
    call  get_cluster_of_a_path
-
 
835
    jnc   make_dir_found_path
-
 
836
    cmp   [hd_error],0
-
 
837
    jne   make_dir_error_1
-
 
838
 
-
 
839
  make_dir_path_not_found:
-
 
840
    popad
-
 
841
    call  update_disk           ; write all of cache and fat to hd
-
 
842
    cmp   [hd_error],0
-
 
843
    jne   make_dir_error_2
-
 
844
 
-
 
845
    mov   [hd1_status],0
-
 
846
    mov   eax,ERROR_FILE_NOT_FOUND
-
 
847
    ret
-
 
848
 
-
 
849
  make_dir_disk_full:
-
 
850
    cmp  [hd_error],0
-
 
851
    jne   make_dir_error_1
-
 
852
    popad
-
 
853
    call  update_disk           ; write all of cache and fat to hd
-
 
854
    cmp   [hd_error],0
-
 
855
    jne   make_dir_error_2
-
 
856
 
-
 
857
    mov   [hd1_status],0
-
 
858
    mov   eax,ERROR_DISK_FULL
-
 
859
    ret
-
 
860
 
-
 
861
  make_dir_already_exist:
-
 
862
    cmp  [hd_error],0
-
 
863
    jne   make_dir_error_1    
-
 
864
    mov   eax,[cluster]         ; directory cluster
-
 
865
    xor   edx,edx               ; free
-
 
866
    call  set_FAT
-
 
867
    cmp  [hd_error],0
-
 
868
    jne   make_dir_error_1
-
 
869
 
-
 
870
    popad
-
 
871
    call  update_disk           ; write all of cache and fat to hd
-
 
872
  make_dir_error_2:
-
 
873
    mov   [hd1_status],0
-
 
874
    mov   eax,ERROR_ACCESS_DENIED
-
 
875
    ret
-
 
876
 
-
 
877
  make_dir_error_1:
-
 
878
    popad
-
 
879
    jmp   make_dir_error_2
-
 
880
 
-
 
881
  make_dir_error_3:
-
 
882
    add  esp,4
-
 
883
    jmp   make_dir_error_1
-
 
884
 
-
 
885
  make_dir_found_path:
-
 
886
    cmp   eax,[ROOT_CLUSTER]
-
 
887
    jnz   make_dir_not_root
-
 
888
    xor   eax,eax
-
 
889
 
-
 
890
  make_dir_not_root:
-
 
891
    mov   ecx,eax               ; directorys start cluster
-
 
892
    mov   word [NewDirEntry2+26],cx ; 16 bits low of cluster
-
 
893
    shr   ecx,16
-
 
894
    mov   word [NewDirEntry2+20],cx ; 16 bits high of cluster (=0 fat16)
-
 
895
 
-
 
896
    push  eax                   ; save parent directory cluster
-
 
897
    mov   eax,2
-
 
898
    call  get_free_FAT
-
 
899
    mov   [cluster],eax         ; first free cluster
-
 
900
    pop   eax
-
 
901
    jc    make_dir_disk_full
-
 
902
 
-
 
903
    push  eax
-
 
904
    mov   eax,[cluster]         ; directory cluster
-
 
905
    mov   edx,[fatEND]          ; end for directory
-
 
906
    call  set_FAT
-
 
907
    cmp  [hd_error],0
-
 
908
    jne   make_dir_error_3
-
 
909
    pop   eax
-
 
910
 
-
 
911
    mov   ebx,PUSHAD_EAX        ; dir name
-
 
912
    push  eax
-
 
913
    call  analyze_directory     ; check if directory already exist
-
 
914
    cmp   [hd_error],0
-
 
915
    jne   make_dir_error_1
-
 
916
 
-
 
917
    pop   eax
-
 
918
    jnc   make_dir_already_exist ; need to free allocated cluster!
-
 
919
 
-
 
920
    call  analyze_directory_to_write
-
 
921
    jc    make_dir_already_exist ; need to free allocated cluster!
-
 
922
 
-
 
923
    mov   esi,PUSHAD_EAX        ; dir name
-
 
924
    mov   edi,ebx               ; pointer in buffer
-
 
925
    mov   ecx,11
-
 
926
    cld
-
 
927
    rep   movsb
-
 
928
 
-
 
929
    mov   dword [ebx+28],0      ; dir size is always 0
-
 
930
    mov   ecx,[cluster]
-
 
931
    mov   [ebx+26],cx           ; 16 bits low of cluster
-
 
932
    mov   word [NewDirEntry1+26],cx
-
 
933
    shr   ecx,16
-
 
934
    mov   [ebx+20],cx           ; 16 bits high of cluster (=0 fat16)
-
 
935
    mov   word [NewDirEntry1+20],cx
-
 
936
    mov   byte [ebx+11],0x10    ; attribute = directory
-
 
937
 
-
 
938
    call  set_current_time_for_entry
-
 
939
    mov   ecx,[ebx+22]
-
 
940
    mov   dword [NewDirEntry1+22],ecx
-
 
941
    mov   dword [NewDirEntry2+22],ecx
-
 
942
 
-
 
943
    mov   ebx,buffer            ; save the directory name,length,cluster
-
 
944
    call  hd_write
-
 
945
    cmp   [hd_error],0
-
 
946
    jne   make_dir_error_1
-
 
947
 
-
 
948
    mov   ecx,512/4
-
 
949
    xor   eax,eax
-
 
950
    mov   edi,buffer
-
 
951
    cld
-
 
952
    rep   stosd                 ; clear new directory cluster
-
 
953
 
-
 
954
    mov   eax,[cluster]         ; new directory cluster
-
 
955
    sub   eax,2
-
 
956
    mov   edx,[SECTORS_PER_CLUSTER]
-
 
957
    imul  eax,edx
-
 
958
    add   eax,[DATA_START]
-
 
959
    mov   ebx,buffer
-
 
960
    add   eax,edx               ; start from last sector
-
 
961
 
-
 
962
  dir_set_empty_directory:
-
 
963
    dec   eax                   ; next sector
-
 
964
    cmp   edx,1                 ; is first directory sector?
-
 
965
    jnz   not_first_sector      ; no. write empty sector
-
 
966
    mov   esi,NewDirEntry1
-
 
967
    mov   edi,buffer
-
 
968
    mov   ecx,64/4
-
 
969
    cld
-
 
970
    rep   movsd                 ; copy 2 first directory entrys "." and ".."
-
 
971
 
-
 
972
  not_first_sector:
-
 
973
    call  hd_write
-
 
974
    cmp   [hd_error],0
-
 
975
    jne   make_dir_error_1
-
 
976
  
-
 
977
    dec   edx
-
 
978
    jnz   dir_set_empty_directory
-
 
979
 
-
 
980
    mov   ecx,-1                ; remove 1 cluster from free disk space
-
 
981
    call  add_disk_free_space
-
 
982
    cmp  [hd_error],0
-
 
983
    jne   make_dir_error_1
-
 
984
 
-
 
985
    popad
-
 
986
    call  update_disk           ; write all of cache and fat to hd
-
 
987
    cmp   [hd_error],0
-
 
988
    jne   make_dir_error_2
-
 
989
    mov   [hd1_status],0
-
 
Line 990... Line 819...
990
    xor   eax,eax
819
 
991
    ret
820
 
992
 
821
 
993
add_disk_free_space:
822
add_disk_free_space:
Line 1662... Line 1491...
1662
 
1491
 
1663
  delete_name_end:
1492
  delete_name_end:
Line 1664... Line -...
1664
    ret
-
 
1665
 
-
 
1666
 
-
 
1667
rename:
-
 
1668
;-----------------------------------------------------------
-
 
1669
; input  : eax = source directory name
-
 
1670
;          edx = source path
-
 
1671
;          ebx = dest directory name
-
 
1672
;          edi = dest path
-
 
1673
; output : eax = 0 - ok
-
 
1674
;                3 - unknown FS
-
 
1675
;                5 - file not found
-
 
1676
;                8 - disk full
-
 
1677
;               10 - access denied
-
 
1678
;-----------------------------------------------------------
-
 
1679
        cmp     [fs_type], 16
-
 
1680
        jz      fat_ok_for_rename
-
 
1681
        cmp     [fs_type], 32
-
 
1682
        jz      fat_ok_for_rename
-
 
1683
        push    ERROR_UNKNOWN_FS
-
 
1684
        pop     eax
-
 
1685
        ret
-
 
1686
 
-
 
1687
  fat_ok_for_rename:
-
 
1688
;    call  reserve_hd1
-
 
1689
 
-
 
1690
    pushad
-
 
1691
 
-
 
1692
    mov   ebx,edx               ; source path
-
 
1693
    call  get_cluster_of_a_path
-
 
1694
    jc    rename_entry_not_found
-
 
1695
 
-
 
1696
    mov   ebx,PUSHAD_EAX        ; source directory name
-
 
1697
    call  analyze_directory
-
 
1698
    jc    rename_entry_not_found
-
 
1699
 
-
 
1700
    mov   [sector_tmp],eax      ; save source sector
-
 
1701
    mov   [entry_pos],ebx
-
 
1702
    mov   esi,ebx
-
 
1703
    mov   edi,dir_entry
-
 
1704
    mov   ecx,32/4
-
 
1705
    cld
-
 
1706
    rep   movsd                 ; save entry
-
 
1707
 
-
 
1708
    mov   ebx,PUSHAD_EDI        ; dest path
-
 
1709
    call  get_cluster_of_a_path
-
 
1710
    jc    rename_entry_not_found
-
 
1711
 
-
 
1712
    mov   edx,eax               ; save dest directory cluster
-
 
1713
    mov   ebx,PUSHAD_EBX        ; dest directory name
-
 
1714
    push  [longname_sec1]
-
 
1715
    push  [longname_sec2]
-
 
1716
    call  analyze_directory     ; check if entry already exist
-
 
1717
    cmp  [hd_error],0
-
 
1718
    jne  rename_entry_already_exist_1
-
 
1719
 
-
 
1720
    pop   [longname_sec2]
-
 
1721
    pop   [longname_sec1]
-
 
1722
    jnc   rename_entry_already_exist
-
 
1723
 
-
 
1724
    mov   eax,edx
-
 
1725
    call  analyze_directory_to_write
-
 
1726
    jc    rename_disk_full
-
 
1727
 
-
 
1728
    mov   esi,dir_entry
-
 
1729
    mov   edi,ebx
-
 
1730
    mov   ecx,32/4
-
 
1731
    cld
-
 
1732
    rep   movsd                 ; copy entry
-
 
1733
    mov   esi,PUSHAD_EBX        ; dest directory name
-
 
1734
    mov   edi,ebx
-
 
1735
    mov   ecx,11
-
 
1736
    rep   movsb                 ; copy name
-
 
1737
 
-
 
1738
    mov   ebx,buffer            ; save the directory name,length,cluster
-
 
1739
    call  hd_write
-
 
1740
 
-
 
1741
    test  byte [dir_entry+11],0x10 ; is it directory?
-
 
1742
    jz    rename_not_dir           ; no
-
 
1743
    mov   eax,[dir_entry+20-2]     ; FAT entry
-
 
1744
    mov   ax,[dir_entry+26]
-
 
1745
    and   eax,[fatMASK]
-
 
1746
    call  change_2dot_cluster
-
 
1747
    cmp   [hd_error],0
-
 
1748
    jne   rename_entry_already_exist
-
 
1749
 
-
 
1750
  rename_not_dir:
-
 
1751
    cmp   [hd_error],0
-
 
1752
    jne   rename_entry_already_exist
-
 
1753
    mov   eax,[sector_tmp]
-
 
1754
    mov   ebx,buffer
-
 
1755
    call  hd_read               ; read source directory sector
-
 
1756
    cmp  [hd_error],0
-
 
1757
    jne  rename_entry_already_exist
-
 
1758
 
-
 
1759
    mov   ebx,[entry_pos]
-
 
1760
    call  delete_entry_name
-
 
1761
    cmp   [hd_error],0
-
 
1762
    jne   rename_entry_already_exist
-
 
1763
 
-
 
1764
    popad
-
 
1765
    call  update_disk           ; write all of cache and fat to hd
-
 
1766
    cmp   [hd_error],0
-
 
1767
    jne   rename_entry_already_exist_2
-
 
1768
    mov   [hd1_status],0
-
 
1769
    xor   eax,eax
-
 
1770
    ret
-
 
1771
 
-
 
1772
  rename_entry_not_found:
-
 
1773
    cmp  [hd_error],0
-
 
1774
    jne  rename_entry_already_exist
-
 
1775
    popad
-
 
1776
    mov   [hd1_status],0
-
 
1777
    mov   eax,ERROR_FILE_NOT_FOUND
-
 
1778
    ret
-
 
1779
 
-
 
1780
  rename_entry_already_exist_1:
-
 
1781
    add   esp,8
-
 
1782
  rename_entry_already_exist:
-
 
1783
    popad
-
 
1784
  rename_entry_already_exist_2:
-
 
1785
    mov   [hd1_status],0
-
 
1786
    mov   eax,ERROR_ACCESS_DENIED
-
 
1787
    ret
-
 
1788
 
-
 
1789
  rename_disk_full:
-
 
1790
    cmp  [hd_error],0
-
 
1791
    jne  rename_entry_already_exist
-
 
1792
    popad
-
 
1793
    mov   [hd1_status],0
-
 
1794
    mov   eax,ERROR_DISK_FULL
-
 
1795
    ret
-
 
1796
 
-
 
1797
 
-
 
1798
change_2dot_cluster:
-
 
1799
;-----------------------------------------------------------
-
 
1800
; input  : eax = directory cluster
-
 
1801
;          edx = value to save
-
 
1802
; change : eax,ebx,edx
-
 
1803
;-----------------------------------------------------------
-
 
1804
    cmp   eax,[LAST_CLUSTER]
-
 
1805
    ja    not_2dot              ; too big cluster number, something is wrong
-
 
1806
    sub   eax,2
-
 
1807
    jb    not_2dot
-
 
1808
 
-
 
1809
    imul  eax,[SECTORS_PER_CLUSTER]
-
 
1810
    add   eax,[DATA_START]
-
 
1811
    mov   ebx,buffer
-
 
1812
    call  hd_read
-
 
1813
    cmp  [hd_error],0
-
 
1814
    jne  not_2dot
-
 
1815
 
-
 
1816
    cmp   dword [ebx+32],'..  '
-
 
1817
    jnz   not_2dot
-
 
1818
 
-
 
1819
    cmp   edx,[ROOT_CLUSTER]    ; is rootdir cluster?
-
 
1820
    jne   not_2dot_root
-
 
1821
    xor   edx,edx               ; yes. set it zero
-
 
1822
 
-
 
1823
  not_2dot_root:
-
 
1824
    mov   [ebx+32+26],dx        ; 16 bits low of cluster
-
 
1825
    shr   edx,16
-
 
1826
    mov   [ebx+32+20],dx        ; 16 bits high of cluster (=0 fat16)
-
 
1827
    call  hd_write
-
 
1828
 
-
 
1829
  not_2dot:
-
 
1830
    ret
1493
    ret
1831
 
1494
 
1832
 
1495
 
1833
get_hd_info:
1496
get_hd_info:
1834
;-----------------------------------------------------------
1497
;-----------------------------------------------------------
Line 2553... Line 2216...
2553
fshrfs:
2216
fshrfs:
2554
        mov     eax, ERROR_UNKNOWN_FS
2217
        mov     eax, ERROR_UNKNOWN_FS
2555
        xor     ebx, ebx
2218
        xor     ebx, ebx
2556
        ret
2219
        ret
Line -... Line 2220...
-
 
2220
 
-
 
2221
fs_HdCreateFolder:
-
 
2222
        mov     al, 1
-
 
2223
        jmp     fs_HdRewrite.common
2557
 
2224
 
-
 
2225
fs_HdRewrite:
-
 
2226
        xor     eax, eax
2558
fs_HdRewrite:
2227
.common:
2559
        cmp     [fs_type], 1
2228
        cmp     [fs_type], 1
2560
        jz      ntfs_HdRewrite
2229
        jz      ntfs_HdRewrite
2561
        cmp     [fs_type], 16
2230
        cmp     [fs_type], 16
2562
        jz      @f
2231
        jz      @f
Line 2625... Line 2294...
2625
        push    fat_notroot_first
2294
        push    fat_notroot_first
2626
        push    fat_notroot_next
2295
        push    fat_notroot_next
2627
.common1:
2296
.common1:
2628
        call    fat_find_lfn
2297
        call    fat_find_lfn
2629
        jc      .notfound
2298
        jc      .notfound
2630
; found; must not be directory
2299
; found
2631
        test    byte [edi+11], 10h
2300
        test    byte [edi+11], 10h
-
 
2301
        jz      .exists_file
-
 
2302
; found directory; if we are creating directory, return OK,
-
 
2303
;                  if we are creating file, say "access denied"
-
 
2304
        add     esp, 32
-
 
2305
        popad
-
 
2306
        test    al, al
-
 
2307
        mov     eax, ERROR_ACCESS_DENIED
-
 
2308
        jz      @f
-
 
2309
        mov     al, 0
-
 
2310
@@:
-
 
2311
        xor     ebx, ebx
-
 
2312
        ret
-
 
2313
.exists_file:
-
 
2314
; found file; if we are creating directory, return "access denied",
-
 
2315
;             if we are creating file, delete existing file and continue
-
 
2316
        cmp     byte [esp+32+28], 0
2632
        jz      @f
2317
        jz      @f
2633
        add     esp, 32
2318
        add     esp, 32
2634
        popad
2319
        popad
2635
        mov     eax, ERROR_ACCESS_DENIED
2320
        mov     eax, ERROR_ACCESS_DENIED
2636
        xor     ebx, ebx
2321
        xor     ebx, ebx
Line 2863... Line 2548...
2863
        mov     [edi+18], ax            ; last access date
2548
        mov     [edi+18], ax            ; last access date
2864
        xor     ecx, ecx
2549
        xor     ecx, ecx
2865
        mov     word [edi+20], cx       ; high word of cluster
2550
        mov     word [edi+20], cx       ; high word of cluster
2866
        mov     word [edi+26], cx       ; low word of cluster - to be filled
2551
        mov     word [edi+26], cx       ; low word of cluster - to be filled
2867
        mov     dword [edi+28], ecx     ; file size - to be filled
2552
        mov     dword [edi+28], ecx     ; file size - to be filled
-
 
2553
        cmp     byte [esp+32+28], cl
-
 
2554
        jz      .doit
-
 
2555
; create directory
-
 
2556
        mov     byte [edi+11], 10h      ; attributes: folder
-
 
2557
        mov     edx, edi
-
 
2558
        lea     eax, [esp+8]
-
 
2559
        call    dword [eax+16]  ; flush directory
-
 
2560
        push    ecx
-
 
2561
        mov     ecx, [SECTORS_PER_CLUSTER]
-
 
2562
        shl     ecx, 9
-
 
2563
        jmp     .doit2
2868
.doit:
2564
.doit:
2869
        lea     eax, [esp+8]
2565
        lea     eax, [esp+8]
2870
        call    dword [eax+16]  ; flush directory
2566
        call    dword [eax+16]  ; flush directory
2871
        push    ecx
2567
        push    ecx
2872
        mov     ecx, [esp+4+32+24]
2568
        mov     ecx, [esp+4+32+24]
-
 
2569
.doit2:
2873
        push    ecx
2570
        push    ecx
2874
        push    edi
2571
        push    edi
2875
        mov     esi, edx
2572
        mov     esi, edx
2876
        test    ecx, ecx
2573
        test    ecx, ecx
2877
        jz      .done
2574
        jz      .done
Line 2896... Line 2593...
2896
        mov     ebp, [SECTORS_PER_CLUSTER]
2593
        mov     ebp, [SECTORS_PER_CLUSTER]
2897
        imul    eax, ebp
2594
        imul    eax, ebp
2898
        add     eax, [DATA_START]
2595
        add     eax, [DATA_START]
2899
; write data
2596
; write data
2900
.write_sector:
2597
.write_sector:
-
 
2598
        cmp     byte [esp+16+32+28], 0
-
 
2599
        jnz     .writedir
2901
        mov     ecx, 512
2600
        mov     ecx, 512
2902
        cmp     dword [esp+8], ecx
2601
        cmp     dword [esp+8], ecx
2903
        jb      .writeshort
2602
        jb      .writeshort
2904
; we can write directly from given buffer
2603
; we can write directly from given buffer
2905
        mov     ebx, esi
2604
        mov     ebx, esi
Line 2909... Line 2608...
2909
        mov     ecx, [esp+8]
2608
        mov     ecx, [esp+8]
2910
        push    ecx
2609
        push    ecx
2911
        mov     edi, buffer
2610
        mov     edi, buffer
2912
        mov     ebx, edi
2611
        mov     ebx, edi
2913
        rep     movsb
2612
        rep     movsb
-
 
2613
.writedircont:
2914
        mov     ecx, buffer+0x200
2614
        mov     ecx, buffer+0x200
2915
        sub     ecx, edi
2615
        sub     ecx, edi
2916
        push    eax
2616
        push    eax
2917
        xor     eax, eax
2617
        xor     eax, eax
2918
        rep     stosb
2618
        rep     stosb
Line 2975... Line 2675...
2975
        call    add_disk_free_space
2675
        call    add_disk_free_space
2976
        add     esp, 32
2676
        add     esp, 32
2977
        call    update_disk
2677
        call    update_disk
2978
        popad
2678
        popad
2979
        ret
2679
        ret
-
 
2680
.writedir:
-
 
2681
        push    512
-
 
2682
        mov     edi, buffer
-
 
2683
        mov     ebx, edi
-
 
2684
        mov     ecx, [SECTORS_PER_CLUSTER]
-
 
2685
        shl     ecx, 9
-
 
2686
        cmp     ecx, [esp+12]
-
 
2687
        jnz     .writedircont
-
 
2688
        dec     dword [esp+16]
-
 
2689
        push    esi
-
 
2690
        mov     ecx, 32/4
-
 
2691
        rep     movsd
-
 
2692
        pop     esi
-
 
2693
        mov     dword [edi-32], '.   '
-
 
2694
        mov     dword [edi-32+4], '    '
-
 
2695
        mov     dword [edi-32+8], '    '
-
 
2696
        mov     byte [edi-32+11], 10h
-
 
2697
        push    esi
-
 
2698
        mov     ecx, 32/4
-
 
2699
        rep     movsd
-
 
2700
        pop     esi
-
 
2701
        mov     dword [edi-32], '..  '
-
 
2702
        mov     dword [edi-32+4], '    '
-
 
2703
        mov     dword [edi-32+8], '    '
-
 
2704
        mov     byte [edi-32+11], 10h
-
 
2705
        mov     ecx, [esp+20+8]
-
 
2706
        cmp     ecx, [ROOT_CLUSTER]
-
 
2707
        jnz     @f
-
 
2708
        xor     ecx, ecx
-
 
2709
@@:
-
 
2710
        mov     word [edi-32+26], cx
-
 
2711
        shr     ecx, 16
-
 
2712
        mov     [edi-32+20], cx
-
 
2713
        jmp     .writedircont
Line 2980... Line 2714...
2980
 
2714
 
2981
;----------------------------------------------------------------
2715
;----------------------------------------------------------------
2982
;
2716
;
2983
;  fs_HdWrite - LFN variant for writing to hard disk
2717
;  fs_HdWrite - LFN variant for writing to hard disk
Line 3117... Line 2851...
3117
 
2851
 
3118
; now ebx=start pos, ecx=end pos, both lie inside file
2852
; now ebx=start pos, ecx=end pos, both lie inside file
3119
        sub     ecx, ebx
2853
        sub     ecx, ebx
3120
        jz      .ret
2854
        jz      .ret
-
 
2855
.write_loop:
-
 
2856
; skip unmodified sectors
-
 
2857
        cmp     dword [esp], 0x200
-
 
2858
        jb      .modify
-
 
2859
        sub     ebx, 0x200
-
 
2860
        jae     .skip
-
 
2861
        add     ebx, 0x200
3121
.write_loop:
2862
.modify:
3122
; get length of data in current sector
2863
; get length of data in current sector
3123
        push    ecx
2864
        push    ecx
3124
        sub     ebx, 0x200
2865
        sub     ebx, 0x200
3125
        jb      .hasdata
2866
        jb      .hasdata
Line 3173... Line 2914...
3173
        jbe     @f
2914
        jbe     @f
3174
        mov     edi, buffer
2915
        mov     edi, buffer
3175
        add     edi, esi
2916
        add     edi, esi
3176
        rep     stosb
2917
        rep     stosb
3177
@@:
2918
@@:
3178
        pop     edi ecx eax
2919
        pop     edi ecx
3179
; copy new data
2920
; copy new data
3180
        push    eax
-
 
3181
        mov     eax, edx
2921
        mov     eax, edx
3182
        neg     ebx
2922
        neg     ebx
3183
        jecxz   @f
2923
        jecxz   @f
3184
        add     ebx, buffer+0x200
2924
        add     ebx, buffer+0x200
3185
        call    memmove
2925
        call    memmove
Line 3195... Line 2935...
3195
        jnz     .device_err2
2935
        jnz     .device_err2
3196
        add     edx, ecx
2936
        add     edx, ecx
3197
        sub     [esp], ecx
2937
        sub     [esp], ecx
3198
        pop     ecx
2938
        pop     ecx
3199
        jz      .ret
2939
        jz      .ret
-
 
2940
.skip:
3200
; next sector
2941
; next sector
3201
        inc     ebp
2942
        inc     ebp
3202
        cmp     ebp, [SECTORS_PER_CLUSTER]
2943
        cmp     ebp, [SECTORS_PER_CLUSTER]
3203
        jb      @f
2944
        jb      @f
3204
        xor     ebp, ebp
2945
        xor     ebp, ebp