Subversion Repositories Kolibri OS

Rev

Rev 9737 | Rev 9744 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2021-2022. All rights reserved. ;;
  4. ;;  Distributed under terms of the GNU General Public License.  ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9738 $
  9.  
  10. ; exFAT external functions
  11. ;   in:
  12. ; ebx -> parameter structure of sysfunc 70
  13. ; ebp -> exFAT structure
  14. ; esi -> path string in UTF-8
  15. ;   out:
  16. ; eax, ebx = return values for sysfunc 70
  17. iglobal
  18. align 4
  19. exFAT_user_functions:
  20.         dd      exFAT_free
  21.         dd      (exFAT_user_functions_end - exFAT_user_functions - 4) / 4
  22.         dd      exFAT_ReadFile
  23.         dd      exFAT_ReadFolder
  24.         dd      0 ;exFAT_CreateFile
  25.         dd      0 ;exFAT_Write
  26.         dd      0 ;exFAT_SetFileEnd
  27.         dd      exFAT_GetFileInfo
  28.         dd      0 ;exFAT_SetFileInfo
  29.         dd      0
  30.         dd      0 ;exFAT_Delete
  31.         dd      0 ;exFAT_CreateFolder
  32.         dd      0 ;exFAT_Rename
  33. exFAT_user_functions_end:
  34. endg
  35.  
  36. struct exFAT PARTITION
  37. fat_change          db  ?   ; 1=fat has changed
  38. createOption        db  ?
  39.                     rb  2
  40. Lock                MUTEX   ; currently operations with one partition
  41. ; can not be executed in parallel since the legacy code is not ready
  42. fat_in_cache        dd  ?
  43. FAT_START           dd  ?   ; start of fat table
  44. ROOT_START          dd  ?   ; start of rootdir
  45. SECTORS_PER_CLUSTER dd  ?
  46. BYTES_PER_SECTOR    dd  ?   ; Note: if BPS <> 512 need lots of changes
  47. SECTORS_PER_FAT     dd  ?
  48. NUMBER_OF_FATS      dd  ?
  49. CLUSTER_HEAP_START  dd  ?
  50. CLUSTER_COUNT       dd  ?
  51. DATA_START          dd  ?   ; start of data area (=first cluster 2)
  52. LAST_CLUSTER        dd  ?   ; last availabe cluster
  53. fatRESERVED         dd  ?
  54. fatBAD              dd  ?
  55. fatEND              dd  ?
  56. fatMASK             dd  ?
  57. fatStartScan        dd  ?
  58. cluster_tmp         dd  ?   ; used by analyze_directory and analyze_directory_to_write
  59. ROOT_CLUSTER        dd  ?   ; first rootdir cluster
  60. fat_cache_ptr       dd  ?
  61. points_to_BDFE      dd  ?
  62. secondary_dir_entry dd  ?
  63. longname_sec1       dd  ?   ; used by analyze_directory to save 2 previous
  64. longname_sec2       dd  ?   ; directory sectors for delete long filename
  65. LFN_reserve_place   dd  ?
  66. path_in_UTF8        dd  ?
  67. General_Sec_Flags   dd  ?
  68. valid_data_length   dd  ?
  69. RAX_high            dd  ?
  70. RCX_high            dd  ?
  71. RDX_high            dd  ?
  72. RDI_high            dd  ?
  73. current_hash        dd  ?
  74. hash_flag           dd  ?
  75. need_hash           dd  ?
  76. volumeLabel         rb  12
  77. ; The next two areas (32+32) should be arranged sequentially.
  78. ; Do not change their location!!!
  79. file_dir_entry      rb  32 ; Entry Type 0x85
  80. str_ext_dir_entry   rb  32 ; Entry Type 0xC0
  81. buffer              rb  512
  82. ends
  83.  
  84. ; these labels are located before the main function to make
  85. ; most of jumps to these be short
  86. exFAT_create_partition.free_return0:
  87.         mov     eax, ebp
  88.         call    free
  89.         pop     ebp
  90. ; DEBUGF  1, "K : exFAT_create_partition.free_return0 EAX: %x\n", eax
  91. exFAT_create_partition.return0:
  92.         xor     eax, eax
  93. ; DEBUGF  1, "K : exFAT_create_partition.return0 EAX: %x\n", eax
  94.         ret
  95.  
  96. ; Mount if it's a valid exFAT partition.
  97. exFAT_create_partition:
  98. ; DEBUGF  1, "K : exFAT_create_partition EAX: %x\n", eax
  99. ;   in:
  100. ; ebp -> PARTITION structure
  101. ; ebx -> boot sector
  102. ; ebx+512 -> buffer
  103. ;   out:
  104. ; eax -> exFAT structure, 0 = not exFAT
  105.         cmp     dword [esi+DISK.MediaInfo.SectorSize], 512
  106.         jnz     .return0
  107. ; DEBUGF  1, "K : exFAT DISK.MediaInfo.SectorSize=512\n"
  108. ; bootsector must have been successfully read
  109.         cmp     dword [esp+4], 0
  110.         jnz     .return0
  111. ; DEBUGF  1, "K : exFAT bootsector successfully read\n"
  112. ; offset +510 = bootsector signature must be correct
  113.         cmp     word [ebx+0x1fe], 0xaa55
  114.         jnz     .return0
  115. ; DEBUGF  1, "K : exFAT bootsector signature correct\n"
  116. ; offset +109 = sectors per cluster must be nonzero
  117.         cmp     byte [ebx+0x6d], 0
  118.         jz      .return0
  119. ; DEBUGF  1, "K : exFAT sectors per cluster = nonzero\n"
  120. ; offset +108 = bytes per sector must be 0x200
  121. ; (LEGACY! In the future, increase support to 4096)
  122. ; the value for exFAT is a power of 2
  123.         cmp     byte [ebx+0x6c], 9
  124.         jnz     .return0
  125. ; DEBUGF  1, "K : exFAT bytes per sector = 512\n"
  126. ; Test name = 'EXFAT   '
  127.         cmp     dword [ebx+3], 'EXFA'
  128.         jnz     .return0
  129.         cmp     dword [ebx+7], 'T   '
  130.         jnz     .return0
  131. ; DEBUGF  1, "K : exFAT Test name EXFAT = OK \n"
  132.         movi    eax, sizeof.exFAT
  133.         call    malloc
  134.         test    eax, eax
  135.         jz      .return0
  136. ; DEBUGF  1, "K : exFAT malloc sizeof.exFAT = OK \n"
  137.         mov     ecx, dword [ebp+PARTITION.FirstSector]
  138.         mov     dword [eax+exFAT.FirstSector], ecx
  139. ; DEBUGF  1, "K : exFAT PARTITION.FirstSector ECX: %x\n", ecx
  140.         mov     ecx, dword [ebp+PARTITION.FirstSector+4]
  141.         mov     dword [eax+exFAT.FirstSector+4], ecx
  142. ; DEBUGF  1, "K : exFAT PARTITION.FirstSector+4 ECX: %x\n", ecx
  143.         mov     ecx, dword [ebp+PARTITION.Length]
  144.         mov     dword [eax+exFAT.Length], ecx
  145. ; DEBUGF  1, "K : exFAT PARTITION.Length ECX: %x\n", ecx
  146.         mov     ecx, dword [ebp+PARTITION.Length+4]
  147.         mov     dword [eax+exFAT.Length+4], ecx
  148. ; DEBUGF  1, "K : exFAT PARTITION.Length+4 ECX: %x\n", ecx
  149.         mov     ecx, [ebp+PARTITION.Disk]
  150.         mov     [eax+exFAT.Disk], ecx
  151. ; DEBUGF  1, "K : exFAT PARTITION.Disk ECX: %x\n", ecx
  152.         mov     [eax+exFAT.FSUserFunctions], exFAT_user_functions
  153.         or      [eax+exFAT.fat_in_cache], -1
  154.         mov     [eax+exFAT.fat_change], 0
  155.  
  156.         push    ebp
  157.         mov     ebp, eax
  158.         lea     ecx, [ebp+exFAT.Lock]
  159.         call    mutex_init
  160. ; offset +80 = sectors reserved
  161.         mov     eax, [ebx+0x50]
  162.         mov     [ebp+exFAT.FAT_START], eax
  163. ; DEBUGF  1, "K : exFAT.FAT_START EAX: %x\n", eax
  164. ; offset +109 = sectors per cluster. This is power of 2; Minimal value is 1;
  165. ; 2^0 =1 sector (512 Bytes) and maximum 32 MB cluster size in bytes
  166.         movzx   ecx, byte [ebx+0x6d]
  167.         mov     eax, 1
  168.         shl     eax, cl
  169.         mov     [ebp+exFAT.SECTORS_PER_CLUSTER], eax
  170. ; DEBUGF  1, "K : exFAT.SECTORS_PER_CLUSTER EAX: %x\n", eax
  171. ; offset +108 = bytes per sector. This is power of 2; Minimal value is 9;
  172. ; 2^9 =512 Bytes and maximum 2^12 =4096 Bytes
  173.         movzx   ecx, byte [ebx+0x6c]     ; bytes per sector
  174.         mov     eax, 1
  175.         shl     eax, cl
  176.         mov     [ebp+exFAT.BYTES_PER_SECTOR], eax
  177. ; DEBUGF  1, "K : exFAT.BYTES_PER_SECTOR EAX: %x\n", eax
  178. ;------------------------------------------------------------------------------
  179. ;        movzx   eax, word [ebx+0x11]    ; count of rootdir entries (=0 fat32)
  180. ;        shl     eax, 5                  ; mul 32
  181. ;        dec     ecx
  182. ;        add     eax, ecx                ; round up if not equal count
  183. ;        inc     ecx                     ; bytes per sector
  184. ;        xor     edx, edx
  185. ;        div     ecx
  186. ;        mov     [ebp+FAT.ROOT_SECTORS], eax     ; count of rootdir sectors
  187. ;------------------------------------------------------------------------------
  188. ; offset +84 = Size of FAT in sectors
  189.         mov     eax, [ebx+0x54]         ; sectors per fat
  190.         mov     [ebp+exFAT.SECTORS_PER_FAT], eax
  191. ; DEBUGF  1, "K : exFAT.SECTORS_PER_FAT EAX: %x\n", eax
  192. ;------------------------------------------------------------------------------
  193. ; offset +88 = Starting sector of cluster heap
  194.         mov     eax, [ebx+0x58]         ; Cluster offset
  195.         mov     [ebp+exFAT.CLUSTER_HEAP_START], eax
  196. ; DEBUGF  1, "K : exFAT.CLUSTER_HEAP_START EAX: %x\n", eax
  197. ;------------------------------------------------------------------------------
  198. ; offset +92 = Number of clusters
  199.         mov     eax, [ebx+0x5c]         ; Cluster count
  200.         mov     [ebp+exFAT.CLUSTER_COUNT], eax
  201. ; DEBUGF  1, "K : exFAT.CLUSTER_COUNT EAX: %x\n", eax
  202. ;------------------------------------------------------------------------------
  203. ; offset +110 = Either 1 or 2; if TexFAT is supported then it will be 2
  204.         movzx   eax, byte [ebx+0x6e]    ; number of fats
  205.         mov     [ebp+exFAT.NUMBER_OF_FATS], eax
  206. ; DEBUGF  1, "K : exFAT.NUMBER_OF_FATS EAX: %x\n", eax
  207.         mul     [ebp+exFAT.SECTORS_PER_FAT]
  208. ; DEBUGF  1, "K : exFAT.SECTORS_PER_FAT mul EAX: %x\n", eax
  209. ;        test    edx, edx
  210. ;        jnz     .free_return0
  211.         add     eax, [ebp+exFAT.FAT_START]
  212.         jc      .free_return0
  213.  
  214. ;        mov     [ebp+FAT.ROOT_START], eax       ; rootdir = fat_start + fat_size * fat_count
  215. ;        add     eax, [ebp+FAT.ROOT_SECTORS]     ; rootdir sectors should be 0 on fat32
  216. ;        jc      .free_return0
  217.         mov     [ebp+exFAT.DATA_START], eax
  218. ; DEBUGF  1, "K : exFAT.DATA_START EAX: %x\n", eax
  219. ;------------------------------------------------------------------------------
  220. ; offset +72 = Total number of Sectors
  221.         mov     eax, [ebx+0x48+4]         ; total sector count high part
  222.         test    eax, eax
  223.         jnz     .free_return0           ; 32-BIT LIMIT - MODIFY LATER WITY RASP !!!
  224. ; DEBUGF  1, "K : exFAT Total number of Sectors+4 EAX: %x\n", eax
  225.         mov     eax, [ebx+0x48]         ; total sector count low part
  226. ; DEBUGF  1, "K : exFAT Total number of Sectors EAX: %x\n", eax
  227.         cmp     dword [ebp+exFAT.Length+4], 0
  228.         jnz     @f
  229. ; DEBUGF  1, "K : exFAT.Length+4 = 0\n"
  230.         cmp     eax, dword [ebp+exFAT.Length]
  231.         ja      .free_return0
  232. ; DEBUGF  1, "K : exFAT.Length >= Total number of Sectors\n"
  233. @@:
  234.         mov     dword [ebp+exFAT.Length], eax
  235.         and     dword [ebp+exFAT.Length+4], 0
  236.         sub     eax, [ebp+exFAT.DATA_START]       ; eax = count of data sectors
  237.         jc      .free_return0
  238. ; DEBUGF  1, "K : EAX - exFAT.DATA_START EAX: %x\n", eax
  239.         xor     edx, edx
  240.         div     [ebp+exFAT.SECTORS_PER_CLUSTER]
  241.         inc     eax
  242.         mov     [ebp+exFAT.LAST_CLUSTER], eax
  243. ; DEBUGF  1, "K : exFAT.LAST_CLUSTER EAX: %x\n", eax
  244.         dec     eax                     ; cluster count
  245.         jz      .free_return0
  246. ; DEBUGF  1, "K : exFAT.LAST_CLUSTER >= 2 EAX: %x\n",eax
  247.         mov     [ebp+exFAT.fatStartScan], 2
  248. ;        cmp     eax, 0xfff5
  249. ;        jb      .fat16
  250. ;------------------------------------------------------------------------------
  251. ;.fat32:
  252. ;        pusha
  253. ;        lea     esi, [ebx+71]
  254. ;        lea     edi, [ebp+exFAT.volumeLabel]
  255. ;        movsd
  256. ;        movsd
  257. ;        movsd
  258. ;        popa
  259. ;------------------------------------------------------------------------------
  260. ; offset +96 = First cluster of root directory
  261.         mov     eax, [ebx+0x60]         ; rootdir cluster
  262.         mov     [ebp+exFAT.ROOT_CLUSTER], eax
  263. ; DEBUGF  1, "K : exFAT.ROOT_CLUSTER EAX: %x\n", eax
  264.         dec     eax
  265.         dec     eax
  266.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  267.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  268.         mov     [ebp+exFAT.ROOT_START], eax
  269. ; DEBUGF  1, "K : exFAT.ROOT_START EAX: %x\n", eax
  270. ;------------------------------------------------------------------------------
  271. ;------------------------------------------------------------------------------
  272. ;        movzx   eax, word [ebx+0x30]
  273. ;        mov     [ebp+FAT.ADR_FSINFO], eax
  274. ;------------------------------------------------------------------------------
  275. ;        push    ebx
  276. ;        add     ebx, 512
  277. ;        call    fs_read32_sys
  278. ;        test    eax, eax
  279. ;        jnz     @f
  280. ;        mov     eax, [ebx+0x1ec]
  281. ;        cmp     eax, -1
  282. ;        jz      @f
  283. ;        mov     [ebp+exFAT.fatStartScan], eax
  284. ;@@:
  285. ;        pop     ebx
  286. ;------------------------------------------------------------------------------
  287.         mov     [ebp+exFAT.fatRESERVED], 0x0FFFFFF6
  288.         mov     [ebp+exFAT.fatBAD], 0x0FFFFFF7
  289.         mov     [ebp+exFAT.fatEND], 0x0FFFFFF8
  290.         mov     [ebp+exFAT.fatMASK], 0x0FFFFFFF
  291. ;------------------------------------------------------------------------------
  292. ;        mov     al, 32
  293. ;.fat_not_12_finalize:
  294. ;        mov     [ebp+FAT.fs_type], al
  295. ;------------------------------------------------------------------------------
  296. ; For FAT16 and FAT32, allocate 512 bytes for FAT cache.
  297.         mov     eax, 512
  298.         call    malloc
  299.         test    eax, eax
  300.         jz      .free_return0
  301.         mov     [ebp+exFAT.fat_cache_ptr], eax
  302. ; DEBUGF  1, "K : malloc exFAT.fat_cache_ptr EAX: %x\n", eax
  303.  
  304.         mov     eax, ebp
  305.         pop     ebp
  306.         ret
  307. ;------------------------------------------------------------------------------
  308. exFAT_free:
  309.         push    eax
  310.         mov     eax, [eax+exFAT.fat_cache_ptr]
  311. ; DEBUGF  1, "K : exFAT_free exFAT.fat_cache_ptr EAX: %x\n", eax
  312.         call    free
  313.         pop     eax
  314.         jmp     free
  315. ;------------------------------------------------------------------------------
  316. exFAT_lock:
  317. ; DEBUGF  1, "K : exFAT_lock \n"
  318.         lea     ecx, [ebp+exFAT.Lock]
  319.         jmp     mutex_lock
  320.  
  321. exFAT_unlock:
  322. ; DEBUGF  1, "K : exFAT_unlock \n"
  323.         lea     ecx, [ebp+exFAT.Lock]
  324.         jmp     mutex_unlock
  325. ;------------------------------------------------------------------------------
  326. exFAT_get_name:
  327.         cmp     byte [edi], 0
  328.         jz      .no
  329. ; DEBUGF  1, "K : exFAT_get_name EDI:%x [EDI]:%x\n", edi, [edi]
  330. ;        push    ebp
  331. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
  332. ; DEBUGF  1, "K : exFAT_get_name START Input FS EBP:%x\n", ebp
  333. ;        pop     ebp
  334. ; in: edi -> FAT entry, esi -> buffer for UTF-16 name
  335. ; out: CF=1 -> no valid entry
  336.         cmp     byte [edi], 0x85 ; File/Folder Directory Entry of ExFAT
  337.         jz      .file_directory_entry
  338.         cmp     byte [edi], 0xC0 ; Stream Extension Directory Entry of ExFAT
  339.         jz      .stream_extension_directory_entry
  340.         cmp     byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT
  341.         jz      .longname
  342.         push    edi esi
  343.         xchg    esi, edi
  344. ; DEBUGF  1, "K : exFAT Volume label dword [ESI]: %x\n", [esi]
  345.         cmp     byte [esi], 0x83 ; Indicates that the Volume label exists
  346.         jnz     .no_label
  347. .label:
  348. ; DEBUGF  1, "K : exFAT_get_name.label \n"
  349.         add     esi, 2
  350.         lea     edi, [ebp+exFAT.volumeLabel]
  351.        
  352.         push    ecx
  353.         mov     ecx, 12
  354.         call    UTF16to8_string
  355.         pop     ecx
  356.        
  357. ;        push    edi
  358. ;        lea     edi, [ebp+exFAT.volumeLabel]
  359. ; DEBUGF  1, "K : exFAT Volume label: %s\n", edi
  360. ;        pop     edi
  361. .no_label:
  362. ; DEBUGF  1, "K : exFAT_get_name.no_label \n"
  363.         pop     esi edi
  364. .no:
  365. ; DEBUGF  1, "K : exFAT_get_name.no \n"
  366.         stc
  367.         ret
  368. ;--------------------------------------
  369. .file_directory_entry:
  370. ; DEBUGF  1, "K : exFAT_get_name 0x85\n"
  371.         xor     eax, eax
  372.         mov     [ebp+exFAT.hash_flag], eax ; dword 0
  373.         mov     al, byte [edi+1]  ; Number of Secondary directory entries
  374.         dec     eax
  375.         mov     [ebp+exFAT.secondary_dir_entry], eax
  376. ; DEBUGF  1, "K : exFAT_get_name 0x85 SDE: %x\n", eax
  377.         lea     esi, [ebp+exFAT.file_dir_entry]
  378. ; DEBUGF  1, "K : exFAT.file_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
  379.         jmp     @f
  380. ;--------------------------------------
  381. .stream_extension_directory_entry:
  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:
  397.         lea     esi, [ebp+exFAT.str_ext_dir_entry]
  398. ; DEBUGF  1, "K : exFAT.str_ext_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
  399. @@:
  400.         push    edi
  401.         xchg    esi, edi
  402.         movsd
  403.         movsd
  404.         movsd
  405.         movsd
  406.         movsd
  407.         movsd
  408.         movsd
  409.         movsd
  410.         pop     edi
  411. ;        lea     esi, [esp+20]
  412.  
  413.         mov     esi, [ebp+exFAT.LFN_reserve_place]
  414.         mov     word [esi+260*2], 0     ; force null-terminating for orphans
  415.         jmp     .no
  416. ;--------------------------------------
  417. .longname:
  418. ; DEBUGF  1, "K : exFAT_get_name 0xC1\n"
  419. ;        push    ebp
  420. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
  421. ; DEBUGF  1, "K : exFAT_get_name.longname 0 Input FS EBP:%x\n", ebp
  422. ;        pop     ebp
  423. ; DEBUGF  1, "K : exFAT_get_name.longname \n"
  424. ; DEBUGF  1, "K : exFAT_get_name.longname EDI:%x [EDI]:%x ESI:%x [ESI]:%x EBP:%x NAME:%s\n", edi, [edi], esi, [esi], ebp, ebp
  425. ; copy name (15 chars in UTF-16)
  426. ;        mov     word [esi+260*2], 0     ; force null-terminating for orphans
  427.  
  428. ;        push    ebp
  429. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
  430. ; DEBUGF  1, "K : exFAT_get_name.longname Input FS EBP:%x\n", ebp
  431. ;        pop     ebp
  432.  
  433.         mov     eax, [ebp+exFAT.hash_flag]
  434.         test    eax, eax
  435.         jnz     .no
  436. ; DEBUGF  1, "K : exFAT_get_name.longname hash match! \n"
  437.         push    edi esi
  438.  
  439.         xchg    esi, edi
  440.         add     esi, 2
  441.  
  442.         movsd
  443.         movsd
  444.         movsd
  445.         movsd
  446.         movsd
  447.         movsd
  448.         movsd
  449.         movsw
  450. ; force null-terminating for incomplete name
  451.         xor     eax, eax
  452.         stosw
  453.         pop     esi edi
  454.        
  455. ;        push    ebp
  456. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4+4]
  457. ; DEBUGF  1, "K : exFAT_get_name.longname Output FS EBP:%x\n", ebp
  458. ;        pop     ebp
  459.  
  460.         mov     eax, [ebp+exFAT.secondary_dir_entry]
  461.         dec     eax
  462.         mov     [ebp+exFAT.secondary_dir_entry], eax
  463.         jz      @f
  464.         add     esi, 30
  465. ; DEBUGF  1, "K : exFAT_get_name 0xC1 CONT\n"
  466.         jmp     .no
  467. ;        test    ax, ax
  468. ;        jnz     .no ; if this is not first entry, more processing required
  469. @@:
  470. ;         mov     esi, [ebp+exFAT.LFN_reserve_place]
  471. ; DEBUGF  1, "K : exFAT_get_name.longname END \n"
  472. ; DEBUGF  1, "K : exFAT_get_name 0xC1 END\n"
  473.         ret
  474. ;------------------------------------------------------------------------------
  475. exFAT_entry_to_bdfe:
  476. ; DEBUGF  1, "K : exFAT_ReadFolder exFAT_entry_to_bdfe \n"
  477. ; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi
  478.         mov     eax, [ebp-4]
  479.         mov     [esi+4], eax    ; cp866/UNICODE name
  480. exFAT_entry_to_bdfe2:
  481. ;        movzx   eax, byte [edi+11]
  482.         movzx   eax, byte [edi+4]
  483.         mov     [esi], eax      ; attributes
  484.  
  485. ;        movzx   eax, word [edi+14]
  486.         movzx   eax, word [edi+8]
  487.         call    fat_time_to_bdfe
  488.         mov     [esi+8], eax    ; creation time
  489.  
  490. ;        movzx   eax, word [edi+16]
  491.         movzx   eax, word [edi+8+2]
  492.         call    fat_date_to_bdfe
  493.         mov     [esi+12], eax   ; creation date
  494.  
  495. ;        and     dword [esi+16], 0       ; last access time is not supported on FAT
  496.         movzx   eax, word [edi+16]
  497.         call    fat_time_to_bdfe
  498.         mov     [esi+16], eax    ; last access time
  499.  
  500. ;        movzx   eax, word [edi+18]
  501.         movzx   eax, word [edi+16+2]
  502.         call    fat_date_to_bdfe
  503.         mov     [esi+20], eax   ; last access date
  504.  
  505. ;        movzx   eax, word [edi+22]
  506.         movzx   eax, word [edi+12]
  507.         call    fat_time_to_bdfe
  508.         mov     [esi+24], eax   ; last write time
  509.  
  510. ;        movzx   eax, word [edi+24]
  511.         movzx   eax, word [edi+12+2]
  512.         call    fat_date_to_bdfe
  513.         mov     [esi+28], eax   ; last write date
  514.  
  515.         mov     al, [esi]
  516.         test    al, 10000b
  517.         jz      .file_size
  518.         xor     eax, eax
  519.         mov     [esi+32], eax   ; file size (low dword)
  520.         mov     [esi+36], eax   ; file size (high dword)
  521.         jmp     @f
  522. .file_size:
  523.         mov     eax, [edi+32+8]
  524.         mov     [esi+32], eax   ; file size (low dword)
  525.         mov     eax, [edi+32+8+4]
  526.         mov     [esi+36], eax   ; file size (high dword)
  527. @@:
  528.         test    ebp, ebp
  529.         jz      .ret
  530. .copy_path:
  531.         add     esi, 40
  532.         push    edi esi
  533.         mov     edi, esi
  534.         mov     esi, ebp
  535.         cmp     byte [ebp-4], 2
  536.         jz      .utf16
  537.         cmp     byte [ebp-4], 3
  538.         jz      .utf8
  539. @@:
  540.         lodsw
  541.         call    uni2ansi_char
  542.         stosb
  543.         test    al, al
  544.         jnz     @b
  545.         pop     esi edi
  546.         add     esi, 264
  547. .ret:
  548. ; DEBUGF  1, "K : exFAT_entry_to_bdfe +264 ESI:%x\n", esi
  549.         ret
  550.  
  551. .utf8:
  552.         push    ecx
  553.         mov     ecx, 519
  554.         call    UTF16to8_string
  555.         pop     ecx
  556.         jmp     @f
  557.  
  558. .utf16:
  559.         lodsw
  560.         stosw
  561.         test    eax, eax
  562.         jnz     .utf16
  563. @@:
  564.         pop     esi edi
  565.         add     esi, 520
  566. ; DEBUGF  1, "K : exFAT_entry_to_bdfe +520 ESI:%x\n", esi
  567.         ret
  568. ;------------------------------------------------------------------------------
  569. exFAT_get_FAT:
  570. ; DEBUGF  1, "K : exFAT_get_FAT \n"
  571. ; in: eax = cluster
  572. ; out: eax = next cluster, CF=1 -> error
  573.         push    ebx esi
  574. ;        cmp     [ebp+FAT.fs_type], 12
  575. ;        je      .FAT12
  576. ;        cmp     [ebp+FAT.fs_type], 16
  577. ;        je      @f
  578. ;        add     eax, eax
  579. ;@@:
  580. ;        add     eax, eax
  581.         shl     eax, 2
  582.         mov     esi, 511
  583.         and     esi, eax
  584.         shr     eax, 9
  585.         add     eax, [ebp+exFAT.FAT_START]
  586.         mov     ebx, [ebp+exFAT.fat_cache_ptr]
  587.         cmp     eax, [ebp+exFAT.fat_in_cache]
  588.         je      .inCache
  589.         cmp     [ebp+exFAT.fat_change], 0
  590.         je      @f
  591. ;        call    write_fat_sector
  592. @@:
  593.         mov     [ebp+exFAT.fat_in_cache], eax
  594.         call    fs_read32_sys
  595.         test    eax, eax
  596.         jnz     .error
  597. .inCache:
  598. ; DEBUGF  1, "K : exFAT_get_FAT.inCache \n"
  599.         mov     eax, [ebx+esi]
  600.         and     eax, [ebp+exFAT.fatMASK]
  601. .ret:
  602.         pop     esi ebx
  603.         ret
  604.  
  605. .error:
  606. ; DEBUGF  1, "K : exFAT_get_FAT.error \n"
  607.         stc
  608.         jmp     .ret
  609. ;------------------------------------------------------------------------------
  610. exFAT_hd_find_lfn:
  611. ; DEBUGF  1, "K : exFAT_hd_find_lfn path ESI: %s\n", esi
  612. ; in: esi -> path string in UTF-8
  613. ; out: CF=1 - file not found, eax=error code
  614. ;      else CF=0 and edi->direntry, eax=sector
  615.         push    esi edi
  616.         push    0
  617.         push    0
  618.         push    exFAT_notroot_first ; 0 ; fat1x_root_first
  619.         push    exFAT_notroot_next ; 0 ; fat1x_root_next
  620.         xor     eax, eax
  621.         mov     [ebp+exFAT.General_Sec_Flags], eax
  622.         mov     dword [ebp+exFAT.valid_data_length], 0xffffffff ; for ROOT
  623.         mov     eax, [ebp+exFAT.ROOT_CLUSTER]
  624. ;        mov     [ebp+exFAT.secondary_dir_entry], dword 1
  625. ;        cmp     [ebp+FAT.fs_type], 32
  626. ;        jz      .fat32
  627.         jmp     @f ; .fat32
  628. .loop:
  629.         and     [ebp+exFAT.longname_sec1], 0
  630.         and     [ebp+exFAT.longname_sec2], 0
  631.  
  632. ;        push    ebp
  633. ;        mov     ebp,[esp+12+8+4+4+7*4]
  634. ; DEBUGF  1, "K : exFAT_find_lfn Input FS EBP:%x\n", ebp
  635. ;        pop     ebp
  636.  
  637.         call    exFAT_find_lfn
  638.  
  639. ;        push    ebp
  640. ;        mov     ebp,[esp+12+8+4+4+7*4]
  641. ; DEBUGF  1, "K : exFAT_find_lfn Output FS EBP:%x\n", ebp
  642. ;        pop     ebp
  643.  
  644.         jc      .notfound
  645. ; DEBUGF  1, "K : exFAT_hd_find_lfn [ESI]: %x\n", [esi]
  646.         cmp     byte [esi], 0
  647.         jz      .found
  648. ;        test    byte [edi+11], 10h
  649.         lea     eax, [ebp+exFAT.file_dir_entry]
  650. ; DEBUGF  1, "K : exFAT_hd_find_lfn exFAT.file_dir_entry [EAX]: %x\n", [eax]
  651.         test    byte [eax+4], 10000b
  652.         jz      .notfound
  653.         and     dword [esp+12], 0
  654. ; this entry’s first cluster number
  655. ;        mov     eax, [edi+20-2]
  656. ;        mov     ax, [edi+26]    ; cluster
  657.         lea     eax, [ebp+exFAT.str_ext_dir_entry]
  658.  
  659.         push    eax
  660.         movzx   eax, byte [eax+1]
  661.         mov     [ebp+exFAT.General_Sec_Flags], eax
  662. ; DEBUGF  1, "K : exFAT General_Sec_Flags %x\n", eax
  663.         mov     eax, [esp]
  664.         mov     eax, [eax+8] ; LOW dword of Valid data length - WARNING!!! late rewrite
  665.         mov     [ebp+exFAT.valid_data_length], eax
  666. ; DEBUGF  1, "K : exFAT.valid_data_length 1 %x\n", eax
  667.         pop     eax
  668.  
  669.         mov     eax, [eax+20]    ; cluster
  670. ;.fat32:
  671. @@:
  672. ; DEBUGF  1, "K : exFAT_hd_find_lfn exFAT cluster EAX: %x\n", eax
  673.         mov     [esp+8], eax
  674. ;        mov     dword [esp+4], exFAT_notroot_first ; fat_notroot_first
  675. ;        mov     dword [esp], exFAT_notroot_next ; fat_notroot_next
  676.         jmp     .loop
  677.  
  678. .notfound:
  679. ; DEBUGF  1, "K : exFAT_hd_find_lfn.notfound \n"
  680.         add     esp, 16
  681.         pop     edi esi
  682.         stc
  683.         ret
  684.  
  685. .found:
  686. ; DEBUGF  1, "K : exFAT_hd_find_lfn.found \n"
  687.         lea     eax, [esp+8]
  688.         cmp     dword [eax], 0
  689.         jz      .root
  690.         call    exFAT_get_sector
  691.         jmp     .cmn
  692.  
  693. .root:
  694. ; DEBUGF  1, "K : exFAT_hd_find_lfn.found.root \n"
  695.         mov     eax, [eax+4]
  696.         add     eax, [ebp+exFAT.ROOT_START]
  697. .cmn:
  698. ; DEBUGF  1, "K : exFAT_hd_find_lfn.found.cmn \n"
  699.         add     esp, 20         ; CF=0
  700.         pop     esi
  701.         ret
  702. ;------------------------------------------------------------------------------
  703. exFAT_find_lfn:
  704. ; DEBUGF  1, "K : exFAT_find_lfn \n"
  705. ;   in:
  706. ; esi -> path in UTF-8
  707. ; parameters in the stack
  708. ;   out:
  709. ; esi -> next name in the path
  710. ; edi -> direntry
  711. ; CF=1 -> file not found, eax = error code
  712.         xor     eax, eax
  713.         inc     eax
  714.         mov     [ebp+exFAT.secondary_dir_entry], eax ; dword 1
  715.         mov     [ebp+exFAT.need_hash], eax ; dword 1
  716.         lea     eax, [esp+12]
  717.         call    dword [eax-4] ; exFAT_notroot_first
  718.         jc      .reterr
  719.         sub     esp, 262*2      ; reserve place for LFN
  720. ;        lea     eax, [esp]
  721.         mov     eax, esp
  722.         mov     [ebp+exFAT.LFN_reserve_place], eax
  723.         mov     [ebp+exFAT.path_in_UTF8], 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
  789. .l1:
  790. ;        push    esi
  791. ;        lea     esi, [esp+4]
  792. ;        mov     esi, [ebp+exFAT.LFN_reserve_place]
  793. ; DEBUGF  1, "K : exFAT_find_lfn.exFAT_get_name \n"
  794.  
  795. ;        push    ebp
  796. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4]
  797. ; DEBUGF  1, "K : exFAT_get_name Input FS EBP:%x\n", ebp
  798. ;        pop     ebp
  799. ; DEBUGF  1, "K : exFAT FL need_hash :%x\n", [ebp+exFAT.need_hash]
  800.         call    exFAT_get_name
  801. ;        mov     [ebp+exFAT.LFN_reserve_place], esi
  802. ;        pop     esi
  803.  
  804. ;        push    ebp
  805. ;        mov     ebp,[esp+12+8+4+4+7*4+262*2+4]
  806. ; DEBUGF  1, "K : exFAT_get_name Output FS EBP:%x\n", ebp
  807. ;        pop     ebp
  808.  
  809.         jc      .no
  810.  
  811. ;        push    eax
  812.         xor     eax, eax
  813.         cmp     [ebp+exFAT.secondary_dir_entry], eax
  814. ;        pop     eax
  815.         jnz     .no
  816.  
  817.         push    edi esi
  818.         mov     esi, [ebp+exFAT.path_in_UTF8]
  819.         lea     edi, [esp+8]
  820. @@:
  821.         call    utf8to16
  822.         call    utf16toUpper
  823.         mov     edx, eax
  824.         mov     ax, [edi]
  825.         call    utf16toUpper
  826.         cmp     ax, dx
  827.         jnz     .done
  828.         add     edi, 2
  829.         test    ax, ax
  830.         jnz     @b
  831.         dec     esi
  832.         pop     eax edi
  833. .found:
  834. ; DEBUGF  1, "K : exFAT_find_lfn.found \n"
  835.         add     esp, 262*2
  836. ; if this is LFN entry, advance to true entry
  837. ;        cmp     byte [edi+11], 0xF
  838. ;        jnz     @f
  839.         xor     eax, eax
  840.         cmp     [ebp+exFAT.secondary_dir_entry], eax
  841.         jz      @f
  842.         lea     eax, [esp+12]
  843.         call    dword[eax-8] ; exFAT_notroot_next
  844.         jc      .reterr
  845. @@:
  846. ; DEBUGF  1, "K : exFAT_find_lfn.OK \n"
  847.         xor     eax, eax
  848.         ret
  849.  
  850. .done:
  851. ; DEBUGF  1, "K : exFAT_find_lfn.done \n"
  852.         cmp     dx, '/'
  853.         jnz     @f
  854.         test    ax, ax
  855.         jnz     @f
  856.         mov     [esp], esi
  857. @@:
  858.         pop     esi edi
  859.         jz      .found
  860. .no:
  861. ; DEBUGF  1, "K : exFAT_find_lfn.no \n"
  862.         lea     eax, [esp+262*2+12]
  863. ; DEBUGF  1, "K : exFAT General_Sec_Flags %x\n", [ebp+exFAT.General_Sec_Flags]
  864. ; DEBUGF  1, "K : exFAT.valid_data_length 2 %x\n", [ebp+exFAT.valid_data_length]
  865.         cmp     [ebp+exFAT.valid_data_length], 0
  866.         jbe     @f
  867.  
  868.         call    dword[eax-8] ; exFAT_notroot_next
  869.         jnc     .l1
  870. @@:
  871.         add     esp, 262*2
  872. .reterr:
  873. ; DEBUGF  1, "K : exFAT_find_lfn.reterr \n"
  874.         stc
  875.         ret
  876. ;------------------------------------------------------------------------------
  877. exFAT_ReadFile:
  878. ; DEBUGF  1, "K : exFAT_ReadFile \n"
  879. ; DEBUGF  1, "K : exFAT F70 +00: %x\n", [ebx]
  880. ; DEBUGF  1, "K : exFAT F70 +04: %x\n", [ebx+4]
  881. ; DEBUGF  1, "K : exFAT F70 +08: %x\n", [ebx+8]
  882. ; DEBUGF  1, "K : exFAT F70 +12: %x\n", [ebx+12]
  883. ; DEBUGF  1, "K : exFAT F70 +16: %x\n", [ebx+16]
  884. ; DEBUGF  1, "K : exFAT F70 +20: %x\n", [ebx+20]
  885. ; DEBUGF  1, "K : exFAT Path: %s\n", esi
  886.        
  887. ;        push    eax
  888. ;        pushfd
  889. ;        pop     eax
  890. ; DEBUGF  1, "K : eFlags:%x\n",eax
  891. ;        pop     eax
  892. ; DEBUGF  1, "K : EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  893. ; DEBUGF  1, "K : EBP:%x ESI:%x EDI:%x\n", ebp, esi, edi
  894. ;   in:
  895. ; ebx -> parameter structure of sysfunc 70
  896. ; ebp -> exFAT structure
  897. ; esi -> path string in UTF-8
  898. ;   out:
  899. ; eax, ebx = return values for sysfunc 70
  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
  904.         call    exFAT_hd_find_lfn
  905.         jc      .notFound
  906. ;        test    byte [edi+11], 0x10     ; do not allow read directories
  907. ;        jnz     .noaccess
  908.         lea     eax, [ebp+exFAT.file_dir_entry]
  909.         test    byte [eax+4], 10000b  ; do not allow read directories
  910.         jnz     .noaccess
  911. ; Rewrite code to work with more than 4 GB files !!!
  912. ;        cmp     dword [ebx+8], 0
  913. ;        jnz     .endOfFile
  914.  
  915.         mov     edx, [ebx+8]    ; file offset high
  916. ; DEBUGF  1, "K : exFAT_ReadFile Hdword file offset EDX:%x\n", edx
  917.         mov     [ebp+exFAT.RDX_high], edx
  918.         mov     edx, [ebx+4]    ; file offset low
  919. ; DEBUGF  1, "K : exFAT_ReadFile Ldword file offset EAX:%x\n", edx
  920.  
  921.         mov     ecx, [ebx+12]   ; size
  922.         mov     ebx, [ebx+16]   ; buffer
  923.         push    ebx
  924.         push    0
  925.         test    ecx, ecx ; read size 0?
  926.         jz      .done
  927.  
  928. ;        mov     eax, [edi+28] ; real file size
  929.         lea     eax, [ebp+exFAT.str_ext_dir_entry]
  930. ; DEBUGF  1, "K : exFAT 0xC0 +00: %x\n", [eax]
  931. ; DEBUGF  1, "K : exFAT 0xC0 +04: %x\n", [eax+4]
  932. ; DEBUGF  1, "K : exFAT 0xC0 +08: %x\n", [eax+8]
  933. ; DEBUGF  1, "K : exFAT 0xC0 +12: %x\n", [eax+12]
  934. ; DEBUGF  1, "K : exFAT 0xC0 +16: %x\n", [eax+16]
  935. ; DEBUGF  1, "K : exFAT 0xC0 +20: %x\n", [eax+20]
  936. ; DEBUGF  1, "K : exFAT 0xC0 +24: %x\n", [eax+24]
  937. ; DEBUGF  1, "K : exFAT 0xC0 +28: %x\n", [eax+28]
  938.         push    eax
  939.         movzx   eax, byte [eax+1]
  940.         mov     [ebp+exFAT.General_Sec_Flags], eax
  941.         pop     eax
  942.  
  943.         push    eax
  944.         mov     eax, [eax+12]    ; high dword of  real file size
  945.         mov     [ebp+exFAT.RAX_high], eax
  946. ; DEBUGF  1, "K : exFAT_ReadFile Hdword file size EAX:%x\n", eax
  947.         pop     eax
  948.  
  949.         mov     eax, [eax+8]    ; low dword of  real file size
  950. ; DEBUGF  1, "K : exFAT_ReadFile Ldword file size EAX:%x\n", eax
  951.  
  952. ;        sub     eax, edx ; low dword file size - file offset low = rest of file
  953. ;        jb      .fileEnd
  954.         sub     eax, edx ; low dword file size - file offset low = rest of file
  955.         push    eax
  956.         mov     eax, [ebp+exFAT.RDX_high]
  957.         sbb     [ebp+exFAT.RAX_high], eax
  958.         pop     eax
  959.         jb      .fileEnd
  960. ; DEBUGF  1, "K : exFAT_ReadFile Hdword rest of file RAX:%x\n", [ebp+exFAT.RAX_high]
  961. ; DEBUGF  1, "K : exFAT_ReadFile Ldword rest of file EAX:%x\n", eax
  962.  
  963.         push    eax
  964.         mov     eax, [ebp+exFAT.RAX_high]
  965.         test    eax, eax
  966.         pop     eax
  967.         jnz     @f
  968.  
  969.         cmp     eax, ecx ; rest of file - requested size
  970.         jae     @f
  971.  
  972. ; DEBUGF  1, "K : exFAT_ReadFile 6=EOF EAX:%x ECX:%x EDX:%x\n", eax, ecx, edx
  973.         mov     ecx, eax
  974.         mov     byte [esp], 6 ; 6 = end of file, EOF
  975. @@:
  976.         lea     eax, [ebp+exFAT.str_ext_dir_entry]
  977.         mov     eax, [eax+20]    ; cluster
  978. ; DEBUGF  1, "K : exFAT EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  979. ; now eax=cluster, ebx=buffer for data, ecx=count, edx=position
  980.         mov     edi, [ebp+exFAT.SECTORS_PER_CLUSTER]
  981.         shl     edi, 9  ; bytes per cluster
  982. @@:
  983.         cmp     eax, 2
  984.         jb      .fileEnd
  985. .continue_1:
  986.         cmp     eax, [ebp+exFAT.fatRESERVED]
  987.         jae     .fileEnd
  988.  
  989.         push    eax
  990.         xor     eax, eax
  991.         sub     edx, edi ; file_offset_low - bytes per cluster
  992.         sbb     [ebp+exFAT.RDX_high], eax
  993.         pop     eax
  994.         jc      @f
  995.  
  996. ;        push    edi
  997. ;        lea     edi, [ebp+exFAT.file_dir_entry]
  998. ; Check - General Secondary Flags
  999. ; Bit 0 : Allocation possible
  1000. ;         0 – No cluster allocated; 1 – cluster allocation is possible
  1001. ; Bit 1 : No FAT chain
  1002. ;         0 – Yes ; The clusters of this file/directory are NOT contiguous
  1003. ;         1 – No; The Contiguous Cluster are allocated to this file/directory;
  1004. ;         This improves the File read performance
  1005. ; Bits 2 – 7 : Reserved
  1006. ;        test    byte [edi+1], 11b
  1007. ;        pop     edi
  1008.         test    byte [ebp+exFAT.General_Sec_Flags], 10b
  1009.         jz      .get_FAT_1
  1010.         inc     eax
  1011.         jmp     .continue_1
  1012. .get_FAT_1:
  1013.  
  1014.         call    exFAT_get_FAT
  1015.         jc      .noaccess2
  1016.  
  1017.         jmp     @b
  1018.  
  1019. .notFound:
  1020. ; DEBUGF  1, "K : exFAT_ReadFile.notFound: \n"
  1021.         push    eax
  1022.         jmp     .ret
  1023.  
  1024. .noaccess:
  1025. ; DEBUGF  1, "K : exFAT_ReadFile.noaccess \n"
  1026.         push    ERROR_ACCESS_DENIED
  1027.         jmp     .ret
  1028.  
  1029. .endOfFile:
  1030. ; DEBUGF  1, "K : exFAT_ReadFile.endOfFile \n"
  1031.         push    ERROR_END_OF_FILE
  1032. .ret:
  1033.         call    exFAT_unlock
  1034.         pop     eax
  1035.         xor     ebx, ebx
  1036. ; DEBUGF  1, "K : exFAT_ReadFile Return EBX:%x\n", ebx
  1037.         ret
  1038.  
  1039. @@:
  1040. ; DEBUGF  1, "K : exFAT_ReadFile CONTINUE cluster EAX:%x\n", eax
  1041.         mov     esi, eax
  1042.         dec     eax
  1043.         dec     eax
  1044.  
  1045.         push    ebx edx
  1046.         xor     edx, edx
  1047. ; DEBUGF  1, "K : exFAT_ReadFile IMUL in EDX:%x EAX:%x\n", EDX, eax
  1048.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER] ; Sector edx:eax
  1049. ; DEBUGF  1, "K : exFAT_ReadFile IMUL out EDX:%x EAX:%x\n", EDX, eax
  1050.         xor     ebx, ebx
  1051.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1052.         adc     edx, ebx
  1053.         mov     [ebp+exFAT.RAX_high], edx
  1054.         pop     edx ebx
  1055. ; DEBUGF  1, "K : exFAT_ReadFile start sector RAX_H:%x EAX:%x RDX_H:%x EDX:%x EDI:%x\n", [ebp+exFAT.RAX_high], eax, [ebp+exFAT.RDX_high], edx, edi
  1056.         push    eax
  1057.         xor     eax, eax
  1058.         add     edx, edi ; file offset low + bytes per cluster
  1059.         adc     [ebp+exFAT.RDX_high], eax
  1060.         pop     eax
  1061.  
  1062.         test    edx, edx
  1063.         jz      .alignedCluster
  1064.  
  1065.         mov     edi, edx ; file offset low
  1066.         push    eax
  1067.         mov     eax, [ebp+exFAT.RDX_high]
  1068.         mov     [ebp+exFAT.RDI_high], eax
  1069.         pop     eax
  1070.  
  1071. ;        shr     edi, 9
  1072.         push    ebx
  1073.         mov     ebx, [ebp+exFAT.RDI_high]
  1074.         shrd    edi, ebx, 5 ; /32
  1075.         shr     ebx, 5 ; /32
  1076.         shrd    edi, ebx, 4 ; /16
  1077.         shr     ebx, 4 ; /16
  1078.         mov     [ebp+exFAT.RDI_high], ebx
  1079.         pop     ebx
  1080.  
  1081.         add     eax, edi ; RFile_start_sector_low - file_sector_offset_low
  1082.         push    ebx
  1083.         mov     ebx, [ebp+exFAT.RDI_high]
  1084.         adc     [ebp+exFAT.RAX_high], ebx
  1085.         pop     ebx
  1086.  
  1087.         and     edx, 511
  1088.         and     dword [ebp+exFAT.RDX_high], 0
  1089.  
  1090.         cmp     ecx, 512
  1091.         jc      .sectorPiece
  1092.         test    edx, edx
  1093.         jz      .alignedSector
  1094. .sectorPiece:
  1095. ; DEBUGF  1, "K : exFAT_ReadFile.sectorPiece \n"
  1096.         push    eax ebx ecx edx
  1097.         lea     ebx, [ebp+exFAT.buffer]
  1098.         mov     edx, [ebp+exFAT.RAX_high]
  1099.         xor     ecx, ecx
  1100.         inc     ecx
  1101. ; DEBUGF  1, "K : exFAT fs_read64_app EDX:%x EAX:%x ECX:%x EBX:%x EBP:%x\n", edx, eax, ecx, ebx, ebp
  1102. ;        call    fs_read32_app
  1103.         call    fs_read64_app
  1104. ; DEBUGF  1, "K : exFAT fs_read64_app Output EAX:%x ECX:%x EBX:%x\n", eax, ecx, ebx
  1105.         test    eax, eax
  1106. ;        lea     eax, [ebp+exFAT.buffer]
  1107.         mov     eax, ebx ; exFAT.buffer
  1108.         pop     edx ecx ebx
  1109.         jne     .noaccess3
  1110. ; DEBUGF  1, "K : exFAT_ReadFile memmove(-1) EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  1111.         add     eax, edx ; exFAT.buffer + offset within a sector
  1112.         push    ecx
  1113.         add     ecx, edx ; requested size + offset within a sector
  1114.         cmp     ecx, 512
  1115.         jbe     @f
  1116.         mov     ecx, 512
  1117. @@:
  1118.         sub     ecx, edx ; requested size - offset within a sector
  1119. ; DEBUGF  1, "K : exFAT_ReadFile memmove EAX:%x EBX:%x ECX:%x\n", eax, ebx, ecx
  1120. ; eax = from
  1121. ; ebx = to
  1122. ; ecx = no of bytes
  1123.         call    memmove
  1124. ; DEBUGF  1, "K : exFAT_ReadFile memmove(1) EAX:%x EBX:%x ECX:%x\n", eax, ebx, ecx
  1125.         sub     [esp], ecx
  1126.         add     ebx, ecx
  1127. ; DEBUGF  1, "K : exFAT_ReadFile memmove(2) EAX:%x EBX:%x ECX:%x\n", eax, ebx, ecx
  1128.         pop     ecx eax
  1129.         xor     edx, edx
  1130. ;        inc     edi ; file_sector_offset_low
  1131.         push    eax
  1132.         xor     eax, eax
  1133.         add     edi, 1 ; you cannot use INC EDI for qword!!!
  1134.         adc     [ebp+exFAT.RDI_high], eax
  1135.         pop     eax
  1136. ;        inc     eax ; RFile_start_sector_low
  1137.         push    ebx
  1138.         xor     ebx, ebx
  1139.         add     eax, 1 ; you cannot use INC EAX for qword!!!
  1140.         adc     [ebp+exFAT.RAX_high], ebx
  1141.         pop     ebx
  1142.         test    ecx, ecx
  1143.         jz      .done
  1144. .alignedSector:
  1145. ; DEBUGF  1, "K : exFAT_ReadFile.alignedSector \n"
  1146. ;        shl     edi, 9 ; RFile_start_sector_low * 512
  1147.         push    ebx
  1148.         mov     ebx, [ebp+exFAT.RDI_high]
  1149.         shld    ebx, edi, 5 ; *32
  1150.         shl     edi, 5 ; *32
  1151.         shld    ebx, edi, 4 ; *16
  1152.         shl     edi, 4 ; *16
  1153.         mov     [ebp+exFAT.RDI_high], ebx
  1154.         pop     ebx
  1155.  
  1156.         push    ebx
  1157.         xor     ebx, ebx
  1158.         mov     [ebp+exFAT.RCX_high], ebx
  1159.         add     ecx, edi ; requested size  + file_offset_low
  1160.         mov     ebx, [ebp+exFAT.RDI_high]
  1161.         adc     [ebp+exFAT.RCX_high], ebx
  1162.         pop     ebx
  1163.  
  1164.         xor     edi, edi
  1165.         mov     [ebp+exFAT.RDI_high], edi
  1166.         mov     edi, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1167.         shl     edi, 9  ; bytes per cluster
  1168. .alignedCluster:
  1169. ; DEBUGF  1, "K : exFAT_ReadFile.alignedCluster RAX_H:%x EAX:%x RDX_H:%x EDX:%x EDI:%x\n", [ebp+exFAT.RAX_high], eax, [ebp+exFAT.RDX_high], edx, edi
  1170.         cmp     ecx, 512
  1171.         jc      .sectorPiece
  1172.         mov     edx, [ebp+exFAT.RAX_high]
  1173.         mov     [ebp+exFAT.RDX_high], edx
  1174.         mov     edx, eax ; edx << RFile_start_sector_low
  1175.  
  1176.         xor     eax, eax
  1177.         mov     [ebp+exFAT.RAX_high], eax
  1178.         mov     eax, esi ; eax << cluster
  1179. @@:
  1180.         push    eax
  1181.         xor     eax, eax
  1182.         sub     ecx, edi ; requested size low - bytes per cluster
  1183.         sbb     [ebp+exFAT.RCX_high], eax
  1184.         pop     eax
  1185.         jbe     .readEnd
  1186.        
  1187. ;        push    edi
  1188. ;        lea     edi, [ebp+exFAT.file_dir_entry]
  1189. ; Check - General Secondary Flags
  1190. ; Bit 0 : Allocation possible
  1191. ;         0 – No cluster allocated; 1 – cluster allocation is possible
  1192. ; Bit 1 : No FAT chain
  1193. ;         0 – Yes ; The clusters of this file/directory are NOT contiguous
  1194. ;         1 – No; The Contiguous Cluster are allocated to this file/directory;
  1195. ;         This improves the File read performance
  1196. ; Bits 2 – 7 : Reserved
  1197. ;        test    byte [edi+1], 11b
  1198. ;        pop     edi
  1199.         test    byte [ebp+exFAT.General_Sec_Flags], 10b
  1200.         jz      .get_FAT
  1201.         inc     eax ; inc cluster
  1202.         jmp     .continue
  1203. .get_FAT:
  1204. ; DEBUGF  1, "K : exFAT_ReadFile.get_FAT \n"
  1205.         call    exFAT_get_FAT
  1206.         jc      .noaccess4
  1207.         cmp     eax, 2
  1208.         jb      .fileEnd2
  1209. .continue:
  1210. ; DEBUGF  1, "K : exFAT_ReadFile.continue \n"
  1211.         cmp     eax, [ebp+exFAT.fatRESERVED]
  1212.         jae     .fileEnd2
  1213.  
  1214.         inc     esi ; inc cluster
  1215.         cmp     eax, esi
  1216.         jz      @b
  1217. .fragmentEnd:
  1218. ; DEBUGF  1, "K : exFAT_ReadFile.fragmentEnd \n"
  1219.         xchg    eax, esi
  1220.         dec     eax
  1221.         dec     eax
  1222.  
  1223.         push    ebx edx
  1224.         xor     edx, edx
  1225.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER] ; Sector edx:eax
  1226.         xor     ebx, ebx
  1227.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1228.         adc     edx, ebx
  1229.         mov     [ebp+exFAT.RAX_high], edx
  1230.         pop     edx ebx
  1231.        
  1232.         push    dword [ebp+exFAT.RCX_high]
  1233.         push    ecx ; requested size low
  1234.        
  1235.         mov     ecx, [ebp+exFAT.RAX_high]
  1236.         mov     [ebp+exFAT.RCX_high], ecx
  1237.         mov     ecx, eax ; ecx << RFile_start_sector_low
  1238.        
  1239.         xor     eax, eax
  1240.         mov     [ebp+exFAT.RAX_high], eax
  1241.         mov     eax, esi ; eax << custer
  1242.  
  1243.         dec     eax
  1244.         dec     eax
  1245.  
  1246.         push    ebx edx
  1247.         xor     edx, edx
  1248.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER] ; Sector edx:eax
  1249.         xor     ebx, ebx
  1250.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1251.         adc     edx, ebx
  1252.         mov     [ebp+exFAT.RAX_high], edx
  1253.         pop     edx ebx
  1254.  
  1255.         push    dword [ebp+exFAT.RAX_high]
  1256.         push    eax
  1257. .readFragment:
  1258. ; DEBUGF  1, "K : exFAT_ReadFile.readFragment \n"
  1259.         push    eax
  1260.         mov     eax, [ebp+exFAT.RDX_high]
  1261.         sub     ecx, edx ; RFile_start_sector_low - RFile_start_sector_low
  1262.         sbb     [ebp+exFAT.RCX_high], eax
  1263.         pop     eax
  1264.  
  1265.         mov     eax, edx
  1266. ;        xor     edx, edx
  1267.         mov     edx, [ebp+exFAT.RDX_high]
  1268.  
  1269. ; DEBUGF  1, "K : exFAT fs_read64_app EDX:%x EAX:%x ECX:%x EBX:%x EBP:%x\n", edx, eax, ecx, ebx, ebp
  1270.         call    fs_read64_app
  1271. ; DEBUGF  1, "K : exFAT fs_read64_app Output EAX:%x ECX:%x EBX:%x\n", eax, ecx, ebx
  1272. ;        shl     ecx, 9
  1273.         push    ebx
  1274.         mov     ebx, [ebp+exFAT.RCX_high]
  1275.         shld    ebx, ecx, 5 ; *32
  1276.         shl     ecx, 5 ; *32
  1277.         shld    ebx, ecx, 4 ; *16
  1278.         shl     ecx, 4 ; *16
  1279.         mov     [ebp+exFAT.RCX_high], ebx
  1280.         pop     ebx
  1281.  
  1282.         add     ebx, ecx
  1283.  
  1284.         test    eax, eax
  1285.         pop     eax
  1286.         pop     dword [ebp+exFAT.RAX_high]
  1287.         jnz     .noaccess3
  1288.         pop     ecx
  1289.         pop     dword [ebp+exFAT.RCX_high]
  1290.         xor     edx, edx
  1291.         mov     [ebp+exFAT.RDX_high], edx
  1292.         jecxz   .done_1
  1293.         jmp     .alignedCluster
  1294. .done_1:
  1295.         jmp     .done
  1296.  
  1297. .readEnd:
  1298. ; DEBUGF  1, "K : exFAT_ReadFile.readEnd \n"
  1299.         push    ebx
  1300.         add     ecx, edi ; requested size  + bytes per cluster
  1301.         mov     ebx, [ebp+exFAT.RDI_high]
  1302.         adc     [ebp+exFAT.RCX_high], ebx
  1303.         pop     ebx
  1304.  
  1305.         mov     edi, [ebp+exFAT.RCX_high]
  1306.         mov     [ebp+exFAT.RDI_high], edi
  1307.         mov     edi, ecx
  1308.  
  1309.         and     ecx, 511
  1310.         and     dword [ebp+exFAT.RCX_high], 0
  1311. ;        shr     edi, 9
  1312.         push    ebx
  1313.         mov     ebx, [ebp+exFAT.RDI_high]
  1314.         shrd    edi, ebx, 5 ; /32
  1315.         shr     ebx, 5 ; /32
  1316.         shrd    edi, ebx, 4 ; /16
  1317.         shr     ebx, 4 ; /16
  1318.         mov     [ebp+exFAT.RDI_high], ebx
  1319.         pop     ebx
  1320.  
  1321.         dec     eax
  1322.         dec     eax
  1323.  
  1324.         push    ebx edx
  1325.         xor     edx, edx
  1326.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER] ; Sector edx:eax
  1327.         xor     ebx, ebx
  1328.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1329.         adc     edx, ebx
  1330.         mov     [ebp+exFAT.RAX_high], edx
  1331.         pop     edx ebx
  1332.  
  1333.         add     eax, edi ; RFile_start_sector_low - file_sector_offset_low
  1334.         push    ebx
  1335.         mov     ebx, [ebp+exFAT.RDI_high]
  1336.         adc     [ebp+exFAT.RAX_high], ebx
  1337.         pop     ebx
  1338.  
  1339.         push    dword [ebp+exFAT.RCX_high]
  1340.         push    ecx
  1341.  
  1342.         push    dword [ebp+exFAT.RAX_high]
  1343.         push    eax
  1344.  
  1345.         mov     ecx, [ebp+exFAT.RAX_high]
  1346.         mov     [ebp+exFAT.RCX_high], ecx
  1347.         mov     ecx, eax
  1348.         jmp     .readFragment
  1349.  
  1350. .noaccess3:
  1351. ; DEBUGF  1, "K : exFAT_ReadFile.noaccess3 \n"
  1352.         pop     eax
  1353.         pop     dword [ebp+exFAT.RAX_high]
  1354. .noaccess2:
  1355. ; DEBUGF  1, "K : exFAT_ReadFile.noaccess2 \n"
  1356.         mov     byte [esp], ERROR_DEVICE
  1357. .done:
  1358. ; DEBUGF  1, "K : exFAT_ReadFile.done \n"
  1359.         call    exFAT_unlock
  1360.         pop     eax edx
  1361.         sub     ebx, edx
  1362. ; DEBUGF  1, "K : exFAT_ReadFile Return EBX:%x\n", ebx
  1363.            
  1364. ;        push    eax
  1365. ;        pushfd
  1366. ;        pop     eax
  1367. ; DEBUGF  1, "K : eFlags:%x\n",eax
  1368. ;        pop     eax
  1369. ; DEBUGF  1, "K : EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  1370. ; DEBUGF  1, "K : EBP:%x ESI:%x EDI:%x\n", ebp, esi, edi
  1371.         ret
  1372.  
  1373. .fileEnd:
  1374. ; DEBUGF  1, "K : exFAT_ReadFile.fileEnd \n"
  1375.         mov     byte [esp], ERROR_END_OF_FILE
  1376.         jmp     .done
  1377.  
  1378. .noaccess4:
  1379. ; DEBUGF  1, "K : exFAT_ReadFile.noaccess4 \n"
  1380.         mov     byte [esp], ERROR_DEVICE
  1381.         jmp     @f
  1382.  
  1383. .fileEnd2:
  1384. ; DEBUGF  1, "K : exFAT_ReadFile.fileEnd2 \n"
  1385.         mov     byte [esp], ERROR_END_OF_FILE
  1386. @@:
  1387.         inc     esi
  1388.         xor     ecx, ecx
  1389.         mov     [ebp+exFAT.RCX_high], ecx
  1390.         jmp     .fragmentEnd
  1391. ;------------------------------------------------------------------------------
  1392. exFAT_ReadFolder:
  1393. ; DEBUGF  1, "K : exFAT_ReadFolder \n"
  1394. ; DEBUGF  1, "K : exFAT F70 +00: %x\n", [ebx]
  1395. ; DEBUGF  1, "K : exFAT F70 +04: %x\n", [ebx+4]
  1396. ; DEBUGF  1, "K : exFAT F70 +08: %x\n", [ebx+8]
  1397. ; DEBUGF  1, "K : exFAT F70 +12: %x\n", [ebx+12]
  1398. ; DEBUGF  1, "K : exFAT F70 +16: %x\n", [ebx+16]
  1399. ; DEBUGF  1, "K : exFAT F70 +20: %x\n", [ebx+20]
  1400. ; DEBUGF  1, "K : exFAT Path: %s\n", esi
  1401. ;        push    eax
  1402. ;        pushfd
  1403. ;        pop     eax
  1404. ; DEBUGF  1, "K : eFlags:%x\n",eax
  1405. ;        pop     eax
  1406. ; DEBUGF  1, "K : EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  1407. ; DEBUGF  1, "K : EBP:%x ESI:%x EDI:%x\n", ebp, esi, edi
  1408. ;   in:
  1409. ; ebx -> parameter structure of sysfunc 70
  1410. ; ebp -> exFAT structure
  1411. ; esi -> path string in UTF-8
  1412. ;   out:
  1413. ; eax, ebx = return values for sysfunc 70
  1414.         call    exFAT_lock
  1415.         xor     eax, eax
  1416.         mov     [ebp+exFAT.need_hash], eax ; dword 0
  1417.         mov     [ebp+exFAT.hash_flag], eax ; dword 0
  1418.         mov     [ebp+exFAT.General_Sec_Flags], eax
  1419. ; DEBUGF  1, "K : exFAT_ReadFolder General_Sec_Flags 1 %x\n", eax
  1420.         mov     eax, [ebp+exFAT.ROOT_CLUSTER]
  1421. ; DEBUGF  1, "K : exFAT.ROOT_CLUSTER: %x\n", eax
  1422.         cmp     byte [esi], 0
  1423.         jz      .doit
  1424.        
  1425. ;        push    ebp
  1426. ;        mov     ebp,[esp+12+8+4+4]
  1427. ; DEBUGF  1, "K : exFAT Input FS EBP:%x\n", ebp
  1428. ;        pop     ebp
  1429.  
  1430.         call    exFAT_hd_find_lfn
  1431.  
  1432. ;        push    ebp
  1433. ;        mov     ebp,[esp+12+8+4+4]
  1434. ; DEBUGF  1, "K : exFAT Output FS EBP:%x\n", ebp
  1435. ;        pop     ebp
  1436.  
  1437.         jc      .error
  1438. ;        jmp     .error
  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
  1443.         mov     [ebp+exFAT.hash_flag], eax ; dword 0
  1444.         lea     eax, [ebp+exFAT.file_dir_entry]
  1445.         test    byte [eax+4], 10000b  ; do not allow read files
  1446.         jz      .accessDenied
  1447. ;        mov     eax, [edi+20-2]
  1448. ;        mov     ax, [edi+26]    ; eax=cluster
  1449.         lea     eax, [ebp+exFAT.str_ext_dir_entry]
  1450.         push    eax
  1451.         movzx   eax, byte [eax+1]
  1452.         mov     [ebp+exFAT.General_Sec_Flags], eax
  1453. ; DEBUGF  1, "K : exFAT_ReadFolder General_Sec_Flags 2 %x\n", eax
  1454.         mov     eax, [esp]
  1455.         mov     eax, [eax+8] ; LOW dword of Valid data length - WARNING!!! late rewrite
  1456.         mov     [ebp+exFAT.valid_data_length], eax
  1457.         pop     eax
  1458.         mov     eax, [eax+20]    ; cluster
  1459.         jmp     .doit_1
  1460. .doit:
  1461.         mov     dword [ebp+exFAT.valid_data_length], 0xffffffff ; for ROOT
  1462. .doit_1:
  1463. ; DEBUGF  1, "K : exFAT.valid_data_length %x\n", [ebp+exFAT.valid_data_length]
  1464. ; DEBUGF  1, "K : exFAT_ReadFolder.doit \n"
  1465.         sub     esp, 262*2      ; reserve space for LFN
  1466.         push    dword [ebx+8]   ; cp866/UNICODE name
  1467.         mov     edx, [ebx+16]   ; pointer to buffer
  1468. ; init header
  1469.         push    eax
  1470.         mov     edi, edx
  1471.         mov     ecx, 32/4
  1472.         xor     eax, eax
  1473.         rep stosd
  1474.         pop     eax
  1475.         mov     byte [edx], 1   ; version
  1476. ;        mov     esi, edi        ; esi points to BDFE
  1477.         mov     [ebp+exFAT.points_to_BDFE], edi
  1478. ; DEBUGF  1, "K : exFAT.points_to_BDFE start EDI: %x\n", edi
  1479.         mov     ecx, [ebx+12]   ; number of blocks to read
  1480.         mov     ebx, [ebx+4]    ; index of the first block
  1481. ;------------------------------------------------------------------------------
  1482. ; DEBUGF  1, "K : exFAT_ReadFolder 1 ECX: %x\n", ecx
  1483.         cmp     [ebp+exFAT.valid_data_length], 0xffffffff
  1484.         je      .num_read_blocks
  1485.         inc     dword [edx+8]   ; new file found
  1486.         test    ecx, ecx
  1487.         jz      .num_read_blocks
  1488.         test    ebx, ebx
  1489.         jnz     .dec_offset
  1490. ; DEBUGF  1, "K : exFAT_ReadFolder create .. dir \n"
  1491.         inc     dword [edx+4]   ; new file block copied
  1492.         push    eax esi
  1493.         mov     esi, edi ; [ebp+exFAT.points_to_BDFE]
  1494.         mov     [esi], dword 0x10      ; attributes
  1495.         xor     eax, eax
  1496.         mov     [esi+8], eax    ; creation time
  1497.         mov     [esi+12], dword 0x010101 ; eax   ; creation date
  1498.         mov     [esi+16], eax    ; last access time
  1499.         mov     [esi+20], dword 0x020202 ;eax   ; last access date
  1500.         mov     [esi+24], eax   ; last write time
  1501.         mov     [esi+28], dword 0x010303 ; eax   ; last write date
  1502.         mov     [esi+32], eax   ; file size (low dword)
  1503.         mov     [esi+36], eax   ; file size (high dword)
  1504.         push    ebp
  1505.         lea     ebp, [esp+4+12]
  1506. ; DEBUGF  1, "K : exFAT_ReadFolder 1 ESI: %x EBP: %x\n", esi, ebp
  1507. ; DEBUGF  1, "K : exFAT_ReadFolder old file [EBP-4]: %x [EBP]: %x [EBP+4]: %x [EBP+8]: %x\n", [ebp-4], [ebp], [ebp+4], [ebp+8]
  1508.         mov     eax, [ebp-4]
  1509.         mov     [esi+4], eax    ; cp866/UNICODE name
  1510.         mov     [ebp], dword 0x002e002e ; imitate dir '..'
  1511.         xor     eax, eax
  1512.         mov     [ebp+4], eax
  1513.         call    exFAT_entry_to_bdfe2.copy_path
  1514.         pop     ebp
  1515.         mov     [ebp+exFAT.points_to_BDFE], esi
  1516. ; DEBUGF  1, "K : exFAT_ReadFolder 2 ESI: %x EBP: %x\n", esi, ebp
  1517.         pop     esi eax
  1518.         dec     ecx
  1519.         jmp     .num_read_blocks
  1520. .dec_offset:
  1521.         dec     ebx
  1522. .num_read_blocks:
  1523. ; DEBUGF  1, "K : exFAT_ReadFolder 2 ECX: %x\n", ecx
  1524. ;------------------------------------------------------------------------------
  1525.         lea     esi, [esp+4]    ; buffer for UTF-16 name (space for LFN)
  1526.         mov     [ebp+exFAT.LFN_reserve_place], esi
  1527. ;        push    eax
  1528. ;        dec     eax
  1529. ;        dec     eax
  1530. ;        imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1531. ;        add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1532. ; DEBUGF  1, "K : exFAT ROOT SECTOR: %x\n", eax
  1533. ;        pop     eax
  1534.         mov     [ebp+exFAT.secondary_dir_entry], dword 1
  1535. .new_cluster:
  1536. ; DEBUGF  1, "K : exFAT_ReadFolder.new_cluster \n"
  1537.         mov     [ebp+exFAT.cluster_tmp], eax
  1538.         test    eax, eax
  1539. ;        jz      .notfound
  1540.         jnz     @f
  1541.         jmp     .notfound
  1542. @@:
  1543.         dec     eax
  1544.         dec     eax
  1545.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1546.         push    [ebp+exFAT.SECTORS_PER_CLUSTER]
  1547.         add     eax, [ebp+exFAT.CLUSTER_HEAP_START]
  1548.         push    ebx
  1549. .new_sector:
  1550. ; DEBUGF  1, "K : exFAT_ReadFolder.new_sector \n"
  1551.         lea     ebx, [ebp+exFAT.buffer]
  1552.         mov     edi, ebx
  1553.         push    eax
  1554. ; DEBUGF  1, "K : exFAT fs_read32_sys N1 EAX: %x\n", eax
  1555.         call    fs_read32_sys
  1556.         test    eax, eax
  1557.         pop     eax
  1558.         jnz     .notfound2
  1559.         add     ebx, 512
  1560.         push    eax
  1561. .l1:
  1562. ; DEBUGF  1, "K : exFAT_ReadFolder.l1 \n"
  1563. ;        push    esi
  1564. ;        lea     esi, [esp+20]
  1565. ; DEBUGF  1, "K : exFAT RD need_hash :%x\n", [ebp+exFAT.need_hash]
  1566.         call    exFAT_get_name
  1567. ;        pop     esi
  1568.         jc      .l2
  1569. ;        cmp     byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT
  1570. ;        jnz     .do_bdfe
  1571. ; DEBUGF  1, "K : exFAT_ReadFolder CMP SDE\n"
  1572.         xor     eax, eax
  1573.         cmp     [ebp+exFAT.secondary_dir_entry], eax
  1574.         jz      .do_bdfe
  1575. ;        add     edi, 0x20
  1576. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe EDI: %x  EBX: %x\n", edi, ebx
  1577. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe EDI:%x [EDI]:%x NAME:%s\n", edi, [edi], edi
  1578.         cmp     edi, ebx
  1579.         jb      .do_bdfe
  1580. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe EDI after\n", edi, ebx
  1581.         pop     eax
  1582.         inc     eax
  1583.         dec     dword [esp+4]
  1584.         jnz     @f
  1585.         mov     eax, [ebp+exFAT.cluster_tmp]
  1586.         test    eax, eax
  1587.         jz      .done
  1588. ; Check - General Secondary Flags
  1589. ; Bit 0 : Allocation possible
  1590. ;         0 – No cluster allocated; 1 – cluster allocation is possible
  1591. ; Bit 1 : No FAT chain
  1592. ;         0 – Yes ; The clusters of this file/directory are NOT contiguous
  1593. ;         1 – No; The Contiguous Cluster are allocated to this file/directory;
  1594. ;         This improves the File read performance
  1595. ; Bits 2 – 7 : Reserved
  1596.         test    byte [ebp+exFAT.General_Sec_Flags], 10b
  1597.         jz      .get_FAT_1
  1598.         inc     eax
  1599.         jmp     .continue_1
  1600. .get_FAT_1:
  1601. ; DEBUGF  1, "K : exFAT_ReadFolder N1 exFAT_get_FAT Input EAX: %x\n", eax
  1602.         call    exFAT_get_FAT
  1603. ; DEBUGF  1, "K : exFAT_ReadFolder N1 exFAT_get_FAT Output EAX: %x\n", eax
  1604.         jc      .notfound2
  1605.         cmp     eax, 2
  1606.         jb      .done
  1607. .continue_1:
  1608. ; DEBUGF  1, "K : exFAT_ReadFolder.continue_1\n"
  1609.         cmp     eax, [ebp+exFAT.fatRESERVED]
  1610.         jae     .done
  1611.         push    eax
  1612.         mov     eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1613.         mov     [esp+8], eax
  1614.         pop     eax
  1615.         mov     [ebp+exFAT.cluster_tmp], eax
  1616.         dec     eax
  1617.         dec     eax
  1618.         imul    eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1619.         add     eax, [ebp+exFAT.DATA_START]
  1620. @@:
  1621. ; DEBUGF  1, "K : exFAT_ReadFolder.@@ \n"
  1622.         lea     ebx, [ebp+exFAT.buffer]
  1623.         mov     edi, ebx
  1624.         push    eax
  1625. ; DEBUGF  1, "K : exFAT fs_read32_sys N2 EAX: %x\n", eax
  1626.         call    fs_read32_sys
  1627.         test    eax, eax
  1628.         pop     eax
  1629.         jnz     .notfound2
  1630.         add     ebx, 512
  1631.         push    eax
  1632. .do_bdfe:
  1633. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe \n"
  1634.         inc     dword [edx+8]   ; new file found
  1635.         dec     dword [esp+4]
  1636.         jns     .l2
  1637. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe ECX: %x\n", ecx
  1638.         dec     ecx
  1639.         js      .l2
  1640. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe 2 \n"
  1641.         inc     dword [edx+4]   ; new file block copied
  1642.         push    esi edi
  1643.         mov     esi, [ebp+exFAT.points_to_BDFE]
  1644.         lea     edi, [ebp+exFAT.file_dir_entry]
  1645.         push    ebp
  1646.         lea     ebp, [esp+20+4+4]
  1647. ; DEBUGF  1, "K : exFAT_ReadFolder ESI: %x EBP: %x\n", esi, ebp
  1648. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe EDI:%x [EDI]:%x ESI:%x [ESI]:%x EBP:%x NAME:%s\n",  edi, [edi], esi, [esi], ebp, ebp
  1649.         call    exFAT_entry_to_bdfe
  1650.         pop     ebp
  1651.         mov     [ebp+exFAT.points_to_BDFE], esi
  1652.         pop     edi esi
  1653. .l2:
  1654. ; DEBUGF  1, "K : exFAT_ReadFolder.l2 \n"
  1655.         add     edi, 0x20
  1656. ; DEBUGF  1, "K : exFAT_ReadFolder.do_bdfe EDI: %x  EBX: %x\n", edi, ebx
  1657.         cmp     edi, ebx
  1658.         jb      .l1
  1659.         pop     eax
  1660.         inc     eax
  1661.         dec     dword [esp+4]
  1662.         jnz     .new_sector
  1663.         mov     eax, [ebp+exFAT.cluster_tmp]
  1664.         test    eax, eax
  1665.         jz      .done
  1666.  
  1667.         push    eax
  1668.         mov     eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1669.         shl     eax, 9
  1670.         sub     [ebp+exFAT.valid_data_length], eax
  1671.         pop     eax
  1672.         jbe     .done
  1673. ; Check - General Secondary Flags
  1674. ; Bit 0 : Allocation possible
  1675. ;         0 – No cluster allocated; 1 – cluster allocation is possible
  1676. ; Bit 1 : No FAT chain
  1677. ;         0 – Yes ; The clusters of this file/directory are NOT contiguous
  1678. ;         1 – No; The Contiguous Cluster are allocated to this file/directory;
  1679. ;         This improves the File read performance
  1680. ; Bits 2 – 7 : Reserved
  1681.         test    byte [ebp+exFAT.General_Sec_Flags], 10b
  1682.         jz      .get_FAT
  1683.         inc     eax
  1684.         jmp     .continue
  1685. .get_FAT:
  1686. ; DEBUGF  1, "K : exFAT_ReadFolder N2 exFAT_get_FAT Input EAX: %x\n", eax
  1687.         call    exFAT_get_FAT
  1688. ; DEBUGF  1, "K : exFAT_ReadFolder N2 exFAT_get_FAT Output EAX: %x\n", eax
  1689.         jc      .notfound2
  1690.         cmp     eax, 2
  1691.         jb      .done
  1692. .continue:
  1693. ; DEBUGF  1, "K : exFAT_ReadFolder.continue \n"
  1694.         cmp     eax, [ebp+exFAT.fatRESERVED]
  1695.         jae     .done
  1696. ; DEBUGF  1, "K : exFAT_ReadFolder.continue after\n"
  1697.         push    eax
  1698.         mov     eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1699.         mov     [esp+8], eax
  1700.         pop     eax
  1701.         pop     ebx
  1702.         add     esp, 4
  1703.         jmp     .new_cluster
  1704. ;------------------------------------------------------------------------------
  1705. .notfound2:
  1706. ; DEBUGF  1, "K : exFAT_ReadFolder.notfound2 \n"
  1707.         add     esp, 8
  1708. .notfound:
  1709. ; DEBUGF  1, "K : exFAT_ReadFolder.notfound \n"
  1710.         add     esp, 262*2+4
  1711. ; DEBUGF  1, "K : exFAT_ReadFolder.ERROR_DEVICE \n"
  1712.         push    ERROR_DEVICE
  1713.         jmp     @f
  1714. ;------------------------------------------------------------------------------
  1715. .done:
  1716. ; DEBUGF  1, "K : exFAT_ReadFolder.done \n"
  1717. ; DEBUGF  1, "K : exFAT_ReadFolder TotalBloks: %x\n", [edx+8]
  1718. ; DEBUGF  1, "K : exFAT_ReadFolder Read Bloks: %x\n", [edx+4]
  1719.         add     esp, 262*2+12
  1720.         pushd   0
  1721. ; DEBUGF  1, "K : exFAT_ReadFolder.done ECX: %x\n", ecx
  1722.         dec     ecx
  1723.         js      @f
  1724. ; DEBUGF  1, "K : exFAT_ReadFolder.ERROR_END_OF_FILE \n"
  1725.         mov     byte [esp], ERROR_END_OF_FILE
  1726. @@:
  1727.         mov     ebx, [edx+4]
  1728. ;------------------------------------------------------------------------------
  1729. .ret:
  1730. ; DEBUGF  1, "K : exFAT_ReadFolder.ret \n"
  1731. ; DEBUGF  1, "K : exFAT_ReadFile Return ESI:%x\n", esi
  1732.         call    exFAT_unlock
  1733.         pop     eax
  1734. ; DEBUGF  1, "K : exFAT_ReadFile Return EBX:%x\n", ebx
  1735. ;        mov     esi, [ebp+exFAT.LFN_reserve_place]
  1736. ;        push    eax
  1737. ;        pushfd
  1738. ;        pop     eax
  1739. ; DEBUGF  1, "K : eFlags:%x\n",eax
  1740. ;        pop     eax
  1741. ; DEBUGF  1, "K : EAX:%x EBX:%x ECX:%x EDX:%x\n", eax, ebx, ecx, edx
  1742. ; DEBUGF  1, "K : EBP:%x ESI:%x EDI:%x\n", ebp, esi, edi
  1743.         ret
  1744. ;------------------------------------------------------------------------------
  1745. .error:
  1746. ; DEBUGF  1, "K : exFAT_ReadFolder.error \n"
  1747.         push    eax
  1748.         xor     ebx, ebx
  1749.         jmp     .ret
  1750. ;------------------------------------------------------------------------------
  1751. .accessDenied:
  1752. ; DEBUGF  1, "K : exFAT_ReadFolder.ERROR_ACCESS_DENIED \n"
  1753.         push    ERROR_ACCESS_DENIED
  1754.         xor     ebx, ebx
  1755.         jmp     .ret
  1756. ;------------------------------------------------------------------------------
  1757. exFAT_GetFileInfo:
  1758. ; DEBUGF  1, "K : exFAT_GetFileInfo \n"
  1759. ; DEBUGF  1, "K : exFAT F70 +00: %x\n", [ebx]
  1760. ; DEBUGF  1, "K : exFAT F70 +04: %x\n", [ebx+4]
  1761. ; DEBUGF  1, "K : exFAT F70 +08: %x\n", [ebx+8]
  1762. ; DEBUGF  1, "K : exFAT F70 +12: %x\n", [ebx+12]
  1763. ; DEBUGF  1, "K : exFAT F70 +16: %x\n", [ebx+16]
  1764. ; DEBUGF  1, "K : exFAT F70 +20: %x\n", [ebx+20]
  1765. ; DEBUGF  1, "K : exFAT Path: %s\n", esi
  1766.         cmp     byte [esi], 0
  1767.         jz      .volume
  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
  1772.         call    exFAT_hd_find_lfn
  1773.         jc      @f
  1774.         lea     edi, [ebp+exFAT.file_dir_entry]
  1775.         push    ebp
  1776.         xor     ebp, ebp
  1777.         mov     esi, [ebx+16]
  1778.         mov     dword [esi+4], ebp
  1779.         call    exFAT_entry_to_bdfe2
  1780.         pop     ebp
  1781.         xor     eax, eax
  1782. @@:
  1783.         push    eax
  1784.         call    exFAT_unlock
  1785.         pop     eax
  1786. @@:
  1787.         ret
  1788.  
  1789. .volume:
  1790. ; DEBUGF  1, "K : exFAT_GetFileInfo.volume \n"
  1791.         mov     eax, dword[ebp+exFAT.Length]
  1792.         mov     edx, dword[ebp+exFAT.Length+4]
  1793.         mov     edi, [ebx+16]
  1794.         shld    edx, eax, 9
  1795.         shl     eax, 9
  1796.         mov     [edi+36], edx
  1797.         mov     [edi+32], eax
  1798.         mov     eax, [ebx+8]
  1799.         mov     byte [edi], 8
  1800.         mov     [edi+4], eax
  1801.         test    eax, eax
  1802.         jz      @b
  1803.         lea     esi, [ebp+exFAT.volumeLabel]
  1804.         mov     ecx, 11
  1805. @@:
  1806.         mov     byte [esi+ecx], 0
  1807.         dec     ecx
  1808.         jz      @f
  1809.         cmp     byte [esi+ecx], ' '
  1810.         jz      @b
  1811. @@:
  1812.         mov     cl, 12
  1813.         add     edi, 40
  1814.         cmp     eax, 2
  1815.         jz      @f
  1816.         rep movsb
  1817.         xor     eax, eax
  1818.         ret
  1819.  
  1820. @@:
  1821.         lodsb
  1822.         stosw
  1823.         loop    @b
  1824.         ret
  1825. ;------------------------------------------------------------------------------
  1826. exFAT_notroot_next:
  1827. ; DEBUGF  1, "K : exFAT_notroot_next\n"
  1828.         push    ecx
  1829.         lea     ecx, [ebp+exFAT.buffer+0x200-0x20]
  1830.         cmp     edi, ecx
  1831.         jae     exFAT_notroot_next_sector
  1832.         add     edi, 0x20
  1833. @@:
  1834. ; DEBUGF  1, "K : exFAT_notroot_next.ret\n"
  1835.         pop     ecx
  1836.         ret
  1837.  
  1838. ;exFAT_notroot_next_write:
  1839. ;        push    ecx
  1840. ;        lea     ecx, [ebp+exFAT.buffer+0x200]
  1841. ;        cmp     edi, ecx
  1842. ;        jc      @b
  1843. ;        push    eax
  1844. ;        call    exFAT_notroot_end_write
  1845. ;        pop     eax
  1846. exFAT_notroot_next_sector:
  1847. ; DEBUGF  1, "K : exFAT_notroot_next_sector\n"
  1848.         push    [ebp+exFAT.longname_sec2]
  1849.         pop     [ebp+exFAT.longname_sec1]
  1850.         push    eax
  1851. ; DEBUGF  1, "K : exFAT_notroot_next.exFAT_get_sector In EAX:%x\n", eax
  1852.         call    exFAT_get_sector
  1853. ; DEBUGF  1, "K : exFAT_notroot_next.exFAT_get_sector Out EAX:%x\n", eax
  1854.         mov     [ebp+exFAT.longname_sec2], eax
  1855.         pop     eax
  1856.         mov     ecx, [eax+4]
  1857.         inc     ecx
  1858.         cmp     ecx, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1859.         jae     exFAT_notroot_next_cluster
  1860.         mov     [eax+4], ecx
  1861.         jmp     @f
  1862.  
  1863. exFAT_notroot_next_err:
  1864. ; DEBUGF  1, "K : exFAT_notroot_next_err\n"
  1865. ;        dec     ecx
  1866.         pop     ecx
  1867. ;        js      .1
  1868.         movi    eax, ERROR_FILE_NOT_FOUND
  1869. ;.1:
  1870.         stc
  1871.         ret
  1872.  
  1873. exFAT_notroot_next_cluster:
  1874. ; DEBUGF  1, "K : exFAT_notroot_next_cluster\n"
  1875.         push    eax
  1876.         mov     eax, [eax]
  1877.  
  1878. ;        push    edi
  1879. ;        lea     edi, [ebp+exFAT.str_ext_dir_entry]
  1880. ; Check - General Secondary Flags
  1881. ; Bit 0 : Allocation possible
  1882. ;         0 – No cluster allocated; 1 – cluster allocation is possible
  1883. ; Bit 1 : No FAT chain
  1884. ;         0 – Yes ; The clusters of this file/directory are NOT contiguous
  1885. ;         1 – No; The Contiguous Cluster are allocated to this file/directory;
  1886. ;         This improves the File read performance
  1887. ; Bits 2 – 7 : Reserved
  1888. ;        push    eax
  1889. ;        movzx   eax, byte [edi+1]
  1890. ; DEBUGF  1, "K : exFAT_notroot_next_cluster GSF 1:%x\n", eax
  1891. ;        movzx   eax, byte [ebp+exFAT.General_Sec_Flags]
  1892. ; DEBUGF  1, "K : exFAT_notroot_next_cluster GSF 2:%x\n", eax
  1893. ;        pop     eax
  1894. ;        test    byte [edi+1], 10b ;11b
  1895. ;        pop     edi
  1896.         test    byte [ebp+exFAT.General_Sec_Flags], 10b
  1897.         jz      .get_FAT
  1898.         inc     eax
  1899.         jmp     .continue
  1900. .get_FAT:
  1901.         call    exFAT_get_FAT
  1902. .continue:
  1903.         mov     ecx, eax
  1904.         pop     eax
  1905.         jc      exFAT_notroot_first.deverr
  1906.         cmp     ecx, 2
  1907.         jb      exFAT_notroot_next_err
  1908.         cmp     ecx, [ebp+exFAT.fatRESERVED]
  1909.         jae     exFAT_notroot_next_err
  1910.         mov     [eax], ecx
  1911.         and     dword [eax+4], 0
  1912. @@:
  1913.         pop     ecx
  1914. exFAT_notroot_first:
  1915. ; DEBUGF  1, "K : exFAT_notroot_first\n"
  1916. ; DEBUGF  1, "K : exFAT_notroot_first.exFAT_get_sector In EAX:%x\n", eax
  1917.         call    exFAT_get_sector
  1918. ; DEBUGF  1, "K : exFAT_notroot_first.exFAT_get_sector Out EAX:%x\n", eax
  1919.         push    ebx
  1920.         lea     edi, [ebp+exFAT.buffer]
  1921.         mov     ebx, edi
  1922.         sub     [ebp+exFAT.valid_data_length], 512
  1923.         call    fs_read32_sys
  1924.         pop     ebx
  1925.         test    eax, eax
  1926.         jz      .ret ; CF=0
  1927.         push    ecx
  1928. .deverr:
  1929. ; DEBUGF  1, "K : exFAT_notroot_first.deverr\n"
  1930.         pop     ecx
  1931.         mov     eax, ERROR_DEVICE
  1932.         stc
  1933. .ret:
  1934. ; DEBUGF  1, "K : exFAT_notroot_first.ret\n"
  1935.         ret
  1936.  
  1937. ;fat_notroot_begin_write:
  1938. ;        push    eax edi
  1939. ;        call    fat_notroot_first
  1940. ;        pop     edi eax
  1941. ;        ret
  1942.  
  1943. ;fat_notroot_end_write:
  1944. ;        call    fat_get_sector
  1945. ;        push    ebx
  1946. ;        lea     ebx, [ebp+FAT.buffer]
  1947. ;        call    fs_write32_sys
  1948. ;        pop     ebx
  1949. ;        ret
  1950. ;--------------------------------------
  1951. exFAT_get_sector:
  1952. ; DEBUGF  1, "K : exFAT_get_sector\n"
  1953.         push    ecx
  1954.         mov     ecx, [eax]
  1955. ; DEBUGF  1, "K : exFAT_get_sector In [EAX]:%x [EAX+4]:%x\n", ecx, [eax+4]
  1956.         dec     ecx
  1957.         dec     ecx
  1958.         imul    ecx, [ebp+exFAT.SECTORS_PER_CLUSTER]
  1959. ;        add     ecx, [ebp+exFAT.DATA_START]
  1960.         add     ecx, [ebp+exFAT.CLUSTER_HEAP_START]
  1961.         add     ecx, [eax+4]
  1962.         mov     eax, ecx
  1963.         pop     ecx
  1964.         ret
  1965. ;------------------------------------------------------------------------------