Subversion Repositories Kolibri OS

Rev

Rev 3724 | Rev 3781 | 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 'KolibriOS',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   68,1
  251.         mcall   70,fileinfo
  252.         mov     [fs_error],eax
  253.         test    eax,eax
  254.         jnz     .file_error
  255. ;--------------------------------------
  256. if debug eq yes
  257. dps 'file info ok'
  258. newline
  259. end if
  260. ;--------------------------------------
  261.         xor     eax,eax
  262.         mov     [fileinfo.subfunction],eax      ;dword 0
  263.         mov     eax,[fileinfo.return]
  264.         mov     ecx,[eax+32]
  265. ;--------------------------------------
  266. if debug eq yes
  267. dps 'real file size: '
  268. dpd ecx
  269. newline
  270. end if
  271. ;--------------------------------------
  272.         test    ecx,ecx
  273.         jz      .file_error
  274.         mov     eax,304*32+32 ; 9 Kb
  275.         cmp     ecx,eax
  276.         jbe     @f
  277.         mov     ecx,eax
  278. ;-----------------------------------
  279. @@:
  280.         mov     [fileinfo.size],ecx
  281. ;--------------------------------------
  282. if debug eq yes
  283. dps 'get file'
  284. newline
  285. end if
  286. ;--------------------------------------
  287.         mcall   68,1
  288.         mcall   70,fileinfo
  289.         mov     [fs_error],eax
  290.         test    eax,eax
  291.         jz      @f
  292. ;       cmp     eax,6
  293. ;       jne     .file_error
  294. ;       xor     eax,eax
  295. ;       mov     [fs_error],eax
  296. ;       jmp     @f
  297. ;-----------------------------------
  298. .file_error:
  299. ;--------------------------------------
  300. if debug eq yes
  301. dps 'read file - error!'
  302. newline
  303. end if
  304. ;--------------------------------------
  305.         ret
  306. ;-----------------------------------
  307. @@:
  308. ;--------------------------------------
  309. if debug eq yes
  310. dps 'read file corrected size: '
  311. dpd dword[fileinfo.size]
  312. newline
  313. end if
  314. ;--------------------------------------
  315.         ret
  316. ;---------------------------------------------------------------------
  317. search_and_load_pointer_file_label:
  318.         mov     [fileinfo.return],dword folder_data_1
  319.         mov     ecx,[retrieved_devices_table_counter]
  320.         dec     ecx     ; /rd/1/ no need to check
  321.         mov     [fileinfo.name],dword read_folder_name
  322.         mov     esi,retrieved_devices_table
  323. ;       sub     esi,10  ; deleted because /rd/1/ no need to check
  324. .next_entry:
  325. ;--------------------------------------
  326. if debug eq yes
  327. newline
  328. dps 'copy next entry'
  329. newline
  330. end if
  331. ;--------------------------------------
  332.         add     esi,10
  333.         push    esi
  334.         add     esi,1
  335.         call    copy_folder_name
  336.         mov     esi,basic_file_name-1
  337.         dec     edi
  338.         call    copy_folder_name.1
  339.         pop     esi
  340. ;--------------------------------------
  341. if debug eq yes
  342.         mov     edx,[fileinfo.name]
  343.         push    ecx
  344.         call    debug_outstr
  345.         pop     ecx
  346. newline
  347. end if
  348. ;--------------------------------------
  349. ;       mcall   5,10
  350.         push    ecx
  351.         call    load_file
  352.         pop     ecx
  353.  
  354.         xor     eax,eax
  355.         cmp     [fs_error],eax
  356.         jne     @f
  357.         mov     eax,[fileinfo.size]
  358.         cmp     eax,[basic_file_size]
  359.         jae     .sucess
  360. @@:
  361.         dec     ecx
  362.         jnz     .next_entry
  363. ;--------------------------------------
  364. if debug eq yes
  365. dps 'additional parttition is not found!'
  366. newline
  367. end if
  368. ;--------------------------------------
  369.         ret
  370. .sucess:
  371.         call    compare_files_and_mount
  372.         cmp     [compare_flag],byte 0
  373.         jne     @b
  374.         ret
  375. ;---------------------------------------------------------------------
  376. compare_files_and_mount:
  377.         push    ecx esi
  378.         mov     ecx,[basic_file_size]
  379.         mov     esi,folder_data
  380.         mov     edi,folder_data_1
  381. .next_char:
  382.         cld
  383.         lodsb
  384.         mov     ah,[edi]
  385.         inc     edi
  386.         cmp     al,ah
  387.         jne     .not_match
  388.         dec     ecx
  389.         jnz     .next_char
  390.         mov     [compare_flag],byte 0
  391.         pop     esi ecx
  392. ;--------------------------------------
  393. if debug eq yes
  394. dps 'compare files sucess!'
  395. newline
  396. dps 'mount directory:'
  397. newline
  398.         mov     edx,esi
  399.         push    esi
  400.         call    debug_outstr
  401.         pop     esi
  402. newline
  403. end if
  404. ;--------------------------------------
  405. ; prepare real directory path for mounting
  406.         inc     esi
  407.         mov     edi,f30_3_work_area+64
  408.         call    proc_copy_patch
  409.         dec     edi
  410.         mov     esi,real_additional_dir
  411.         call    proc_copy_patch
  412. ; prepare fake directory name
  413.         mov     esi,additional_dir_name
  414.         mov     edi,f30_3_work_area
  415.         call    proc_copy_patch
  416. ; here is call kernel function to mount the found partition
  417. ; as "/KolibriOS" directory to root directory "/"
  418.         mcall   30,3,f30_3_work_area
  419.         ret
  420. ;--------------------------------------
  421. .not_match:
  422.         mov     [compare_flag],byte 1
  423.         pop     esi ecx
  424. ;--------------------------------------
  425. if debug eq yes
  426. dps 'compare files is not match!'
  427. newline
  428. end if
  429. ;--------------------------------------
  430.         ret
  431. ;---------------------------------------------------------------------
  432. copy_folder_name:
  433.         mov     edi,read_folder_name+1
  434. .1:
  435. proc_copy_patch:
  436.         cld
  437. @@:
  438.         lodsb
  439.         stosb
  440.         test    al,al
  441.         jnz     @r
  442.         ret
  443. ;---------------------------------------------------------------------
  444. copy_folder_name_1:
  445.         mov     edi,read_folder_1_name+1
  446.         jmp     proc_copy_patch
  447. ;---------------------------------------------------------------------
  448. if debug eq yes
  449. print_retrieved_devices_table:
  450.         mov     ecx,[retrieved_devices_table_counter]
  451.         mov     edx,retrieved_devices_table
  452. dps 'retrieved_devices_table:'
  453. newline
  454. dps '----------'
  455. newline
  456. @@:
  457.         push    ecx edx
  458.         call    debug_outstr
  459. newline
  460.         pop     edx ecx
  461.         add     edx,10
  462.         dec     ecx
  463.         jnz     @b
  464. newline
  465. dps '----------'
  466. newline
  467.         ret
  468. ;---------------------------------------------------------------------
  469. print_root_dir:
  470. dps '----------'
  471. dps 'root dir:'
  472. dps '----------'
  473. newline
  474.         pusha
  475.         mov     ecx,ebx
  476.         mov     edx,folder_data+32+40
  477. @@:
  478.         push    ecx edx
  479.         call    debug_outstr
  480. newline
  481.         pop     edx ecx
  482.         add     edx,304
  483.         dec     ecx
  484.         jnz     @b
  485.         popa
  486. newline
  487. dps '----------'
  488. newline
  489.         ret
  490. end if
  491. ;-------------------------------------------------------------------------------
  492. IM_END:
  493. ;-------------------------------------------------------------------------------
  494. align 4
  495. left_folder_block       rd 1
  496. right_folder_block      rd 1
  497. temp_counter_1          rd 1
  498. retrieved_devices_table_counter rd 1
  499. basic_file_size         rd 1
  500. fs_error                rd 1
  501. compare_flag            rb 1
  502. ;-------------------------------------------------------------------------------
  503. align 4
  504. f30_3_work_area:
  505.         rb 128
  506. ;-------------------------------------------------------------------------------
  507. align 4
  508. retrieved_devices_table:
  509.         rb 10*100
  510. ;-------------------------------------------------------------------------------
  511. align 4
  512. read_folder_name:
  513.         rb 256
  514. ;-------------------------------------------------------------------------------
  515. align 4
  516. read_folder_1_name:
  517.         rb 256
  518. ;-------------------------------------------------------------------------------
  519. align 4
  520. folder_data:
  521.         rb 304*32+32 ; 9 Kb
  522. ;-------------------------------------------------------------------------------
  523. align 4
  524. folder_data_1:
  525.         rb 304*32+32 ; 9 Kb
  526. ;-------------------------------------------------------------------------------
  527. align 4
  528.         rb 512
  529. stacktop:
  530. ;-------------------------------------------------------------------------------
  531. I_END:
  532. ;-------------------------------------------------------------------------------
  533.