Subversion Repositories Kolibri OS

Rev

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

Rev 9737 Rev 9738
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2021-2022. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2021-2022. 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: 9737 $
8
$Revision: 9738 $
9
 
9
 
10
; exFAT external functions
10
; exFAT external functions
11
;   in:
11
;   in:
Line 68... Line 68...
68
valid_data_length   dd  ?
68
valid_data_length   dd  ?
69
RAX_high            dd  ?
69
RAX_high            dd  ?
70
RCX_high            dd  ?
70
RCX_high            dd  ?
71
RDX_high            dd  ?
71
RDX_high            dd  ?
72
RDI_high            dd  ?
72
RDI_high            dd  ?
-
 
73
current_hash        dd  ?
-
 
74
hash_flag           dd  ?
-
 
75
need_hash           dd  ?
73
volumeLabel         rb  12
76
volumeLabel         rb  12
74
; The next two areas (32+32) should be arranged sequentially.
77
; The next two areas (32+32) should be arranged sequentially.
75
; Do not change their location!!!
78
; Do not change their location!!!
76
file_dir_entry      rb  32 ; Entry Type 0x85
79
file_dir_entry      rb  32 ; Entry Type 0x85
77
str_ext_dir_entry   rb  32 ; Entry Type 0xC0
80
str_ext_dir_entry   rb  32 ; Entry Type 0xC0
Line 363... Line 366...
363
        stc
366
        stc
364
        ret
367
        ret
365
;--------------------------------------
368
;--------------------------------------
366
.file_directory_entry:
369
.file_directory_entry:
367
; DEBUGF  1, "K : exFAT_get_name 0x85\n"
370
; DEBUGF  1, "K : exFAT_get_name 0x85\n"
-
 
371
        xor     eax, eax
-
 
372
        mov     [ebp+exFAT.hash_flag], eax ; dword 0
368
        movzx   eax, byte [edi+1]  ; Number of Secondary directory entries
373
        mov     al, byte [edi+1]  ; Number of Secondary directory entries
369
        dec     eax
374
        dec     eax
370
        mov     [ebp+exFAT.secondary_dir_entry], eax
375
        mov     [ebp+exFAT.secondary_dir_entry], eax
371
; DEBUGF  1, "K : exFAT_get_name 0x85 SDE: %x\n", eax
376
; DEBUGF  1, "K : exFAT_get_name 0x85 SDE: %x\n", eax
372
        lea     esi, [ebp+exFAT.file_dir_entry]
377
        lea     esi, [ebp+exFAT.file_dir_entry]
373
; DEBUGF  1, "K : exFAT.file_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
378
; DEBUGF  1, "K : exFAT.file_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
374
        jmp     @f
379
        jmp     @f
375
;--------------------------------------
380
;--------------------------------------
376
.stream_extension_directory_entry:
381
.stream_extension_directory_entry:
377
; DEBUGF  1, "K : exFAT_get_name 0xC0\n"
382
; DEBUGF  1, "K : exFAT_get_name 0xC0\n"
-
 
383
; DEBUGF  1, "K : exFAT SEDE need_hash :%x\n", [ebp+exFAT.need_hash]
-
 
384
        mov     eax, [ebp+exFAT.need_hash]
-
 
385
        test    eax, eax
-
 
386
        jz      .stream_extension_directory_entry_1 ; @f
-
 
387
        movzx   eax, word [edi+4] ; hash of the file name
-
 
388
; DEBUGF  1, "K : exFAT hash 1 :%x\n", eax
-
 
389
; DEBUGF  1, "K : exFAT hash 2 :%x\n", [ebp+exFAT.current_hash]
-
 
390
        cmp     eax, [ebp+exFAT.current_hash]
-
 
391
        je      .stream_extension_directory_entry_1 ; @f
-
 
392
        xor     eax, eax
-
 
393
        inc     eax
-
 
394
        mov     [ebp+exFAT.hash_flag], eax ; dword 1
-
 
395
; DEBUGF  1, "K : exFAT hashes don't match! \n"
-
 
396
.stream_extension_directory_entry_1:
378
        lea     esi, [ebp+exFAT.str_ext_dir_entry]
397
        lea     esi, [ebp+exFAT.str_ext_dir_entry]
379
; DEBUGF  1, "K : exFAT.str_ext_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
398
; DEBUGF  1, "K : exFAT.str_ext_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
380
@@:
399
@@:
381
        push    edi
400
        push    edi
382
        xchg    esi, edi
401
        xchg    esi, edi
