Subversion Repositories Kolibri OS

Rev

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