Subversion Repositories Kolibri OS

Rev

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

Rev 6867 Rev 6868
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 6867 $
8
$Revision: 6868 $
9
 
9
 
10
; FAT external functions
10
; FAT external functions
11
;   in:
11
;   in:
Line 76... Line 76...
76
; additional memory and additional code for packing/unpacking.
76
; additional memory and additional code for packing/unpacking.
77
; I'm not sure that the economy justifies the cost, but anyway,
77
; I'm not sure that the economy justifies the cost, but anyway,
78
; there is how work was done before my edits, and I'm just keeping the principle.
78
; there is how work was done before my edits, and I'm just keeping the principle.
79
fat_cache_ptr       dd  ?
79
fat_cache_ptr       dd  ?
80
fat12_unpacked_ptr  dd  ?
80
fat12_unpacked_ptr  dd  ?
-
 
81
volumeLabel         rb  12
81
buffer              rb  512
82
buffer              rb  512
82
fsinfo_buffer       rb  512
83
fsinfo_buffer       rb  512
83
ends
84
ends
Line 84... Line 85...
84
 
85
 
Line 197... Line 198...
197
        inc     eax
198
        inc     eax
198
        mov     [ebp+FAT.LAST_CLUSTER], eax
199
        mov     [ebp+FAT.LAST_CLUSTER], eax
199
        dec     eax                     ; cluster count
200
        dec     eax                     ; cluster count
200
        jz      .free_return0
201
        jz      .free_return0
201
        mov     [ebp+FAT.fatStartScan], 2
202
        mov     [ebp+FAT.fatStartScan], 2
202
; limits by Microsoft Hardware White Paper v1.03
-
 
203
        cmp     eax, 0xff5
-
 
204
        jb      .fat12
-
 
205
        cmp     eax, 0xfff5
203
        cmp     eax, 0xfff5
206
        jb      .fat16
204
        jb      .fat16
207
.fat32:
205
.fat32:
-
 
206
        pusha
-
 
207
        lea     esi, [ebx+71]
-
 
208
        lea     edi, [ebp+FAT.volumeLabel]
-
 
209
        movsd
-
 
210
        movsd
-
 
211
        movsd
-
 
212
        popa
208
        mov     eax, [ebx+0x2c]         ; rootdir cluster
213
        mov     eax, [ebx+0x2c]         ; rootdir cluster
209
        mov     [ebp+FAT.ROOT_CLUSTER], eax
214
        mov     [ebp+FAT.ROOT_CLUSTER], eax
210
        movzx   eax, word [ebx+0x30]
215
        movzx   eax, word [ebx+0x30]
211
        mov     [ebp+FAT.ADR_FSINFO], eax
216
        mov     [ebp+FAT.ADR_FSINFO], eax
212
        push    ebx
217
        push    ebx
Line 236... Line 241...
236
        mov     eax, ebp
241
        mov     eax, ebp
237
        pop     ebp
242
        pop     ebp
238
        ret
243
        ret
Line 239... Line 244...
239
 
244
 
-
 
245
.fat16:
-
 
246
        pusha
-
 
247
        lea     esi, [ebx+43]
-
 
248
        lea     edi, [ebp+FAT.volumeLabel]
-
 
249
        movsd
-
 
250
        movsd
-
 
251
        movsd
-
 
252
        popa
-
 
253
        cmp     eax, 0xff5
240
.fat16:
254
        jb      .fat12
241
        and     [ebp+FAT.ROOT_CLUSTER], 0
255
        and     [ebp+FAT.ROOT_CLUSTER], 0
242
        mov     [ebp+FAT.fatRESERVED], 0x0000FFF6
256
        mov     [ebp+FAT.fatRESERVED], 0x0000FFF6
243
        mov     [ebp+FAT.fatBAD], 0x0000FFF7
257
        mov     [ebp+FAT.fatBAD], 0x0000FFF7
244
        mov     [ebp+FAT.fatEND], 0x0000FFF8
258
        mov     [ebp+FAT.fatEND], 0x0000FFF8
Line 910... Line 924...
910
fat_unlock:
924
fat_unlock:
911
        lea     ecx, [ebp+FAT.Lock]
925
        lea     ecx, [ebp+FAT.Lock]
912
        jmp     mutex_unlock
926
        jmp     mutex_unlock
Line 913... Line 927...
913
 
927
 
914
fat_get_name:
928
fat_get_name:
915
; in: edi -> FAT entry
929
; in: edi -> FAT entry, esi -> buffer for UTF-16 name
916
; out: ebp -> UTF-16 name, CF=1 -> no valid entry
930
; out: CF=1 -> no valid entry
917
        cmp     byte [edi], 0
