Subversion Repositories Kolibri OS

Rev

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