Subversion Repositories Kolibri OS

Rev

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