Subversion Repositories Kolibri OS

Rev

Rev 87 | Rev 90 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; System function 70 - files with long names (LFN)
  2. ; diamond, 2006
  3.  
  4. iglobal
  5. ; in this table names must be in lowercase
  6. rootdirs:
  7.         db      2,'rd'
  8.         dd      fs_OnRamdisk
  9.         dd      fs_NextRamdisk
  10.         db      7,'ramdisk'
  11.         dd      fs_OnRamdisk
  12.         dd      fs_NextRamdisk
  13.         db      2,'fd'
  14.         dd      fs_OnFloppy
  15.         dd      fs_NextFloppy
  16.         db      10,'floppydisk'
  17.         dd      fs_OnFloppy
  18.         dd      fs_NextFloppy
  19.         db      3,'hd0'
  20.         dd      fs_OnHd0
  21.         dd      fs_NextHd0
  22.         db      3,'hd1'
  23.         dd      fs_OnHd1
  24.         dd      fs_NextHd1
  25.         db      3,'hd2'
  26.         dd      fs_OnHd2
  27.         dd      fs_NextHd2
  28.         db      3,'hd3'
  29.         dd      fs_OnHd3
  30.         dd      fs_NextHd3
  31. ;**********************************************
  32.         db      3,'cd0'
  33.         dd      fs_OnCd0
  34.         dd      fs_NextCd
  35.         db      3,'cd1'
  36.         dd      fs_OnCd1
  37.         dd      fs_NextCd
  38.         db      3,'cd2'
  39.         dd      fs_OnCd2
  40.         dd      fs_NextCd
  41.         db      3,'cd3'
  42.         dd      fs_OnCd3
  43.         dd      fs_NextCd
  44. ;***********************************************        
  45.         db      0
  46.  
  47.  
  48. virtual_root_query:
  49.         dd      fs_HasRamdisk
  50.         db      'rd',0
  51.         dd      fs_HasFloppy
  52.         db      'fd',0
  53.         dd      fs_HasHd0
  54.         db      'hd0',0
  55.         dd      fs_HasHd1
  56.         db      'hd1',0
  57.         dd      fs_HasHd2
  58.         db      'hd2',0
  59.         dd      fs_HasHd3
  60.         db      'hd3',0
  61. ;**********************************************
  62.         dd      fs_HasCd0
  63.         db      'cd0',0
  64.         dd      fs_HasCd1
  65.         db      'cd1',0
  66.         dd      fs_HasCd2
  67.         db      'cd2',0
  68.         dd      fs_HasCd3
  69.         db      'cd3',0
  70. ;**********************************************
  71.         dd      0
  72. endg
  73.  
  74. file_system_lfn:
  75. ; in: eax->fileinfo block
  76. ; operation codes:
  77. ; 0 : read file
  78. ; 1 : read folder
  79. ; 2 : create/rewrite file
  80. ; 3 : write/append to file - not implemented yet
  81. ; 4 : set end of file - not implemented yet
  82. ; 5 : get file/directory attributes structure
  83. ; 6 : set file/directory attributes structure
  84. ; 7 : start application - not implemented yet
  85. ; 8 : delete file - not implemented yet
  86. ; 9 : create directory - not implemented yet
  87. ; 10: rename file/directory - not implemented yet
  88.  
  89.         add     eax, std_application_base_address
  90. ; parse file name
  91.         xchg    ebx, eax
  92.         lea     esi, [ebx+20]
  93.         lodsb
  94.         test    al, al
  95.         jnz     @f
  96.         mov     esi, [esi]
  97.         add     esi, std_application_base_address
  98.         lodsb
  99. @@:
  100.         cmp     al, '/'
  101.         jz      @f
  102. .notfound:
  103.         mov     dword [esp+36], 5       ; file not found
  104.         ret
  105. @@:
  106.         cmp     byte [esi], 0
  107.         jz      .rootdir
  108.         mov     edi, rootdirs-8
  109.         xor     ecx, ecx
  110.         push    esi
  111. .scan1:
  112.         pop     esi
  113.         add     edi, ecx
  114.         scasd
  115.         scasd
  116.         mov     cl, byte [edi]
  117.         jecxz   .notfound
  118.         inc     edi
  119.         push    esi
  120. @@:
  121.         lodsb
  122.         or      al, 20h
  123.         scasb
  124.         loopz   @b
  125.         jnz     .scan1
  126.         lodsb
  127.         cmp     al, '/'
  128.         jz      .found1
  129.         test    al, al
  130.         jnz     .scan1
  131.         pop     eax
  132. ; directory /xxx
  133. .maindir:
  134.         cmp     dword [ebx], 1
  135.         jnz     .access_denied
  136.         xor     eax, eax
  137.         mov     ebp, [ebx+12]
  138.         mov     edx, [ebx+16]
  139.         add     edx, std_application_base_address
  140.         push    dword [ebx+4]   ; first block
  141.         mov     ebx, [ebx+8]    ; flags
  142.         mov     esi, [edi+4]
  143. ; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
  144.         mov     edi, edx
  145.         mov     ecx, 32/4
  146.         rep     stosd
  147.         mov     byte [edx], 1   ; version
  148. .maindir_loop:
  149.         call    esi
  150.         jc      .maindir_done
  151.         inc     dword [edx+8]
  152.         dec     dword [esp]
  153.         jns     .maindir_loop
  154.         dec     ebp
  155.         js      .maindir_loop
  156.         inc     dword [edx+4]
  157.         mov     dword [edi], 0x10       ; attributes: folder
  158.         mov     dword [edi+4], 1        ; name type: UNICODE
  159.         push    eax
  160.         xor     eax, eax
  161.         add     edi, 8
  162.         mov     ecx, 40/4-2
  163.         rep     stosd
  164.         pop     eax
  165.         push    eax edx
  166. ; convert number in eax to decimal UNICODE string
  167.         push    edi
  168.         push    -'0'
  169.         mov     cl, 10
  170. @@:
  171.         xor     edx, edx
  172.         div     ecx
  173.         push    edx
  174.         test    eax, eax
  175.         jnz     @b
  176. @@:
  177.         pop     eax
  178.         add     al, '0'
  179.         stosb
  180.         test    bl, 1           ; UNICODE name?
  181.         jz      .ansi2
  182.         mov     byte [edi], 0
  183.         inc     edi
  184. .ansi2:
  185.         test    al, al
  186.         jnz     @b
  187.         mov     byte [edi-1], 0
  188.         pop     edi
  189. ; UNICODE name length is 520 bytes, ANSI - 264
  190.         add     edi, 520
  191.         test    bl, 1
  192.         jnz     @f
  193.         sub     edi, 520-264
  194. @@:
  195.         pop     edx eax
  196.         jmp     .maindir_loop
  197. .maindir_done:
  198.         pop     eax
  199.         mov     ebx, [edx+4]
  200.         xor     eax, eax
  201.         dec     ebp
  202.         js      @f
  203.         mov     al, ERROR_END_OF_FILE
  204. @@:
  205.         mov     [esp+36], eax
  206.         mov     [esp+24], ebx
  207.         ret
  208. ; directory /
  209. .rootdir:
  210.         cmp     dword [ebx], 1  ; read folder?
  211.         jz      .readroot
  212. .access_denied:
  213.         mov     dword [esp+36], 10      ; access denied
  214.         ret
  215.  
  216. .readroot:
  217. ; virtual root folder - special handler
  218.         mov     esi, virtual_root_query
  219.         mov     ebp, [ebx+12]
  220.         mov     edx, [ebx+16]
  221.         add     edx, std_application_base_address
  222.         push    dword [ebx+4]   ; first block
  223.         mov     ebx, [ebx+8]    ; flags
  224.         xor     eax, eax
  225. ; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
  226.         mov     edi, edx
  227.         mov     ecx, 32/4
  228.         rep     stosd
  229.         mov     byte [edx], 1   ; version
  230. .readroot_loop:
  231.         cmp     dword [esi], eax
  232.         jz      .readroot_done
  233.         call    dword [esi]
  234.         add     esi, 4
  235.         test    eax, eax
  236.         jnz     @f
  237. .readroot_next:
  238.         or      ecx, -1
  239.         xchg    esi, edi
  240.         repnz   scasb
  241.         xchg    esi, edi
  242.         jmp     .readroot_loop
  243. @@:
  244.         xor     eax, eax
  245.         inc     dword [edx+8]
  246.         dec     dword [esp]
  247.         jns     .readroot_next
  248.         dec     ebp
  249.         js      .readroot_next
  250.         inc     dword [edx+4]
  251.         mov     dword [edi], 0x10       ; attributes: folder
  252.         mov     dword [edi+4], 1        ; name type: UNICODE
  253.         add     edi, 8
  254.         mov     ecx, 40/4-2
  255.         rep     stosd
  256.         push    edi
  257. @@:
  258.         lodsb
  259.         stosb
  260.         test    bl, 1
  261.         jz      .ansi
  262.         mov     byte [edi], 0
  263.         inc     edi
  264. .ansi:
  265.         test    eax, eax
  266.         jnz     @b
  267.         pop     edi
  268.         add     edi, 520
  269.         test    bl, 1
  270.         jnz     .readroot_loop
  271.         sub     edi, 520-264
  272.         jmp     .readroot_loop
  273. .readroot_done:
  274.         pop     eax
  275.         mov     ebx, [edx+4]
  276.         xor     eax, eax
  277.         dec     ebp
  278.         js      @f
  279.         mov     al, ERROR_END_OF_FILE
  280. @@:
  281.         mov     [esp+36], eax
  282.         mov     [esp+24], ebx
  283.         ret
  284.  
  285. .found1:
  286.         pop     eax
  287.         cmp     byte [esi], 0
  288.         jz      .maindir
  289. ; read partition number
  290.         xor     ecx, ecx
  291.         xor     eax, eax
  292. @@:
  293.         lodsb
  294.         cmp     al, '/'
  295.         jz      .done1
  296.         test    al, al
  297.         jz      .done1
  298.         sub     al, '0'
  299.         cmp     al, 9
  300.         ja      .notfound
  301.         imul    ecx, 10
  302.         add     ecx, eax
  303.         jmp     @b
  304. .done1:
  305.         test    ecx, ecx
  306.         jz      .notfound
  307.         test    al, al
  308.         jnz     @f
  309.         dec     esi
  310. @@:
  311. ; now [edi] contains handler address, ecx - partition number,
  312. ; esi points to ASCIIZ string - rest of name
  313.         jmp     dword [edi]
  314.  
  315. ; handlers for devices
  316. ; in: ecx = 0 => query virtual directory /xxx
  317. ; in: ecx = partition number
  318. ;     esi -> relative (for device) name
  319. ;     ebx -> fileinfo
  320. ; out: [esp+36]=image of eax, [esp+24]=image of ebx
  321.  
  322. fs_OnRamdisk:
  323.         cmp     ecx, 1
  324.         jnz     file_system_lfn.notfound
  325.         mov     eax, [ebx]
  326.         cmp     eax, fs_NumRamdiskServices
  327.         jae     .not_impl
  328.         mov     ecx, [ebx+12]
  329.         mov     edx, [ebx+16]
  330.         add     edx, std_application_base_address
  331.         add     ebx, 4
  332.         call    dword [fs_RamdiskServices + eax*4]
  333.         mov     [esp+36], eax
  334.         mov     [esp+24], ebx
  335.         ret
  336. .not_impl:
  337.         mov     dword [esp+36], 2       ; not implemented
  338.         ret
  339.  
  340. fs_NotImplemented:
  341.         mov     eax, 2
  342.         ret
  343.  
  344. fs_RamdiskServices:
  345.         dd      fs_RamdiskRead
  346.         dd      fs_RamdiskReadFolder
  347.         dd      fs_RamdiskRewrite
  348.         dd      fs_NotImplemented
  349.         dd      fs_NotImplemented
  350.         dd      fs_RamdiskGetFileInfo
  351.         dd      fs_RamdiskSetFileInfo
  352. fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
  353.  
  354. fs_OnFloppy:
  355.         cmp     ecx, 2
  356.         ja      file_system_lfn.notfound
  357.         mov     eax, [ebx]
  358.         cmp     eax, fs_NumFloppyServices
  359.         jae     fs_OnRamdisk.not_impl
  360.         call    reserve_flp
  361.         mov     [flp_number], cl
  362.         mov     ecx, [ebx+12]
  363.         mov     edx, [ebx+16]
  364.         add     edx, std_application_base_address
  365.         add     ebx, 4
  366.         call    dword [fs_FloppyServices + eax*4]
  367.         and     [flp_status], 0
  368.         mov     [esp+36], eax
  369.         mov     [esp+24], ebx
  370.         ret
  371.  
  372. fs_FloppyServices:
  373.         dd      fs_FloppyRead
  374.         dd      fs_FloppyReadFolder
  375.         dd      fs_FloppyRewrite
  376.         dd      fs_NotImplemented
  377.         dd      fs_NotImplemented
  378.         dd      fs_FloppyGetFileInfo
  379.         dd      fs_FloppySetFileInfo
  380. fs_NumFloppyServices = ($ - fs_FloppyServices)/4
  381.  
  382. fs_OnHd0:
  383.         call    reserve_hd1
  384.         mov     [hdbase], 0x1F0
  385.         mov     [hdid], 0
  386.         push    1
  387.         jmp     fs_OnHd
  388. fs_OnHd1:
  389.         call    reserve_hd1
  390.         mov     [hdbase], 0x1F0
  391.         mov     [hdid], 0x10
  392.         push    2
  393.         jmp     fs_OnHd
  394. fs_OnHd2:
  395.         call    reserve_hd1
  396.         mov     [hdbase], 0x170
  397.         mov     [hdid], 0
  398.         push    3
  399.         jmp     fs_OnHd
  400. fs_OnHd3:
  401.         call    reserve_hd1
  402.         mov     [hdbase], 0x170
  403.         mov     [hdid], 0x10
  404.         push    4
  405. fs_OnHd:
  406.         pop     eax
  407.         mov     [hdpos], eax
  408.         cmp     ecx, 0x100
  409.         jae     .nf
  410.         cmp     cl, [0x40001+eax]
  411.         jbe     @f
  412. .nf:
  413.         and     [hd1_status], 0
  414.         mov     dword [esp+36], 5       ; not found
  415.         ret
  416. @@:
  417.         mov     [fat32part], ecx
  418.         push    ebx esi
  419.         call    choice_necessity_partition_1
  420.         pop     esi ebx
  421.         mov     ecx, [ebx+12]
  422.         mov     edx, [ebx+16]
  423.         add     edx, std_application_base_address
  424.         mov     eax, [ebx]
  425.         cmp     eax, fs_NumHdServices
  426.         jae     .not_impl
  427.         add     ebx, 4
  428.         call    dword [fs_HdServices + eax*4]
  429.         and     [hd1_status], 0
  430.         mov     [esp+36], eax
  431.         mov     [esp+24], ebx
  432.         ret
  433. .not_impl:
  434.         and     [hd1_status], 0
  435.         mov     dword [esp+36], 2       ; not implemented
  436.         ret
  437.  
  438. fs_HdServices:
  439.         dd      fs_HdRead
  440.         dd      fs_HdReadFolder
  441.         dd      fs_HdRewrite
  442.         dd      fs_NotImplemented
  443.         dd      fs_NotImplemented
  444.         dd      fs_HdGetFileInfo
  445.         dd      fs_HdSetFileInfo
  446. fs_NumHdServices = ($ - fs_HdServices)/4
  447.  
  448. ;*******************************************************
  449. fs_OnCd0:
  450.         call    reserve_cd
  451.         mov  [ChannelNumber],1
  452.         mov  [DiskNumber],0
  453.         push    6
  454.         jmp     fs_OnCd
  455. fs_OnCd1:
  456.         call    reserve_cd
  457.         mov  [ChannelNumber],1
  458.         mov  [DiskNumber],1
  459.         push    4
  460.         jmp     fs_OnCd
  461. fs_OnCd2:
  462.         call    reserve_cd
  463.         mov  [ChannelNumber],2
  464.         mov  [DiskNumber],0
  465.         push    2
  466.         jmp     fs_OnCd
  467. fs_OnCd3:
  468.         call    reserve_cd
  469.         mov  [ChannelNumber],2
  470.         mov  [DiskNumber],1
  471.         push    0
  472. fs_OnCd:
  473.  
  474.         pop     eax
  475.         mov     [hdpos], eax
  476.         cmp     ecx, 0x100
  477.         jae     .nf
  478.         push    cx bx
  479.         mov     cl,al
  480.         mov     bl,[0x40001]
  481.         shr     bl,cl
  482.         test    bl,2
  483.         pop     bx cx
  484.  
  485.         jnz     @f
  486. .nf:
  487.         and    [cd_status], 0
  488.         mov     dword [esp+36], 5       ; not found
  489.         ret
  490. @@:
  491.         mov     ecx, [ebx+12]
  492.         mov     edx, [ebx+16]
  493.         add     edx, std_application_base_address
  494.         mov     eax, [ebx]
  495.         cmp     eax, 1
  496.         ja      .not_impl
  497.         add     ebx, 4
  498.         call    dword [fs_CdServices + eax*4]
  499.         and     [cd_status], 0
  500.         mov     [esp+36], eax
  501.         mov     [esp+24], ebx
  502.         ret
  503. .not_impl:
  504.         and     [cd_status], 0
  505.         mov     dword [esp+36], 2       ; not implemented
  506.         ret
  507.  
  508. fs_CdServices:
  509.         dd      fs_CdRead
  510.         dd      fs_CdReadFolder
  511. ;*******************************************************
  512.  
  513. fs_HasRamdisk:
  514.         mov     al, 1   ; we always have ramdisk
  515.         ret
  516.  
  517. fs_HasFloppy:
  518.         cmp     byte [0x40000], 0
  519.         setnz   al
  520.         ret
  521.  
  522. fs_HasHd0:
  523.         mov     al, [0x40001]
  524.         and     al, 11000000b
  525.         cmp     al, 01000000b
  526.         setz    al
  527.         ret
  528. fs_HasHd1:
  529.         mov     al, [0x40001]
  530.         and     al, 00110000b
  531.         cmp     al, 00010000b
  532.         setz    al
  533.         ret
  534. fs_HasHd2:
  535.         mov     al, [0x40001]
  536.         and     al, 00001100b
  537.         cmp     al, 00000100b
  538.         setz    al
  539.         ret
  540. fs_HasHd3:
  541.         mov     al, [0x40001]
  542.         and     al, 00000011b
  543.         cmp     al, 00000001b
  544.         setz    al
  545.         ret
  546.  
  547. ;*******************************************************
  548. fs_HasCd0:
  549.         mov     al, [0x40001]
  550.         and     al, 11000000b
  551.         cmp     al, 10000000b
  552.         setz    al
  553.         ret
  554. fs_HasCd1:
  555.         mov     al, [0x40001]
  556.         and     al, 00110000b
  557.         cmp     al, 00100000b
  558.         setz    al
  559.         ret
  560. fs_HasCd2:
  561.         mov     al, [0x40001]
  562.         and     al, 00001100b
  563.         cmp     al, 00001000b
  564.         setz    al
  565.         ret
  566. fs_HasCd3:
  567.         mov     al, [0x40001]
  568.         and     al, 00000011b
  569.         cmp     al, 00000010b
  570.         setz    al
  571.         ret
  572. ;*******************************************************        
  573.  
  574. ; fs_NextXXX functions:
  575. ; in: eax = partition number, from which start to scan
  576. ; out: CF=1 => no more partitions
  577. ;      CF=0 => eax=next partition number
  578.  
  579. fs_NextRamdisk:
  580. ; we always have /rd/1
  581.         test    eax, eax
  582.         stc
  583.         jnz     @f
  584.         mov     al, 1
  585.         clc
  586. @@:
  587.         ret
  588.  
  589. fs_NextFloppy:
  590. ; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0)
  591.         test    byte [0x40000], 0xF0
  592.         jz      .no1
  593.         test    eax, eax
  594.         jnz     .no1
  595.         inc     eax
  596.         ret     ; CF cleared
  597. .no1:
  598.         test    byte [0x40000], 0x0F
  599.         jz      .no2
  600.         cmp     al, 2
  601.         jae     .no2
  602.         mov     al, 2
  603.         clc
  604.         ret
  605. .no2:
  606.         stc
  607.         ret
  608.  
  609. ; on hdx, we have partitions from 1 to [0x40002+x]
  610. fs_NextHd0:
  611.         push    0
  612.         jmp     fs_NextHd
  613. fs_NextHd1:
  614.         push    1
  615.         jmp     fs_NextHd
  616. fs_NextHd2:
  617.         push    2
  618.         jmp     fs_NextHd
  619. fs_NextHd3:
  620.         push    3
  621. fs_NextHd:
  622.         pop     ecx
  623.         movzx   ecx, byte [0x40002+ecx]
  624.         cmp     eax, ecx
  625.         jae     fs_NextFloppy.no2
  626.         inc     eax
  627.         clc
  628.         ret
  629.        
  630. ;*******************************************************
  631. fs_NextCd:
  632. ; we always have /cdX/1
  633.         test    eax, eax
  634.         stc
  635.         jnz     @f
  636.         mov     al, 1
  637.         clc
  638. @@:
  639.         ret
  640. ;*******************************************************
  641.  
  642.