Subversion Repositories Kolibri OS

Rev

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