Subversion Repositories Kolibri OS

Rev

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