Subversion Repositories Kolibri OS

Rev

Rev 3664 | Rev 3676 | 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. ;-------------------------------------------------------------------------------
  77. debug equ no    ;yes
  78.  
  79. include '../../macros.inc'
  80.  
  81. if debug eq yes
  82. include '../../debug.inc'
  83. end if
  84. ;-------------------------------------------------------------------------------
  85. START:
  86.         mov     ebx,start_dir
  87.         mov     ax,[ebx]
  88.         mov     ebx,read_folder_name
  89.         mov     [ebx],ax
  90.         mov     ebx,read_folder_1_name
  91.         mov     [ebx],ax
  92.         call    device_detect_f70
  93. ;--------------------------------------
  94. if debug eq yes
  95.         call    print_retrieved_devices_table
  96. dps 'get basic file'
  97. newline
  98. end if
  99. ;--------------------------------------
  100.         call    load_file       ; download the master file
  101.         xor     eax,eax
  102.         cmp     [fs_error],eax
  103.         jne     exit
  104.         mov     eax,[fileinfo.size]
  105.         mov     [basic_file_size],eax  
  106.        
  107.         call    search_and_load_pointer_file_label
  108. ;---------------------------------------------------------------------
  109. exit:
  110. ;--------------------------------------
  111. if debug eq yes
  112. dps 'just exit'
  113. ;newline
  114. ;       mov     edx,read_folder_name
  115. ;       call    debug_outstr
  116. ;newline
  117. ;       mov     edx,read_folder_1_name
  118. ;       call    debug_outstr
  119. ;newline
  120. end if
  121. ;--------------------------------------
  122.         mcall   -1
  123. ;---------------------------------------------------------------------
  124. device_detect_f70:
  125. ;--------------------------------------
  126. if debug eq yes
  127. dps     'read_folder_name: '
  128.         mov     edx,read_folder_name
  129.         call    debug_outstr
  130. newline
  131. end if
  132. ;--------------------------------------
  133.         mcall   70,read_folder
  134.         test    eax,eax
  135.         jz      @f
  136.         cmp     eax,6
  137.         je      @f
  138. ;--------------------------------------
  139. if debug eq yes
  140. dps 'read_folder_error'
  141. newline
  142. ;       mov     edx,read_folder_name
  143. ;       call    debug_outstr
  144. ;newline
  145. end if
  146. ;--------------------------------------
  147.         jmp     exit
  148. @@:
  149. ;--------------------------------------
  150. if debug eq yes
  151.         call    print_root_dir
  152. end if
  153. ;--------------------------------------
  154.         mov     [left_folder_block],ebx
  155.         xor     eax,eax
  156.         mov     [temp_counter_1],eax
  157.         mov     [retrieved_devices_table_counter],eax
  158. .start_temp_counter_1:
  159.         imul    esi,[temp_counter_1],304
  160.         add     esi,[read_folder.return]
  161.         add     esi,32+40
  162.         call    copy_folder_name_1
  163. ;--------------------------------------
  164. if debug eq yes
  165. ;dps    'read_folder_1_name: '
  166. ;       mov     edx,read_folder_1_name
  167. ;       call    debug_outstr
  168. ;newline
  169. end if
  170. ;--------------------------------------
  171.         mcall   70,read_folder_1
  172.         test    eax,eax
  173.         jz      @f
  174.         cmp     eax,6
  175.         je      @f
  176. ;--------------------------------------
  177. if debug eq yes
  178. dps 'read_folder_error_1'
  179. newline
  180. ;       mov     edx,read_folder_1_name
  181. ;       call    debug_outstr
  182. ;newline
  183. end if
  184. ;--------------------------------------
  185.         jmp     exit
  186. @@:
  187.         mov     eax,[read_folder_1.return]
  188.         cmp     [eax+4],dword 0
  189.         je      .continue
  190.         mov     [right_folder_block],ebx
  191.         xor     ebp,ebp
  192. .start_copy_device_patch:
  193.         imul    edi,[retrieved_devices_table_counter],10
  194.         add     edi,retrieved_devices_table
  195.         mov     [edi],byte '/'
  196.         inc     edi
  197.         imul    esi,[temp_counter_1],304
  198.         add     esi,[read_folder.return]
  199.         add     esi,32+40
  200.         call    proc_copy_patch
  201.         imul    esi,ebp,304
  202.         add     esi,[read_folder_1.return]
  203.         add     esi,32+40
  204.         mov     [edi-1],byte '/'
  205.         call    proc_copy_patch
  206.         inc     [retrieved_devices_table_counter]
  207.         inc     ebp
  208.         cmp     ebp,[right_folder_block]
  209.         jb      .start_copy_device_patch
  210. .continue:
  211.         inc     [temp_counter_1]
  212.         mov     eax,[temp_counter_1]
  213.         cmp     eax,[left_folder_block]
  214.         jb      .start_temp_counter_1
  215.         mov     esi,retrieved_devices_table+1
  216.         call    copy_folder_name
  217.         mov     esi,retrieved_devices_table+3
  218.         xor     ecx,ecx
  219. @@:
  220.         add     esi,8
  221.         cld
  222.         lodsw
  223.         inc     ecx
  224.         cmp     ecx,[retrieved_devices_table_counter]
  225.         ja      @f
  226.         cmp     ax,'hd'
  227.         jne     @r
  228.         sub     esi,2
  229.         call    copy_folder_name_1
  230.         ret
  231. @@:
  232.         mov     esi,retrieved_devices_table+1
  233.         call    copy_folder_name_1
  234.         ret
  235. ;---------------------------------------------------------------------
  236. load_file:
  237.         mov     [fileinfo.subfunction],dword 5
  238.         xor     eax,eax
  239.         mov     [fileinfo.size],eax
  240.         mov     [fs_error],eax
  241. ;--------------------------------------
  242. if debug eq yes
  243. dps 'get file info'
  244. newline
  245. end if
  246. ;--------------------------------------
  247.         mcall   70,fileinfo
  248.         mov     [fs_error],eax
  249.         test    eax,eax
  250.         jnz     .file_error
  251. ;--------------------------------------
  252. if debug eq yes
  253. dps 'file info ok'
  254. newline
  255. end if
  256. ;--------------------------------------
  257.         xor     eax,eax
  258.         mov     [fileinfo.subfunction],eax      ;dword 0
  259.         mov     eax,[fileinfo.return]
  260.         mov     ecx,[eax+32]
  261. ;--------------------------------------
  262. if debug eq yes
  263. dps 'real file size: '
  264. dpd ecx
  265. newline
  266. end if
  267. ;--------------------------------------
  268.         test    ecx,ecx
  269.         jz      .file_error
  270.         mov     eax,304*32+32 ; 9 Kb
  271.         cmp     ecx,eax
  272.         jbe     @f
  273.         mov     ecx,eax
  274. ;-----------------------------------
  275. @@:    
  276.         mov     [fileinfo.size],ecx
  277. ;--------------------------------------
  278. if debug eq yes
  279. dps 'get file'
  280. newline
  281. end if
  282. ;--------------------------------------
  283.         mcall   70,fileinfo
  284.         mov     [fs_error],eax
  285.         test    eax,eax
  286.         jz      @f
  287. ;       cmp     eax,6
  288. ;       jne     .file_error
  289. ;       xor     eax,eax
  290. ;       mov     [fs_error],eax
  291. ;       jmp     @f
  292. ;-----------------------------------
  293. .file_error:
  294. ;--------------------------------------
  295. if debug eq yes
  296. dps 'read file - error!'
  297. newline
  298. end if
  299. ;--------------------------------------
  300.         ret
  301. ;-----------------------------------   
  302. @@:
  303. ;--------------------------------------
  304. if debug eq yes
  305. dps 'read file corrected size: '
  306. dpd dword[fileinfo.size]
  307. newline
  308. end if
  309. ;--------------------------------------
  310.         ret
  311. ;---------------------------------------------------------------------
  312. search_and_load_pointer_file_label:
  313.         mov     [fileinfo.return],dword folder_data_1
  314.         mov     ecx,[retrieved_devices_table_counter]
  315.         dec     ecx     ; /rd/1/ no need to check
  316.         mov     [fileinfo.name],dword read_folder_name
  317.         mov     esi,retrieved_devices_table
  318. ;       sub     esi,10  ; deleted because /rd/1/ no need to check
  319. .next_entry:
  320. ;--------------------------------------
  321. if debug eq yes
  322. newline
  323. dps 'copy next entry'
  324. newline
  325. end if
  326. ;--------------------------------------
  327.         add     esi,10
  328.         push    esi
  329.         add     esi,1
  330.         call    copy_folder_name
  331.         mov     esi,basic_file_name-1
  332.         dec     edi
  333.         call    copy_folder_name.1
  334.         pop     esi
  335. ;--------------------------------------
  336. if debug eq yes
  337.         mov     edx,[fileinfo.name]
  338.         push    ecx
  339.         call    debug_outstr
  340.         pop     ecx
  341. newline
  342. end if
  343. ;--------------------------------------
  344. ;       mcall   5,10
  345.         push    ecx
  346.         call    load_file
  347.         pop     ecx
  348.  
  349.         xor     eax,eax
  350.         cmp     [fs_error],eax
  351.         jne     @f
  352.         mov     eax,[fileinfo.size]
  353.         cmp     eax,[basic_file_size]
  354.         jae     .sucess
  355. @@:
  356.         dec     ecx
  357.         jnz     .next_entry
  358. ;--------------------------------------
  359. if debug eq yes
  360. dps 'additional parttition is not found!'
  361. newline
  362. end if
  363. ;--------------------------------------
  364.         ret
  365. .sucess:
  366.         call    compare_files_and_mount
  367.         cmp     [compare_flag],byte 0
  368.         jne     @b
  369.         ret
  370. ;---------------------------------------------------------------------
  371. compare_files_and_mount:
  372.         push    ecx esi
  373.         mov     ecx,[basic_file_size]
  374.         mov     esi,folder_data
  375.         mov     edi,folder_data_1
  376. .next_char:
  377.         cld
  378.         lodsb
  379.         mov     ah,[edi]
  380.         inc     edi
  381.         cmp     al,ah
  382.         jne     .not_match
  383.         dec     ecx
  384.         jnz     .next_char
  385.         mov     [compare_flag],byte 0
  386.         pop     esi ecx
  387. ;--------------------------------------
  388. if debug eq yes
  389. dps 'compare files sucess!'
  390. newline
  391. dps 'mount directory:'
  392. newline
  393.         mov     edx,esi
  394.         push    esi
  395.         call    debug_outstr
  396.         pop     esi
  397. newline
  398. end if
  399. ;--------------------------------------
  400. ; prepare real directory path for mounting
  401.         inc     esi
  402.         mov     edi,f30_3_work_area+64
  403.         call    proc_copy_patch
  404. ; prepare fake directory name
  405.         mov     esi,additional_dir_name
  406.         mov     edi,f30_3_work_area
  407.         call    proc_copy_patch
  408. ; here is call kernel function to mount the found partition
  409. ; as "/addappl" directory to root directory "/"
  410.         mcall   30,3,f30_3_work_area
  411.         ret
  412. ;--------------------------------------
  413. .not_match:
  414.         mov     [compare_flag],byte 1
  415.         pop     esi ecx
  416. ;--------------------------------------
  417. if debug eq yes
  418. dps 'compare files is not match!'
  419. newline
  420. end if
  421. ;--------------------------------------
  422.         ret
  423. ;---------------------------------------------------------------------
  424. copy_folder_name:
  425.         mov     edi,read_folder_name+1
  426. .1:
  427. proc_copy_patch:
  428.         cld
  429. @@:
  430.         lodsb
  431.         stosb
  432.         test    al,al
  433.         jnz     @r
  434.         ret
  435. ;---------------------------------------------------------------------
  436. copy_folder_name_1:
  437.         mov     edi,read_folder_1_name+1
  438.         jmp     proc_copy_patch
  439. ;---------------------------------------------------------------------
  440. if debug eq yes
  441. print_retrieved_devices_table:
  442.         mov     ecx,[retrieved_devices_table_counter]
  443.         mov     edx,retrieved_devices_table
  444. dps 'retrieved_devices_table:'
  445. newline
  446. dps '----------'
  447. newline
  448. @@:
  449.         push    ecx edx
  450.         call    debug_outstr
  451. newline
  452.         pop     edx ecx
  453.         add     edx,10
  454.         dec     ecx
  455.         jnz     @b
  456. newline
  457. dps '----------'
  458. newline
  459.         ret
  460. ;---------------------------------------------------------------------
  461. print_root_dir:
  462. dps '----------'
  463. dps 'root dir:'
  464. dps '----------'
  465. newline
  466.         pusha
  467.         mov     ecx,ebx
  468.         mov     edx,folder_data+32+40
  469. @@:
  470.         push    ecx edx
  471.         call    debug_outstr
  472. newline
  473.         pop     edx ecx
  474.         add     edx,304
  475.         dec     ecx
  476.         jnz     @b
  477.         popa
  478. newline
  479. dps '----------'
  480. newline
  481.         ret
  482. end if
  483. ;-------------------------------------------------------------------------------
  484. IM_END:
  485. ;-------------------------------------------------------------------------------
  486. align 4
  487. left_folder_block       rd 1
  488. right_folder_block      rd 1
  489. temp_counter_1          rd 1
  490. retrieved_devices_table_counter rd 1
  491. basic_file_size         rd 1
  492. fs_error                rd 1
  493. compare_flag            rb 1
  494. ;-------------------------------------------------------------------------------
  495. align 4
  496. f30_3_work_area:
  497.         rb 128
  498. ;-------------------------------------------------------------------------------
  499. align 4
  500. retrieved_devices_table:
  501.         rb 10*100
  502. ;-------------------------------------------------------------------------------
  503. align 4
  504. read_folder_name:
  505.         rb 256
  506. ;-------------------------------------------------------------------------------
  507. align 4
  508. read_folder_1_name:
  509.         rb 256
  510. ;-------------------------------------------------------------------------------
  511. align 4
  512. folder_data:
  513.         rb 304*32+32 ; 9 Kb
  514. ;-------------------------------------------------------------------------------
  515. align 4
  516. folder_data_1:
  517.         rb 304*32+32 ; 9 Kb
  518. ;-------------------------------------------------------------------------------
  519. align 4
  520.         rb 512
  521. stacktop:
  522. ;-------------------------------------------------------------------------------
  523. I_END:
  524. ;-------------------------------------------------------------------------------