Line 409... Line 428...
409
;        push    ebp
428
;        push    ebp
410
;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
429
;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
411
; DEBUGF  1, "K : exFAT_get_name.longname Input FS EBP:%x\n", ebp
430
; DEBUGF  1, "K : exFAT_get_name.longname Input FS EBP:%x\n", ebp
412
;        pop     ebp
431
;        pop     ebp
Line -... Line 432...
-
 
432
 
-
 
433
        mov     eax, [ebp+exFAT.hash_flag]
-
 
434
        test    eax, eax
-
 
435
        jnz     .no
413
        
436
; DEBUGF  1, "K : exFAT_get_name.longname hash match! \n"
Line 414... Line 437...
414
        push    edi esi
437
        push    edi esi
415
 
438
 
Line 684... Line 707...
684
; parameters in the stack
707
; parameters in the stack
685
;   out:
708
;   out:
686
; esi -> next name in the path
709
; esi -> next name in the path
687
; edi -> direntry
710
; edi -> direntry
688
; CF=1 -> file not found, eax = error code
711
; CF=1 -> file not found, eax = error code
-
 
712
        xor     eax, eax
-
 
713
        inc     eax
689
        mov     [ebp+exFAT.secondary_dir_entry], dword 1
714
        mov     [ebp+exFAT.secondary_dir_entry], eax ; dword 1
-
 
715
        mov     [ebp+exFAT.need_hash], eax ; dword 1
690
        lea     eax, [esp+12]
716
        lea     eax, [esp+12]
691
        call    dword [eax-4] ; exFAT_notroot_first
717
        call    dword [eax-4] ; exFAT_notroot_first
692
        jc      .reterr
718
        jc      .reterr
693
        sub     esp, 262*2      ; reserve place for LFN
719
        sub     esp, 262*2      ; reserve place for LFN
694
;        lea     eax, [esp]
720
;        lea     eax, [esp]
695
        mov     eax, esp
721
        mov     eax, esp
696
        mov     [ebp+exFAT.LFN_reserve_place], eax
722
        mov     [ebp+exFAT.LFN_reserve_place], eax
697
        mov     [ebp+exFAT.path_in_UTF8], esi
723
        mov     [ebp+exFAT.path_in_UTF8], esi
698
; DEBUGF  1, "K : exFAT_find_lfn Path: %s\n", esi
724
; DEBUGF  1, "K : exFAT_find_lfn Path: %s\n", esi
-
 
725
; DEBUGF  1, "K : exFAT Path: %s\n", esi
-
 
726
; DEBUGF  1, "K : exFAT Path1: %x %x %x\n", [esi], [esi+4], [esi+8]
-
 
727
        push    esi edi
-
 
728
;        lea     edi, [esp+8]
-
 
729
        mov     edi, eax
-
 
730
align 4
-
 
731
@@:
-
 
732
; in: esi -> UTF-8 char (increasing)
-
 
733
; out: ax = UTF-16 char
-
 
734
        call    utf8to16
-
 
735
        call    utf16toUpper
-
 
736
        stosw
-
 
737
        test    ax, ax
-
 
738
        jz      @f
-
 
739
        cmp     ax, word 0x002f ; "/"
-
 
740
        jne     @b
-
 
741
@@:
-
 
742
;        mov     [edi-2], dword 0
-
 
743
        mov     esi, [ebp+exFAT.LFN_reserve_place]
-
 
744
; DEBUGF  1, "K : exFAT Path2: %x %x %x\n", [esi], [esi+4], [esi+8]
-
 
745
        push    ebx ecx
-
 
746
        mov     ecx, edi
-
 
747
        sub     ecx, esi
-
 
748
        sub     ecx, 2 ; correction for zero or "/"
-
 
749
; exFAT_hash_calculate
-
 
750
;   in:
-
 
751
; esi -> NameUTF16
-
 
752
; ecx -> NameUTF16 length
-
 
753
; out: ax = hash
-
 
754
        xor     eax, eax
-
 
755
        xor     ebx, ebx
-
 
756
;--------------------------------------
-
 
757
align 4
-
 
758
.start:
-
 
759
; DEBUGF 1, "Hash start EAX:%x ECX:%x\n", eax, ecx
-
 
760
        mov     bx, ax
-
 
761
; (Hash&1) ? 0x8000 : 0)
-
 
762
        and     ax, 0x1
-
 
763
        jz      .else
-
 
764
 
-
 
765
        mov     ax, 0x8000
-
 
766
        jmp     @f
-
 
767
;--------------------------------------
-
 