931
        cmp     byte [edi], 0
918
        jz      .no
932
        jz      .no
919
        cmp     byte [edi], 0xE5
933
        cmp     byte [edi], 0xE5
920
        jz      .no
934
        jz      .no
921
        cmp     byte [edi+11], 0xF
935
        cmp     byte [edi+11], 0xF
922
        jz      .longname
936
        jz      .longname
923
        test    byte [edi+11], 8
937
        push    edi
924
        jnz     .no
938
        xchg    esi, edi
925
        push    ecx esi edi
939
        test    byte [esi+11], 8
-
 
940
        jnz     .label
926
        mov     esi, edi
941
        pushd   ecx 8
927
        mov     edi, ebp
942
        pop     ecx
928
        mov     ecx, 8
943
        xor     eax, eax
929
@@:
944
@@:
930
        lodsb
-
 
931
        call    ansi2uni_char
945
        lodsb
932
        stosw
946
        stosw
933
        loop    @b
947
        loop    @b
934
        mov     cl, 8
948
        mov     cl, 8
935
@@:
949
@@:
Line 941... Line 955...
941
        mov     word [edi], '.'
955
        mov     word [edi], '.'
942
        add     edi, 2
956
        add     edi, 2
943
        mov     cl, 3
957
        mov     cl, 3
944
@@:
958
@@:
945
        lodsb
959
        lodsb
946
        call    ansi2uni_char
-
 
947
        stosw
960
        stosw
948
        loop    @b
961
        loop    @b
949
        mov     cl, 3
962
        mov     cl, 3
950
@@:
963
@@:
951
        cmp     word [edi-2], ' '
964
        cmp     word [edi-2], ' '
Line 953... Line 966...
953
        sub     edi, 2
966
        sub     edi, 2
954
        loop    @b
967
        loop    @b
955
        sub     edi, 2
968
        sub     edi, 2
956
@@:
969
@@:
957
        and     word [edi], 0   ; CF=0
970
        and     word [edi], 0   ; CF=0
958
        pop     edi esi ecx
971
        pop     ecx edi
959
        ret
972
        ret
Line -... Line 973...
-
 
973
 
-
 
974
.label:
-
 
975
        lea     edi, [ebp+FAT.volumeLabel]
-
 
976
        movsd
-
 
977
        movsd
-
 
978
        movsd
960
 
979
        pop     edi
961
.no:
980
.no:
962
        stc
981
        stc
Line 963... Line 982...
963
        ret
982
        ret
964
 
983
 
965
.longname:
984
.longname:
966
        mov     al, byte [edi]
985
        mov     al, byte [edi]
967
        and     eax, 0x3F
986
        and     eax, 0x3F
968
        dec     eax
987
        dec     eax
969
        cmp     al, 20
988
        cmp     al, 20
970
        jae     .no     ; ignore invalid entries
989
        jae     .no     ; ignore invalid entries
971
        mov     word [ebp+260*2], 0     ; force null-terminating for orphans
990
        mov     word [esi+260*2], 0     ; force null-terminating for orphans
972
        imul    eax, 13*2
991
        imul    eax, 13*2
973
        test    byte [edi], 0x40
992
        test    byte [edi], 0x40
974
        jz      @f
993
        jz      @f
975
        mov     word [ebp+eax+13*2], 0
994
        mov     word [esi+eax+13*2], 0
-
 
995
@@: ; copy name (13 chars in UTF-16)
976
@@: ; copy name (13 chars in UTF-16)
996
        push    edi
977
        push    esi edi
997
        inc     edi
978
        lea     esi, [edi+1]
998
        add     esi, eax
979
        lea     edi, [ebp+eax]
999
        xchg    esi, edi
980
        movsd
1000
        movsd
981
        movsd
-
 
982
        movsd
1001
        movsd
983
        inc     esi
1002
        movsw
984
        sub     edi, 2
1003
        add     esi, 3
985
        movsd
1004
        movsd
986
        movsd
1005
        movsd
987
        movsd
1006
        movsd
988
        add     esi, 2
1007
        add     esi, 2
989
        movsd
1008
        movsd
990
        pop     edi esi
1009
        pop     edi
991
        test    eax, eax
1010
        test    eax, eax
Line 992... Line 1011...
992
        jnz     .no ; if this is not first entry, more processing required
1011
        jnz     .no ; if this is not first entry, more processing required
-
 
1012
        ret
993
        ret
1013
 
-
 
