Subversion Repositories Kolibri OS

Rev

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