768
.else:
-
 
769
        xor     ax, ax
-
 
770
;--------------------------------------
-
 
771
@@:
-
 
772
; DEBUGF 1, "(Hash&1) EAX:%x\n", eax
-
 
773
; (Hash>>1)
-
 
774
        shr     bx, 1
-
 
775
; DEBUGF 1, "(Hash>>1) EBX:%x\n", ebx
-
 
776
        add     ax, bx
-
 
777
; DEBUGF 1, "+ (Hash>>1)) EAX:%x\n", eax
-
 
778
        movzx   bx, byte [esi]
-
 
779
        add     ax, bx
-
 
780
; DEBUGF 1, "+ (UInt16)Buffer[Index] EAX:%x\n", eax        
-
 
781
        inc     esi
-
 
782
        dec     ecx
-
 
783
        jnz     .start
-
 
784
;--------------------------------------
-
 
785
        pop     ecx ebx
-
 
786
        mov     [ebp+exFAT.current_hash], eax
-
 
787
; DEBUGF  1, "K : exFAT current hash :%x\n", eax        
-
 
788
        pop     edi esi
699
.l1:
789
.l1:
700
;        push    esi
790
;        push    esi
701
;        lea     esi, [esp+4]
791
;        lea     esi, [esp+4]
702
;        mov     esi, [ebp+exFAT.LFN_reserve_place]
792
;        mov     esi, [ebp+exFAT.LFN_reserve_place]
703
; DEBUGF  1, "K : exFAT_find_lfn.exFAT_get_name \n"
793
; DEBUGF  1, "K : exFAT_find_lfn.exFAT_get_name \n"
Line 704... Line 794...
704
 
794
 
705
;        push    ebp
795
;        push    ebp
706
;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4]
796
;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4]
707
; DEBUGF  1, "K : exFAT_get_name Input FS EBP:%x\n", ebp
797
; DEBUGF  1, "K : exFAT_get_name Input FS EBP:%x\n", ebp
708
;        pop     ebp
-
 
-
 
798
;        pop     ebp
709
 
799
; DEBUGF  1, "K : exFAT FL need_hash :%x\n", [ebp+exFAT.need_hash]
710
        call    exFAT_get_name
800
        call    exFAT_get_name
711
;        mov     [ebp+exFAT.LFN_reserve_place], esi
801
;        mov     [ebp+exFAT.LFN_reserve_place], esi
Line 712... Line 802...
712
;        pop     esi
802
;        pop     esi
Line 716... Line 806...
716
; DEBUGF  1, "K : exFAT_get_name Output FS EBP:%x\n", ebp
806
; DEBUGF  1, "K : exFAT_get_name Output FS EBP:%x\n", ebp
717
;        pop     ebp
807
;        pop     ebp
Line 718... Line 808...
718
 
808
 
Line 719... Line 809...
719
        jc      .no
809
        jc      .no
720
 
810
 
721
        push    eax
811
;        push    eax
722
        xor     eax, eax
812
        xor     eax, eax
723
        cmp     [ebp+exFAT.secondary_dir_entry], eax
813
        cmp     [ebp+exFAT.secondary_dir_entry], eax
Line 724... Line 814...
724
        pop     eax
814
;        pop     eax
725
        jnz     .no
815
        jnz     .no
726
 
816
 
Line 806... Line 896...
806
; ebp -> exFAT structure
896
; ebp -> exFAT structure
807
; esi -> path string in UTF-8
897
; esi -> path string in UTF-8
808
;   out:
898
;   out:
809
; eax, ebx = return values for sysfunc 70
899
; eax, ebx = return values for sysfunc 70
810
        call    exFAT_lock
900
        call    exFAT_lock
-
 
901
        xor     eax, eax
-
 
902
        mov     [ebp+exFAT.need_hash], eax ; dword 0
-
 
903
        mov     [ebp+exFAT.hash_flag], eax ; dword 0
811
        call    exFAT_hd_find_lfn
904
        call    exFAT_hd_find_lfn
812
        jc      .notFound
905
        jc      .notFound
813
;        test    byte [edi+11], 0x10     ; do not allow read directories
906
;        test    byte [edi+11], 0x10     ; do not allow read directories
814
;        jnz     .noaccess
907
;        jnz     .noaccess
815
        lea     eax, [ebp+exFAT.file_dir_entry]
908
        lea     eax, [ebp+exFAT.file_dir_entry]
