Subversion Repositories Kolibri OS

Rev

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