Subversion Repositories Kolibri OS

Rev

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

  1. ; data for parsing string
  2. param_cmd: dd 0 ;set when for "-a" command
  3.  
  4. ; virtdisk -d <DISK_NUMBER>
  5. ; virtdisk -i <DISK_NUMBER>
  6. ; virtdisk -a <PATH> -s <SECTOR_SIZE> -t <IMAGE_TYPE> -f <FLAGS>
  7. ; virtdisk -l
  8. parse_cmd:
  9.         mov     edi, PATH
  10.         ; find string length
  11.         xor     al, al
  12.         mov     ecx, 4096
  13.         repne   scasb
  14.  
  15.         mov     ecx, edi
  16.         sub     ecx, PATH
  17.         mov     edi, PATH
  18. .still:
  19.         mov     al, ' '
  20.         repz    scasb
  21.  
  22.         test    ecx, ecx
  23.         jz      .end_parser
  24.  
  25.         dec     edi
  26.         or      word[edi], 0x2020 ; ïåðåâîäèì â íèæíèé ðåãèñòð
  27.         ; -a -d -i -l -s -t -f
  28.  
  29.         cmp     word[edi], '-a'
  30.         jnz     @f
  31.         ;add virt disk
  32.         mov     dword[param_cmd],-1
  33.  
  34.         add     edi, 3
  35.         sub     ecx, 2
  36.         js      ERROR_EXIT ; error not found path
  37.  
  38.         mov     edx, add_disk.file
  39.         call    .copy_str
  40.         or      dword[edx -4], 0x20202020
  41.         mov     dword[add_disk.size], 512
  42.         cmp     dword[edx -4], '.iso'
  43.         jnz     .still
  44.         mov     dword[add_disk.size], 2048
  45.  
  46.         jmp     .still
  47. @@:
  48.         cmp     word[edi], '-d'
  49.         jnz     @f
  50.  
  51.         add     edi, 3
  52.         sub     ecx, 2
  53.         js      ERROR_EXIT ; error not found path
  54.  
  55.         call    .get_number
  56.         mov     [disk_num],eax
  57.  
  58.         pusha
  59.         mov     al, 68
  60.         mov     bl, 17
  61.         mov     ecx, ioctl_del_disk
  62.         int     0x40
  63.  
  64.         push    str_command_successfully
  65.         call    _sc_puts
  66.         popa
  67.  
  68.         jmp     .still
  69. @@:
  70.         cmp     word[edi], '-i'
  71.         jnz     .no_disk_info
  72.         ; write info
  73.         add     edi, 3
  74.         sub     ecx, 2
  75.         js      ERROR_EXIT ; error not found path
  76.         ; get disk number
  77.         call    .get_number
  78.         mov     [disk_num],eax
  79.  
  80.         pusha
  81.         mov     al, 68
  82.         mov     bl, 17
  83.         mov     ecx, ioctl_info_disk
  84.         int     0x40
  85.  
  86.         call    write_disk_info
  87.         popa
  88.         jmp     .still
  89.  
  90. .no_disk_info:
  91.         cmp     word[edi], '-l'
  92.         jnz     .no_disk_list
  93.         ; write list disks
  94.         add     edi, 2
  95.         sub     ecx, 1
  96.         pusha
  97.  
  98.         mov     al, 68
  99.         mov     bl, 17
  100.         mov     ecx, ioctl_count_disk
  101.         int     0x40
  102.         test    eax, eax
  103.         jnz     ERROR_EXIT
  104.  
  105.         push    str_header_disk_list
  106.         call    _sc_puts
  107.  
  108.         mov     ecx, ioctl_list_disk.count
  109.         mov     eax, 68
  110.         mov     bl, 12
  111.         imul    ecx, sizeof.info_buffer
  112.         add     ecx, 4
  113.         mov     [ioctl_list_disk.size_buffer], ecx
  114.         int     0x40
  115.         test    eax, eax
  116.         jz      ERROR_EXIT
  117.  
  118.         mov     [ioctl_list_disk.buffer], eax
  119.         mov     esi, eax
  120.         mov     edi, eax
  121.         add     esi, 4
  122.  
  123.         mov     al, 68
  124.         mov     bl, 17
  125.         mov     ecx, ioctl_list_disk
  126.         int     0x40
  127.         test    eax, eax
  128.         jnz     ERROR_EXIT
  129.  
  130.         cmp     dword[edi], 0
  131.         jz      .end_list
  132. .next_item_list:
  133.  
  134.         ; num2str
  135.         push    dword 10
  136.         mov     ecx, esp
  137.         mov     eax, [esi + info_buffer.disk_num - info_buffer]
  138. @@:
  139.         xor     edx, edx
  140.         div     dword[esp]
  141.         dec     ecx
  142.         add     dl, '0'
  143.         mov     byte[ecx], dl
  144.         test    eax, eax
  145.         jnz     @b
  146.  
  147.         mov     edx, str_input_disk_number + 1
  148.         mov     dword[edx], '    '
  149. @@:
  150.         mov     al, byte[ecx]
  151.         mov     byte[edx], al
  152.         inc     edx
  153.         inc     ecx
  154.         cmp     ecx, esp
  155.         jnz      @b
  156.         ;-------
  157.         mov     ecx, esp
  158.         mov     eax, [esi + info_buffer.sector_size - info_buffer]
  159. @@:
  160.         xor     edx, edx
  161.         div     dword[esp]
  162.         dec     ecx
  163.         add     dl, '0'
  164.         mov     byte[ecx], dl
  165.         test    eax, eax
  166.         jnz     @b
  167.  
  168.         mov     edx, str_input_disk_sector
  169.         mov     dword[edx], '    '
  170. @@:
  171.         mov     al, byte[ecx]
  172.         mov     byte[edx], al
  173.         inc     edx
  174.         inc     ecx
  175.         cmp     ecx, esp
  176.         jnz      @b
  177.         ;-------
  178.         add      esp, 4
  179.         ; flags
  180.         mov     dword[str_input_disk_flags], '    '
  181.         cmp     dword[esi + info_buffer.flags - info_buffer], 1b
  182.         jnz     @f
  183.         mov     word[str_input_disk_flags], 'ro'
  184. @@:
  185.         cmp     dword[esi + info_buffer.flags - info_buffer], 11b
  186.         jnz     @f
  187.         mov     word[str_input_disk_flags], 'rw'
  188. @@:
  189.         ;-------
  190.         pusha
  191.         add     esi, info_buffer.path - info_buffer
  192.         push    esi
  193.         push    str_input_disk_number
  194.         call    _sc_puts
  195.         call    _sc_puts
  196.         push    str_newline
  197.         call    _sc_puts
  198.         popa
  199.  
  200.         add     esi, sizeof.info_buffer
  201.         dec     dword[edi]
  202.         jnz     .next_item_list
  203. .end_list:
  204.  
  205.         mov     eax, 68
  206.         mov     ebx, 13
  207.         mov     ecx, edi
  208.         int     0x40
  209.  
  210.         popa
  211.         jmp     .still
  212. .no_disk_list:
  213.         cmp     dword[param_cmd],0
  214.         jz      .no_cmd
  215.  
  216.         cmp     word[edi], '-s'
  217.         jnz     .no_sector_size
  218.         ; set sector size for -a command
  219.         add     edi, 3
  220.         sub     ecx, 2
  221.         js      ERROR_EXIT ; error
  222.         ; get number
  223.         call    .get_number
  224.         mov     [add_disk.size], eax
  225.         jmp     .still
  226. .no_sector_size:
  227.         cmp     word[edi], '-t'
  228.         jnz     .no_disk_type
  229.         ; set image type for -a command
  230.         add     edi, 3+3
  231.         sub     ecx, 2+3
  232.         js      ERROR_EXIT ; error
  233.  
  234.         or      dword[edi - 4], 0x20202020
  235.         cmp     dword[edi - 4], ' raw'
  236.         jnz     .still
  237.         ; TODO!!!
  238.         mov     dword[add_disk.type], 0
  239.         jmp     .still
  240. .no_disk_type:
  241.         cmp     word[edi], '-f'
  242.         jnz     .no_cmd
  243.         ; set flags for -a command
  244.         add     edi, 3+2
  245.         sub     ecx, 2+2
  246.         js      ERROR_EXIT ; error
  247.  
  248.         or      word[edi - 2], 0x2020
  249.         cmp     word[edi - 2], 'ro'
  250.         jnz     @f
  251.         mov     dword[add_disk.flags], 1b
  252.  
  253. @@:     cmp     word[edi - 2], 'rw'
  254.         jnz     .still
  255.         mov     dword[add_disk.flags], 11b
  256.         jmp     .still
  257. .no_cmd:
  258.         inc     edi
  259.         jmp     .still
  260. .end_parser:
  261.         ret
  262.  
  263. .get_str:
  264.         push    edi
  265.         inc     dword[esp]
  266.         mov     al, '"'
  267.         cmp     byte[edi], al
  268.         jz      @f
  269.         dec     dword[esp]
  270.         mov     al, ' '
  271.         dec     edi
  272. @@:
  273.         inc     edi
  274.         repne   scasb
  275.         and     byte[edi - 1], 0
  276.         pop     eax
  277.         ret
  278.  
  279. ; edx - buffer
  280. .copy_str:
  281.         mov     al, ' '
  282.         cmp     byte[edi], '"'
  283.         jnz     @f
  284.         mov     al, '"'
  285.         inc     edi
  286.         dec     ecx
  287. @@:
  288.         mov     ah, byte[edi]
  289.         test    ah, ah
  290.         jz      @f
  291.         cmp     ah, al
  292.         jz      @f
  293.         mov     byte[edx], ah
  294.         inc     edx
  295.         inc     edi
  296.         dec     ecx
  297.         jmp     @b
  298. @@:
  299.         mov     byte[edx], 0
  300.         ret
  301.  
  302. .get_number:
  303.         xor     eax, eax
  304. @@:
  305.         movzx   edx, byte[edi]
  306.         test    edx, edx
  307.         jz      @f
  308.         cmp     dl, ' '
  309.         jz      @f
  310.         sub     dl, '0'
  311.         js      ERROR_EXIT
  312.  
  313.         cmp     dl, 9
  314.         ja      ERROR_EXIT
  315.  
  316.         imul    eax, 10
  317.         add     eax, edx
  318.         dec     ecx
  319.         inc     edi
  320.         jmp     @b
  321. @@:
  322.         ret