Subversion Repositories Kolibri OS

Rev

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