Subversion Repositories Kolibri OS

Rev

Rev 7451 | 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  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
7756 leency 108
;--------------------------------------
109
	DEBUGF	1, "Searchap: get basic file\n"
110
	call	load_file	; download the master file
111
	xor	eax,eax
112
	cmp	[fs_error],eax
113
	jne	exit
114
	mov	eax,[fileinfo.size]
115
	mov	[basic_file_size],eax
7446 0CodErr 116
.params_done:
117
;--------------------------------------
3650 mario79 118
	mov	ebx,start_dir
119
	mov	ax,[ebx]
120
	mov	ebx,read_folder_name
121
	mov	[ebx],ax
122
	mov	ebx,read_folder_1_name
123
	mov	[ebx],ax
124
	call	device_detect_f70
3664 mario79 125
;--------------------------------------
3650 mario79 126
	call	print_retrieved_devices_table
127
	call	search_and_load_pointer_file_label
128
;---------------------------------------------------------------------
129
exit:
3664 mario79 130
;--------------------------------------
4607 mario79 131
	DEBUGF	1, "Searchap: just exit\n"
3664 mario79 132
;--------------------------------------
7449 leency 133
	cmp [mount_dir],1
134
	je @f
135
	cmp [mount_attempt], 1
136
	je @f
137
	mov [mount_attempt], 1 ;second mount attempt with delay
7756 leency 138
	DEBUGF	2, "Searchap: second attempt after 5 seconds!\n"
7449 leency 139
	mcall	5,[delay]
140
	jmp START.params_done
7451 leency 141
@@:
3650 mario79 142
	mcall	-1
143
;---------------------------------------------------------------------
144
device_detect_f70:
145
;--------------------------------------
4607 mario79 146
	DEBUGF	1, "Searchap: read_folder_name: %s\n",read_folder_name
3650 mario79 147
;--------------------------------------
148
	mcall	70,read_folder
149
	test	eax,eax
150
	jz	@f
151
	cmp	eax,6
152
	je	@f
3664 mario79 153
;--------------------------------------
4607 mario79 154
	DEBUGF	1, "Searchap: read_folder_error\n"
3664 mario79 155
;--------------------------------------
3650 mario79 156
	jmp	exit
157
@@:
158
;--------------------------------------
159
	call	print_root_dir
3664 mario79 160
;--------------------------------------
3650 mario79 161
	mov	[left_folder_block],ebx
3664 mario79 162
	xor	eax,eax
163
	mov	[temp_counter_1],eax
164
	mov	[retrieved_devices_table_counter],eax
3650 mario79 165
.start_temp_counter_1:
166
	imul	esi,[temp_counter_1],304
167
	add	esi,[read_folder.return]
168
	add	esi,32+40
169
	call	copy_folder_name_1
3664 mario79 170
;--------------------------------------
4607 mario79 171
	DEBUGF	1, "Searchap: read_folder_1_name: %s\n",read_folder_1_name
3664 mario79 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
;--------------------------------------
4607 mario79 179
	DEBUGF	1, "Searchap: read_folder_error_1\n"
3664 mario79 180
;--------------------------------------
3650 mario79 181
	jmp	exit
182
@@:
183
	mov	eax,[read_folder_1.return]
184
	cmp	[eax+4],dword 0
185
	je	.continue
186
	mov	[right_folder_block],ebx
3664 mario79 187
	xor	ebp,ebp
3650 mario79 188
.start_copy_device_patch:
189
	imul	edi,[retrieved_devices_table_counter],10
190
	add	edi,retrieved_devices_table
191
	mov	[edi],byte '/'
192
	inc	edi
193
	imul	esi,[temp_counter_1],304
194
	add	esi,[read_folder.return]
195
	add	esi,32+40
196
	call	proc_copy_patch
197
	imul	esi,ebp,304
198
	add	esi,[read_folder_1.return]
199
	add	esi,32+40
200
	mov	[edi-1],byte '/'
201
	call	proc_copy_patch
202
	inc	[retrieved_devices_table_counter]
203
	inc	ebp
204
	cmp	ebp,[right_folder_block]
205
	jb	.start_copy_device_patch
206
.continue:
207
	inc	[temp_counter_1]
208
	mov	eax,[temp_counter_1]
209
	cmp	eax,[left_folder_block]
210
	jb	.start_temp_counter_1
211
	mov	esi,retrieved_devices_table+1
212
	call	copy_folder_name
213
	mov	esi,retrieved_devices_table+3
3664 mario79 214
	xor	ecx,ecx
3650 mario79 215
@@:
216
	add	esi,8
217
	cld
