Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
  4. ;;  Distributed under terms of the GNU General Public License.  ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 6464 $
  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
  29.  
  30. file_system_lfn_protected:
  31.         pushad
  32.         call    protect_from_terminate
  33.         call    file_system_lfn
  34.         call    unprotect_from_terminate
  35.         popad
  36.         mov     [image_of_eax], eax
  37.         mov     [image_of_ebx], ebx
  38.         ret
  39.  
  40. file_system_lfn:
  41. ; in: ebx -> parameter structure
  42. ;   operation codes:
  43. ; 0 = read file
  44. ; 1 = read folder
  45. ; 2 = create/rewrite file
  46. ; 3 = write/append to file
  47. ; 4 = set file end
  48. ; 5 = get file info
  49. ; 6 = set file info
  50. ; start application
  51. ; 8 = delete file/folder
  52. ; 9 = create folder
  53.         lea     esi, [ebx+20]
  54.         lodsb
  55.         test    al, al
  56.         jnz     @f
  57.         mov     esi, [esi]
  58.         lodsb
  59. @@:
  60.         lea     ebp, [esi-1]
  61. if 0
  62.         cmp     [ebx], dword 0
  63.         jne     .1
  64.         DEBUGF 1,'read file %s\n',ebp
  65.         jmp     @f
  66. .1:
  67.         cmp     [ebx], dword 5
  68.         jne     @f
  69.         DEBUGF 1,'get file attributes %s\n',ebp
  70. @@:
  71. end if
  72.         cmp     dword[ebx], 7   ; start application
  73.         jne     @f
  74.         mov     edx, [ebx+4]
  75.         mov     ebx, [ebx+8]
  76.         call    fs_execute      ; ebp, ebx, edx
  77.         mov     [image_of_eax], eax
  78.         ret
  79.  
  80. @@:
  81.         cmp     al, '/'
  82.         jz      .notcurdir
  83.         dec     esi
  84.         mov     ebp, esi
  85.         test    al, al
  86.         jnz     @f
  87.         xor     ebp, ebp
  88. @@:
  89.         mov     esi, [current_slot]
  90.         mov     esi, [esi+APPDATA.cur_dir]
  91.         jmp     .parse_normal
  92.  
  93. .notcurdir:
  94.         cmp     byte [esi], 0
  95.         jz      .rootdir
  96.         call    process_replace_file_name
  97. .parse_normal:
  98.         mov     ax, [esi]
  99.         or      ax, 2020h
  100.         cmp     ax, 'cd'
  101.         jz      .CD
  102.         call    dyndisk_handler ; not returns if success
  103. .notfound:
  104.         mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
  105.         ret
  106.  
  107. .CD:
  108.         add     esi, 2
  109.         xor     eax, eax
  110.         lodsb       ; disk number
  111.         sub     eax, '0'
  112.         cmp     eax, 10
  113.         jnc     .notfound
  114.         mov     edi, eax
  115.         lodsb
  116.         test    eax, eax
  117.         jz      .maindir
  118.         cmp     al, '/'
  119.         jnz     .notfound
  120.         lodsb       ; partition number
  121.         test    eax, eax
  122.         jz      .maindir
  123.         cmp     al, '1'
  124.         jnz     .notfound
  125.         cmp     byte [esi], '/'
  126.         jnz     @f
  127.         inc     esi
  128. @@:
  129.         cmp     byte [esi], 0
  130.         jnz     @f
  131.         test    ebp, ebp
  132.         jz      @f
  133.         mov     esi, ebp
  134.         xor     ebp, ebp
  135. @@:
  136.         call    reserve_cd
  137.         mov     eax, edi
  138.         bt      eax, 0
  139.         setc    [DiskNumber]
  140.         bt      eax, 1
  141.         setc    [ChannelNumber]
  142.         inc     [ChannelNumber]
  143.         inc     eax
  144.         mov     [cdpos], eax
  145.         call    reserve_cd_channel
  146.         mov     eax, edi
  147.         not     eax
  148.         and     eax, 3
  149.         shl     eax, 1
  150.         inc     eax
  151.         shr     edi, 2
  152.         mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
  153.         bt      [edi*5+DRIVE_DATA+1], ax
  154.         jnc     @f
  155.         mov     ecx, [ebx+12]
  156.         mov     edx, [ebx+16]
  157.         mov     eax, [ebx]
  158.         mov     dword[image_of_eax], ERROR_UNSUPPORTED_FS
  159.         cmp     eax, fs_NumCdServices
  160.         jae     @f
  161.         add     ebx, 4
  162.         call    dword[fs_CdServices + eax*4]
  163.         call    free_cd_channel
  164.         and     [cd_status], 0
  165.         mov     [image_of_eax], eax
  166.         mov     [image_of_ebx], ebx
  167.         ret
  168.  
  169. @@:
  170.         call    free_cd_channel
  171.         and     [cd_status], 0
  172.         ret
  173.  
  174. .nextCD:
  175.         test    eax, eax    ; partition number
  176.         stc
  177.         jnz     @f      ; no more partitions
  178.         mov     al, 1   ; /cdX/1
  179.         clc
  180. @@:
  181.         ret
  182.  
  183. .maindir:   ; list partitions
  184.         mov     esi, .nextCD
  185. .maindir_noesi:     ; backjump from dyndisk_handler
  186.         cmp     dword[ebx], 1
  187.         jnz     .access_denied  ; read folder?
  188.         push    ecx
  189.         mov     ebp, [ebx+12]   ; the number of blocks to read
  190.         mov     edx, [ebx+16]   ; where to write the result
  191.         push    dword[ebx+4]    ; first block
  192.         mov     ebx, [ebx+8]    ; flags
  193.         mov     ecx, 32/4
  194.         mov     edi, edx
  195.         xor     eax, eax
  196.         rep stosd
  197.         mov     byte [edx], 1   ; version
  198. .maindir_loop:
  199.         call    esi
  200.         jc      .maindir_done
  201.         inc     dword[edx+8]
  202.         dec     dword[esp]
  203.         jns     .maindir_loop
  204.         dec     ebp
  205.         js      .maindir_loop
  206.         inc     dword[edx+4]
  207.         mov     dword[edi], 16      ; attributes: folder
  208.         mov     dword[edi+4], ebx   ; name encoding
  209.         push    eax
  210.         mov     ecx, 32/4
  211.         add     edi, 8
  212.         xor     eax, eax
  213.         rep stosd
  214.         pop     eax
  215.         push    eax edx edi
  216. ; convert number in eax to decimal string
  217.         push    -'0'
  218.         mov     ecx, 10
  219. @@:
  220.         xor     edx, edx
  221.         div     ecx
  222.         push    edx
  223.         test    eax, eax
  224.         jnz     @b
  225.         cmp     ebx, 1
  226.         jz      .uni
  227. @@:
  228.         pop     eax
  229.         add     eax, '0'
  230.         stosb
  231.         test    eax, eax
  232.         jnz     @b
  233.         pop     edi edx eax
  234.         add     edi, 264
  235.         jmp     .maindir_loop
  236.  
  237. .uni:
  238.         pop     eax
  239.         add     eax, '0'
  240.         stosw
  241.         test    eax, eax
  242.         jnz     .uni
  243.         pop     edi edx eax
  244.         add     edi, 520
  245.         jmp     .maindir_loop
  246.  
  247. .maindir_done:
  248.         pop     eax eax
  249.         mov     ebx, [edx+4]
  250.         xor     eax, eax
  251.         dec     ebp
  252.         js      @f
  253.         mov     al, ERROR_END_OF_FILE
  254. @@:
  255.         mov     [image_of_eax], eax
  256.         mov     [image_of_ebx], ebx
  257.         ret
  258.  
  259. .access_denied:
  260.         mov     dword[image_of_eax], ERROR_ACCESS_DENIED
  261.         ret
  262.  
  263. .rootdir:   ; / - virtual root folder
  264.         cmp     dword[ebx], 1   ; read folder?
  265.         jnz     .access_denied
  266.         mov     ebp, [ebx+12]   ; number of blocks
  267.         mov     edx, [ebx+16]   ; return area
  268.         push    dword[ebx+4]    ; first block
  269.         mov     ebx, [ebx+8]    ; flags
  270.         mov     ecx, 32/4
  271.         mov     edi, edx
  272.         xor     eax, eax
  273.         rep stosd
  274.         mov     byte [edx], 1   ; version
  275.         sub     esp, 16
  276. .rootdir_loop:
  277.         push    edi
  278.         lea     edi, [esp+4]
  279.         call    dyndisk_enum_root
  280.         pop     edi
  281.         test    eax, eax
  282.         jz      .rootdirCD
  283.         inc     dword[edx+8]
  284.         dec     dword[esp+16]
  285.         jns     .rootdir_loop
  286.         dec     ebp
  287.         js      .rootdir_loop
  288.         inc     dword[edx+4]
  289.         mov     dword[edi], 16      ; attributes: folder
  290.         mov     dword[edi+4], ebx   ; name encoding
  291.         push    eax
  292.         mov     ecx, 32/4
  293.         add     edi, 8
  294.         xor     eax, eax
  295.         rep stosd
  296.         push    esi edi
  297.         lea     esi, [esp+12]
  298.         cmp     ebx, 1
  299.         jz      .uni2
  300. @@:
  301.         lodsb
  302.         stosb
  303.         test    eax, eax
  304.         jnz     @b
  305.         pop     edi esi eax
  306.         add     edi, 264
  307.         jmp     .rootdir_loop
  308.  
  309. .uni2:
  310.         lodsb
  311.         stosw
  312.         test    eax, eax
  313.         jnz     .uni2
  314.         pop     edi esi eax
  315.         add     edi, 520
  316.         jmp     .rootdir_loop
  317.  
  318. .rootdirCD:
  319.         add     esp, 16
  320.         or      esi, -1
  321. .rootdirCD_loop:
  322.         inc     esi
  323.         cmp     esi, 10
  324.         jnc     .rootdir_done
  325.         mov     eax, esi
  326.         not     eax
  327.         and     eax, 3
  328.         shl     eax, 1
  329.         inc     eax
  330.         mov     ecx, esi
  331.         shr     ecx, 2
  332.         bt      [ecx*5+DRIVE_DATA+1], ax
  333.         jnc     .rootdirCD_loop
  334.         inc     dword[edx+8]
  335.         dec     dword[esp]
  336.         jns     .rootdirCD_loop
  337.         dec     ebp
  338.         js      .rootdirCD_loop
  339.         inc     dword[edx+4]
  340.         mov     dword[edi], 16      ; attributes: folder
  341.         mov     dword[edi+4], ebx   ; name encoding
  342.         mov     ecx, 32/4
  343.         add     edi, 8
  344.         xor     eax, eax
  345.         rep stosd
  346.         mov     eax, esi
  347.         add     eax, '0'
  348.         cmp     ebx, 1
  349.         jz      @f
  350.         mov     word [edi], 'cd'
  351.         mov     [edi+2], ax
  352.         add     edi, 264
  353.         jmp     .rootdirCD_loop
  354.  
  355. @@:
  356.         mov     dword[edi], 640063h
  357.         mov     [edi+4], eax
  358.         add     edi, 520
  359.         jmp     .rootdirCD_loop
  360.  
  361. .rootdir_done:
  362.         pop     eax
  363.         mov     ebx, [edx+4]
  364.         xor     eax, eax
  365.         dec     ebp
  366.         js      @f
  367.         mov     al, ERROR_END_OF_FILE
  368. @@:
  369.         mov     [image_of_eax], eax
  370.         mov     [image_of_ebx], ebx
  371.         ret
  372.  
  373. fs_NotImplemented:
  374.         mov     eax, 2
  375.         ret
  376.  
  377. ;-----------------------------------------------------------------------------
  378. fs_CdServices:
  379.         dd      fs_CdRead
  380.         dd      fs_CdReadFolder
  381.         dd      fs_NotImplemented
  382.         dd      fs_NotImplemented
  383.         dd      fs_NotImplemented
  384.         dd      fs_CdGetFileInfo
  385.         dd      fs_NotImplemented
  386.         dd      0
  387.         dd      fs_NotImplemented
  388.         dd      fs_NotImplemented
  389. fs_NumCdServices = ($ - fs_CdServices)/4
  390. ;-----------------------------------------------------------------------------
  391. process_replace_file_name:
  392. ; in: [esi] = virtual path
  393. ; out: [esi]+[ebp] = physical path
  394.         pushfd
  395.         cli
  396.         mov     ebp, [full_file_name_table]
  397.         xor     edi, edi
  398. .loop:
  399.         cmp     edi, [full_file_name_table.size]
  400.         jae     .notfound
  401.         push    esi edi
  402.         shl     edi, 7
  403.         add     edi, ebp
  404. @@:
  405.         cmp     byte [edi], 0
  406.         jz      .dest_done
  407.         lodsb
  408.         test    al, al
  409.         jz      .cont
  410.         or      al, 20h
  411.         scasb
  412.         jz      @b
  413. .cont:
  414.         pop     edi esi
  415.         inc     edi
  416.         jmp     .loop
  417.  
  418. .dest_done:
  419.         cmp     byte [esi], 0
  420.         jz      .found
  421.         cmp     byte [esi], '/'
  422.         jnz     .cont
  423.         inc     esi
  424. .found:
  425.         pop     edi eax
  426.         shl     edi, 7
  427.         add     edi, ebp
  428.         mov     ebp, esi
  429.         cmp     byte [esi], 0
  430.         lea     esi, [edi+64]
  431.         jnz     .ret
  432. .notfound:
  433.         xor     ebp, ebp
  434. .ret:
  435.         popfd
  436.         ret
  437.  
  438. ;-----------------------------------------------------------------------------
  439. uglobal
  440. lock_flag_for_f30_3 rb 1
  441. endg
  442.  
  443. sys_current_directory:  ; sysfunction 30
  444.         mov     eax, [current_slot]
  445.         mov     edi, [eax+APPDATA.cur_dir]
  446.         dec     ebx
  447.         jz      .set
  448.         dec     ebx
  449.         jz      .get
  450.         dec     ebx
  451.         jz      .mount_additional_directory
  452.         ret
  453.  
  454. .mount_additional_directory:
  455. ; in: ecx -> dir name+dir path (128)
  456.         cmp     [lock_flag_for_f30_3], 1    ; check lock
  457.         je      @f
  458.         mov     esi, ecx
  459.         mov     edi, sysdir_name1
  460.         mov     ecx, 63
  461.         pushfd
  462.         cli
  463.         cld
  464.         rep movsb   ; copying fake directory name
  465.         inc     esi
  466.         xor     eax, eax
  467.         stosb       ; terminator of name, in case if we get the inlet trash
  468.         mov     ecx, 63
  469.         rep movsb   ; copying real directory path for mounting
  470.         xor     eax, eax
  471.         stosb
  472. ; increase the pointer of inputs for procedure "process_replace_file_name"
  473.         mov     [full_file_name_table.size], 2
  474.         mov     [lock_flag_for_f30_3], 1    ; lock
  475.         popfd
  476. @@:
  477.         ret
  478.  
  479. max_cur_dir equ 0x1000  ; length
  480.  
  481. .get:       ; in: ecx -> buffer, edx = length
  482.         mov     ebx, edi    ; buffer
  483.         push    ecx
  484.         push    edi
  485.         xor     eax, eax
  486.         mov     ecx, max_cur_dir
  487.         repne scasb
  488.         jnz     .error
  489.         sub     edi, ebx
  490.         inc     edi
  491.         mov     [esp+32+8], edi ; return in eax
  492.         cmp     edx, edi
  493.         jbe     @f
  494.         mov     edx, edi
  495. @@:
  496.         pop     esi
  497.         pop     edi
  498.         cmp     edx, 1
  499.         jbe     .ret
  500.         mov     al, '/'
  501.         stosb
  502.         mov     ecx, edx
  503.         rep movsb
  504. .ret:
  505.         ret
  506.  
  507. .error:
  508.         add     esp, 8
  509.         or      dword[esp+32], -1
  510.         ret
  511.  
  512. .set:
  513.         pop     eax
  514.         push    max_cur_dir
  515.         push    edi
  516.         push    eax
  517.         mov     ebx, ecx
  518. get_full_file_name:
  519. ; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
  520. ; destroys all registers
  521.         push    ebp
  522.         mov     esi, [current_slot]
  523.         mov     esi, [esi+APPDATA.cur_dir]
  524.         mov     edx, esi
  525. @@:
  526.         inc     esi
  527.         cmp     byte [esi-1], 0
  528.         jnz     @b
  529.         dec     esi
  530.         cmp     byte [ebx], '/'
  531.         jz      .set_absolute
  532.         mov     edi, [esp+8]
  533. .relative:
  534.         cmp     byte [ebx], 0
  535.         jz      .set_ok
  536.         cmp     word [ebx], '.'
  537.         jz      .set_ok
  538.         cmp     word [ebx], './'
  539.         jnz     @f
  540.         add     ebx, 2
  541.         jmp     .relative
  542.  
  543. @@:
  544.         cmp     word [ebx], '..'
  545.         jnz     .doset_relative
  546.         cmp     byte [ebx+2], 0
  547.         jz      @f
  548.         cmp     byte [ebx+2], '/'
  549.         jnz     .doset_relative
  550. @@:
  551.         dec     esi
  552.         cmp     byte [esi], '/'
  553.         jnz     @b
  554.         add     ebx, 3
  555.         jmp     .relative
  556.  
  557. .set_ok:
  558.         cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
  559.         jz      .set_ok.cur_dir
  560.         sub     esi, edx
  561.         cmp     esi, [esp+12]
  562.         jb      .set_ok.copy
  563. .fail:
  564.         mov     byte [edi], 0
  565.         xor     eax, eax
  566.         pop     ebp
  567.         ret     8
  568.  
  569. .set_ok.copy:
  570.         mov     ecx, esi
  571.         mov     esi, edx
  572.         rep movsb
  573.         mov     byte [edi], 0
  574. .ret.ok:
  575.         mov     al, 1
  576.         pop     ebp
  577.         ret     8
  578.  
  579. .set_ok.cur_dir:
  580.         mov     byte [esi], 0
  581.         jmp     .ret.ok
  582.  
  583. .doset_relative:
  584.         cmp     edx, edi
  585.         jz      .doset_relative.cur_dir
  586.         sub     esi, edx
  587.         cmp     esi, [esp+12]
  588.         jae     .fail
  589.         mov     ecx, esi
  590.         mov     esi, edx
  591.         mov     edx, edi
  592.         rep movsb
  593.         jmp     .doset_relative.copy
  594.  
  595. .doset_relative.cur_dir:
  596.         mov     edi, esi
  597. .doset_relative.copy:
  598.         add     edx, [esp+12]
  599.         mov     byte [edi], '/'
  600.         inc     edi
  601.         cmp     edi, edx
  602.         jae     .overflow
  603. @@:
  604.         mov     al, [ebx]
  605.         inc     ebx
  606.         stosb
  607.         test    al, al
  608.         jz      .ret.ok
  609.         cmp     edi, edx
  610.         jb      @b
  611. .overflow:
  612.         dec     edi
  613.         jmp     .fail
  614.  
  615. .set_absolute:
  616.         lea     esi, [ebx+1]
  617.         call    process_replace_file_name
  618.         mov     edi, [esp+8]
  619.         mov     edx, [esp+12]
  620.         add     edx, edi
  621. .set_copy:
  622.         lodsb
  623.         stosb
  624.         test    al, al
  625.         jz      .set_part2
  626. .set_copy_cont:
  627.         cmp     edi, edx
  628.         jb      .set_copy
  629.         jmp     .overflow
  630.  
  631. .set_part2:
  632.         mov     esi, ebp
  633.         xor     ebp, ebp
  634.         test    esi, esi
  635.         jz      .ret.ok
  636.         mov     byte [edi-1], '/'
  637.         jmp     .set_copy_cont
  638.  
  639. include "parse_fn.inc"
  640. include "fs_common.inc"
  641. include "iso9660.inc"   ; read for CD filesystem
  642. include "fat.inc"
  643. include "ntfs.inc"
  644. include "ext.inc"
  645. include "xfs.asm"
  646.