1014
fat_find_lfn:
994
 
1015
;   in:
-
 
1016
; esi -> path in UTF-8
-
 
1017
; parameters in the stack
995
fat_compare_name:
1018
;   out:
-
 
1019
; esi -> next name in the path
996
; in: esi -> name in UTF-8, ebp -> name in UTF-16
1020
; edi -> direntry
-
 
1021
; CF=1 -> file not found, eax = error code
-
 
1022
        lea     eax, [esp+12]
-
 
1023
        call    dword [eax-4]
-
 
1024
        jc      .reterr
-
 
1025
        sub     esp, 262*2      ; reserve place for LFN
-
 
1026
.l1:
-
 
1027
        push    esi
-
 
1028
        lea     esi, [esp+4]
997
;   out:
1029
        call    fat_get_name
-
 
1030
        pop     esi
998
; ZF=1 -> names match, esi -> next component of name
1031
        jc      .no
999
; ZF=0 -> esi is not changed
1032
        push    edi esi
1000
        push    ebp esi
1033
        lea     edi, [esp+8]
1001
@@:
1034
@@:
1002
        call    utf8to16
1035
        call    utf8to16
1003
        call    utf16toUpper
1036
        call    utf16toUpper
1004
        mov     edx, eax
1037
        mov     edx, eax
1005
        mov     ax, [ebp]
1038
        mov     ax, [edi]
1006
        call    utf16toUpper
1039
        call    utf16toUpper
1007
        cmp     ax, dx
1040
        cmp     ax, dx
1008
        jnz     .done
1041
        jnz     .done
1009
        add     ebp, 2
1042
        add     edi, 2
1010
        test    ax, ax
1043
        test    ax, ax
-
 
1044
        jnz     @b
-
 
1045
        dec     esi
-
 
1046
        pop     eax edi
-
 
1047
.found:
-
 
1048
        add     esp, 262*2
-
 
1049
; if this is LFN entry, advance to true entry
-
 
1050
        cmp     byte [edi+11], 0xF
-
 
1051
        jnz     @f
-
 
1052
        lea     eax, [esp+12]
1011
        jnz     @b
1053
        call    dword[eax-8]
1012
        dec     esi
1054
        jc      .reterr
Line 1013... Line 1055...
1013
        pop     eax ebp
1055
@@:
1014
        xor     eax, eax    ; set ZF
1056
        xor     eax, eax
1015
        ret
1057
        ret
1016
 
1058
 
1017
.done:
1059
.done:
1018
        cmp     dx, '/'
1060
        cmp     dx, '/'
1019
        jnz     @f
1061
        jnz     @f
1020
        test    ax, ax
1062
        test    ax, ax
1021
        jnz     @f
-
 
1022
        mov     [esp], esi
-
 
1023
@@:
-
 
1024
        pop     esi ebp
-
 
1025
        ret
-
 
1026
 
-
 
1027
fat_find_lfn:
-
 
1028
; in: esi -> name in UTF-8
-
 
1029
;     [esp+4] = next
-
 
1030
;     [esp+8] = first
-
 
1031
;     [esp+C]... - possibly parameters for first and next
-
 
1032
; out: CF=1 - file not found, eax=error code
-
 
1033
;      else CF=0, esi->next name component, edi->direntry
-
 
1034
        pusha
-
 
1035
        lea     eax, [esp+0Ch+20h]
-
 
1036
        call    dword [eax-4]
-
 
1037
        jc      .reterr
-
 
1038
        sub     esp, 262*2      ; reserve place for LFN
-
 
1039
.l1:
-
 
1040
        lea     ebp, [esp]
1063
        jnz     @f
1041
        call    fat_get_name
1064
        mov     [esp], esi
1042
        jc      .l2
-
 
1043
        call    fat_compare_name
1065
@@:
1044
        jz      .found
1066
        pop     esi edi
1045
.l2:
1067
        jz      .found
1046
        mov     ebp, [esp+8+262*2]
1068
.no:
1047
        lea     eax, [esp+0Ch+20h+262*2]
1069
        lea     eax, [esp+262*2+12]
1048
        call    dword [eax-8]
-
 
1049
        jnc     .l1
1070
        call    dword[eax-8]
1050
        add     esp, 262*2
-
 
1051
.reterr:
-
 
1052
        mov     [esp+28], eax
-
 
1053
        stc
-
 
1054
        popa
-
 
1055
        ret
-
 
1056
 
-
 
1057
.found:
-
 
1058
        add     esp, 262*2
-
 
1059
        mov     ebp, [esp+8]