218
	lodsw
219
	inc	ecx
220
	cmp	ecx,[retrieved_devices_table_counter]
221
	ja	@f
222
	cmp	ax,'hd'
223
	jne	@r
224
	sub	esi,2
225
	call	copy_folder_name_1
226
	ret
227
@@:
228
	mov	esi,retrieved_devices_table+1
229
	call	copy_folder_name_1
230
	ret
231
;---------------------------------------------------------------------
232
load_file:
233
	mov	[fileinfo.subfunction],dword 5
234
	xor	eax,eax
235
	mov	[fileinfo.size],eax
236
	mov	[fs_error],eax
3664 mario79 237
;--------------------------------------
4607 mario79 238
	DEBUGF	1, "Searchap: get file info\n"
3664 mario79 239
;--------------------------------------
3724 mario79 240
	mcall	68,1
3650 mario79 241
	mcall	70,fileinfo
242
	mov	[fs_error],eax
243
	test	eax,eax
244
	jnz	.file_error
3664 mario79 245
;--------------------------------------
4607 mario79 246
	DEBUGF	1, "Searchap: file info ok\n"
3664 mario79 247
;--------------------------------------
248
	xor	eax,eax
249
	mov	[fileinfo.subfunction],eax	;dword 0
3650 mario79 250
	mov	eax,[fileinfo.return]
251
	mov	ecx,[eax+32]
3664 mario79 252
;--------------------------------------
4607 mario79 253
	DEBUGF	1, "Searchap: real file size: %d\n",ecx
3664 mario79 254
;--------------------------------------
3650 mario79 255
	test	ecx,ecx
256
	jz	.file_error
3664 mario79 257
	mov	eax,304*32+32 ; 9 Kb
258
	cmp	ecx,eax
3650 mario79 259
	jbe	@f
3664 mario79 260
	mov	ecx,eax
3650 mario79 261
;-----------------------------------
3781 Serge 262
@@:
3650 mario79 263
	mov	[fileinfo.size],ecx
3664 mario79 264
;--------------------------------------
4607 mario79 265
	DEBUGF	1, "Searchap: get file\n"
3664 mario79 266
;--------------------------------------
3724 mario79 267
	mcall	68,1
3650 mario79 268
	mcall	70,fileinfo
269
	mov	[fs_error],eax
270
	test	eax,eax
271
	jz	@f
272
;	cmp	eax,6
273
;	jne	.file_error
274
;	xor	eax,eax
275
;	mov	[fs_error],eax
276
;	jmp	@f
277
;-----------------------------------
278
.file_error:
3664 mario79 279
;--------------------------------------
4607 mario79 280
	DEBUGF	1, "Searchap: read file - error!\n"
3664 mario79 281
;--------------------------------------
3650 mario79 282
	ret
3781 Serge 283
;-----------------------------------
3664 mario79 284
@@:
285
;--------------------------------------
4607 mario79 286
	DEBUGF	1, "Searchap: read file corrected size: %d\n",[fileinfo.size]
3664 mario79 287
;--------------------------------------
3650 mario79 288
	ret
289
;---------------------------------------------------------------------
290
search_and_load_pointer_file_label:
291
	mov	[fileinfo.return],dword folder_data_1
292
	mov	ecx,[retrieved_devices_table_counter]
293
	dec	ecx	; /rd/1/ no need to check
294
	mov	[fileinfo.name],dword read_folder_name
295
	mov	esi,retrieved_devices_table
296
;	sub	esi,10	; deleted because /rd/1/ no need to check
297
.next_entry:
3664 mario79 298
;--------------------------------------
4607 mario79 299
	DEBUGF	1, "\nSearchap: copy next entry\n"
3664 mario79 300
;--------------------------------------
3650 mario79 301
	add	esi,10
302
	push	esi
303
	add	esi,1
304
	call	copy_folder_name
305
	mov	esi,basic_file_name-1
306
	dec	edi
307
	call	copy_folder_name.1
308
	pop	esi
3664 mario79 309
;--------------------------------------
4607 mario79 310
	DEBUGF	1, "Searchap: %s\n",dword[fileinfo.name]
3664 mario79 311
;--------------------------------------
3650 mario79 312
;	mcall	5,10
313
	push	ecx
314
	call	load_file
315
	pop	ecx
316
 
317
	xor	eax,eax
318
	cmp	[fs_error],eax
319
	jne	@f
320
	mov	eax,[fileinfo.size]
321
	cmp	eax,[basic_file_size]
322
	jae	.sucess
323
@@:
324
	dec	ecx
325
	jnz	.next_entry
