Subversion Repositories Kolibri OS

Rev

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