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