Subversion Repositories Kolibri OS

Rev

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

  1. ; Search Additional Partition for KolibriOS applications
  2. ;
  3. ; Copyright (c) 2013, Marat Zakiyanov aka Mario79, aka Mario
  4. ; All rights reserved.
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions are met:
  8. ;        * Redistributions of source code must retain the above copyright
  9. ;          notice, this list of conditions and the following disclaimer.
  10. ;        * Redistributions in binary form must reproduce the above copyright
  11. ;          notice, this list of conditions and the following disclaimer in the
  12. ;          documentation and/or other materials provided with the distribution.
  13. ;        * Neither the name of the <organization> nor the
  14. ;          names of its contributors may be used to endorse or promote products
  15. ;          derived from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
  18. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ;*****************************************************************************
  28.         use32
  29.         org     0x0
  30.  
  31.         db      'MENUET01'
  32.         dd 0x01
  33.         dd START
  34.         dd IM_END
  35.         dd I_END
  36.         dd stacktop
  37.         dd 0x0
  38.         dd 0x0
  39. ;---------------------------------------------------------------------
  40. fileinfo:
  41. .subfunction    dd 5
  42. .Offset         dd 0
  43. .Offset_1       dd 0
  44. .size           dd 0
  45. .return         dd folder_data
  46.                 db 0
  47. .name:          dd basic_file_path
  48. ;---------------------------------------------------------------------
  49. read_folder:
  50. .subfunction    dd 1
  51. .start          dd 0
  52. .flags          dd 0
  53. .size           dd 32
  54. .return         dd folder_data
  55.                 db 0
  56. .name:          dd read_folder_name
  57. ;---------------------------------------------------------------------
  58. read_folder_1:
  59. .subfunction    dd 1
  60. .start          dd 0
  61. .flags          dd 0
  62. .size           dd 32
  63. .return         dd folder_data_1
  64.                 db 0
  65. .name:          dd read_folder_1_name
  66. ;---------------------------------------------------------------------
  67. start_dir:
  68.         db '/',0
  69. ;-------------------------------------------------------------------------------
  70. basic_file_path:
  71.         db '/rd/1/'
  72. basic_file_name:
  73.         db 'kolibri.lbl',0
  74. additional_dir_name:
  75.         db 'addappl',0
  76. real_additional_dir:
  77.         db '/kolibrios',0
  78. ;-------------------------------------------------------------------------------
  79. debug equ no    ;yes
  80.  
  81. include '../../macros.inc'
  82.  
  83. if debug eq yes
  84. include '../../debug.inc'
  85. end if
  86. ;-------------------------------------------------------------------------------
  87. START:
  88.         mcall   5,500
  89.         mov     ebx,start_dir
  90.         mov     ax,[ebx]
  91.         mov     ebx,read_folder_name
  92.         mov     [ebx],ax
  93.         mov     ebx,read_folder_1_name
  94.         mov     [ebx],ax
  95.         call    device_detect_f70
  96. ;--------------------------------------
  97. if debug eq yes
  98.         call    print_retrieved_devices_table
  99. dps 'get basic file'
  100. newline
  101. end if
  102. ;--------------------------------------
  103.         call    load_file       ; download the master file
  104.         xor     eax,eax
  105.         cmp     [fs_error],eax
  106.         jne     exit
  107.         mov     eax,[fileinfo.size]
  108.         mov     [basic_file_size],eax  
  109.        
  110.         call    search_and_load_pointer_file_label
  111. ;---------------------------------------------------------------------
  112. exit:
  113. ;--------------------------------------
  114. if debug eq yes
  115. dps 'just exit'
  116. ;newline
  117. ;       mov     edx,read_folder_name
  118. ;       call    debug_outstr
  119. ;newline
  120. ;       mov     edx,read_folder_1_name
  121. ;       call    debug_outstr
  122. ;newline
  123. end if
  124. ;--------------------------------------
  125.         mcall   -1
  126. ;---------------------------------------------------------------------
  127. device_detect_f70:
  128. ;--------------------------------------
  129. if debug eq yes
  130. dps     'read_folder_name: '
  131.         mov     edx,read_folder_name
  132.         call    debug_outstr
  133. newline
  134. end if
  135. ;--------------------------------------
  136.         mcall   70,read_folder
  137.         test    eax,eax
  138.         jz      @f
  139.         cmp     eax,6
  140.         je      @f
  141. ;--------------------------------------
  142. if debug eq yes
  143. dps 'read_folder_error'
  144. newline
  145. ;       mov     edx,read_folder_name
  146. ;       call    debug_outstr
  147. ;newline
  148. end if
  149. ;--------------------------------------
  150.         jmp     exit
  151. @@:
  152. ;--------------------------------------
  153. if debug eq yes
  154.         call    print_root_dir
  155. end if
  156. ;--------------------------------------
  157.         mov     [left_folder_block],ebx
  158.         xor     eax,eax
  159.         mov     [temp_counter_1],eax
  160.         mov     [retrieved_devices_table_counter],eax
  161. .start_temp_counter_1:
  162.         imul    esi,[temp_counter_1],304
  163.         add     esi,[read_folder.return]
  164.         add     esi,32+40
  165.         call    copy_folder_name_1
  166. ;--------------------------------------
  167. if debug eq yes
  168. ;dps    'read_folder_1_name: '
  169. ;       mov     edx,read_folder_1_name
  170. ;       call    debug_outstr
  171. ;newline
  172. end if
  173. ;--------------------------------------
  174.         mcall   70,read_folder_1
  175.         test    eax,eax
  176.         jz      @f
  177.         cmp     eax,6
  178.         je      @f
  179. ;--------------------------------------
  180. if debug eq yes
  181. dps 'read_folder_error_1'
  182. newline
  183. ;       mov     edx,read_folder_1_name
  184. ;       call    debug_outstr
  185. ;newline
  186. end if
  187. ;--------------------------------------
  188.         jmp     exit
  189. @@:
  190.         mov     eax,[read_folder_1.return]
  191.         cmp     [eax+4],dword 0
  192.         je      .continue
  193.         mov     [right_folder_block],ebx
  194.         xor     ebp,ebp
  195. .start_copy_device_patch:
  196.         imul    edi,[retrieved_devices_table_counter],10
  197.         add     edi,retrieved_devices_table
  198.         mov     [edi],byte '/'
  199.         inc     edi
  200.         imul    esi,[temp_counter_1],304
  201.         add     esi,[read_folder.return]
  202.         add     esi,32+40
  203.         call    proc_copy_patch
  204.         imul    esi,ebp,304
  205.         add     esi,[read_folder_1.return]
  206.         add     esi,32+40
  207.         mov     [edi-1],byte '/'
  208.         call    proc_copy_patch
  209.         inc     [retrieved_devices_table_counter]
  210.         inc     ebp
  211.         cmp     ebp,[right_folder_block]
  212.         jb      .start_copy_device_patch
  213. .continue:
  214.         inc     [temp_counter_1]
  215.         mov     eax,[temp_counter_1]
  216.         cmp     eax,[left_folder_block]
  217.         jb      .start_temp_counter_1
  218.         mov     esi,retrieved_devices_table+1
  219.         call    copy_folder_name
  220.         mov     esi,retrieved_devices_table+3
  221.         xor     ecx,ecx
  222. @@:
  223.         add     esi,8
  224.         cld
  225.         lodsw
  226.         inc     ecx
  227.         cmp     ecx,[retrieved_devices_table_counter]
  228.         ja      @f
  229.         cmp     ax,'hd'
  230.         jne     @r
  231.         sub     esi,2
  232.         call    copy_folder_name_1
  233.         ret
  234. @@:
  235.         mov     esi,retrieved_devices_table+1
  236.         call    copy_folder_name_1
  237.         ret
  238. ;---------------------------------------------------------------------
  239. load_file:
  240.         mov     [fileinfo.subfunction],dword 5
  241.         xor     eax,eax
  242.         mov     [fileinfo.size],eax
  243.         mov     [fs_error],eax
  244. ;--------------------------------------
  245. if debug eq yes
  246. dps 'get file info'
  247. newline
  248. end if
  249. ;--------------------------------------
  250.         mcall   70,fileinfo
  251.         mov     [fs_error],eax
  252.         test    eax,eax
  253.         jnz     .file_error
  254. ;--------------------------------------
  255. if debug eq yes
  256. dps 'file info ok'
  257. newline
  258. end if
  259. ;--------------------------------------
  260.         xor     eax,eax
  261.         mov     [fileinfo.subfunction],eax      ;dword 0
  262.         mov     eax,[fileinfo.return]
  263.         mov     ecx,[eax+32]
  264. ;--------------------------------------
  265. if debug eq yes
  266. dps 'real file size: '
  267. dpd ecx
  268. newline
  269. end if
  270. ;--------------------------------------
  271.         test    ecx,ecx
  272.         jz      .file_error
  273.         mov     eax,304*32+32 ; 9 Kb
  274.         cmp     ecx,eax
  275.         jbe     @f
  276.         mov     ecx,eax
  277. ;-----------------------------------
  278. @@:    
  279.         mov     [fileinfo.size],ecx
  280. ;--------------------------------------
  281. if debug eq yes
  282. dps 'get file'
  283. newline
  284. end if
  285. ;--------------------------------------
  286.         mcall   70,fileinfo
  287.         mov     [fs_error],eax
  288.         test    eax,eax
  289.         jz      @f
  290. ;       cmp     eax,6
  291. ;       jne     .file_error
  292. ;       xor     eax,eax
  293. ;       mov     [fs_error],eax
  294. ;       jmp     @f
  295. ;-----------------------------------
  296. .file_error:
  297. ;--------------------------------------
  298. if debug eq yes
  299. dps 'read file - error!'
  300. newline
  301. end if
  302. ;--------------------------------------
  303.         ret
  304. ;-----------------------------------   
  305. @@:
  306. ;--------------------------------------
  307. if debug eq yes
  308. dps 'read file corrected size: '
  309. dpd dword[fileinfo.size]
  310. newline
  311. end if
  312. ;--------------------------------------
  313.         ret
  314. ;---------------------------------------------------------------------
  315. search_and_load_pointer_file_label:
  316.         mov     [fileinfo.return],dword folder_data_1
  317.         mov     ecx,[retrieved_devices_table_counter]
  318.         dec     ecx     ; /rd/1/ no need to check
  319.         mov     [fileinfo.name],dword read_folder_name
  320.         mov     esi,retrieved_devices_table
  321. ;       sub     esi,10  ; deleted because /rd/1/ no need to check
  322. .next_entry:
  323. ;--------------------------------------
  324. if debug eq yes
  325. newline
  326. dps 'copy next entry'
  327. newline
  328. end if
  329. ;--------------------------------------
  330.         add     esi,10
  331.         push    esi
  332.         add     esi,1
  333.         call    copy_folder_name
  334.         mov     esi,basic_file_name-1
  335.         dec     edi
  336.         call    copy_folder_name.1
  337.         pop     esi
  338. ;--------------------------------------
  339. if debug eq yes
  340.         mov     edx,[fileinfo.name]
  341.         push    ecx
  342.         call    debug_outstr
  343.         pop     ecx
  344. newline
  345. end if
  346. ;--------------------------------------
  347. ;       mcall   5,10
  348.         push    ecx
  349.         call    load_file
  350.         pop     ecx
  351.  
  352.         xor     eax,eax
  353.         cmp     [fs_error],eax
  354.         jne     @f
  355.         mov     eax,[fileinfo.size]
  356.         cmp     eax,[basic_file_size]
  357.         jae     .sucess
  358. @@:
  359.         dec     ecx
  360.         jnz     .next_entry
  361. ;--------------------------------------
  362. if debug eq yes
  363. dps 'additional parttition is not found!'
  364. newline
  365. end if
  366. ;--------------------------------------
  367.         ret
  368. .sucess:
  369.         call    compare_files_and_mount
  370.         cmp     [compare_flag],byte 0
  371.         jne     @b
  372.         ret
  373. ;---------------------------------------------------------------------
  374. compare_files_and_mount:
  375.         push    ecx esi
  376.         mov     ecx,[basic_file_size]
  377.         mov     esi,folder_data
  378.         mov     edi,folder_data_1
  379. .next_char:
  380.         cld
  381.         lodsb
  382.         mov     ah,[edi]
  383.         inc     edi
  384.         cmp     al,ah
  385.         jne     .not_match
  386.         dec     ecx
  387.         jnz     .next_char
  388.         mov     [compare_flag],byte 0
  389.         pop     esi ecx
  390. ;--------------------------------------
  391. if debug eq yes
  392. dps 'compare files sucess!'
  393. newline
  394. dps 'mount directory:'
  395. newline
  396.         mov     edx,esi
  397.         push    esi
  398.         call    debug_outstr
  399.         pop     esi
  400. newline
  401. end if
  402. ;--------------------------------------
  403. ; prepare real directory path for mounting
  404.         inc     esi
  405.         mov     edi,f30_3_work_area+64
  406.         call    proc_copy_patch
  407.         dec     edi
  408.         mov     esi,real_additional_dir
  409.         call    proc_copy_patch
  410. ; prepare fake directory name
  411.         mov     esi,additional_dir_name
  412.         mov     edi,f30_3_work_area
  413.         call    proc_copy_patch
  414. ; here is call kernel function to mount the found partition
  415. ; as "/addappl" directory to root directory "/"
  416.         mcall   30,3,f30_3_work_area
  417.         ret
  418. ;--------------------------------------
  419. .not_match:
  420.         mov     [compare_flag],byte 1
  421.         pop     esi ecx
  422. ;--------------------------------------
  423. if debug eq yes
  424. dps 'compare files is not match!'
  425. newline
  426. end if
  427. ;--------------------------------------
  428.         ret
  429. ;---------------------------------------------------------------------
  430. copy_folder_name:
  431.         mov     edi,read_folder_name+1
  432. .1:
  433. proc_copy_patch:
  434.         cld
  435. @@:
  436.         lodsb
  437.         stosb
  438.         test    al,al
  439.         jnz     @r
  440.         ret
  441. ;---------------------------------------------------------------------
  442. copy_folder_name_1:
  443.         mov     edi,read_folder_1_name+1
  444.         jmp     proc_copy_patch
  445. ;---------------------------------------------------------------------
  446. if debug eq yes
  447. print_retrieved_devices_table:
  448.         mov     ecx,[retrieved_devices_table_counter]
  449.         mov     edx,retrieved_devices_table
  450. dps 'retrieved_devices_table:'
  451. newline
  452. dps '----------'
  453. newline
  454. @@:
  455.         push    ecx edx
  456.         call    debug_outstr
  457. newline
  458.         pop     edx ecx
  459.         add     edx,10
  460.         dec     ecx
  461.         jnz     @b
  462. newline
  463. dps '----------'
  464. newline
  465.         ret
  466. ;---------------------------------------------------------------------
  467. print_root_dir:
  468. dps '----------'
  469. dps 'root dir:'
  470. dps '----------'
  471. newline
  472.         pusha
  473.         mov     ecx,ebx
  474.         mov     edx,folder_data+32+40
  475. @@:
  476.         push    ecx edx
  477.         call    debug_outstr
  478. newline
  479.         pop     edx ecx
  480.         add     edx,304
  481.         dec     ecx
  482.         jnz     @b
  483.         popa
  484. newline
  485. dps '----------'
  486. newline
  487.         ret
  488. end if
  489. ;-------------------------------------------------------------------------------
  490. IM_END:
  491. ;-------------------------------------------------------------------------------
  492. align 4
  493. left_folder_block       rd 1
  494. right_folder_block      rd 1
  495. temp_counter_1          rd 1
  496. retrieved_devices_table_counter rd 1
  497. basic_file_size         rd 1
  498. fs_error                rd 1
  499. compare_flag            rb 1
  500. ;-------------------------------------------------------------------------------
  501. align 4
  502. f30_3_work_area:
  503.         rb 128
  504. ;-------------------------------------------------------------------------------
  505. align 4
  506. retrieved_devices_table:
  507.         rb 10*100
  508. ;-------------------------------------------------------------------------------
  509. align 4
  510. read_folder_name:
  511.         rb 256
  512. ;-------------------------------------------------------------------------------
  513. align 4
  514. read_folder_1_name:
  515.         rb 256
  516. ;-------------------------------------------------------------------------------
  517. align 4
  518. folder_data:
  519.         rb 304*32+32 ; 9 Kb
  520. ;-------------------------------------------------------------------------------
  521. align 4
  522. folder_data_1:
  523.         rb 304*32+32 ; 9 Kb
  524. ;-------------------------------------------------------------------------------
  525. align 4
  526.         rb 512
  527. stacktop:
  528. ;-------------------------------------------------------------------------------
  529. I_END:
  530. ;-------------------------------------------------------------------------------