3664 mario79 326
;--------------------------------------
5146 mario79 327
	DEBUGF	2, "Searchap: additional partition is not found!\n"
3664 mario79 328
;--------------------------------------
3650 mario79 329
	ret
330
.sucess:
7756 leency 331
	;call	compare_files_and_mount
332
	call	compare_files_and_mount.mount_now ;no need to compare files content
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
7756 leency 355
	pop	esi ecx
356
.mount_now:
3650 mario79 357
	mov	[compare_flag],byte 0
3664 mario79 358
;--------------------------------------
5146 mario79 359
	DEBUGF	2, "Searchap: compare files - success!\n"
4607 mario79 360
	DEBUGF	2, "Searchap: mount directory: %s\n",esi
361
	mov	[mount_dir],1
3664 mario79 362
;--------------------------------------
363
; prepare real directory path for mounting
364
	inc	esi
365
	mov	edi,f30_3_work_area+64
366
	call	proc_copy_patch
3676 mario79 367
	dec	edi
368
	mov	esi,real_additional_dir
369
	call	proc_copy_patch
3664 mario79 370
; prepare fake directory name
371
	mov	esi,additional_dir_name
372
	mov	edi,f30_3_work_area
373
	call	proc_copy_patch
3650 mario79 374
; here is call kernel function to mount the found partition
3781 Serge 375
; as "/kolibrios" directory to root directory "/"
3664 mario79 376
	mcall	30,3,f30_3_work_area
3650 mario79 377
	ret
378
;--------------------------------------
379
.not_match:
380
	mov	[compare_flag],byte 1
381
	pop	esi ecx
3664 mario79 382
;--------------------------------------
5146 mario79 383
	DEBUGF	1, "Searchap: compared files doesn't match!\n"
3664 mario79 384
;--------------------------------------
3650 mario79 385
	ret
386
;---------------------------------------------------------------------
387
copy_folder_name:
388
	mov	edi,read_folder_name+1
389
.1:
3664 mario79 390
proc_copy_patch:
391
	cld
3650 mario79 392
@@:
393
	lodsb
394
	stosb
3664 mario79 395
	test	al,al
396
	jnz	@r
3650 mario79 397
	ret
398
;---------------------------------------------------------------------
399
copy_folder_name_1:
400
	mov	edi,read_folder_1_name+1
3664 mario79 401
	jmp	proc_copy_patch
3650 mario79 402
;---------------------------------------------------------------------
403
print_retrieved_devices_table:
404
	mov	ecx,[retrieved_devices_table_counter]
405
	mov	edx,retrieved_devices_table
4607 mario79 406
	DEBUGF	1, "Searchap: retrieved_devices_table:\n"
407
	DEBUGF	1, "Searchap: ----------\n"
3650 mario79 408
@@:
4607 mario79 409
	DEBUGF	1, "Searchap: %s\n",edx
3650 mario79 410
	add	edx,10
411
	dec	ecx
412
	jnz	@b
4607 mario79 413
	DEBUGF	1, "\nSearchap: ----------\n"
3650 mario79 414
	ret
415
;---------------------------------------------------------------------
416
print_root_dir:
4607 mario79 417
	DEBUGF	1, "Searchap: ----------\n"
418
	DEBUGF	1, "Searchap: root dir:\n"
419
	DEBUGF	1, "Searchap: ----------\n"
3650 mario79 420
	pusha
421
	mov	ecx,ebx
422
	mov	edx,folder_data+32+40
423
@@:
4607 mario79 424
	DEBUGF	1, "Searchap: %s\n",edx
3650 mario79 425
	add	edx,304
426
	dec	ecx
427
	jnz	@b
428
	popa
4607 mario79 429
	DEBUGF	1, "\nSearchap: ----------\n"
3650 mario79 430
	ret
431
;-------------------------------------------------------------------------------
4607 mario79 432
include_debug_strings
433
;-------------------------------------------------------------------------------
3650 mario79 434
IM_END:
435
;-------------------------------------------------------------------------------
436
align 4
7446 0CodErr 437
PARAMS: rb 256
438
align 4
3650 mario79 439
left_folder_block	rd 1
440
right_folder_block	rd 1
441
temp_counter_1		rd 1
442
retrieved_devices_table_counter	rd 1
443
basic_file_size		rd 1
444
fs_error		rd 1
445
compare_flag		rb 1
4607 mario79 446
mount_dir		rb 1
3650 mario79 447
;-------------------------------------------------------------------------------
448
align 4
3664 mario79 449
f30_3_work_area:
450
	rb 128
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
;-------------------------------------------------------------------------------