Subversion Repositories Kolibri OS

Rev

Rev 6502 | Rev 6534 | 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: 6503 $
  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.         mov     edi, ecx
  448.         cmp     edx, maxPathLength
  449.         jc      @f
  450.         mov     edx, maxPathLength
  451. @@:
  452.         mov     al, '/'
  453.         stosb
  454.         mov     ecx, edx
  455.         dec     ecx
  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.         mov     edi, ecx
  473.         cmp     edx, maxPathLength
  474.         jc      @f
  475.         mov     edx, maxPathLength
  476. @@:
  477.         shr     edx, 1
  478.         mov     ax, '/'
  479.         stosw
  480.         mov     ecx, edx
  481.         dec     ecx
  482. @@:
  483.         dec     ecx
  484.         js      @f
  485.         call    utf8to16
  486.         stosw
  487.         test    ax, ax
  488.         jnz     @b
  489.         sub     edx, ecx
  490.         mov     ecx, edx
  491. @@:
  492.         mov     [esp+32], ecx
  493.         ret
  494.  
  495. .set:
  496.         pop     eax
  497.         push    maxPathLength
  498.         push    edi
  499.         push    eax
  500.         mov     ebx, ecx
  501. get_full_file_name:
  502. ; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
  503. ; out: UTF-8 string, eax=0 -> out of length
  504.         push    ebp ebx
  505.         cmp     byte [ebx], 0
  506.         jz      .set_relative
  507.         mov     esi, ebx
  508.         cmp     byte [ebx], 4
  509.         jnc     @f
  510.         inc     esi
  511. @@:
  512.         cmp     byte [esi], '/'
  513.         jnz     .set_relative
  514.         inc     esi
  515.         cmp     byte [ebx], 2
  516.         jnz     @f
  517.         inc     esi
  518. @@:
  519.         call    process_replace_file_name
  520.         mov     edi, [esp+12]
  521.         mov     ecx, [esp+16]
  522.         mov     al, 3
  523.         mov     ah, '/'
  524.         stosw
  525.         sub     ecx, 2
  526.         test    ebp, ebp
  527.         jz      .absolute
  528. @@:
  529.         lodsb
  530.         stosb
  531.         dec     ecx
  532.         test    al, al
  533.         jnz     @b
  534.         mov     esi, ebp
  535.         dec     edi
  536. .absolute:
  537.         cmp     byte [ebx], 2
  538.         jz      .utf16
  539.         cmp     byte [ebx], 3
  540.         jz      .utf8
  541.         call    cp866toUTF8_string
  542.         jns     .ret
  543.         jmp     .fail
  544.  
  545. .utf8:
  546.         dec     ecx
  547.         js      .fail
  548.         lodsb
  549.         stosb
  550.         test    al, al
  551.         jz      .ret
  552.         jmp     .utf8
  553.  
  554. .utf16:
  555.         call    UTF16to8_string
  556.         jns     .ret
  557. .fail:
  558.         mov     byte [edi], 0
  559.         xor     eax, eax
  560.         pop     ebx ebp
  561.         ret     8
  562.  
  563. .set_relative:
  564.         mov     edi, [current_slot]
  565.         mov     edi, [edi+APPDATA.cur_dir]
  566.         mov     edx, edi
  567.         mov     ecx, [esp+16]
  568.         xor     eax, eax
  569.         repnz scasb
  570.         mov     esi, edi
  571.         dec     esi
  572.         mov     edi, [esp+12]
  573.         jecxz   .fail
  574.         cmp     byte [ebx], 0
  575.         jz      .set_ok
  576.         cmp     byte [ebx], 4
  577.         jnc     .relative
  578.         inc     ebx
  579.         cmp     byte [ebx-1], 2
  580.         jz      .relative16
  581. .relative:
  582.         cmp     byte [ebx], 0
  583.         jz      .set_ok
  584.         cmp     word [ebx], '.'
  585.         jz      .set_ok
  586.         cmp     word [ebx], './'
  587.         jz      .next
  588.         cmp     word [ebx], '..'
  589.         jnz     .doset_relative
  590.         cmp     byte [ebx+2], 0
  591.         jz      @f
  592.         cmp     byte [ebx+2], '/'
  593.         jnz     .doset_relative
  594.         inc     ebx
  595. @@:
  596.         dec     esi
  597.         cmp     byte [esi], '/'
  598.         jnz     @b
  599. .next:
  600.         add     ebx, 2
  601.         jmp     .relative
  602.  
  603. .set_ok:
  604.         cmp     edx, edi    ; is destination equal to cur_dir?
  605.         jz      @f
  606.         mov     ecx, esi
  607.         sub     ecx, edx
  608.         mov     esi, edx
  609.         rep movsb
  610.         mov     byte [edi], 0
  611. .ret:
  612.         mov     al, 1
  613.         pop     ebx ebp
  614.         ret     8
  615.  
  616. @@:
  617.         mov     byte [esi], 0
  618.         jmp     .ret
  619.  
  620. .doset_relative:
  621.         cmp     edx, edi    ; is destination equal to cur_dir?
  622.         mov     edi, esi
  623.         jz      @f
  624.         mov     edi, [esp+12]
  625.         mov     ecx, esi
  626.         sub     ecx, edx
  627.         mov     esi, edx
  628.         mov     edx, edi
  629.         rep movsb
  630. @@:
  631.         mov     byte [edi], '/'
  632.         inc     edi
  633.         mov     esi, ebx
  634.         mov     ecx, edx
  635.         add     ecx, [esp+16]
  636.         sub     ecx, edi
  637.         mov     ebx, [esp]
  638.         jmp     .absolute
  639.  
  640. .relative16:
  641.         cmp     word [ebx], 0
  642.         jz      .set_ok
  643.         cmp     word [ebx], '.'
  644.         jnz     .doset_relative
  645.         cmp     word [ebx+2], 0
  646.         jz      .set_ok
  647.         cmp     word [ebx+2], '/'
  648.         jz      .next16
  649.         cmp     word [ebx+2], '.'
  650.         jnz     .doset_relative
  651.         cmp     word [ebx+4], 0
  652.         jz      @f
  653.         cmp     word [ebx+4], '/'
  654.         jnz     .doset_relative
  655.         add     ebx, 2
  656. @@:
  657.         dec     esi
  658.         cmp     byte [esi], '/'
  659.         jnz     @b
  660. .next16:
  661.         add     ebx, 4
  662.         jmp     .relative16
  663.  
  664. include "parse_fn.inc"
  665. include "fs_common.inc"
  666. include "iso9660.inc"   ; read for CD filesystem
  667. include "fat.inc"
  668. include "ntfs.inc"
  669. include "ext.inc"
  670. ; include "xfs.asm"
  671.  
  672. xfs_create_partition:
  673.         xor     eax, eax
  674.         ret
  675.