Subversion Repositories Kolibri OS

Rev

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