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