Subversion Repositories Kolibri OS

Rev

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