Subversion Repositories Kolibri OS

Rev

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