Subversion Repositories Kolibri OS

Rev

Rev 389 | Blame | Last modification | View Log | Download | RSS feed

  1. $Revision: 425 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                                      ;;
  4. ;; System service for filesystem call                                   ;;
  5. ;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
  6. ;; 29.04.2006 Elimination of hangup after the                           ;;
  7. ;;            expiration hd_wait_timeout (for LBA) -  Mario79           ;;
  8. ;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV  ;;
  9. ;; 23.11.2004 test if hd/partition is set - ATV                         ;;
  10. ;; 18.11.2004 get_disk_info and more error codes - ATV                  ;;
  11. ;; 08.11.2004 expand_pathz and rename (only for hd) - ATV               ;;
  12. ;; 20.10.2004 Makedir/Removedir (only for hd) - ATV                     ;;
  13. ;;                                                                      ;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15.  
  16. iglobal
  17. dir0:        db  'HARDDISK   '
  18.              db  'RAMDISK    '
  19.              db  'FLOPPYDISK '
  20.              db  0
  21.  
  22. dir1:        db  'FIRST      '
  23.              db  'SECOND     '
  24.              db  'THIRD      '
  25.              db  'FOURTH     '
  26.              db  0
  27.  
  28. not_select_IDE db 0
  29.  
  30. hd_address_table:  dd  0x1f0,0x00,0x1f0,0x10
  31.                    dd  0x170,0x00,0x170,0x10
  32. endg
  33.  
  34. file_system:
  35.  
  36. ; IN:
  37. ;
  38. ; eax = 0  ; read file          /RamDisk/First  6
  39. ; eax = 1  ; write file         /RamDisk/First 33   /HardDisk/First 56
  40. ; eax = 8  ; lba read
  41. ; eax = 15 ; get_disk_info
  42. ;
  43. ; OUT:
  44. ;
  45. ; eax = 0  : read ok
  46. ; eax = 1  : no hd base and/or partition defined
  47. ; eax = 2  : function is unsupported for this FS
  48. ; eax = 3  : unknown FS
  49. ; eax = 4  : partition not defined at hd
  50. ; eax = 5  : file not found
  51. ; eax = 6  : end of file
  52. ; eax = 7  : memory pointer not in application area
  53. ; eax = 8  : disk full
  54. ; eax = 9  : fat table corrupted
  55. ; eax = 10 : access denied
  56. ; eax = 11 : disk error
  57. ;
  58. ; ebx = size
  59.  
  60. ; \begin{diamond}[18.03.2006]
  61. ; for subfunction 16 (start application) error codes must be negative
  62. ;    because positive values are valid PIDs
  63. ; so possible return values are:
  64. ; eax > 0 : process created, eax=PID
  65.  
  66. ; -0x10 <= eax < 0 : -eax is filesystem error code:
  67. ; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
  68. ; eax = -3  = 0xFFFFFFFD : unknown FS
  69. ; eax = -5  = 0xFFFFFFFB : file not found
  70. ; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
  71. ; eax = -9  = 0xFFFFFFF7 : fat table corrupted
  72. ; eax = -10 = 0xFFFFFFF6 : access denied
  73.  
  74. ; -0x20 <= eax < -0x10: eax is process creation error code:
  75. ; eax = -0x20 = 0xFFFFFFE0 : too many processes
  76. ; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
  77. ; eax = -0x1E = 0xFFFFFFE2 : no memory
  78.  
  79. ; ebx is not changed
  80.  
  81. ; \end{diamond}[18.03.2006]
  82.  
  83.     ; Extract parameters
  84.     add    eax, std_application_base_address    ; abs start of info block
  85.  
  86.     cmp   dword [eax+0],15      ; GET_DISK_INFO
  87.     je    fs_info
  88.  
  89.     cmp   dword [CURRENT_TASK],1      ; no memory checks for kernel requests
  90.     jz    no_checks_for_kernel
  91.     mov   edx,eax
  92.     cmp   dword [eax+0],1
  93.     jnz   .usual_check
  94.     mov   ebx,[eax+12]
  95.     add   ebx,std_application_base_address
  96.     mov   ecx,[eax+8]
  97.     call  check_region
  98.     test  eax,eax
  99.     jnz   area_in_app_mem
  100.  
  101. .error_output:
  102.     mov   esi,buffer_failed
  103.     call  sys_msg_board_str
  104. ;    mov   eax,7
  105.     mov   dword [esp+36],7
  106.     ret
  107. iglobal
  108.   buffer_failed db 'K : Buffer check failed',13,10,0
  109. endg
  110. .usual_check:
  111.     cmp   dword [eax+0],0
  112.     mov   ecx,512
  113.     jnz   .small_size
  114.     mov   ecx,[eax+8]
  115.     shl   ecx,9
  116. .small_size:
  117.     mov   ebx,[eax+12]
  118.     add   ebx,std_application_base_address
  119.     call  check_region
  120.     test  eax,eax
  121.     jz    .error_output
  122.   area_in_app_mem:
  123.     mov   eax,edx
  124.   no_checks_for_kernel:
  125.  
  126.   fs_read:
  127.  
  128.     mov   ebx,[eax+20]          ; program wants root directory ?
  129.     test  bl,bl
  130.     je    fs_getroot
  131.     test  bh,bh
  132.     jne   fs_noroot
  133.   fs_getroot:
  134. ; \begin{diamond}[18.03.2006]
  135. ; root - only read is allowed
  136. ; other operations return "access denied", eax=10
  137. ; (execute operation returns eax=-10)
  138.     cmp    dword [eax], 0
  139.     jz    .read_root
  140.     mov    dword [esp+36], 10
  141.     ret
  142. .read_root:
  143. ; \end{diamond}[18.03.2006]
  144.     mov   esi,dir0
  145.     mov   edi,[eax+12]
  146.     add   edi,std_application_base_address
  147.     mov   ecx,11
  148.     push  ecx
  149. ;    cld    ; already is
  150.     rep   movsb
  151.     mov   al,0x10
  152.     stosb
  153.     add   edi,32-11-1
  154.     pop   ecx
  155.     rep   movsb
  156.     stosb
  157.     and   dword [esp+36],0      ; ok read
  158.     mov   dword [esp+24],32*2   ; size of root
  159.     ret
  160.  
  161.   fs_info:                      ;start of code - Mihasik
  162.     push  eax
  163.     cmp   [eax+21],byte 'h'
  164.     je    fs_info_h
  165.     cmp   [eax+21],byte 'H'
  166.     je    fs_info_h
  167.     cmp   [eax+21],byte 'r'
  168.     je    fs_info_r
  169.     cmp   [eax+21],byte 'R'
  170.     je    fs_info_r
  171.     mov   eax,3                 ;if unknown disk
  172.     xor   ebx,ebx
  173.     xor   ecx,ecx
  174.     xor   edx,edx
  175.     jmp   fs_info1
  176.   fs_info_r:
  177.     call  ramdisk_free_space    ;if ramdisk
  178.     mov   ecx,edi               ;free space in ecx
  179.     shr   ecx,9                 ;free clusters
  180.     mov   ebx,2847              ;total clusters
  181.     mov   edx,512               ;cluster size
  182.     xor   eax,eax               ;always 0
  183.     jmp   fs_info1
  184.   fs_info_h:                    ;if harddisk
  185.     call  get_hd_info
  186.   fs_info1:
  187.     pop   edi
  188.     mov   [esp+36],eax
  189.     mov   [esp+24],ebx           ; total clusters on disk
  190.     mov   [esp+32],ecx           ; free clusters on disk
  191.     mov   [edi],edx              ; cluster size in bytes
  192.     ret                          ;end of code - Mihasik
  193.  
  194.   fs_noroot:
  195.  
  196.     push  dword [eax+0]         ; read/write/delete/.../makedir/rename/lba/run
  197.     push  dword [eax+4]         ; 512 block number to read
  198.     push  dword [eax+8]         ; bytes to write/append or 512 blocks to read
  199.     mov   ebx,[eax+12]
  200.     add   ebx,std_application_base_address
  201.     push  ebx                   ; abs start of return/save area
  202.  
  203.     lea   esi,[eax+20]          ; abs start of dir + filename
  204.     mov   edi,[eax+16]
  205.     add   edi,std_application_base_address    ; abs start of work area
  206.  
  207.     call  expand_pathz
  208.  
  209.     push  edi                   ; dir start
  210.     push  ebx                   ; name of file start
  211.  
  212.     mov   eax,[edi+1]
  213.     cmp   eax,'RD  '
  214.     je    fs_yesramdisk
  215.     cmp   eax,'RAMD'
  216.     jne   fs_noramdisk
  217.  
  218.   fs_yesramdisk:
  219.  
  220.     cmp   byte [edi+1+11],0
  221.     je    fs_give_dir1
  222.  
  223.     mov   eax,[edi+1+12]
  224.     cmp   eax,'1   '
  225.     je    fs_yesramdisk_first
  226.     cmp   eax,'FIRS'
  227.     jne   fs_noramdisk
  228.  
  229.   fs_yesramdisk_first:
  230.  
  231.     cmp   dword [esp+20],8      ; LBA read ramdisk
  232.     jne   fs_no_LBA_read_ramdisk
  233.  
  234.     mov   eax,[esp+16]          ; LBA block to read
  235.     mov   ecx,[esp+8]           ; abs pointer to return area
  236.  
  237.     call  LBA_read_ramdisk
  238.     jmp   file_system_return
  239.  
  240.  
  241.   fs_no_LBA_read_ramdisk:
  242.  
  243.     cmp   dword [esp+20],0      ; READ
  244.     jne   fs_noramdisk_read
  245.  
  246.     mov   eax,[esp+4]           ; fname
  247.     add   eax,2*12+1
  248.     mov   ebx,[esp+16]          ; block start
  249.     inc   ebx
  250.     mov   ecx,[esp+12]          ; block count
  251.     mov   edx,[esp+8]           ; return
  252.     mov   esi,[esp+0]
  253.     sub   esi,eax
  254.     add   esi,12+1              ; file name length
  255.     call  fileread
  256.  
  257.     jmp   file_system_return
  258.  
  259.  
  260.   fs_noramdisk_read:
  261.  
  262.     cmp   dword [esp+20],1      ; WRITE
  263.     jne   fs_noramdisk_write
  264.  
  265.     mov   eax,[esp+4]           ; fname
  266.     add   eax,2*12+1
  267.     mov   ebx,[esp+8]           ; buffer
  268.     mov   ecx,[esp+12]          ; count to write
  269.     mov   edx,0                 ; create new
  270.     call  filesave
  271.  
  272.     ; eax=0 ok - eax=1 not enough free space
  273.  
  274.     jmp   file_system_return
  275.  
  276.   fs_noramdisk_write:
  277.   fs_noramdisk:
  278.  
  279.   ;********************************************************************
  280.     mov   eax,[edi+1]
  281.     cmp   eax,'FD  '
  282.     je    fs_yesflpdisk
  283.     cmp   eax,'FLOP'
  284.     jne   fs_noflpdisk
  285.  
  286.   fs_yesflpdisk:
  287.     call   reserve_flp
  288.  
  289.     cmp   byte [edi+1+11],0
  290.     je    fs_give_dir1
  291.  
  292.     mov   eax,[edi+1+12]
  293.     cmp   eax,'1   '
  294.     je    fs_yesflpdisk_first
  295.     cmp   eax,'FIRS'
  296.     je    fs_yesflpdisk_first
  297.     cmp   eax,'2   '
  298.     je    fs_yesflpdisk_second
  299.     cmp   eax,'SECO'
  300.     jne   fs_noflpdisk
  301.     jmp   fs_yesflpdisk_second
  302.  
  303.   fs_yesflpdisk_first:
  304.     mov   [flp_number],1
  305.     jmp   fs_yesflpdisk_start
  306.   fs_yesflpdisk_second:
  307.     mov   [flp_number],2
  308.   fs_yesflpdisk_start:
  309.     cmp   dword [esp+20],0      ; READ
  310.     jne   fs_noflpdisk_read
  311.  
  312.     mov   eax,[esp+4]           ; fname
  313.     add   eax,2*12+1
  314.     mov   ebx,[esp+16]          ; block start
  315.     inc   ebx
  316.     mov   ecx,[esp+12]          ; block count
  317.     mov   edx,[esp+8]           ; return
  318.     mov   esi,[esp+0]
  319.     sub   esi,eax
  320.     add   esi,12+1              ; file name length
  321.     call  floppy_fileread
  322.  
  323.     jmp   file_system_return
  324.  
  325.  
  326.   fs_noflpdisk_read:
  327.  
  328.     cmp   dword [esp+20],1      ; WRITE
  329.     jne   fs_noflpdisk_write
  330.  
  331.     mov   eax,[esp+4]           ; fname
  332.     add   eax,2*12+1
  333.     mov   ebx,[esp+8]           ; buffer
  334.     mov   ecx,[esp+12]          ; count to write
  335.     mov   edx,0                 ; create new
  336.     call  floppy_filesave
  337.  
  338.     ; eax=0 ok - eax=1 not enough free space
  339.  
  340.     jmp   file_system_return
  341.  
  342.   fs_noflpdisk_write:
  343.  
  344.   fs_noflpdisk:
  345.   ;*****************************************************************
  346.  
  347.     mov   eax,[edi+1]
  348.     cmp   eax,'HD0 '
  349.     je    fs_yesharddisk_IDE0
  350.     cmp   eax,'HD1 '
  351.     je    fs_yesharddisk_IDE1
  352.     cmp   eax,'HD2 '
  353.     je    fs_yesharddisk_IDE2
  354.     cmp   eax,'HD3 '
  355.     je    fs_yesharddisk_IDE3
  356.     jmp   old_path_harddisk
  357. fs_yesharddisk_IDE0:
  358.      call  reserve_hd1
  359.      mov  [hdbase],0x1f0
  360.      mov  [hdid],0x0
  361.      mov  [hdpos],1
  362.      jmp  fs_yesharddisk_partition
  363. fs_yesharddisk_IDE1:
  364.      call  reserve_hd1
  365.      mov  [hdbase],0x1f0
  366.      mov  [hdid],0x10
  367.      mov  [hdpos],2
  368.      jmp  fs_yesharddisk_partition
  369. fs_yesharddisk_IDE2:
  370.      call  reserve_hd1
  371.      mov  [hdbase],0x170
  372.      mov  [hdid],0x0
  373.      mov  [hdpos],3
  374.      jmp  fs_yesharddisk_partition
  375. fs_yesharddisk_IDE3:
  376.      call  reserve_hd1
  377.      mov  [hdbase],0x170
  378.      mov  [hdid],0x10
  379.      mov  [hdpos],4
  380. fs_yesharddisk_partition:
  381.         call    reserve_hd_channel
  382. ;    call  choice_necessity_partition
  383. ;    jmp   fs_yesharddisk_all
  384.     jmp   fs_for_new_semantic
  385.  
  386. choice_necessity_partition:
  387.     mov   eax,[edi+1+12]
  388.     call  StringToNumber
  389.         mov   [fat32part],eax
  390. choice_necessity_partition_1:
  391.     mov   ecx,[hdpos]
  392.     xor   eax,eax
  393.     mov   [hd_entries], eax    ; entries in hd cache
  394.     mov   edx,DRIVE_DATA+2
  395.  search_partition_array:
  396.     mov   bl,[edx]
  397.     movzx ebx,bl
  398.     add   eax,ebx
  399.     inc   edx
  400.     loop  search_partition_array
  401.     sub   eax,ebx
  402.     add   eax,[fat32part]
  403.     dec   eax
  404.     xor   edx,edx
  405.     imul  eax,100
  406.     add   eax,DRIVE_DATA+0xa
  407.     mov   [transfer_adress],eax
  408.     call  partition_data_transfer_1
  409.     ret
  410.  
  411.  old_path_harddisk:
  412.     mov   eax,[edi+1]
  413.     cmp   eax,'HD  '
  414.     je    fs_yesharddisk
  415.     cmp   eax,'HARD'
  416.     jne   fs_noharddisk
  417.  
  418.   fs_yesharddisk:
  419.     cmp   dword [esp+20],8      ; LBA read
  420.     jne   fs_no_LBA_read
  421.     mov   eax,[esp+16]          ; LBA block to read
  422.     lea   ebx,[edi+1+12]        ; pointer to FIRST/SECOND/THIRD/FOURTH
  423.     mov   ecx,[esp+8]           ; abs pointer to return area
  424.     call  LBA_read
  425.     jmp   file_system_return
  426.  
  427.   fs_no_LBA_read:
  428.  
  429.     cmp   byte [edi+1+11],0     ; directory read
  430.     je    fs_give_dir1
  431.     call  reserve_hd1
  432.  fs_for_new_semantic:
  433.     call  choice_necessity_partition
  434.  
  435.   fs_yesharddisk_all:
  436.     mov   eax,1
  437.     mov    ebx, [esp+24+24]
  438.     cmp   [hdpos],0             ; is hd base set?
  439.     jz    hd_err_return
  440.     cmp   [fat32part],0         ; is partition set?
  441.     jnz   @f
  442. hd_err_return:
  443.     call  free_hd_channel
  444.     and   [hd1_status], 0
  445.     jmp   file_system_return
  446. @@:
  447.  
  448.     cmp   dword [esp+20],0      ; READ
  449.     jne   fs_noharddisk_read
  450.  
  451.     mov   eax,[esp+0]           ; /fname
  452.     lea   edi,[eax+12]
  453.     mov   byte [eax],0          ; path to asciiz
  454.     inc   eax                   ; filename start
  455.  
  456.     mov   ebx,[esp+12]          ; count to read
  457.     mov   ecx,[esp+8]           ; buffer
  458.     mov   edx,[esp+4]
  459.     add   edx,12*2              ; dir start
  460.     sub   edi,edx               ; path length
  461.     mov   esi,[esp+16]          ; blocks to read
  462.  
  463.     call  file_read
  464.  
  465.     mov   edi,[esp+0]
  466.     mov   byte [edi],'/'
  467.  
  468.     call  free_hd_channel
  469.     and   [hd1_status], 0
  470.     jmp   file_system_return
  471.  
  472.   fs_noharddisk_read:
  473.  
  474.  
  475.     cmp   dword [esp+20],1      ; WRITE
  476.     jne   fs_noharddisk_write
  477.  
  478.     mov   eax,[esp+0]           ; /fname
  479.     mov   byte [eax],0          ; path to asciiz
  480.     inc   eax                   ; filename start
  481.  
  482.     mov   ebx,[esp+12]          ; count to write
  483.     mov   ecx,[esp+8]           ; buffer
  484.     mov   edx,[esp+4]
  485.     add   edx,12*2              ; path start
  486.  
  487.     call  file_write
  488.  
  489.     mov   edi,[esp+0]
  490.     mov   byte [edi],'/'
  491.  
  492.     ; eax=0 ok - eax=1 not enough free space
  493.  
  494.     call  free_hd_channel
  495.     and   [hd1_status], 0
  496.     jmp   file_system_return
  497.  
  498.  
  499.   fs_noharddisk_write:
  500.  
  501.  
  502.     call  free_hd_channel
  503.     and   [hd1_status], 0
  504.  
  505.   fs_noharddisk:
  506. ; \begin{diamond}[18.03.2006]
  507.     mov    eax, 5        ; file not found
  508. ; à ìîæåò áûòü, âîçâðàùàòü äðóãîé êîä îøèáêè?
  509.     mov    ebx, [esp+24+24]    ; do not change ebx in application
  510. ; \end{diamond}[18.03.2006]
  511.  
  512.   file_system_return:
  513.  
  514.     add   esp,24
  515.  
  516.     mov   [esp+36],eax
  517.     mov   [esp+24],ebx
  518.     ret
  519.  
  520.  
  521.   fs_give_dir1:
  522.  
  523. ; \begin{diamond}[18.03.2006]
  524. ; /RD,/FD,/HD - only read is allowed
  525. ; other operations return "access denied", eax=10
  526. ; (execute operation returns eax=-10)
  527.     cmp    dword [esp+20], 0
  528.     jz    .read
  529.     add    esp, 20
  530.     pop    ecx
  531.     mov    dword [esp+36], 10
  532.     ret
  533. .read:
  534. ; \end{diamond}[18.03.2006]
  535.     mov   al,0x10
  536.     mov   ebx,1
  537.     mov   edi,[esp+8]
  538.     mov   esi,dir1
  539.   fs_d1_new:
  540.     mov   ecx,11
  541. ;    cld
  542.     rep   movsb
  543.     stosb
  544.     add   edi,32-11-1
  545.     dec   ebx
  546.     jne   fs_d1_new
  547.  
  548.     add   esp,24
  549.  
  550.     and   dword [esp+36],0      ; ok read
  551.     mov   dword [esp+24],32*1   ; dir/data size
  552.     ret
  553.  
  554.  
  555.  
  556. LBA_read_ramdisk:
  557.  
  558.     cmp   [lba_read_enabled],1
  559.     je    lbarrl1
  560.  
  561.     xor   ebx,ebx
  562.     mov   eax,2
  563.     ret
  564.  
  565.   lbarrl1:
  566.  
  567.     cmp   eax,18*2*80
  568.     jb    lbarrl2
  569.     xor   ebx,ebx
  570.     mov   eax,3
  571.     ret
  572.  
  573.   lbarrl2:
  574.  
  575.     pushad
  576.  
  577.     call  restorefatchain
  578.  
  579.     mov   edi,ecx
  580.     mov   esi,eax
  581.  
  582.     shl   esi,9
  583.     add   esi,RAMDISK
  584.     mov   ecx,512/4
  585. ;    cld
  586.     rep   movsd
  587.  
  588.     popad
  589.  
  590.     xor   ebx,ebx
  591.     xor   eax,eax
  592.     ret
  593.  
  594. LBA_read:
  595.  
  596. ; IN:
  597. ;
  598. ; eax = LBA block to read
  599. ; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
  600. ; ecx = abs pointer to return area
  601.  
  602.     cmp   [lba_read_enabled],1
  603.     je    lbarl1
  604.     mov   eax,2
  605.     ret
  606.  
  607.   lbarl1:
  608.  
  609.     call  reserve_hd1
  610.  
  611.     push  eax
  612.     push  ecx
  613.  
  614.     mov   edi,hd_address_table
  615.     mov   esi,dir1
  616.     mov   eax,[ebx]
  617.     mov   edx,'1   '
  618.     mov   ecx,4
  619.   blar0:
  620.     cmp   eax,[esi]
  621.     je    blar2
  622.     cmp   eax,edx
  623.     je    blar2
  624.     inc   edx
  625.     add   edi,8
  626.     add   esi,11
  627.     dec   ecx
  628.     jnz   blar0
  629.  
  630.     mov   eax,1
  631.     mov   ebx,1
  632.     jmp   LBA_read_ret
  633.  
  634.   blar2:
  635.     mov   eax,[edi+0]
  636.     mov   ebx,[edi+4]
  637.  
  638.     mov  [hdbase],eax
  639.     mov  [hdid],ebx
  640.  
  641.     call  wait_for_hd_idle
  642.     cmp   [hd_error],0
  643.     jne   hd_lba_error
  644.  
  645.     ; eax = hd port
  646.     ; ebx = set for primary (0x00) or slave (0x10)
  647.  
  648.     cli
  649.  
  650.     mov   edx,eax
  651.     inc   edx
  652.     xor   eax,eax
  653.     out   dx,al
  654.     inc   edx
  655.     inc   eax
  656.     out   dx,al
  657.     inc   edx
  658.     mov   eax,[esp+4]
  659.     out   dx,al
  660.     shr   eax,8
  661.     inc   edx
  662.     out   dx,al
  663.     shr   eax,8
  664.     inc   edx
  665.     out   dx,al
  666.     shr   eax,8
  667.     inc   edx
  668.     and   al,1+2+4+8
  669.     add   al,bl
  670.     add   al,128+64+32
  671.     out   dx,al
  672.  
  673.     inc   edx
  674.     mov   al,20h
  675.     out   dx,al
  676.  
  677.     sti
  678.  
  679.     call  wait_for_sector_buffer
  680.     cmp   [hd_error],0
  681.     jne   hd_lba_error
  682.  
  683.     cli
  684.  
  685.     mov   edi,[esp+0]
  686.     mov   ecx,256
  687.     sub   edx,7
  688.     cld
  689.     rep   insw
  690.  
  691.     sti
  692.  
  693.     xor   eax,eax
  694.     xor   ebx,ebx
  695.  
  696.   LBA_read_ret:
  697.     mov [hd_error],0
  698.     mov   [hd1_status],0
  699.     add   esp,2*4
  700.  
  701.     ret
  702.  
  703.  
  704. expand_pathz:
  705. ; IN:
  706. ;   esi = asciiz path & file
  707. ;   edi = buffer for path & file name
  708. ; OUT:
  709. ;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
  710. ;   ebx = /file name - zero terminated
  711. ;   esi = pointer after source
  712.  
  713.     push  eax
  714.     push  ecx
  715.     push  edi ;[esp+0]
  716.  
  717.   pathz_start:
  718.     mov   byte [edi],'/'
  719.     inc   edi
  720.     mov   al,32
  721.     mov   ecx,11
  722.     cld
  723.     rep   stosb                 ; clear filename area
  724.     sub   edi,11
  725.     mov   ebx,edi               ; start of dir/file name
  726.  
  727.   pathz_new_char:
  728.     mov   al,[esi]
  729.     inc   esi
  730.     cmp   al,0
  731.     je    pathz_end
  732.  
  733.     cmp   al,'/'
  734.     jne   pathz_not_path
  735.     cmp   edi,ebx               ; skip first '/'
  736.     jz    pathz_new_char
  737.     lea   edi,[ebx+11]          ; start of next directory
  738.     jmp   pathz_start
  739.  
  740.   pathz_not_path:
  741.     cmp   al,'.'
  742.     jne   pathz_not_ext
  743.     lea   edi,[ebx+8]           ; start of extension
  744.     jmp   pathz_new_char
  745.  
  746.   pathz_not_ext:
  747.     cmp   al,'a'
  748.     jb    pathz_not_low
  749.     cmp   al,'z'
  750.     ja    pathz_not_low
  751.     sub   al,0x20               ; char to uppercase
  752.  
  753.   pathz_not_low:
  754.     mov   [edi],al
  755.     inc   edi
  756.     mov   eax,[esp+0]           ; start_of_dest_path
  757.     add   eax,512               ; keep maximum path under 512 bytes
  758.     cmp   edi,eax
  759.     jb    pathz_new_char
  760.  
  761.   pathz_end:
  762.     cmp   ebx,edi               ; if path end with '/'
  763.     jnz   pathz_put_zero        ; go back 1 level
  764.     sub   ebx,12
  765.  
  766.   pathz_put_zero:
  767.     mov   byte [ebx+11],0
  768.     dec   ebx                   ; include '/' char into file name
  769.     pop   edi
  770.     pop   ecx
  771.     pop   eax
  772.     ret
  773.  
  774. ;*******************************************
  775. ;* string to number
  776. ;* input eax - 4 byte string
  777. ;* output eax - number
  778. ;*******************************************
  779. StringToNumber:
  780. ;    ÏÅÐÅÂÎÄ ÑÒÐÎÊÎÂÎÃÎ ×ÈÑËÀ  ×ÈÑËÎÂÎÉ ÂÈÄ
  781. ;    Âõîä:
  782. ;        EDI - àäðåñ ñòðîêè ñ ÷èñëîì. Êîíåö ÷èñëà îòìå÷åí êîäîì 0Dh
  783. ;    Âûõîä:
  784. ;        CF - èíäèêàòîð îøèáîê:
  785. ;            0 - îøèáîê íåò;
  786. ;            1 - îøèáêà
  787. ;        Åñëè CF=0, òî AX - ÷èñëî.
  788.  
  789.     push    bx
  790.     push    cx
  791.     push    dx
  792.     push    edi
  793.     mov   [partition_string],eax
  794.     mov    edi,partition_string
  795.     xor    cx,cx
  796. i1:
  797.     mov    al,[edi]
  798.     cmp    al,32  ;13
  799.     je    i_exit
  800. ;    cmp    al,'0'
  801. ;    jb    err
  802. ;    cmp    al,'9'
  803. ;    ja    err
  804.     sub    al,48
  805.     shl    cx,1
  806.     jc    err
  807.     mov    bx,cx
  808.     shl    cx,1
  809.     jc    err
  810.     shl    cx,1
  811.     jc    err
  812.     add    cx,bx
  813.     jc    err
  814.     cbw
  815.     add    cx,ax
  816.     jc    err
  817. i3:
  818.     inc    edi
  819.     jmp    i1
  820. i_exit:
  821.     mov    ax,cx
  822.     clc
  823. i4:
  824.     movzx  eax,ax
  825.     pop    edi
  826.     pop    dx
  827.     pop    cx
  828.     pop    bx
  829.     ret
  830.  
  831. err:
  832.     stc
  833.     jmp    i4
  834.  
  835. partition_string: dd 0
  836.                   db 32
  837.