Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------;
  2. ;      Copyright (C) 2023, Mikhail Frolov aka Doczom . All rights reserved.   ;
  3. ;           Distributed under terms of the GNU General Public License         ;
  4. ;                                                                             ;
  5. ;                   Demo program for the VIRT_DISK driver.                    ;
  6. ;                                                                             ;
  7. ;                       GNU GENERAL PUBLIC LICENSE                            ;
  8. ;                          Version 2, June 1991                               ;
  9. ;                                                                             ;
  10. ;-----------------------------------------------------------------------------;
  11. format  binary as ""
  12.   use32
  13.   org    0
  14.   db     'MENUET01'
  15.   dd     1, START, I_END, MEM, STACKTOP, PATH, 0
  16.  
  17. include 'parser.inc'
  18. include 'shell.inc'
  19. START:
  20.         call    _sc_init
  21.  
  22.         mov     al, 68
  23.         mov     bl, 16
  24.         mov     ecx, drv_name
  25.         int     0x40
  26.         mov     [ioctl_add_disk.hand], eax
  27.         mov     [ioctl_del_disk.hand], eax
  28.         mov     [ioctl_info_disk.hand], eax
  29.         mov     [ioctl_list_disk.hand], eax
  30.         mov     [ioctl_count_disk.hand], eax
  31.         test    eax, eax
  32.         jz      .end
  33.  
  34.         cmp     byte[PATH], 0
  35.         jz      .end
  36.  
  37.         call    parse_cmd
  38.  
  39.         cmp     dword[param_cmd],0
  40.         jz      .end
  41.  
  42.         mov     al, 68
  43.         mov     bl, 17
  44.         mov     ecx, ioctl_add_disk
  45.         int     0x40
  46.         test    eax, eax
  47.         jnz     @f
  48.         push    str_command_successfully
  49.         call    _sc_puts
  50.         jmp     .end
  51. @@:
  52.         push    str_error
  53.         call    _sc_puts
  54. .end:
  55.         call    _sc_exit
  56.         mov     eax,-1
  57.         int     0x40
  58. ERROR_EXIT:
  59.         push    str_runtime_err
  60.         call    _sc_puts
  61.  
  62.         call    _sc_exit
  63.         mov     eax,-1
  64.         int     0x40
  65. write_disk_info:
  66.         pusha
  67.         push    str_disk_info.path
  68.         call    _sc_puts
  69.  
  70.         push    info_buffer.path
  71.         call    _sc_puts
  72.  
  73.         push    str_newline
  74.         call    _sc_puts
  75.         popa
  76.         ret
  77.  
  78.  
  79. I_END:
  80. drv_name: db 'VIRT_DISK',0
  81.  
  82. ; messages
  83. str_runtime_err:
  84.         db 'Runtime error', 13, 10, 0
  85. str_command_successfully:
  86.         db 'Command successfully', 13, 10, 0
  87. str_header_disk_list:
  88.         db ' disk  | sector | flags | file', 13, 10
  89.         db '-------|--------|-------|---------------------',13, 10, 0
  90. str_input_disk_number:
  91.         db '       | ' ; ,0
  92. str_input_disk_sector:
  93.         db '       | ';,0
  94. str_input_disk_flags:
  95.         db '      | ',0
  96. str_error:
  97.         db 'Error',0
  98. str_disk_info:
  99. .num:   db 'Disk number: ',0
  100. ;.type:  db 'Type: ', 0
  101. ;.sector_size:
  102. ;        db 'Sector size: ', 0
  103. .path:  db 'File: ', 0
  104. str_newline:
  105.         db ' ', 13, 10, 0
  106.  
  107. ioctl_count_disk:
  108. .hand:  dd      0, 3 ;iocode
  109.         dd      .get_count_disk, 8
  110.         dd      ioctl_list_disk.count, 4
  111. .get_count_disk:
  112.         dd      0, 0
  113.  
  114. ioctl_list_disk:
  115. .hand:  dd      0, 3 ;iocode
  116.         dd      .inp, 8
  117. .buffer:
  118.         dd      0
  119. .size_buffer:
  120.         dd      0
  121. .inp:
  122.         dd      0
  123. .count: dd      0
  124.  
  125. ioctl_info_disk:
  126. .hand:  dd      0, 4 ;iocode
  127.         dd      disk_num, 4
  128.         dd      info_buffer, sizeof.info_buffer
  129. ioctl_del_disk:
  130. .hand:  dd      0, 2 ;iocode
  131.         dd      disk_num, 4
  132.         dd      0, 0
  133. ioctl_add_disk:
  134. .hand:  dd      0, 1 ;iocode
  135.         dd      add_disk, add_disk.end - add_disk
  136.         dd      disk_num, 4
  137.  
  138. disk_num: rd 0
  139. add_disk:
  140. .flags: dd 11b ;rw
  141. .type:  dd 0   ; TypeImage 0 - RAW
  142. .size:  dd 512
  143. .file:  rb 4096
  144. .end:
  145.  
  146. PATH:   rb 4096
  147.  
  148. info_buffer:
  149. .sector_count: rd 2
  150. .disk_hand:    rd 1
  151. .disk_num:     rd 1
  152. .flags:        rd 1
  153. .type:         rd 1
  154. .sector_size:  rd 1
  155. .path:         rb 4096
  156. sizeof.info_buffer =  $ - info_buffer
  157.  
  158.         rb      4096
  159. STACKTOP:
  160. MEM:
  161. ; EXAMPLE COMMANDS:
  162. ; virtdisk -f/sd0/4/kolibri.img -s512
  163. ; virtdisk -f/sd0/4/kolibri.img
  164. ; virtdisk -f/sd0/4/kolibri.iso -s2048
  165. ; default sector size = 512 for all disk
  166. ;                       2048 for ISO disk
  167.  
  168. ;struct  IMAGE_ADD_STRUCT
  169. ;        Flags           rd      1 ; 1-ro 2-wo 3-rw
  170. ;        TypeImage       rd      1 ; 0-raw 1-vhd 2-vdi 3-imd
  171. ;        SectorSize      rd      1
  172. ;        DiskPath        rb      maxPathLength
  173. ;ends