Subversion Repositories Kolibri OS

Rev

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