-
 
1060
; if this is LFN entry, advance to true entry
-
 
1061
        cmp     byte [edi+11], 0xF
-
 
1062
        jnz     @f
-
 
1063
        lea     eax, [esp+0Ch+20h]
-
 
1064
        call    dword [eax-8]
-
 
1065
        jc      .reterr
-
 
1066
@@:
-
 
1067
        add     esp, 8  ; CF=0
1071
        jnc     .l1
Line 1068... Line 1072...
1068
        push    esi
1072
        add     esp, 262*2
1069
        push    edi
1073
.reterr:
1070
        popa
1074
        stc
Line 1473... Line 1477...
1473
        test    byte [edi+11], 0x10     ; do not allow read files
1477
        test    byte [edi+11], 0x10     ; do not allow read files
1474
        jz      .accessDenied
1478
        jz      .accessDenied
1475
        mov     eax, [edi+20-2]
1479
        mov     eax, [edi+20-2]
1476
        mov     ax, [edi+26]    ; eax=cluster
1480
        mov     ax, [edi+26]    ; eax=cluster
1477
.doit:
1481
.doit:
1478
        push    esi
-
 
1479
        sub     esp, 262*2      ; reserve space for LFN
1482
        sub     esp, 262*2      ; reserve space for LFN
1480
        push    dword [ebx+8]   ; cp866/UNICODE name
1483
        push    dword [ebx+8]   ; cp866/UNICODE name
1481
        mov     edx, [ebx+16]   ; pointer to buffer
1484
        mov     edx, [ebx+16]   ; pointer to buffer
1482
; init header
1485
; init header
1483
        push    eax
1486
        push    eax
Line 1517... Line 1520...
1517
        pop     eax
1520
        pop     eax
1518
        jnz     .notfound2
1521
        jnz     .notfound2
1519
        add     ebx, 512
1522
        add     ebx, 512
1520
        push    eax
1523
        push    eax
1521
.l1:
1524
.l1:
1522
        push    ebp
1525
        push    esi
1523
        lea     ebp, [esp+20]
1526
        lea     esi, [esp+20]
1524
        call    fat_get_name
1527
        call    fat_get_name
1525
        pop     ebp
1528
        pop     esi
1526
        jc      .l2
1529
        jc      .l2
1527
        cmp     byte [edi+11], 0xF
1530
        cmp     byte [edi+11], 0xF
1528
        jnz     .do_bdfe
1531
        jnz     .do_bdfe
1529
        add     edi, 0x20
1532
        add     edi, 0x20
1530
        cmp     edi, ebx
1533
        cmp     edi, ebx
Line 1598... Line 1601...
1598
        jmp     .new_cluster
1601
        jmp     .new_cluster
Line 1599... Line 1602...
1599
 
1602
 
1600
.notfound2:
1603
.notfound2:
1601
        add     esp, 8
1604
        add     esp, 8
1602
.notfound:
1605
.notfound:
1603
        add     esp, 262*2+8
1606
        add     esp, 262*2+4
1604
        push    ERROR_DEVICE
1607
        push    ERROR_DEVICE
Line 1605... Line 1608...
1605
        jmp     @f
1608
        jmp     @f
1606
 
1609
 
1607
.done:
1610
.done:
1608
        add     esp, 262*2+16
1611
        add     esp, 262*2+12
1609
        pushd   0
1612
        pushd   0
1610
        dec     ecx
1613
        dec     ecx
1611
        js      @f
1614
        js      @f
Line 1959... Line 1962...
1959
        test    eax, eax
1962
        test    eax, eax
1960
        jz      .done1
1963
        jz      .done1
1961
@@:
1964
@@:
1962
        cmp     eax, [ebp+FAT.fatRESERVED]
1965
        cmp     eax, [ebp+FAT.fatRESERVED]
1963
        jae     .done1
1966
        jae     .done1
1964
        push    edx
-
 
1965
        xor     edx, edx
1967
        xor     edx, edx
1966
        call    set_FAT
1968
        call    set_FAT
1967
        mov     eax, edx
1969
        mov     eax, edx
1968
        pop     edx
-
 
1969
        jc      .done1
1970
        jc      .done1
1970
        inc     ecx
1971
        inc     ecx
1971
        jmp     @b
1972
        jmp     @b
Line 1972... Line 1973...
1972
 
1973
 
Line 2216... Line 2217...
2216
        shr     eax, 16
2217
        shr     eax, 16
2217
        mov     [edi+20], ax
2218
        mov     [edi+20], ax
2218
        lea     eax, [esp+16+8]