Line 1318... Line 1411...
1318
; esi -> path string in UTF-8
1411
; esi -> path string in UTF-8
1319
;   out:
1412
;   out:
1320
; eax, ebx = return values for sysfunc 70
1413
; eax, ebx = return values for sysfunc 70
1321
        call    exFAT_lock
1414
        call    exFAT_lock
1322
        xor     eax, eax
1415
        xor     eax, eax
-
 
1416
        mov     [ebp+exFAT.need_hash], eax ; dword 0
-
 
1417
        mov     [ebp+exFAT.hash_flag], eax ; dword 0
1323
        mov     [ebp+exFAT.General_Sec_Flags], eax
1418
        mov     [ebp+exFAT.General_Sec_Flags], eax
1324
; DEBUGF  1, "K : exFAT_ReadFolder General_Sec_Flags 1 %x\n", eax
1419
; DEBUGF  1, "K : exFAT_ReadFolder General_Sec_Flags 1 %x\n", eax
1325
        mov     eax, [ebp+exFAT.ROOT_CLUSTER]
1420
        mov     eax, [ebp+exFAT.ROOT_CLUSTER]
1326
; DEBUGF  1, "K : exFAT.ROOT_CLUSTER: %x\n", eax
1421
; DEBUGF  1, "K : exFAT.ROOT_CLUSTER: %x\n", eax
1327
        cmp     byte [esi], 0
1422
        cmp     byte [esi], 0
Line 1341... Line 1436...
1341
 
1436
 
1342
        jc      .error
1437
        jc      .error
1343
;        jmp     .error
1438
;        jmp     .error
1344
;        test    byte [edi+11], 0x10     ; do not allow read files
1439
;        test    byte [edi+11], 0x10     ; do not allow read files
-
 
1440
;        jz      .accessDenied
-
 
1441
        xor     eax, eax
-
 
1442
        mov     [ebp+exFAT.need_hash], eax ; dword 0
1345
;        jz      .accessDenied
1443
        mov     [ebp+exFAT.hash_flag], eax ; dword 0
1346
        lea     eax, [ebp+exFAT.file_dir_entry]
1444
        lea     eax, [ebp+exFAT.file_dir_entry]
1347
        test    byte [eax+4], 10000b  ; do not allow read files
1445
        test    byte [eax+4], 10000b  ; do not allow read files
1348
        jz      .accessDenied
1446
        jz      .accessDenied
1349
;        mov     eax, [edi+20-2]
1447
;        mov     eax, [edi+20-2]
Line 1462... Line 1560...
1462
        push    eax
1560
        push    eax
1463
.l1:
1561
.l1:
1464
; DEBUGF  1, "K : exFAT_ReadFolder.l1 \n"
1562
; DEBUGF  1, "K : exFAT_ReadFolder.l1 \n"
1465
;        push    esi
1563
;        push    esi
1466
;        lea     esi, [esp+20]
1564
;        lea     esi, [esp+20]
-
 
1565
; DEBUGF  1, "K : exFAT RD need_hash :%x\n", [ebp+exFAT.need_hash]
1467
        call    exFAT_get_name
1566
        call    exFAT_get_name
1468
;        pop     esi
1567
;        pop     esi
1469
        jc      .l2
1568
        jc      .l2
1470
;        cmp     byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT
1569
;        cmp     byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT
1471
;        jnz     .do_bdfe
1570
;        jnz     .do_bdfe
Line 1665... Line 1764...
1665
; DEBUGF  1, "K : exFAT F70 +20: %x\n", [ebx+20]
1764
; DEBUGF  1, "K : exFAT F70 +20: %x\n", [ebx+20]
1666
; DEBUGF  1, "K : exFAT Path: %s\n", esi
1765
; DEBUGF  1, "K : exFAT Path: %s\n", esi
1667
        cmp     byte [esi], 0
1766
        cmp     byte [esi], 0
1668
        jz      .volume
1767
        jz      .volume
1669
        call    exFAT_lock
1768
        call    exFAT_lock
-
 
1769
        xor     eax, eax
-
 
1770
        mov     [ebp+exFAT.need_hash], eax ; dword 0
-
 
1771
        mov     [ebp+exFAT.hash_flag], eax ; dword 0
1670
        call    exFAT_hd_find_lfn
1772
        call    exFAT_hd_find_lfn
1671
        jc      @f
1773
        jc      @f
1672
        lea     edi, [ebp+exFAT.file_dir_entry]
1774
        lea     edi, [ebp+exFAT.file_dir_entry]
1673
        push    ebp
1775
        push    ebp
1674
        xor     ebp, ebp
1776
        xor     ebp, ebp