Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 5994 $
  9.  
  10. ERROR_SUCCESS        = 0
  11. ERROR_DISK_BASE      = 1
  12. ERROR_UNSUPPORTED_FS = 2
  13. ERROR_UNKNOWN_FS     = 3
  14. ERROR_PARTITION      = 4
  15. ERROR_FILE_NOT_FOUND = 5
  16. ERROR_END_OF_FILE    = 6
  17. ERROR_MEMORY_POINTER = 7
  18. ERROR_DISK_FULL      = 8
  19. ERROR_FAT_TABLE      = 9 ;deprecated
  20. ERROR_FS_FAIL        = 9
  21. ERROR_ACCESS_DENIED  = 10
  22. ERROR_DEVICE         = 11
  23. ERROR_OUT_OF_MEMORY  = 12
  24.  
  25. image_of_eax EQU esp+32
  26. image_of_ebx EQU esp+20
  27.  
  28. ; System function 70 - files with long names (LFN)
  29. ; diamond, 2006
  30.  
  31. iglobal
  32. ; in this table names must be in lowercase
  33. rootdirs:
  34. ;**********************************************
  35.         db      3,'cd0'
  36.         dd      fs_OnCd0
  37.         dd      fs_NextCd
  38.         db      3,'cd1'
  39.         dd      fs_OnCd1
  40.         dd      fs_NextCd
  41.         db      3,'cd2'
  42.         dd      fs_OnCd2
  43.         dd      fs_NextCd
  44.         db      3,'cd3'
  45.         dd      fs_OnCd3
  46.         dd      fs_NextCd
  47.         db      3,'cd4'
  48.         dd      fs_OnCd4
  49.         dd      fs_NextCd
  50.         db      3,'cd5'
  51.         dd      fs_OnCd5
  52.         dd      fs_NextCd
  53.         db      3,'cd6'
  54.         dd      fs_OnCd6
  55.         dd      fs_NextCd
  56.         db      3,'cd7'
  57.         dd      fs_OnCd7
  58.         dd      fs_NextCd
  59.         db      3,'cd8'
  60.         dd      fs_OnCd8
  61.         dd      fs_NextCd
  62.         db      3,'cd9'
  63.         dd      fs_OnCd9
  64.         dd      fs_NextCd
  65.         db      4,'cd10'
  66.         dd      fs_OnCd10
  67.         dd      fs_NextCd
  68.         db      4,'cd11'
  69.         dd      fs_OnCd11
  70.         dd      fs_NextCd
  71. ;***********************************************
  72.         db      0
  73.  
  74.  
  75. virtual_root_query:
  76. ;**********************************************
  77.         dd      fs_HasCd0
  78.         db      'cd0',0
  79.         dd      fs_HasCd1
  80.         db      'cd1',0
  81.         dd      fs_HasCd2
  82.         db      'cd2',0
  83.         dd      fs_HasCd3
  84.         db      'cd3',0
  85.         dd      fs_HasCd4
  86.         db      'cd4',0
  87.         dd      fs_HasCd5
  88.         db      'cd5',0
  89.         dd      fs_HasCd6
  90.         db      'cd6',0
  91.         dd      fs_HasCd7
  92.         db      'cd7',0
  93.         dd      fs_HasCd8
  94.         db      'cd8',0
  95.         dd      fs_HasCd9
  96.         db      'cd9',0
  97.         dd      fs_HasCd10
  98.         db      'cd10',0
  99.         dd      fs_HasCd11
  100.         db      'cd11',0
  101. ;**********************************************
  102.         dd      0
  103. endg
  104.  
  105. file_system_lfn_protected:
  106.         pushad
  107.         call    protect_from_terminate
  108.         call    file_system_lfn
  109.         call    unprotect_from_terminate
  110.         popad
  111.         mov     [image_of_eax], eax
  112.         mov     [image_of_ebx], ebx
  113.         ret
  114.  
  115. file_system_lfn:
  116. ; in: ebx->fileinfo block
  117. ; operation codes:
  118. ; 0 : read file
  119. ; 1 : read folder
  120. ; 2 : create/rewrite file
  121. ; 3 : write/append to file
  122. ; 4 : set end of file
  123. ; 5 : get file/directory attributes structure
  124. ; 6 : set file/directory attributes structure
  125. ; 7 : start application
  126. ; 8 : delete file
  127. ; 9 : create directory
  128.  
  129. ; parse file name
  130.         lea     esi, [ebx+20]
  131.         lodsb
  132.         test    al, al
  133.         jnz     @f
  134.         mov     esi, [esi]
  135.         lodsb
  136. @@:
  137.         cmp     al, '/'
  138.         jz      .notcurdir
  139.         dec     esi
  140.         mov     ebp, esi
  141.         test    al, al
  142.         jnz     @f
  143.         xor     ebp, ebp
  144. @@:
  145.         mov     esi, [current_slot]
  146.         mov     esi, [esi+APPDATA.cur_dir]
  147.         jmp     .parse_normal
  148. .notcurdir:
  149.         cmp     byte [esi], 0
  150.         jz      .rootdir
  151.         call    process_replace_file_name
  152. .parse_normal:
  153.         cmp     dword [ebx], 7
  154.         jne     @F
  155.         mov     edx, [ebx+4]
  156.         mov     ebx, [ebx+8]
  157.         call    fs_execute; esi+ebp, ebx, edx
  158.         mov     [image_of_eax], eax
  159.         ret
  160. @@:
  161.         mov     edi, rootdirs-8
  162.         xor     ecx, ecx
  163.         push    esi
  164. .scan1:
  165.         pop     esi
  166.         add     edi, ecx
  167.         scasd
  168.         scasd
  169.         mov     cl, byte [edi]
  170.         test    cl, cl
  171.         jz      .notfound_try
  172.         inc     edi
  173.         push    esi
  174. @@:
  175.         lodsb
  176.         or      al, 20h
  177.         scasb
  178.         loopz   @b
  179.         jnz     .scan1
  180.         lodsb
  181.         cmp     al, '/'
  182.         jz      .found1
  183.         test    al, al
  184.         jnz     .scan1
  185.         pop     eax
  186. ; directory /xxx
  187. .maindir:
  188.         mov     esi, [edi+4]
  189. .maindir_noesi:
  190.         cmp     dword [ebx], 1
  191.         jnz     .access_denied
  192.         xor     eax, eax
  193.         mov     ebp, [ebx+12] ;the number of blocks to read
  194.         mov     edx, [ebx+16] ;where to write the result
  195.     ;    add     edx, std_application_base_address
  196.         push    dword [ebx+4]   ; first block
  197.         mov     ebx, [ebx+8]    ; flags
  198. ; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
  199.         mov     edi, edx
  200.         push    ecx
  201.         mov     ecx, 32/4
  202.         rep stosd
  203.         pop     ecx
  204.         mov     byte [edx], 1   ; version
  205. .maindir_loop:
  206.         call    esi
  207.         jc      .maindir_done
  208.         inc     dword [edx+8]
  209.         dec     dword [esp]
  210.         jns     .maindir_loop
  211.         dec     ebp
  212.         js      .maindir_loop
  213.         inc     dword [edx+4]
  214.         mov     dword [edi], 0x10       ; attributes: folder
  215.         mov     dword [edi+4], 1        ; name type: UNICODE
  216.         push    eax
  217.         xor     eax, eax
  218.         add     edi, 8
  219.         push    ecx
  220.         mov     ecx, 40/4-2
  221.         rep stosd
  222.         pop     ecx
  223.         pop     eax
  224.         push    eax edx
  225. ; convert number in eax to decimal UNICODE string
  226.         push    edi
  227.         push    ecx
  228.         push    -'0'
  229.         mov     ecx, 10
  230. @@:
  231.         xor     edx, edx
  232.         div     ecx
  233.         push    edx
  234.         test    eax, eax
  235.         jnz     @b
  236. @@:
  237.         pop     eax
  238.         add     al, '0'
  239.         stosb
  240.         test    bl, 1           ; UNICODE name?
  241.         jz      .ansi2
  242.         mov     byte [edi], 0
  243.         inc     edi
  244. .ansi2:
  245.         test    al, al
  246.         jnz     @b
  247.         mov     byte [edi-1], 0
  248.         pop     ecx
  249.         pop     edi
  250. ; UNICODE name length is 520 bytes, ANSI - 264
  251.         add     edi, 520
  252.         test    bl, 1
  253.         jnz     @f
  254.         sub     edi, 520-264
  255. @@:
  256.         pop     edx eax
  257.         jmp     .maindir_loop
  258. .maindir_done:
  259.         pop     eax
  260.         mov     ebx, [edx+4]
  261.         xor     eax, eax
  262.         dec     ebp
  263.         js      @f
  264.         mov     al, ERROR_END_OF_FILE
  265. @@:
  266.         mov     [image_of_eax], eax
  267.         mov     [image_of_ebx], ebx
  268.         ret
  269. ; directory /
  270. .rootdir:
  271.         cmp     dword [ebx], 1  ; read folder?
  272.         jz      .readroot
  273. .access_denied:
  274.         mov     dword [image_of_eax], 10      ; access denied
  275.         ret
  276.  
  277. .readroot:
  278. ; virtual root folder - special handler
  279.         mov     ebp, [ebx+12]
  280.         mov     edx, [ebx+16]
  281.     ;    add     edx, std_application_base_address
  282.         push    dword [ebx+4]   ; first block
  283.         mov     ebx, [ebx+8]    ; flags
  284.         xor     eax, eax
  285. ; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
  286.         mov     edi, edx
  287.         mov     ecx, 32/4
  288.         rep stosd
  289.         mov     byte [edx], 1   ; version
  290.         sub     esp, 16
  291. .readroot_ah_loop2:
  292.         push    edi
  293.         lea     edi, [esp+4]
  294.         call    dyndisk_enum_root
  295.         pop     edi
  296.         test    eax, eax
  297.         jz      .readroot_done_dynamic
  298.         inc     dword [edx+8]
  299.         dec     dword [esp+16]
  300.         jns     .readroot_ah_loop2
  301.         dec     ebp
  302.         js      .readroot_ah_loop2
  303.         push    eax
  304.         xor     eax, eax
  305.         inc     dword [edx+4]
  306.         mov     dword [edi], 0x10       ; attributes: folder
  307.         mov     dword [edi+4], ebx
  308.         add     edi, 8
  309.         mov     ecx, 40/4-2
  310.         rep stosd
  311.         push    esi edi
  312.         lea     esi, [esp+12]
  313. @@:
  314.         lodsb
  315.         stosb
  316.         test    bl, 1
  317.         jz      .ansi3
  318.         mov     byte [edi], 0
  319.         inc     edi
  320. .ansi3:
  321.         test    al, al
  322.         jnz     @b
  323.         pop     edi esi eax
  324.         add     edi, 520
  325.         test    bl, 1
  326.         jnz     .readroot_ah_loop2
  327.         sub     edi, 520-264
  328.         jmp     .readroot_ah_loop2
  329. .readroot_done_dynamic:
  330.         add     esp, 16
  331.         mov     esi, virtual_root_query
  332. .readroot_loop:
  333.         cmp     dword [esi], eax
  334.         jz      .readroot_done
  335.         call    dword [esi]
  336.         add     esi, 4
  337.         test    eax, eax
  338.         jnz     @f
  339. .readroot_next:
  340.         or      ecx, -1
  341.         xchg    esi, edi
  342.         repnz scasb
  343.         xchg    esi, edi
  344.         jmp     .readroot_loop
  345. @@:
  346.         xor     eax, eax
  347.         inc     dword [edx+8]
  348.         dec     dword [esp]
  349.         jns     .readroot_next
  350.         dec     ebp
  351.         js      .readroot_next
  352.         inc     dword [edx+4]
  353.         mov     dword [edi], 0x10       ; attributes: folder
  354.         mov     dword [edi+4], ebx      ; name type: UNICODE
  355.         add     edi, 8
  356.         mov     ecx, 40/4-2
  357.         rep stosd
  358.         push    edi
  359. @@:
  360.         lodsb
  361.         stosb
  362.         test    bl, 1
  363.         jz      .ansi
  364.         mov     byte [edi], 0
  365.         inc     edi
  366. .ansi:
  367.         test    eax, eax
  368.         jnz     @b
  369.         pop     edi
  370.         add     edi, 520
  371.         test    bl, 1
  372.         jnz     .readroot_loop
  373.         sub     edi, 520-264
  374.         jmp     .readroot_loop
  375. .readroot_done:
  376.         pop     eax
  377.         mov     ebx, [edx+4]
  378.         xor     eax, eax
  379.         dec     ebp
  380.         js      @f
  381.         mov     al, ERROR_END_OF_FILE
  382. @@:
  383.         mov     [image_of_eax], eax
  384.         mov     [image_of_ebx], ebx
  385.         ret
  386. .notfound_try:
  387.         call    dyndisk_handler
  388. .notfound:
  389.         mov     dword [image_of_eax], ERROR_FILE_NOT_FOUND
  390.         and     dword [image_of_ebx], 0
  391.         ret
  392.  
  393. .notfounda:
  394.         cmp     edi, esp
  395.         jnz     .notfound
  396.         call    dword [edi+4]
  397.         add     esp, 16
  398.         jmp     .notfound
  399.  
  400. .found1:
  401.         pop     eax
  402.         cmp     byte [esi], 0
  403.         jz      .maindir
  404. .found2:
  405. ; read partition number
  406.         xor     ecx, ecx
  407.         xor     eax, eax
  408. @@:
  409.         lodsb
  410.         cmp     al, '/'
  411.         jz      .done1
  412.         test    al, al
  413.         jz      .done1
  414.         sub     al, '0'
  415.         cmp     al, 9
  416.         ja      .notfounda
  417.         lea     ecx, [ecx*5]
  418.         lea     ecx, [ecx*2+eax]
  419.         jmp     @b
  420. .done1:
  421.         jecxz   .notfounda
  422.         test    al, al
  423.         jnz     @f
  424.         dec     esi
  425. @@:
  426.         cmp     byte [esi], 0
  427.         jnz     @f
  428.         test    ebp, ebp
  429.         jz      @f
  430.         mov     esi, ebp
  431.         xor     ebp, ebp
  432. @@:
  433. ; now [edi] contains handler address, ecx - partition number,
  434. ; esi points to ASCIIZ string - rest of name
  435.         jmp     dword [edi]
  436.  
  437. ; handlers for devices
  438. ; in: ecx = 0 => query virtual directory /xxx
  439. ; in: ecx = partition number
  440. ;     esi -> relative (for device) name
  441. ;     ebx -> fileinfo
  442. ;     ebp = 0 or pointer to rest of name from folder addressed by esi
  443. ; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
  444.  
  445. fs_NotImplemented:
  446.         mov     eax, 2
  447.         ret
  448. ;-----------------------------------------------------------------------------
  449. fs_OnCd0:
  450.         call    reserve_cd
  451.         mov     [ChannelNumber], 1
  452.         mov     [DiskNumber], 0
  453.         push    6
  454.         push    1
  455.         jmp     fs_OnCd
  456. ;-----------------------------------------------------------------------------
  457. fs_OnCd1:
  458.         call    reserve_cd
  459.         mov     [ChannelNumber], 1
  460.         mov     [DiskNumber], 1
  461.         push    4
  462.         push    2
  463.         jmp     fs_OnCd
  464. ;-----------------------------------------------------------------------------
  465. fs_OnCd2:
  466.         call    reserve_cd
  467.         mov     [ChannelNumber], 2
  468.         mov     [DiskNumber], 0
  469.         push    2
  470.         push    3
  471.         jmp     fs_OnCd
  472. ;-----------------------------------------------------------------------------
  473. fs_OnCd3:
  474.         call    reserve_cd
  475.         mov     [ChannelNumber], 2
  476.         mov     [DiskNumber], 1
  477.         push    0
  478.         push    4
  479.         jmp     fs_OnCd
  480. ;-----------------------------------------------------------------------------
  481. fs_OnCd4:
  482.         call    reserve_cd
  483.         mov     [ChannelNumber], 1
  484.         mov     [DiskNumber], 0
  485.         push    6
  486.         push    5
  487.         jmp     fs_OnCd
  488. ;-----------------------------------------------------------------------------
  489. fs_OnCd5:
  490.         call    reserve_cd
  491.         mov     [ChannelNumber], 1
  492.         mov     [DiskNumber], 1
  493.         push    4
  494.         push    6
  495.         jmp     fs_OnCd
  496. ;-----------------------------------------------------------------------------
  497. fs_OnCd6:
  498.         call    reserve_cd
  499.         mov     [ChannelNumber], 2
  500.         mov     [DiskNumber], 0
  501.         push    2
  502.         push    7
  503.         jmp     fs_OnCd
  504. ;-----------------------------------------------------------------------------
  505. fs_OnCd7:
  506.         call    reserve_cd
  507.         mov     [ChannelNumber], 2
  508.         mov     [DiskNumber], 1
  509.         push    0
  510.         push    8
  511.         jmp     fs_OnCd
  512. ;-----------------------------------------------------------------------------
  513. fs_OnCd8:
  514.         call    reserve_cd
  515.         mov     [ChannelNumber], 1
  516.         mov     [DiskNumber], 0
  517.         push    6
  518.         push    9
  519.         jmp     fs_OnCd
  520. ;-----------------------------------------------------------------------------
  521. fs_OnCd9:
  522.         call    reserve_cd
  523.         mov     [ChannelNumber], 1
  524.         mov     [DiskNumber], 1
  525.         push    4
  526.         push    10
  527.         jmp     fs_OnCd
  528. ;-----------------------------------------------------------------------------
  529. fs_OnCd10:
  530.         call    reserve_cd
  531.         mov     [ChannelNumber], 2
  532.         mov     [DiskNumber], 0
  533.         push    2
  534.         push    11
  535.         jmp     fs_OnCd
  536. ;-----------------------------------------------------------------------------
  537. fs_OnCd11:
  538.         call    reserve_cd
  539.         mov     [ChannelNumber], 2
  540.         mov     [DiskNumber], 1
  541.         push    0
  542.         push    12
  543. ;-----------------------------------------------------------------------------
  544. fs_OnCd:
  545.         pop     eax
  546.         mov     [cdpos], eax
  547.         call    reserve_cd_channel
  548.         pop     eax
  549.         cmp     ecx, 0x100
  550.         jae     .nf
  551.         push    ecx ebx
  552.         mov     cl, al
  553.  
  554.         push    eax
  555.         mov     eax, [cdpos]
  556.         dec     eax
  557.         shr     eax, 2
  558.         lea     eax, [eax*5]
  559.         mov     bl, [eax+DRIVE_DATA+1]
  560.         pop     eax
  561.  
  562.         shr     bl, cl
  563.         test    bl, 2
  564.         pop     ebx ecx
  565.  
  566.         jnz     @f
  567. .nf:
  568.         call    free_cd_channel
  569.         and     [cd_status], 0
  570.         mov     dword [image_of_eax], 5       ; not found
  571.         ret
  572. @@:
  573.         mov     ecx, [ebx+12]
  574.         mov     edx, [ebx+16]
  575.     ;    add     edx, std_application_base_address
  576.         mov     eax, [ebx]
  577.         cmp     eax, fs_NumCdServices
  578.         jae     .not_impl
  579.         add     ebx, 4
  580.         call    dword [fs_CdServices + eax*4]
  581.         call    free_cd_channel
  582.         and     [cd_status], 0
  583.         mov     [image_of_eax], eax
  584.         mov     [image_of_ebx], ebx
  585.         ret
  586. .not_impl:
  587.         call    free_cd_channel
  588.         and     [cd_status], 0
  589.         mov     dword [image_of_eax], 2       ; not implemented
  590.         ret
  591. ;-----------------------------------------------------------------------------
  592. fs_CdServices:
  593.         dd      fs_CdRead
  594.         dd      fs_CdReadFolder
  595.         dd      fs_NotImplemented
  596.         dd      fs_NotImplemented
  597.         dd      fs_NotImplemented
  598.         dd      fs_CdGetFileInfo
  599.         dd      fs_NotImplemented
  600.         dd      0
  601.         dd      fs_NotImplemented
  602.         dd      fs_NotImplemented
  603. fs_NumCdServices = ($ - fs_CdServices)/4
  604. ;-----------------------------------------------------------------------------
  605. fs_HasCd0:
  606.         test    byte [DRIVE_DATA+1], 10000000b
  607.         setnz   al
  608.         ret
  609. ;--------------------------------------
  610. fs_HasCd1:
  611.         test    byte [DRIVE_DATA+1], 00100000b
  612.         setnz   al
  613.         ret
  614. ;--------------------------------------
  615. fs_HasCd2:
  616.         test    byte [DRIVE_DATA+1], 00001000b
  617.         setnz   al
  618.         ret
  619. ;--------------------------------------
  620. fs_HasCd3:
  621.         test    byte [DRIVE_DATA+1], 00000010b
  622.         setnz   al
  623.         ret
  624. ;--------------------------------------
  625. fs_HasCd4:
  626.         test    byte [DRIVE_DATA+6], 10000000b
  627.         setnz   al
  628.         ret
  629. ;--------------------------------------
  630. fs_HasCd5:
  631.         test    byte [DRIVE_DATA+6], 00100000b
  632.         setnz   al
  633.         ret
  634. ;--------------------------------------
  635. fs_HasCd6:
  636.         test    byte [DRIVE_DATA+6], 00001000b
  637.         setnz   al
  638.         ret
  639. ;--------------------------------------
  640. fs_HasCd7:
  641.         test    byte [DRIVE_DATA+6], 00000010b
  642.         setnz   al
  643.         ret
  644. ;--------------------------------------
  645. fs_HasCd8:
  646.         test    byte [DRIVE_DATA+11], 10000000b
  647.         setnz   al
  648.         ret
  649. ;--------------------------------------
  650. fs_HasCd9:
  651.         test    byte [DRIVE_DATA+11], 00100000b
  652.         setnz   al
  653.         ret
  654. ;--------------------------------------
  655. fs_HasCd10:
  656.         test    byte [DRIVE_DATA+11], 00001000b
  657.         setnz   al
  658.         ret
  659. ;--------------------------------------
  660. fs_HasCd11:
  661.         test    byte [DRIVE_DATA+11], 00000010b
  662.         setnz   al
  663.         ret
  664. ;-----------------------------------------------------------------------------
  665. ;
  666. ; fs_NextXXX functions:
  667. ; in: eax = partition number, from which start to scan
  668. ; out: CF=1 => no more partitions
  669. ;      CF=0 => eax=next partition number
  670. ;
  671. ;-----------------------------------------------------------------------------
  672. fs_NextCd:
  673. ; we always have /cdX/1
  674.         test    eax, eax
  675.         stc
  676.         jnz     @f
  677.         mov     al, 1
  678.         clc
  679. @@:
  680.         ret
  681. ;-----------------------------------------------------------------------------
  682. process_replace_file_name:
  683. ; in
  684. ; esi - path with filename(f.70)
  685. ;
  686. ; out
  687. ; ebp - full filename
  688.         pushfd
  689.         cli
  690.         mov     ebp, [full_file_name_table]
  691.         xor     edi, edi
  692. .loop:
  693.         cmp     edi, [full_file_name_table.size]
  694.         jae     .notfound
  695.         push    esi edi
  696.         shl     edi, 7 ; edi*128
  697.         add     edi, ebp
  698. @@:
  699.         cmp     byte [edi], 0 ; end of dir_name
  700.         jz      .dest_done
  701.         lodsb
  702.         test    al, al
  703.         jz      .cont
  704.         or      al, 20h ; 32 - space char
  705.         scasb
  706.         jz      @b
  707.         jmp     .cont
  708. .dest_done:
  709.         cmp     byte [esi], 0
  710.         jz      .found
  711.         cmp     byte [esi], '/'
  712.         jnz     .cont
  713.         inc     esi
  714.         jmp     .found
  715. .cont:
  716.         pop     edi esi
  717.         inc     edi
  718.         jmp     .loop
  719. .found:
  720.         pop     edi eax
  721.         shl     edi, 7 ; edi*128
  722.         add     edi, ebp
  723.         mov     ebp, esi
  724.         cmp     byte [esi], 0
  725.         lea     esi, [edi+64]
  726.         jnz     .ret
  727. .notfound:
  728.         xor     ebp, ebp
  729. .ret:
  730.         popfd
  731.         ret
  732. ;-----------------------------------------------------------------------------
  733. uglobal
  734. lock_flag_for_f30_3 rb 1
  735. endg
  736.        
  737. sys_current_directory:
  738. ;       mov     esi, [current_slot]
  739. ;       mov     esi, [esi+APPDATA.cur_dir]
  740. ;       mov     edx, esi
  741.  
  742. ;get length string of appdata.cur_dir
  743.         mov     eax, [current_slot]
  744.         mov     edi, [eax+APPDATA.cur_dir]
  745.  
  746.         dec     ebx
  747.         jz      .set
  748.         dec     ebx
  749.         jz      .get
  750.         dec     ebx
  751.         jz      .mount_additional_directory
  752.         ret
  753.  
  754. .mount_additional_directory:
  755. ; sysfunction 30.2: [for app] eax=30,ebx=3,ecx->dir name+dir path (128)
  756. ; for our code: nothing
  757.  
  758. ; check lock of the function
  759.         cmp     [lock_flag_for_f30_3], 1
  760.         je      @f
  761.        
  762.         mov     esi, ecx
  763.         mov     edi, sysdir_name1
  764. ; copying fake directory name
  765.         mov     ecx, 63
  766.         pushfd
  767.         cli
  768.         cld
  769.         rep movsb
  770. ; terminator of name, in case if we get the inlet trash
  771.         inc     esi
  772.         xor     eax, eax
  773.         stosb
  774. ; copying real directory path for mounting
  775.         mov     ecx, 63
  776.         rep movsb
  777. ; terminator of name, in case if we get the inlet trash
  778.         xor     eax, eax
  779.         stosb
  780. ; increase the pointer of inputs for procedure "process_replace_file_name"        
  781.         mov     [full_file_name_table.size], 2
  782. ; block the ability to call f.30.3 because for one session is necessary
  783. ; for us only once
  784.         mov     [lock_flag_for_f30_3], 1
  785.         popfd
  786. @@:
  787.         ret
  788.        
  789. .get:
  790. ; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
  791. ; for our code: ebx->buffer,ecx=len
  792. max_cur_dir     equ     0x1000
  793.  
  794.         mov     ebx, edi
  795.  
  796.         push    ecx
  797.         push    edi
  798.  
  799.         xor     eax, eax
  800.         mov     ecx, max_cur_dir
  801.  
  802.         repne scasb             ;find zerro at and string
  803.         jnz     .error          ; no zero in cur_dir: internal error, should not happen
  804.  
  805.         sub     edi, ebx        ;lenght for copy
  806.         inc     edi
  807.         mov     [esp+32+8], edi ;return in eax
  808.  
  809.         cmp     edx, edi
  810.         jbe     @f
  811.         mov     edx, edi
  812. @@:
  813. ;source string
  814.         pop     esi
  815. ;destination string
  816.         pop     edi
  817.         cmp     edx, 1
  818.         jbe     .ret
  819.  
  820.         mov     al, '/'         ;start string with '/'
  821.         stosb
  822.         mov     ecx, edx
  823.         rep movsb               ;copy string
  824. .ret:
  825.         ret
  826.  
  827. .error:
  828.         add     esp, 8
  829.         or      dword [esp+32], -1      ;error not found zerro at string ->[eax+APPDATA.cur_dir]
  830.         ret
  831. .set:
  832. ; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
  833. ; for our code: ebx->string to set
  834. ; use generic resolver with APPDATA.cur_dir as destination
  835.         push    max_cur_dir     ;0x1000
  836.         push    edi     ;destination
  837.         mov     ebx, ecx
  838.         call    get_full_file_name
  839.         ret
  840.  
  841. ; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
  842. ; destroys all registers except ebp,esp
  843. get_full_file_name:
  844.         push    ebp
  845.         mov     esi, [current_slot]
  846.         mov     esi, [esi+APPDATA.cur_dir]
  847.         mov     edx, esi
  848. @@:
  849.         inc     esi
  850.         cmp     byte [esi-1], 0
  851.         jnz     @b
  852.         dec     esi
  853.         cmp     byte [ebx], '/'
  854.         jz      .set_absolute
  855. ; string gives relative path
  856.         mov     edi, [esp+8]    ; destination
  857. .relative:
  858.         cmp     byte [ebx], 0
  859.         jz      .set_ok
  860.         cmp     word [ebx], '.'
  861.         jz      .set_ok
  862.         cmp     word [ebx], './'
  863.         jnz     @f
  864.         add     ebx, 2
  865.         jmp     .relative
  866. @@:
  867.         cmp     word [ebx], '..'
  868.         jnz     .doset_relative
  869.         cmp     byte [ebx+2], 0
  870.         jz      @f
  871.         cmp     byte [ebx+2], '/'
  872.         jnz     .doset_relative
  873. @@:
  874.         dec     esi
  875.         cmp     byte [esi], '/'
  876.         jnz     @b
  877.         add     ebx, 3
  878.         jmp     .relative
  879. .set_ok:
  880.         cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
  881.         jz      .set_ok.cur_dir
  882.         sub     esi, edx
  883.         cmp     esi, [esp+12]
  884.         jb      .set_ok.copy
  885. .fail:
  886.         mov     byte [edi], 0
  887.         xor     eax, eax        ; fail
  888.         pop     ebp
  889.         ret     8
  890. .set_ok.copy:
  891.         mov     ecx, esi
  892.         mov     esi, edx
  893.         rep movsb
  894.         mov     byte [edi], 0
  895. .ret.ok:
  896.         mov     al, 1   ; ok
  897.         pop     ebp
  898.         ret     8
  899. .set_ok.cur_dir:
  900.         mov     byte [esi], 0
  901.         jmp     .ret.ok
  902. .doset_relative:
  903.         cmp     edx, edi
  904.         jz      .doset_relative.cur_dir
  905.         sub     esi, edx
  906.         cmp     esi, [esp+12]
  907.         jae     .fail
  908.         mov     ecx, esi
  909.         mov     esi, edx
  910.         mov     edx, edi
  911.         rep movsb
  912.         jmp     .doset_relative.copy
  913. .doset_relative.cur_dir:
  914.         mov     edi, esi
  915. .doset_relative.copy:
  916.         add     edx, [esp+12]
  917.         mov     byte [edi], '/'
  918.         inc     edi
  919.         cmp     edi, edx
  920.         jae     .overflow
  921. @@:
  922.         mov     al, [ebx]
  923.         inc     ebx
  924.         stosb
  925.         test    al, al
  926.         jz      .ret.ok
  927.         cmp     edi, edx
  928.         jb      @b
  929. .overflow:
  930.         dec     edi
  931.         jmp     .fail
  932. .set_absolute:
  933.         lea     esi, [ebx+1]
  934.         call    process_replace_file_name
  935.         mov     edi, [esp+8]
  936.         mov     edx, [esp+12]
  937.         add     edx, edi
  938. .set_copy:
  939.         lodsb
  940.         stosb
  941.         test    al, al
  942.         jz      .set_part2
  943. .set_copy_cont:
  944.         cmp     edi, edx
  945.         jb      .set_copy
  946.         jmp     .overflow
  947. .set_part2:
  948.         mov     esi, ebp
  949.         xor     ebp, ebp
  950.         test    esi, esi
  951.         jz      .ret.ok
  952.         mov     byte [edi-1], '/'
  953.         jmp     .set_copy_cont
  954.