Subversion Repositories Kolibri OS

Rev

Rev 7736 | 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: 8676 $
  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.         stdcall is_region_userspace, ecx, edx
  462.         jnz     @f
  463.  
  464.         ; if illegal buffer given
  465.         xor     edx, edx
  466.         jmp     .ret
  467. @@:
  468.  
  469.         mov     esi, edi
  470.         inc     esi
  471.         mov     edi, ecx
  472.         cmp     edx, maxPathLength
  473.         jc      @f
  474.         mov     edx, maxPathLength
  475. @@:
  476.         mov     ecx, edx
  477.         jecxz   .ret
  478.         cmp     eax, 2
  479.         jz      .get16
  480.         cmp     eax, 3
  481.         jz      .get8
  482. @@:
  483.         dec     ecx
  484.         js      @f
  485.         call    utf8to16
  486.         call    uni2ansi_char
  487.         stosb
  488.         test    al, al
  489.         jnz     @b
  490.         sub     edx, ecx
  491. @@:
  492.         mov     byte [edi-1], 0
  493. .ret:
  494.         mov     [esp+32], edx
  495.         ret
  496.  
  497. .get8:
  498.         push    edi
  499.         mov     edi, esi
  500.         xor     eax, eax
  501.         repnz scasb
  502.         sub     edx, ecx
  503.         mov     ecx, edx
  504.         pop     edi
  505.         rep movsb
  506.         jmp     @b
  507.  
  508. .get16:
  509.         shr     ecx, 1
  510.         shr     edx, 1
  511. @@:
  512.         dec     ecx
  513.         js      @f
  514.         call    utf8to16
  515.         stosw
  516.         test    ax, ax
  517.         jnz     @b
  518.         sub     edx, ecx
  519. @@:
  520.         shl     edx, 1
  521.         mov     word [edi-2], 0
  522.         jmp     .ret
  523.  
  524. .set:
  525.         mov     esi, ecx
  526. getFullPath:
  527. ; in: esi -> file path, eax = string encoding, edi -> destination
  528. ; out: UTF-8 string (with marker), eax = length, 0 -> error
  529.         test    eax, eax
  530.         jnz     @f
  531.         cmp     byte [esi], 4
  532.         jnc     @f
  533.         cmp     byte [esi], 0
  534.         jz      @f
  535.         lodsb
  536. @@:
  537.         cmp     byte [esi], '/'
  538.         jnz     .relative
  539.         cmp     eax, 2
  540.         jnz     @f
  541.         cmp     word [esi], '/'
  542.         jnz     .relative
  543.         inc     esi
  544.         inc     esi
  545.         jmp     .start
  546.  
  547. @@:
  548.         inc     esi
  549.         cmp     byte [esi], 4
  550.         jnc     .start
  551.         lodsb
  552.         cmp     byte [esi], '/'
  553.         jnz     .start
  554.         inc     esi
  555. .start:
  556.         push    eax edi
  557.         call    process_replace_file_name
  558.         mov     edi, [esp]
  559.         mov     ecx, maxPathLength
  560.         mov     al, 3
  561.         mov     ah, '/'
  562.         stosw
  563.         sub     ecx, 2
  564.         test    ebp, ebp
  565.         jz      .absolute
  566. @@:
  567.         lodsb
  568.         stosb
  569.         dec     ecx
  570.         test    al, al
  571.         jnz     @b
  572.         mov     esi, ebp
  573.         dec     edi
  574. .absolute:
  575.         cmp     byte [esp+4], 2
  576.         jz      .utf16
  577.         cmp     byte [esp+4], 3
  578.         jz      .utf8
  579.         call    cp866toUTF8_string
  580.         jns     .end
  581.         jmp     .fail
  582.  
  583. .utf8:
  584.         dec     ecx
  585.         js      .fail
  586.         lodsb
  587.         stosb
  588.         test    al, al
  589.         jz      .end
  590.         jmp     .utf8
  591.  
  592. .utf16:
  593.         call    UTF16to8_string
  594.         jns     .end
  595. .fail:
  596.         mov     byte [edi], 0
  597.         pop     eax eax
  598.         xor     eax, eax
  599.         ret
  600.  
  601. .relative:
  602.         push    eax edi
  603.         mov     ebx, esi
  604.         mov     edi, [current_slot]
  605.         mov     edi, [edi+APPDATA.cur_dir]
  606.         mov     edx, edi
  607.         mov     ecx, maxPathLength
  608.         xor     eax, eax
  609.         repnz scasb
  610.         mov     esi, edi
  611.         mov     edi, [esp]
  612.         jecxz   .fail
  613.         cmp     byte [ebx], 0
  614.         jz      .set_ok
  615.         dec     esi
  616.         cmp     edx, edi    ; is destination equal to cur_dir?
  617.         mov     edi, esi
  618.         jz      @f
  619.         mov     edi, [esp]
  620.         mov     ecx, esi
  621.         sub     ecx, edx
  622.         mov     esi, edx
  623.         mov     edx, edi
  624.         rep movsb
  625. @@:
  626.         mov     byte [edi], '/'
  627.         inc     edi
  628.         mov     esi, ebx
  629.         mov     ecx, edx
  630.         add     ecx, maxPathLength
  631.         sub     ecx, edi
  632.         jmp     .absolute
  633.  
  634. .set_ok:
  635.         cmp     edx, edi    ; is destination equal to cur_dir?
  636.         jz      @f
  637.         mov     ecx, esi
  638.         sub     ecx, edx
  639.         mov     esi, edx
  640.         rep movsb
  641. @@:
  642.         pop     eax
  643.         sub     edi, eax
  644.         pop     eax
  645.         mov     eax, edi
  646.         ret
  647.  
  648. .end:
  649.         or      ecx, -1
  650.         mov     edi, [esp]
  651.         xor     eax, eax
  652.         push    edi
  653.         repnz scasb
  654.         not     ecx
  655.         pop     edi
  656. .parse:
  657.         mov     al, '/'
  658.         repnz scasb
  659.         jecxz   @b
  660.         cmp     byte [edi], '.'
  661.         jnz     .parse
  662.         mov     esi, edi
  663. @@:
  664.         lodsw
  665.         sub     ecx, 2
  666.         cmp     ax, './'
  667.         jz      @b
  668.         cmp     ax, '..'
  669.         jnz     @f
  670.         cmp     byte [esi], '/'
  671.         jnz     @f
  672.         mov     edx, ecx
  673.         mov     ecx, edi
  674.         sub     ecx, [esp]
  675.         sub     ecx, 2
  676.         jc      .fail
  677.         sub     edi, 2
  678.         lodsb
  679.         dec     edx
  680.         std
  681.         repnz scasb
  682.         cld
  683.         add     edi, 2
  684.         mov     ecx, edx
  685.         jmp     @b
  686.  
  687. @@:
  688.         sub     esi, 2
  689.         add     ecx, 2
  690.         cmp     esi, edi
  691.         jz      .parse
  692.         push    edi ecx
  693.         rep movsb
  694.         pop     ecx edi
  695.         jmp     .parse
  696.  
  697. include "parse_fn.inc"
  698. include "fs_common.inc"
  699. include "iso9660.inc"   ; read for CD filesystem
  700. include "fat.inc"
  701. include "ntfs.inc"
  702. include "ext.inc"
  703. include "xfs.asm"
  704.