Rev 3668 | Rev 3679 | 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 | ; |
||
3 | ; Copyright (c) 2013, 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 |
||
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 | |||
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 |
||
3668 | mario79 | 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 |
||
3650 | mario79 | 69 | ;------------------------------------------------------------------------------- |
3668 | mario79 | 70 | basic_file_path: |
71 | db '/rd/1/' |
||
72 | basic_file_name: |
||
73 | db 'kolibri.lbl',0 |
||
74 | additional_dir_name: |
||
75 | db 'addappl',0 |
||
3676 | mario79 | 76 | real_additional_dir: |
77 | db '/kolibrios',0 |
||
3668 | mario79 | 78 | ;------------------------------------------------------------------------------- |
3664 | mario79 | 79 | debug equ no ;yes |
80 | |||
3650 | mario79 | 81 | include '../../macros.inc' |
3664 | mario79 | 82 | |
83 | if debug eq yes |
||
3650 | mario79 | 84 | include '../../debug.inc' |
3664 | mario79 | 85 | end if |
3650 | mario79 | 86 | ;------------------------------------------------------------------------------- |
87 | START: |
||
88 | mov ebx,start_dir |
||
89 | mov ax,[ebx] |
||
90 | mov ebx,read_folder_name |
||
91 | mov [ebx],ax |
||
92 | mov ebx,read_folder_1_name |
||
93 | mov [ebx],ax |
||
94 | call device_detect_f70 |
||
3664 | mario79 | 95 | ;-------------------------------------- |
96 | if debug eq yes |
||
3650 | mario79 | 97 | call print_retrieved_devices_table |
98 | dps 'get basic file' |
||
99 | newline |
||
3664 | mario79 | 100 | end if |
3650 | mario79 | 101 | ;-------------------------------------- |
102 | call load_file ; download the master file |
||
103 | xor eax,eax |
||
104 | cmp [fs_error],eax |
||
105 | jne exit |
||
106 | mov eax,[fileinfo.size] |
||
107 | mov [basic_file_size],eax |
||
108 | |||
109 | call search_and_load_pointer_file_label |
||
110 | ;--------------------------------------------------------------------- |
||
111 | exit: |
||
3664 | mario79 | 112 | ;-------------------------------------- |
113 | if debug eq yes |
||
3650 | mario79 | 114 | dps 'just exit' |
115 | ;newline |
||
116 | ; mov edx,read_folder_name |
||
117 | ; call debug_outstr |
||
118 | ;newline |
||
119 | ; mov edx,read_folder_1_name |
||
120 | ; call debug_outstr |
||
121 | ;newline |
||
3664 | mario79 | 122 | end if |
123 | ;-------------------------------------- |
||
3650 | mario79 | 124 | mcall -1 |
125 | ;--------------------------------------------------------------------- |
||
126 | device_detect_f70: |
||
127 | ;-------------------------------------- |
||
3664 | mario79 | 128 | if debug eq yes |
3650 | mario79 | 129 | dps 'read_folder_name: ' |
130 | mov edx,read_folder_name |
||
131 | call debug_outstr |
||
132 | newline |
||
3664 | mario79 | 133 | end if |
3650 | mario79 | 134 | ;-------------------------------------- |
135 | mcall 70,read_folder |
||
136 | test eax,eax |
||
137 | jz @f |
||
138 | cmp eax,6 |
||
139 | je @f |
||
3664 | mario79 | 140 | ;-------------------------------------- |
141 | if debug eq yes |
||
3650 | mario79 | 142 | dps 'read_folder_error' |
143 | newline |
||
144 | ; mov edx,read_folder_name |
||
145 | ; call debug_outstr |
||
146 | ;newline |
||
3664 | mario79 | 147 | end if |
148 | ;-------------------------------------- |
||
3650 | mario79 | 149 | jmp exit |
150 | @@: |
||
151 | ;-------------------------------------- |
||
3664 | mario79 | 152 | if debug eq yes |
3650 | mario79 | 153 | call print_root_dir |
3664 | mario79 | 154 | end if |
155 | ;-------------------------------------- |
||
3650 | mario79 | 156 | mov [left_folder_block],ebx |
3664 | mario79 | 157 | xor eax,eax |
158 | mov [temp_counter_1],eax |
||
159 | mov [retrieved_devices_table_counter],eax |
||
3650 | mario79 | 160 | .start_temp_counter_1: |
161 | imul esi,[temp_counter_1],304 |
||
162 | add esi,[read_folder.return] |
||
163 | add esi,32+40 |
||
164 | call copy_folder_name_1 |
||
3664 | mario79 | 165 | ;-------------------------------------- |
166 | if debug eq yes |
||
3650 | mario79 | 167 | ;dps 'read_folder_1_name: ' |
168 | ; mov edx,read_folder_1_name |
||
169 | ; call debug_outstr |
||
170 | ;newline |
||
3664 | mario79 | 171 | end if |
172 | ;-------------------------------------- |
||
3650 | mario79 | 173 | mcall 70,read_folder_1 |
174 | test eax,eax |
||
175 | jz @f |
||
176 | cmp eax,6 |
||
177 | je @f |
||
3664 | mario79 | 178 | ;-------------------------------------- |
179 | if debug eq yes |
||
3650 | mario79 | 180 | dps 'read_folder_error_1' |
181 | newline |
||
182 | ; mov edx,read_folder_1_name |
||
183 | ; call debug_outstr |
||
184 | ;newline |
||
3664 | mario79 | 185 | end if |
186 | ;-------------------------------------- |
||
3650 | mario79 | 187 | jmp exit |
188 | @@: |
||
189 | mov eax,[read_folder_1.return] |
||
190 | cmp [eax+4],dword 0 |
||
191 | je .continue |
||
192 | mov [right_folder_block],ebx |
||
3664 | mario79 | 193 | xor ebp,ebp |
3650 | mario79 | 194 | .start_copy_device_patch: |
195 | imul edi,[retrieved_devices_table_counter],10 |
||
196 | add edi,retrieved_devices_table |
||
197 | mov [edi],byte '/' |
||
198 | inc edi |
||
199 | imul esi,[temp_counter_1],304 |
||
200 | add esi,[read_folder.return] |
||
201 | add esi,32+40 |
||
202 | call proc_copy_patch |
||
203 | imul esi,ebp,304 |
||
204 | add esi,[read_folder_1.return] |
||
205 | add esi,32+40 |
||
206 | mov [edi-1],byte '/' |
||
207 | call proc_copy_patch |
||
208 | inc [retrieved_devices_table_counter] |
||
209 | inc ebp |
||
210 | cmp ebp,[right_folder_block] |
||
211 | jb .start_copy_device_patch |
||
212 | .continue: |
||
213 | inc [temp_counter_1] |
||
214 | mov eax,[temp_counter_1] |
||
215 | cmp eax,[left_folder_block] |
||
216 | jb .start_temp_counter_1 |
||
217 | mov esi,retrieved_devices_table+1 |
||
218 | call copy_folder_name |
||
219 | mov esi,retrieved_devices_table+3 |
||
3664 | mario79 | 220 | xor ecx,ecx |
3650 | mario79 | 221 | @@: |
222 | add esi,8 |
||
223 | cld |
||
224 | lodsw |
||
225 | inc ecx |
||
226 | cmp ecx,[retrieved_devices_table_counter] |
||
227 | ja @f |
||
228 | cmp ax,'hd' |
||
229 | jne @r |
||
230 | sub esi,2 |
||
231 | call copy_folder_name_1 |
||
232 | ret |
||
233 | @@: |
||
234 | mov esi,retrieved_devices_table+1 |
||
235 | call copy_folder_name_1 |
||
236 | ret |
||
237 | ;--------------------------------------------------------------------- |
||
238 | load_file: |
||
239 | mov [fileinfo.subfunction],dword 5 |
||
240 | xor eax,eax |
||
241 | mov [fileinfo.size],eax |
||
242 | mov [fs_error],eax |
||
3664 | mario79 | 243 | ;-------------------------------------- |
244 | if debug eq yes |
||
3650 | mario79 | 245 | dps 'get file info' |
246 | newline |
||
3664 | mario79 | 247 | end if |
248 | ;-------------------------------------- |
||
3650 | mario79 | 249 | mcall 70,fileinfo |
250 | mov [fs_error],eax |
||
251 | test eax,eax |
||
252 | jnz .file_error |
||
3664 | mario79 | 253 | ;-------------------------------------- |
254 | if debug eq yes |
||
3650 | mario79 | 255 | dps 'file info ok' |
256 | newline |
||
3664 | mario79 | 257 | end if |
258 | ;-------------------------------------- |
||
259 | xor eax,eax |
||
260 | mov [fileinfo.subfunction],eax ;dword 0 |
||
3650 | mario79 | 261 | mov eax,[fileinfo.return] |
262 | mov ecx,[eax+32] |
||
3664 | mario79 | 263 | ;-------------------------------------- |
264 | if debug eq yes |
||
3650 | mario79 | 265 | dps 'real file size: ' |
266 | dpd ecx |
||
267 | newline |
||
3664 | mario79 | 268 | end if |
269 | ;-------------------------------------- |
||
3650 | mario79 | 270 | test ecx,ecx |
271 | jz .file_error |
||
3664 | mario79 | 272 | mov eax,304*32+32 ; 9 Kb |
273 | cmp ecx,eax |
||
3650 | mario79 | 274 | jbe @f |
3664 | mario79 | 275 | mov ecx,eax |
3650 | mario79 | 276 | ;----------------------------------- |
277 | @@: |
||
278 | mov [fileinfo.size],ecx |
||
3664 | mario79 | 279 | ;-------------------------------------- |
280 | if debug eq yes |
||
3650 | mario79 | 281 | dps 'get file' |
282 | newline |
||
3664 | mario79 | 283 | end if |
284 | ;-------------------------------------- |
||
3650 | mario79 | 285 | mcall 70,fileinfo |
286 | mov [fs_error],eax |
||
287 | test eax,eax |
||
288 | jz @f |
||
289 | ; cmp eax,6 |
||
290 | ; jne .file_error |
||
291 | ; xor eax,eax |
||
292 | ; mov [fs_error],eax |
||
293 | ; jmp @f |
||
294 | ;----------------------------------- |
||
295 | .file_error: |
||
3664 | mario79 | 296 | ;-------------------------------------- |
297 | if debug eq yes |
||
3650 | mario79 | 298 | dps 'read file - error!' |
299 | newline |
||
3664 | mario79 | 300 | end if |
301 | ;-------------------------------------- |
||
3650 | mario79 | 302 | ret |
303 | ;----------------------------------- |
||
3664 | mario79 | 304 | @@: |
305 | ;-------------------------------------- |
||
306 | if debug eq yes |
||
3650 | mario79 | 307 | dps 'read file corrected size: ' |
308 | dpd dword[fileinfo.size] |
||
309 | newline |
||
3664 | mario79 | 310 | end if |
311 | ;-------------------------------------- |
||
3650 | mario79 | 312 | ret |
313 | ;--------------------------------------------------------------------- |
||
314 | search_and_load_pointer_file_label: |
||
315 | mov [fileinfo.return],dword folder_data_1 |
||
316 | mov ecx,[retrieved_devices_table_counter] |
||
317 | dec ecx ; /rd/1/ no need to check |
||
318 | mov [fileinfo.name],dword read_folder_name |
||
319 | mov esi,retrieved_devices_table |
||
320 | ; sub esi,10 ; deleted because /rd/1/ no need to check |
||
321 | .next_entry: |
||
3664 | mario79 | 322 | ;-------------------------------------- |
323 | if debug eq yes |
||
3650 | mario79 | 324 | newline |
325 | dps 'copy next entry' |
||
326 | newline |
||
3664 | mario79 | 327 | end if |
328 | ;-------------------------------------- |
||
3650 | mario79 | 329 | add esi,10 |
330 | push esi |
||
331 | add esi,1 |
||
332 | call copy_folder_name |
||
333 | mov esi,basic_file_name-1 |
||
334 | dec edi |
||
335 | call copy_folder_name.1 |
||
336 | pop esi |
||
3664 | mario79 | 337 | ;-------------------------------------- |
338 | if debug eq yes |
||
3650 | mario79 | 339 | mov edx,[fileinfo.name] |
340 | push ecx |
||
341 | call debug_outstr |
||
342 | pop ecx |
||
343 | newline |
||
3664 | mario79 | 344 | end if |
345 | ;-------------------------------------- |
||
3650 | mario79 | 346 | ; mcall 5,10 |
347 | push ecx |
||
348 | call load_file |
||
349 | pop ecx |
||
350 | |||
351 | xor eax,eax |
||
352 | cmp [fs_error],eax |
||
353 | jne @f |
||
354 | mov eax,[fileinfo.size] |
||
355 | cmp eax,[basic_file_size] |
||
356 | jae .sucess |
||
357 | @@: |
||
358 | dec ecx |
||
359 | jnz .next_entry |
||
3664 | mario79 | 360 | ;-------------------------------------- |
361 | if debug eq yes |
||
3650 | mario79 | 362 | dps 'additional parttition is not found!' |
363 | newline |
||
3664 | mario79 | 364 | end if |
365 | ;-------------------------------------- |
||
3650 | mario79 | 366 | ret |
367 | .sucess: |
||
368 | call compare_files_and_mount |
||
3668 | mario79 | 369 | cmp [compare_flag],byte 0 |
3650 | mario79 | 370 | jne @b |
371 | ret |
||
372 | ;--------------------------------------------------------------------- |
||
373 | compare_files_and_mount: |
||
374 | push ecx esi |
||
375 | mov ecx,[basic_file_size] |
||
376 | mov esi,folder_data |
||
377 | mov edi,folder_data_1 |
||
378 | .next_char: |
||
379 | cld |
||
380 | lodsb |
||
381 | mov ah,[edi] |
||
382 | inc edi |
||
383 | cmp al,ah |
||
384 | jne .not_match |
||
385 | dec ecx |
||
386 | jnz .next_char |
||
387 | mov [compare_flag],byte 0 |
||
388 | pop esi ecx |
||
3664 | mario79 | 389 | ;-------------------------------------- |
390 | if debug eq yes |
||
3650 | mario79 | 391 | dps 'compare files sucess!' |
392 | newline |
||
393 | dps 'mount directory:' |
||
394 | newline |
||
395 | mov edx,esi |
||
3664 | mario79 | 396 | push esi |
3650 | mario79 | 397 | call debug_outstr |
3664 | mario79 | 398 | pop esi |
3650 | mario79 | 399 | newline |
3664 | mario79 | 400 | end if |
401 | ;-------------------------------------- |
||
402 | ; prepare real directory path for mounting |
||
403 | inc esi |
||
404 | mov edi,f30_3_work_area+64 |
||
405 | call proc_copy_patch |
||
3676 | mario79 | 406 | dec edi |
407 | mov esi,real_additional_dir |
||
408 | call proc_copy_patch |
||
3664 | mario79 | 409 | ; prepare fake directory name |
410 | mov esi,additional_dir_name |
||
411 | mov edi,f30_3_work_area |
||
412 | call proc_copy_patch |
||
3650 | mario79 | 413 | ; here is call kernel function to mount the found partition |
414 | ; as "/addappl" directory to root directory "/" |
||
3664 | mario79 | 415 | mcall 30,3,f30_3_work_area |
3650 | mario79 | 416 | ret |
417 | ;-------------------------------------- |
||
418 | .not_match: |
||
419 | mov [compare_flag],byte 1 |
||
420 | pop esi ecx |
||
3664 | mario79 | 421 | ;-------------------------------------- |
422 | if debug eq yes |
||
3650 | mario79 | 423 | dps 'compare files is not match!' |
424 | newline |
||
3664 | mario79 | 425 | end if |
426 | ;-------------------------------------- |
||
3650 | mario79 | 427 | ret |
428 | ;--------------------------------------------------------------------- |
||
429 | copy_folder_name: |
||
430 | mov edi,read_folder_name+1 |
||
431 | .1: |
||
3664 | mario79 | 432 | proc_copy_patch: |
433 | cld |
||
3650 | mario79 | 434 | @@: |
435 | lodsb |
||
436 | stosb |
||
3664 | mario79 | 437 | test al,al |
438 | jnz @r |
||
3650 | mario79 | 439 | ret |
440 | ;--------------------------------------------------------------------- |
||
441 | copy_folder_name_1: |
||
442 | mov edi,read_folder_1_name+1 |
||
3664 | mario79 | 443 | jmp proc_copy_patch |
3650 | mario79 | 444 | ;--------------------------------------------------------------------- |
3664 | mario79 | 445 | if debug eq yes |
3650 | mario79 | 446 | print_retrieved_devices_table: |
447 | mov ecx,[retrieved_devices_table_counter] |
||
448 | mov edx,retrieved_devices_table |
||
449 | dps 'retrieved_devices_table:' |
||
450 | newline |
||
451 | dps '----------' |
||
452 | newline |
||
453 | @@: |
||
454 | push ecx edx |
||
455 | call debug_outstr |
||
456 | newline |
||
457 | pop edx ecx |
||
458 | add edx,10 |
||
459 | dec ecx |
||
460 | jnz @b |
||
461 | newline |
||
462 | dps '----------' |
||
463 | newline |
||
464 | ret |
||
465 | ;--------------------------------------------------------------------- |
||
466 | print_root_dir: |
||
467 | dps '----------' |
||
468 | dps 'root dir:' |
||
469 | dps '----------' |
||
470 | newline |
||
471 | pusha |
||
472 | mov ecx,ebx |
||
473 | mov edx,folder_data+32+40 |
||
474 | @@: |
||
475 | push ecx edx |
||
476 | call debug_outstr |
||
477 | newline |
||
478 | pop edx ecx |
||
479 | add edx,304 |
||
480 | dec ecx |
||
481 | jnz @b |
||
482 | popa |
||
483 | newline |
||
484 | dps '----------' |
||
485 | newline |
||
486 | ret |
||
3664 | mario79 | 487 | end if |
3650 | mario79 | 488 | ;------------------------------------------------------------------------------- |
489 | IM_END: |
||
490 | ;------------------------------------------------------------------------------- |
||
491 | align 4 |
||
492 | left_folder_block rd 1 |
||
493 | right_folder_block rd 1 |
||
494 | temp_counter_1 rd 1 |
||
495 | retrieved_devices_table_counter rd 1 |
||
496 | basic_file_size rd 1 |
||
497 | fs_error rd 1 |
||
498 | compare_flag rb 1 |
||
499 | ;------------------------------------------------------------------------------- |
||
500 | align 4 |
||
3664 | mario79 | 501 | f30_3_work_area: |
502 | rb 128 |
||
503 | ;------------------------------------------------------------------------------- |
||
504 | align 4 |
||
3650 | mario79 | 505 | retrieved_devices_table: |
506 | rb 10*100 |
||
507 | ;------------------------------------------------------------------------------- |
||
508 | align 4 |
||
509 | read_folder_name: |
||
510 | rb 256 |
||
511 | ;------------------------------------------------------------------------------- |
||
512 | align 4 |
||
513 | read_folder_1_name: |
||
514 | rb 256 |
||
515 | ;------------------------------------------------------------------------------- |
||
516 | align 4 |
||
517 | folder_data: |
||
518 | rb 304*32+32 ; 9 Kb |
||
519 | ;------------------------------------------------------------------------------- |
||
520 | align 4 |
||
521 | folder_data_1: |
||
522 | rb 304*32+32 ; 9 Kb |
||
523 | ;------------------------------------------------------------------------------- |
||
524 | align 4 |
||
525 | rb 512 |
||
526 | stacktop: |
||
527 | ;------------------------------------------------------------------------------- |
||
528 | I_END: |
||
529 | ;------------------------------------------------------------------------------- |