Subversion Repositories Kolibri OS

Rev

Rev 8241 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; Search Additional Partition for KolibriOS applications
  2. ;
  3. ; Copyright (c) 2013-2014, 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, START, IM_END, I_END, stacktop
  33.         params dd PARAMS
  34.         dd 0x0
  35. ;---------------------------------------------------------------------
  36. delay dd 500
  37. mount_attempt dd 0
  38. ;---------------------------------------------------------------------
  39. fileinfo:
  40. .subfunction    dd 5
  41. .Offset         dd 0
  42. .Offset_1       dd 0
  43. .size           dd 0
  44. .return         dd folder_data
  45.                 db 0
  46. .name:          dd basic_file_path
  47. ;---------------------------------------------------------------------
  48. read_folder:
  49. .subfunction    dd 1
  50. .start          dd 0
  51. .flags          dd 0
  52. .size           dd 32
  53. .return         dd folder_data
  54.                 db 0
  55. .name:          dd read_folder_name
  56. ;---------------------------------------------------------------------
  57. read_folder_1:
  58. .subfunction    dd 1
  59. .start          dd 0
  60. .flags          dd 0
  61. .size           dd 32
  62. .return         dd folder_data_1
  63.                 db 0
  64. .name:          dd read_folder_1_name
  65. ;---------------------------------------------------------------------
  66. start_dir:
  67.         db '/',0
  68. ;-------------------------------------------------------------------------------
  69. basic_file_path:
  70.         db '/sys/settings/'
  71. basic_file_name:
  72.         db 'kolibrios/res/system/kolibri.lbl',0
  73. real_additional_dir:
  74.         db '/kolibrios',0
  75. ;-------------------------------------------------------------------------------
  76. include '../../macros.inc'
  77.  
  78. define __DEBUG__ 1
  79. define __DEBUG_LEVEL__ 2        ; 1 = verbose, 2 = main only
  80. include "../../debug-fdo.inc"
  81. ;-------------------------------------------------------------------------------
  82. START:
  83. ; process cmdline params
  84.         mov     esi, [params]
  85.         cmp     [esi], byte '/'
  86.         jne @f
  87.         mov esi, [params] ;user gave us the path so lets mount it
  88.         inc     esi
  89.         mov     edi,f30_3_work_area+64
  90.         call    proc_copy_path
  91.         mcall   30,3,f30_3_work_area
  92.         mcall   -1
  93. @@:    
  94.         test    [esi], byte 0xFF
  95.         jz      .params_done
  96.         cmp     word[esi], '-d' ; delay
  97.         jne     .params_done
  98.         add     esi, 2
  99. ; str2uint(delay)
  100.         xor     eax, eax
  101.         xor     ecx, ecx
  102. .convert:
  103.         lodsb
  104.         test    al, al
  105.         jz      .converted
  106.         lea     ecx, [ecx + ecx * 4]
  107.         lea     ecx, [eax + ecx * 2 - '0']
  108.         jmp     .convert
  109. .converted:
  110.         mov     [delay], ecx
  111. ;--------------------------------------
  112.         DEBUGF  1, "Searchap: get basic file\n"
  113.         call    load_file       ; download the master file
  114.         xor     eax,eax
  115.         cmp     [fs_error],eax
  116.         jne     exit
  117.         mov     eax,[fileinfo.size]
  118.         mov     [basic_file_size],eax
  119. .params_done:
  120. ;--------------------------------------
  121.         mov     ebx,start_dir
  122.         mov     ax,[ebx]
  123.         mov     ebx,read_folder_name
  124.         mov     [ebx],ax
  125.         mov     ebx,read_folder_1_name
  126.         mov     [ebx],ax
  127.         call    device_detect_f70
  128. ;--------------------------------------
  129.         call    print_retrieved_devices_table
  130.         call    search_and_load_pointer_file_label
  131. ;---------------------------------------------------------------------
  132. exit:
  133. ;--------------------------------------
  134.         DEBUGF  1, "Searchap: just exit\n"
  135. ;--------------------------------------
  136.         cmp [mount_dir],1
  137.         je @f
  138.         cmp [mount_attempt], 1
  139.         je @f
  140.         mov [mount_attempt], 1 ;second mount attempt with delay
  141.         DEBUGF  2, "Searchap: second attempt after 5 seconds!\n"
  142.         mcall   5, [delay]
  143.         jmp START.params_done
  144. @@:
  145.         mcall   -1
  146. ;---------------------------------------------------------------------
  147. device_detect_f70:
  148. ;--------------------------------------
  149.         DEBUGF  1, "Searchap: read_folder_name: %s\n",read_folder_name
  150. ;--------------------------------------
  151.         mcall   70,read_folder
  152.         test    eax,eax
  153.         jz      @f
  154.         cmp     eax,6
  155.         je      @f
  156. ;--------------------------------------
  157.         DEBUGF  1, "Searchap: read_folder_error\n"
  158. ;--------------------------------------
  159.         jmp     exit
  160. @@:
  161. ;--------------------------------------
  162.         call    print_root_dir
  163. ;--------------------------------------
  164.         mov     [left_folder_block],ebx
  165.         xor     eax,eax
  166.         mov     [temp_counter_1],eax
  167.         mov     [retrieved_devices_table_counter],eax
  168. .start_temp_counter_1:
  169.         imul    esi,[temp_counter_1],304
  170.         add     esi,[read_folder.return]
  171.         add     esi,32+40
  172.         call    copy_folder_name_1
  173. ;--------------------------------------
  174.         DEBUGF  1, "Searchap: read_folder_1_name: %s\n",read_folder_1_name
  175. ;--------------------------------------
  176.         mcall   70,read_folder_1
  177.         test    eax,eax
  178.         jz      @f
  179.         cmp     eax,6
  180.         je      @f
  181. ;--------------------------------------
  182.         DEBUGF  1, "Searchap: read_folder_error_1\n"
  183. ;--------------------------------------
  184.         jmp     exit
  185. @@:
  186.         mov     eax,[read_folder_1.return]
  187.         cmp     [eax+4],dword 0
  188.         je      .continue
  189.         mov     [right_folder_block],ebx
  190.         xor     ebp,ebp
  191. .start_copy_device_path:
  192.         imul    edi,[retrieved_devices_table_counter],10
  193.         add     edi,retrieved_devices_table
  194.         mov     [edi],byte '/'
  195.         inc     edi
  196.         imul    esi,[temp_counter_1],304
  197.         add     esi,[read_folder.return]
  198.         add     esi,32+40
  199.         call    proc_copy_path
  200.         imul    esi,ebp,304
  201.         add     esi,[read_folder_1.return]
  202.         add     esi,32+40
  203.         mov     [edi-1],byte '/'
  204.         call    proc_copy_path
  205.         inc     [retrieved_devices_table_counter]
  206.         inc     ebp
  207.         cmp     ebp,[right_folder_block]
  208.         jb      .start_copy_device_path
  209. .continue:
  210.         inc     [temp_counter_1]
  211.         mov     eax,[temp_counter_1]
  212.         cmp     eax,[left_folder_block]
  213.         jb      .start_temp_counter_1
  214.         mov     esi,retrieved_devices_table+1
  215.         call    copy_folder_name
  216.         mov     esi,retrieved_devices_table+3
  217.         xor     ecx,ecx
  218. @@:
  219.         add     esi,8
  220.         cld
  221.         lodsw
  222.         inc     ecx
  223.         cmp     ecx,[retrieved_devices_table_counter]
  224.         ja      @f
  225.         cmp     ax,'hd'
  226.         jne     @r
  227.         sub     esi,2
  228.         call    copy_folder_name_1
  229.         ret
  230. @@:
  231.         mov     esi,retrieved_devices_table+1
  232.         call    copy_folder_name_1
  233.         ret
  234. ;---------------------------------------------------------------------
  235. load_file:
  236.         mov     [fileinfo.subfunction],dword 5
  237.         xor     eax,eax
  238.         mov     [fileinfo.size],eax
  239.         mov     [fs_error],eax
  240. ;--------------------------------------
  241.         DEBUGF  1, "Searchap: get file info\n"
  242. ;--------------------------------------
  243.         mcall   68,1
  244.         mcall   70,fileinfo
  245.         mov     [fs_error],eax
  246.         test    eax,eax
  247.         jnz     .file_error
  248. ;--------------------------------------
  249.         DEBUGF  1, "Searchap: file info ok\n"
  250. ;--------------------------------------
  251.         xor     eax,eax
  252.         mov     [fileinfo.subfunction],eax      ;dword 0
  253.         mov     eax,[fileinfo.return]
  254.         mov     ecx,[eax+32]
  255. ;--------------------------------------
  256.         DEBUGF  1, "Searchap: real file size: %d\n",ecx
  257. ;--------------------------------------
  258.         test    ecx,ecx
  259.         jz      .file_error
  260.         mov     eax,304*32+32 ; 9 Kb
  261.         cmp     ecx,eax
  262.         jbe     @f
  263.         mov     ecx,eax
  264. ;-----------------------------------
  265. @@:    
  266.         mov     [fileinfo.size],ecx
  267. ;--------------------------------------
  268.         DEBUGF  1, "Searchap: get file\n"
  269. ;--------------------------------------
  270.         mcall   68,1
  271.         mcall   70,fileinfo
  272.         mov     [fs_error],eax
  273.         test    eax,eax
  274.         jz      @f
  275. ;       cmp     eax,6
  276. ;       jne     .file_error
  277. ;       xor     eax,eax
  278. ;       mov     [fs_error],eax
  279. ;       jmp     @f
  280. ;-----------------------------------
  281. .file_error:
  282. ;--------------------------------------
  283.         DEBUGF  1, "Searchap: read file - error!\n"
  284. ;--------------------------------------
  285.         ret
  286. ;-----------------------------------   
  287. @@:
  288. ;--------------------------------------
  289.         DEBUGF  1, "Searchap: read file corrected size: %d\n",[fileinfo.size]
  290. ;--------------------------------------
  291.         ret
  292. ;---------------------------------------------------------------------
  293. search_and_load_pointer_file_label:
  294.         mov     [fileinfo.return],dword folder_data_1
  295.         mov     ecx,[retrieved_devices_table_counter]
  296.         dec     ecx     ; /rd/1/ no need to check
  297.         mov     [fileinfo.name],dword read_folder_name
  298.         mov     esi,retrieved_devices_table
  299. ;       sub     esi,10  ; deleted because /rd/1/ no need to check
  300. .next_entry:
  301. ;--------------------------------------
  302.         DEBUGF  1, "\nSearchap: copy next entry\n"
  303. ;--------------------------------------
  304.         add     esi,10
  305.         push    esi
  306.         add     esi,1
  307.         call    copy_folder_name
  308.         mov     esi,basic_file_name-1
  309.         dec     edi
  310.         call    copy_folder_name.1
  311.         pop     esi
  312. ;--------------------------------------
  313.         DEBUGF  1, "Searchap: %s\n",dword[fileinfo.name]
  314. ;--------------------------------------
  315. ;       mcall   5,10
  316.         push    ecx
  317.         call    load_file
  318.         pop     ecx
  319.  
  320.         xor     eax,eax
  321.         cmp     [fs_error],eax
  322.         jne     @f
  323.         mov     eax,[fileinfo.size]
  324.         cmp     eax,[basic_file_size]
  325.         jae     .sucess
  326. @@:
  327.         dec     ecx
  328.         jnz     .next_entry
  329. ;--------------------------------------
  330.         DEBUGF  2, "Searchap: additional partition is not found!\n"
  331. ;--------------------------------------
  332.         ret
  333. .sucess:
  334.         ;call   compare_files_and_mount
  335.         call    compare_files_and_mount.mount_now ;no need to compare files content
  336.         cmp     [compare_flag],byte 0
  337.         jne     @b
  338.         cmp     [mount_dir],1
  339.         je      @f
  340.         DEBUGF  2, "Searchap: sorry, but the additional partition is not found!\n"
  341. @@:
  342.         ret
  343. ;---------------------------------------------------------------------
  344. compare_files_and_mount:
  345.         push    ecx esi
  346.         mov     ecx,[basic_file_size]
  347.         mov     esi,folder_data
  348.         mov     edi,folder_data_1
  349. .next_char:
  350.         cld
  351.         lodsb
  352.         mov     ah,[edi]
  353.         inc     edi
  354.         cmp     al,ah
  355.         jne     .not_match
  356.         dec     ecx
  357.         jnz     .next_char
  358.         pop     esi ecx
  359. .mount_now:
  360.         mov     [compare_flag],byte 0
  361. ;--------------------------------------
  362.         DEBUGF  2, "Searchap: compare files - success!\n"
  363.         DEBUGF  2, "Searchap: mount directory: %s\n",esi
  364.         mov     [mount_dir],1
  365. ;--------------------------------------
  366. ; prepare real directory path for mounting
  367.         inc     esi
  368.         mov     edi,f30_3_work_area+64
  369.         call    proc_copy_path
  370.         dec     edi
  371.         mov     esi,real_additional_dir
  372.         call    proc_copy_path
  373. ; here is call kernel function to mount the found partition
  374. ; as "/kolibrios" directory to root directory "/"
  375.         mcall   30,3,f30_3_work_area
  376.         ret
  377. ;--------------------------------------
  378. .not_match:
  379.         mov     [compare_flag],byte 1
  380.         pop     esi ecx
  381. ;--------------------------------------
  382.         DEBUGF  1, "Searchap: compared files doesn't match!\n"
  383. ;--------------------------------------
  384.         ret
  385. ;---------------------------------------------------------------------
  386. copy_folder_name:
  387.         mov     edi,read_folder_name+1
  388. .1:
  389. proc_copy_path:
  390.         cld
  391. @@:
  392.         lodsb
  393.         stosb
  394.         test    al,al
  395.         jnz     @r
  396.         ret
  397. ;---------------------------------------------------------------------
  398. copy_folder_name_1:
  399.         mov     edi,read_folder_1_name+1
  400.         jmp     proc_copy_path
  401. ;---------------------------------------------------------------------
  402. print_retrieved_devices_table:
  403.         mov     ecx,[retrieved_devices_table_counter]
  404.         mov     edx,retrieved_devices_table
  405.         DEBUGF  1, "Searchap: retrieved_devices_table:\n"
  406.         DEBUGF  1, "Searchap: ----------\n"
  407. @@:
  408.         DEBUGF  1, "Searchap: %s\n",edx
  409.         add     edx,10
  410.         dec     ecx
  411.         jnz     @b
  412.         DEBUGF  1, "\nSearchap: ----------\n"
  413.         ret
  414. ;---------------------------------------------------------------------
  415. print_root_dir:
  416.         DEBUGF  1, "Searchap: ----------\n"
  417.         DEBUGF  1, "Searchap: root dir:\n"
  418.         DEBUGF  1, "Searchap: ----------\n"
  419.         pusha
  420.         mov     ecx,ebx
  421.         mov     edx,folder_data+32+40
  422. @@:
  423.         DEBUGF  1, "Searchap: %s\n",edx
  424.         add     edx,304
  425.         dec     ecx
  426.         jnz     @b
  427.         popa
  428.         DEBUGF  1, "\nSearchap: ----------\n"
  429.         ret
  430. ;-------------------------------------------------------------------------------
  431. include_debug_strings
  432. ;-------------------------------------------------------------------------------
  433. IM_END:
  434. ;-------------------------------------------------------------------------------
  435. align 4
  436. PARAMS: rb 256
  437. align 4
  438. left_folder_block       rd 1
  439. right_folder_block      rd 1
  440. temp_counter_1          rd 1
  441. retrieved_devices_table_counter rd 1
  442. basic_file_size         rd 1
  443. fs_error                rd 1
  444. compare_flag            rb 1
  445. mount_dir               rb 1
  446. ;-------------------------------------------------------------------------------
  447. align 4
  448. f30_3_work_area:
  449.         db 'kolibrios',0
  450.         rb 118
  451. ;-------------------------------------------------------------------------------
  452. align 4
  453. retrieved_devices_table:
  454.         rb 10*100
  455. ;-------------------------------------------------------------------------------
  456. align 4
  457. read_folder_name:
  458.         rb 256
  459. ;-------------------------------------------------------------------------------
  460. align 4
  461. read_folder_1_name:
  462.         rb 256
  463. ;-------------------------------------------------------------------------------
  464. align 4
  465. folder_data:
  466.         rb 304*32+32 ; 9 Kb
  467. ;-------------------------------------------------------------------------------
  468. align 4
  469. folder_data_1:
  470.         rb 304*32+32 ; 9 Kb
  471. ;-------------------------------------------------------------------------------
  472. align 4
  473.         rb 512
  474. stacktop:
  475. ;-------------------------------------------------------------------------------
  476. I_END:
  477. ;-------------------------------------------------------------------------------