2219
        lea     eax, [esp+16+8]
2219
        call    dword [eax+16]  ; flush directory
2220
        call    dword [eax+16]  ; flush directory
2220
        pop     eax
2221
        pop     eax
2221
        push    edx
-
 
2222
        mov     edx, [ebp+FAT.fatEND]
2222
        mov     edx, [ebp+FAT.fatEND]
2223
        call    set_FAT
2223
        call    set_FAT
2224
        pop     edx
-
 
2225
.write_cluster:
2224
.write_cluster:
2226
        push    eax
2225
        push    eax
2227
        dec     eax
2226
        dec     eax
2228
        dec     eax
2227
        dec     eax
2229
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2228
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
Line 2304... Line 2303...
2304
; allocate new cluster
2303
; allocate new cluster
2305
        pop     eax
2304
        pop     eax
2306
        mov     ecx, eax
2305
        mov     ecx, eax
2307
        call    get_free_FAT
2306
        call    get_free_FAT
2308
        jc      .diskfull
2307
        jc      .diskfull
2309
        push    edx
-
 
2310
        mov     edx, [ebp+FAT.fatEND]
2308
        mov     edx, [ebp+FAT.fatEND]
2311
        call    set_FAT
2309
        call    set_FAT
2312
        xchg    eax, ecx
2310
        xchg    eax, ecx
2313
        mov     edx, ecx
2311
        mov     edx, ecx
2314
        call    set_FAT
2312
        call    set_FAT
2315
        pop     edx
-
 
2316
        xchg    eax, ecx
2313
        xchg    eax, ecx
2317
        jmp     .write_cluster
2314
        jmp     .write_cluster
Line 2318... Line 2315...
2318
 
2315
 
2319
.diskfull:
2316
.diskfull:
Line 2907... Line 2904...
2907
        ret
2904
        ret
Line 2908... Line 2905...
2908
 
2905
 
2909
;----------------------------------------------------------------
2906
;----------------------------------------------------------------
2910
fat_GetFileInfo:
2907
fat_GetFileInfo:
2911
        cmp     byte [esi], 0
2908
        cmp     byte [esi], 0
2912
        jnz     @f
-
 
2913
        mov     eax, 2
-
 
2914
        ret
-
 
2915
@@:
2909
        jz      .volume
2916
        call    fat_lock
2910
        call    fat_lock
2917
        call    hd_find_lfn
2911
        call    hd_find_lfn
2918
        jc      @f
2912
        jc      @f
2919
        push    ebp
2913
        push    ebp
Line 2927... Line 2921...
2927
        push    eax
2921
        push    eax
2928
        call    fat_unlock
2922
        call    fat_unlock
2929
        pop     eax
2923
        pop     eax
2930
        ret
2924
        ret
Line -... Line 2925...
-
 
2925
 
-
 
2926
.volume:
-
 
2927
        mov     eax, dword[ebp+FAT.Length]
-
 
2928
        mov     edx, dword[ebp+FAT.Length+4]
-
 
2929
        mov     edi, [ebx+16]
-
 
2930
        shld    edx, eax, 9
-
 
2931
        shl     eax, 9
-
 
2932
        mov     [edi+36], edx
-
 
2933
        mov     [edi+32], eax
-
 
2934
        mov     eax, [ebx+8]
-
 
2935
        mov     byte [edi], 8
-
 
2936
        mov     [edi+4], eax
-
 
2937
        lea     esi, [ebp+FAT.volumeLabel]
-
 
2938
        mov     ecx, 11
-
 
2939
@@:
-
 
2940
        mov     byte [esi+ecx], 0
-
 
2941
        dec     ecx
-
 
2942
        jz      @f
-
 
2943
        cmp     byte [esi+ecx], ' '
-
 
2944
        jz      @b
-
 
2945
@@:
-
 
2946
        mov     cl, 12
-
 
2947
        add     edi, 40
-
 
2948
        cmp     eax, 2
-
 
2949
        jz      @f
-
 
2950
        rep movsb
-
 
2951
        xor     eax, eax
-
 
2952
        ret
-
 
2953
 
-
 
2954
@@:
-
 
2955
        lodsb
-
 
2956
        stosw
-
 
2957
        loop    @b
-
 
2958
        ret
2931
 
2959
 
2932
;----------------------------------------------------------------
2960
;----------------------------------------------------------------
2933
fat_SetFileInfo:
2961
fat_SetFileInfo:
2934
        call    fat_lock
2962
        call    fat_lock
2935
        call    hd_find_lfn
2963
        call    hd_find_lfn