Subversion Repositories Kolibri OS

Rev

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