Rev 5146 | Rev 7449 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3650 | mario79 | 1 | ; Search Additional Partition for KolibriOS applications |
2 | ; |
||
4607 | mario79 | 3 | ; Copyright (c) 2013-2014, Marat Zakiyanov aka Mario79, aka Mario |
3650 | mario79 | 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 |
||
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 |
||
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 | |||
4086 | mario79 | 31 | db 'MENUET01' |
3650 | mario79 | 32 | dd 0x01 |
33 | dd START |
||
34 | dd IM_END |
||
35 | dd I_END |
||
36 | dd stacktop |
||
7446 | 0CodErr | 37 | params dd PARAMS |
3650 | mario79 | 38 | dd 0x0 |
3668 | mario79 | 39 | ;--------------------------------------------------------------------- |
7446 | 0CodErr | 40 | delay dd 0;500 |
41 | ;--------------------------------------------------------------------- |
||
3668 | mario79 | 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 |
||
3650 | mario79 | 71 | ;------------------------------------------------------------------------------- |
3668 | mario79 | 72 | basic_file_path: |
4086 | mario79 | 73 | db '/sys/settings/' |
3668 | mario79 | 74 | basic_file_name: |
75 | db 'kolibri.lbl',0 |
||
76 | additional_dir_name: |
||
3781 | Serge | 77 | db 'kolibrios',0 |
3676 | mario79 | 78 | real_additional_dir: |
79 | db '/kolibrios',0 |
||
3668 | mario79 | 80 | ;------------------------------------------------------------------------------- |
3650 | mario79 | 81 | include '../../macros.inc' |
3664 | mario79 | 82 | |
4607 | mario79 | 83 | define __DEBUG__ 1 |
84 | define __DEBUG_LEVEL__ 2 ; 1 = verbose, 2 = main only |
||
85 | include "../../debug-fdo.inc" |
||
3650 | mario79 | 86 | ;------------------------------------------------------------------------------- |
87 | START: |
||
7446 | 0CodErr | 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] |
||
3650 | mario79 | 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 |
||
3664 | mario79 | 117 | ;-------------------------------------- |
3650 | mario79 | 118 | call print_retrieved_devices_table |
4607 | mario79 | 119 | DEBUGF 1, "Searchap: get basic file\n" |
3650 | mario79 | 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] |
||
3780 | Serge | 126 | mov [basic_file_size],eax |
127 | |||
3650 | mario79 | 128 | call search_and_load_pointer_file_label |
129 | ;--------------------------------------------------------------------- |
||
130 | exit: |
||
3664 | mario79 | 131 | ;-------------------------------------- |
4607 | mario79 | 132 | DEBUGF 1, "Searchap: just exit\n" |
3664 | mario79 | 133 | ;-------------------------------------- |
3650 | mario79 | 134 | mcall -1 |
135 | ;--------------------------------------------------------------------- |
||
136 | device_detect_f70: |
||
137 | ;-------------------------------------- |
||
4607 | mario79 | 138 | DEBUGF 1, "Searchap: read_folder_name: %s\n",read_folder_name |
3650 | mario79 | 139 | ;-------------------------------------- |
140 | mcall 70,read_folder |
||
141 | test eax,eax |
||
142 | jz @f |
||
143 | cmp eax,6 |
||
144 | je @f |
||
3664 | mario79 | 145 | ;-------------------------------------- |
4607 | mario79 | 146 | DEBUGF 1, "Searchap: read_folder_error\n" |
3664 | mario79 | 147 | ;-------------------------------------- |
3650 | mario79 | 148 | jmp exit |
149 | @@: |
||
150 | ;-------------------------------------- |
||
151 | call print_root_dir |
||
3664 | mario79 | 152 | ;-------------------------------------- |
3650 | mario79 | 153 | mov [left_folder_block],ebx |
3664 | mario79 | 154 | xor eax,eax |
155 | mov [temp_counter_1],eax |
||
156 | mov [retrieved_devices_table_counter],eax |
||
3650 | mario79 | 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 |
||
3664 | mario79 | 162 | ;-------------------------------------- |
4607 | mario79 | 163 | DEBUGF 1, "Searchap: read_folder_1_name: %s\n",read_folder_1_name |
3664 | mario79 | 164 | ;-------------------------------------- |
3650 | mario79 | 165 | mcall 70,read_folder_1 |
166 | test eax,eax |
||
167 | jz @f |
||
168 | cmp eax,6 |
||
169 | je @f |
||
3664 | mario79 | 170 | ;-------------------------------------- |
4607 | mario79 | 171 | DEBUGF 1, "Searchap: read_folder_error_1\n" |
3664 | mario79 | 172 | ;-------------------------------------- |
3650 | mario79 | 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 |
||
3664 | mario79 | 179 | xor ebp,ebp |
3650 | mario79 | 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 |
||
3664 | mario79 | 206 | xor ecx,ecx |
3650 | mario79 | 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 |
||
3664 | mario79 | 229 | ;-------------------------------------- |
4607 | mario79 | 230 | DEBUGF 1, "Searchap: get file info\n" |
3664 | mario79 | 231 | ;-------------------------------------- |
3724 | mario79 | 232 | mcall 68,1 |
3650 | mario79 | 233 | mcall 70,fileinfo |
234 | mov [fs_error],eax |
||
235 | test eax,eax |
||
236 | jnz .file_error |
||
3664 | mario79 | 237 | ;-------------------------------------- |
4607 | mario79 | 238 | DEBUGF 1, "Searchap: file info ok\n" |
3664 | mario79 | 239 | ;-------------------------------------- |
240 | xor eax,eax |
||
241 | mov [fileinfo.subfunction],eax ;dword 0 |
||
3650 | mario79 | 242 | mov eax,[fileinfo.return] |
243 | mov ecx,[eax+32] |
||
3664 | mario79 | 244 | ;-------------------------------------- |
4607 | mario79 | 245 | DEBUGF 1, "Searchap: real file size: %d\n",ecx |
3664 | mario79 | 246 | ;-------------------------------------- |
3650 | mario79 | 247 | test ecx,ecx |
248 | jz .file_error |
||
3664 | mario79 | 249 | mov eax,304*32+32 ; 9 Kb |
250 | cmp ecx,eax |
||
3650 | mario79 | 251 | jbe @f |
3664 | mario79 | 252 | mov ecx,eax |
3650 | mario79 | 253 | ;----------------------------------- |
3781 | Serge | 254 | @@: |
3650 | mario79 | 255 | mov [fileinfo.size],ecx |
3664 | mario79 | 256 | ;-------------------------------------- |
4607 | mario79 | 257 | DEBUGF 1, "Searchap: get file\n" |
3664 | mario79 | 258 | ;-------------------------------------- |
3724 | mario79 | 259 | mcall 68,1 |
3650 | mario79 | 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: |
||
3664 | mario79 | 271 | ;-------------------------------------- |
4607 | mario79 | 272 | DEBUGF 1, "Searchap: read file - error!\n" |
3664 | mario79 | 273 | ;-------------------------------------- |
3650 | mario79 | 274 | ret |
3781 | Serge | 275 | ;----------------------------------- |
3664 | mario79 | 276 | @@: |
277 | ;-------------------------------------- |
||
4607 | mario79 | 278 | DEBUGF 1, "Searchap: read file corrected size: %d\n",[fileinfo.size] |
3664 | mario79 | 279 | ;-------------------------------------- |
3650 | mario79 | 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: |
||
3664 | mario79 | 290 | ;-------------------------------------- |
4607 | mario79 | 291 | DEBUGF 1, "\nSearchap: copy next entry\n" |
3664 | mario79 | 292 | ;-------------------------------------- |
3650 | mario79 | 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 |
||
3664 | mario79 | 301 | ;-------------------------------------- |
4607 | mario79 | 302 | DEBUGF 1, "Searchap: %s\n",dword[fileinfo.name] |
3664 | mario79 | 303 | ;-------------------------------------- |
3650 | mario79 | 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 |
||
3664 | mario79 | 318 | ;-------------------------------------- |
5146 | mario79 | 319 | DEBUGF 2, "Searchap: additional partition is not found!\n" |
3664 | mario79 | 320 | ;-------------------------------------- |
3650 | mario79 | 321 | ret |
322 | .sucess: |
||
323 | call compare_files_and_mount |
||
3668 | mario79 | 324 | cmp [compare_flag],byte 0 |
3650 | mario79 | 325 | jne @b |
4607 | mario79 | 326 | cmp [mount_dir],1 |
327 | je @f |
||
328 | DEBUGF 2, "Searchap: sorry, but the additional partition is not found!\n" |
||
329 | @@: |
||
3650 | mario79 | 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 |
||
3664 | mario79 | 348 | ;-------------------------------------- |
5146 | mario79 | 349 | DEBUGF 2, "Searchap: compare files - success!\n" |
4607 | mario79 | 350 | DEBUGF 2, "Searchap: mount directory: %s\n",esi |
351 | mov [mount_dir],1 |
||
3664 | mario79 | 352 | ;-------------------------------------- |
353 | ; prepare real directory path for mounting |
||
354 | inc esi |
||
355 | mov edi,f30_3_work_area+64 |
||
356 | call proc_copy_patch |
||
3676 | mario79 | 357 | dec edi |
358 | mov esi,real_additional_dir |
||
359 | call proc_copy_patch |
||
3664 | mario79 | 360 | ; prepare fake directory name |
361 | mov esi,additional_dir_name |
||
362 | mov edi,f30_3_work_area |
||
363 | call proc_copy_patch |
||
3650 | mario79 | 364 | ; here is call kernel function to mount the found partition |
3781 | Serge | 365 | ; as "/kolibrios" directory to root directory "/" |
3664 | mario79 | 366 | mcall 30,3,f30_3_work_area |
3650 | mario79 | 367 | ret |
368 | ;-------------------------------------- |
||
369 | .not_match: |
||
370 | mov [compare_flag],byte 1 |
||
371 | pop esi ecx |
||
3664 | mario79 | 372 | ;-------------------------------------- |
5146 | mario79 | 373 | DEBUGF 1, "Searchap: compared files doesn't match!\n" |
3664 | mario79 | 374 | ;-------------------------------------- |
3650 | mario79 | 375 | ret |
376 | ;--------------------------------------------------------------------- |
||
377 | copy_folder_name: |
||
378 | mov edi,read_folder_name+1 |
||
379 | .1: |
||
3664 | mario79 | 380 | proc_copy_patch: |
381 | cld |
||
3650 | mario79 | 382 | @@: |
383 | lodsb |
||
384 | stosb |
||
3664 | mario79 | 385 | test al,al |
386 | jnz @r |
||
3650 | mario79 | 387 | ret |
388 | ;--------------------------------------------------------------------- |
||
389 | copy_folder_name_1: |
||
390 | mov edi,read_folder_1_name+1 |
||
3664 | mario79 | 391 | jmp proc_copy_patch |
3650 | mario79 | 392 | ;--------------------------------------------------------------------- |
393 | print_retrieved_devices_table: |
||
394 | mov ecx,[retrieved_devices_table_counter] |
||
395 | mov edx,retrieved_devices_table |
||
4607 | mario79 | 396 | DEBUGF 1, "Searchap: retrieved_devices_table:\n" |
397 | DEBUGF 1, "Searchap: ----------\n" |
||
3650 | mario79 | 398 | @@: |
4607 | mario79 | 399 | DEBUGF 1, "Searchap: %s\n",edx |
3650 | mario79 | 400 | add edx,10 |
401 | dec ecx |
||
402 | jnz @b |
||
4607 | mario79 | 403 | DEBUGF 1, "\nSearchap: ----------\n" |
3650 | mario79 | 404 | ret |
405 | ;--------------------------------------------------------------------- |
||
406 | print_root_dir: |
||
4607 | mario79 | 407 | DEBUGF 1, "Searchap: ----------\n" |
408 | DEBUGF 1, "Searchap: root dir:\n" |
||
409 | DEBUGF 1, "Searchap: ----------\n" |
||
3650 | mario79 | 410 | pusha |
411 | mov ecx,ebx |
||
412 | mov edx,folder_data+32+40 |
||
413 | @@: |
||
4607 | mario79 | 414 | DEBUGF 1, "Searchap: %s\n",edx |
3650 | mario79 | 415 | add edx,304 |
416 | dec ecx |
||
417 | jnz @b |
||
418 | popa |
||
4607 | mario79 | 419 | DEBUGF 1, "\nSearchap: ----------\n" |
3650 | mario79 | 420 | ret |
421 | ;------------------------------------------------------------------------------- |
||
4607 | mario79 | 422 | include_debug_strings |
423 | ;------------------------------------------------------------------------------- |
||
3650 | mario79 | 424 | IM_END: |
425 | ;------------------------------------------------------------------------------- |
||
426 | align 4 |
||
7446 | 0CodErr | 427 | PARAMS: rb 256 |
428 | align 4 |
||
3650 | mario79 | 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 |
||
4607 | mario79 | 436 | mount_dir rb 1 |
3650 | mario79 | 437 | ;------------------------------------------------------------------------------- |
438 | align 4 |
||
3664 | mario79 | 439 | f30_3_work_area: |
440 | rb 128 |
||
441 | ;------------------------------------------------------------------------------- |
||
442 | align 4 |
||
3650 | mario79 | 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: |
||
3781 | Serge | 467 | ;------------------------------------------------------------------------------- |