Subversion Repositories Kolibri OS

Rev

Rev 1689 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;                                                              ;;
1289 diamond 2
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
431 serge 3
;; Distributed under terms of the GNU General Public License    ;;
4
;;                                                              ;;
5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
 
593 mikedld 7
$Revision: 3487 $
8
 
9
 
1491 Lrz 10
image_of_eax EQU esp+32
11
image_of_ebx EQU esp+20
488 spraid 12
 
72 diamond 13
; System function 70 - files with long names (LFN)
71 diamond 14
; diamond, 2006
15
 
16
iglobal
17
; in this table names must be in lowercase
18
rootdirs:
585 mario79 19
	db	2,'rd'
20
	dd	fs_OnRamdisk
21
	dd	fs_NextRamdisk
22
	db	7,'ramdisk'
23
	dd	fs_OnRamdisk
24
	dd	fs_NextRamdisk
25
	db	3,'hd0'
26
	dd	fs_OnHd0
27
	dd	fs_NextHd0
28
	db	3,'hd1'
29
	dd	fs_OnHd1
30
	dd	fs_NextHd1
31
	db	3,'hd2'
32
	dd	fs_OnHd2
33
	dd	fs_NextHd2
34
	db	3,'hd3'
35
	dd	fs_OnHd3
36
	dd	fs_NextHd3
37
	db	0
75 diamond 38
 
87 mario79 39
 
75 diamond 40
virtual_root_query:
585 mario79 41
	dd	fs_HasRamdisk
42
	db	'rd',0
43
	dd	fs_HasFloppy
44
	db	'fd',0
45
	dd	fs_HasHd0
46
	db	'hd0',0
47
	dd	fs_HasHd1
48
	db	'hd1',0
49
	dd	fs_HasHd2
50
	db	'hd2',0
51
	dd	fs_HasHd3
52
	db	'hd3',0
53
	dd	0
709 diamond 54
 
55
fs_additional_handlers:
56
        dd      biosdisk_handler, biosdisk_enum_root
57
; add new handlers here
58
        dd      0
59
 
71 diamond 60
endg
61
file_system_lfn:
1491 Lrz 62
; in: ebx->fileinfo block
71 diamond 63
; operation codes:
72 diamond 64
; 0 : read file
75 diamond 65
; 1 : read folder
83 diamond 66
; 2 : create/rewrite file
133 diamond 67
; 3 : write/append to file
68
; 4 : set end of file
86 diamond 69
; 5 : get file/directory attributes structure
70
; 6 : set file/directory attributes structure
91 diamond 71
; 7 : start application
171 diamond 72
; 8 : delete file
321 diamond 73
; 9 : create directory
71 diamond 74
 
1379 turbanoff 75
; parse file name
585 mario79 76
	lea	esi, [ebx+20]
77
	lodsb
78
	test	al, al
79
	jnz	@f
80
	mov	esi, [esi]
81
	lodsb
84 diamond 82
@@:
585 mario79 83
	cmp	al, '/'
84
	jz	.notcurdir
85
	dec	esi
86
	mov	ebp, esi
87
	test	al, al
88
	jnz	@f
89
	xor	ebp, ebp
521 diamond 90
@@:
585 mario79 91
	mov	esi, [current_slot]
92
	mov	esi, [esi+APPDATA.cur_dir]
93
	jmp	.parse_normal
521 diamond 94
.notcurdir:
585 mario79 95
	cmp	byte [esi], 0
96
	jz	.rootdir
97
	call	process_replace_file_name
521 diamond 98
.parse_normal:
585 mario79 99
	cmp dword [ebx], 7
100
	jne @F
101
	mov edx, [ebx+4]
102
	mov ebx, [ebx+8]
103
	call fs_execute  ; esi+ebp, ebx, edx
104
	mov [image_of_eax], eax
105
	ret
237 serge 106
@@:
585 mario79 107
	mov	edi, rootdirs-8
108
	xor	ecx, ecx
109
	push	esi
71 diamond 110
.scan1:
585 mario79 111
	pop	esi
112
	add	edi, ecx
113
	scasd
114
	scasd
115
	mov	cl, byte [edi]
116
	test	cl, cl
709 diamond 117
	jz	.notfound_try
585 mario79 118
	inc	edi
119
	push	esi
71 diamond 120
@@:
585 mario79 121
	lodsb
122
	or	al, 20h
123
	scasb
124
	loopz	@b
125
	jnz	.scan1
126
	lodsb
127
	cmp	al, '/'
128
	jz	.found1
129
	test	al, al
130
	jnz	.scan1
131
	pop	eax
71 diamond 132
; directory /xxx
133
.maindir:
709 diamond 134
	mov	esi, [edi+4]
135
.maindir_noesi:
585 mario79 136
	cmp	dword [ebx], 1
137
	jnz	.access_denied
138
	xor	eax, eax
1664 art_zh 139
	mov	ebp, [ebx+12]			;   
140
	mov	edx, [ebx+16]			;  
465 serge 141
    ;    add     edx, std_application_base_address
585 mario79 142
	push	dword [ebx+4]	; first block
143
	mov	ebx, [ebx+8]	; flags
78 diamond 144
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
585 mario79 145
	mov	edi, edx
709 diamond 146
	push    ecx
585 mario79 147
	mov	ecx, 32/4
148
	rep	stosd
709 diamond 149
	pop     ecx
585 mario79 150
	mov	byte [edx], 1	; version
75 diamond 151
.maindir_loop:
1379 turbanoff 152
	call	esi
585 mario79 153
	jc	.maindir_done
154
	inc	dword [edx+8]
155
	dec	dword [esp]
156
	jns	.maindir_loop
157
	dec	ebp
158
	js	.maindir_loop
159
	inc	dword [edx+4]
160
	mov	dword [edi], 0x10	; attributes: folder
161
	mov	dword [edi+4], 1	; name type: UNICODE
162
	push	eax
163
	xor	eax, eax
164
	add	edi, 8
709 diamond 165
	push    ecx
585 mario79 166
	mov	ecx, 40/4-2
167
	rep	stosd
709 diamond 168
	pop     ecx
585 mario79 169
	pop	eax
170
	push	eax edx
75 diamond 171
; convert number in eax to decimal UNICODE string
585 mario79 172
	push	edi
709 diamond 173
	push    ecx
585 mario79 174
	push	-'0'
709 diamond 175
	mov	ecx, 10
75 diamond 176
@@:
585 mario79 177
	xor	edx, edx
178
	div	ecx
179
	push	edx
180
	test	eax, eax
181
	jnz	@b
75 diamond 182
@@:
585 mario79 183
	pop	eax
184
	add	al, '0'
185
	stosb
186
	test	bl, 1		; UNICODE name?
187
	jz	.ansi2
188
	mov	byte [edi], 0
189
	inc	edi
78 diamond 190
.ansi2:
585 mario79 191
	test	al, al
192
	jnz	@b
193
	mov	byte [edi-1], 0
709 diamond 194
	pop     ecx
585 mario79 195
	pop	edi
78 diamond 196
; UNICODE name length is 520 bytes, ANSI - 264
585 mario79 197
	add	edi, 520
198
	test	bl, 1
199
	jnz	@f
200
	sub	edi, 520-264
78 diamond 201
@@:
585 mario79 202
	pop	edx eax
203
	jmp	.maindir_loop
75 diamond 204
.maindir_done:
585 mario79 205
	pop	eax
206
	mov	ebx, [edx+4]
207
	xor	eax, eax
208
	dec	ebp
209
	js	@f
210
	mov	al, ERROR_END_OF_FILE
75 diamond 211
@@:
585 mario79 212
	mov	[image_of_eax], eax
213
	mov	[image_of_ebx], ebx
214
	ret
71 diamond 215
; directory /
216
.rootdir:
585 mario79 217
	cmp	dword [ebx], 1	; read folder?
218
	jz	.readroot
75 diamond 219
.access_denied:
585 mario79 220
	mov	dword [image_of_eax], 10      ; access denied
221
	ret
71 diamond 222
 
75 diamond 223
.readroot:
224
; virtual root folder - special handler
585 mario79 225
	mov	esi, virtual_root_query
226
	mov	ebp, [ebx+12]
227
	mov	edx, [ebx+16]
465 serge 228
    ;    add     edx, std_application_base_address
585 mario79 229
	push	dword [ebx+4]	; first block
230
	mov	ebx, [ebx+8]	; flags
231
	xor	eax, eax
78 diamond 232
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
585 mario79 233
	mov	edi, edx
234
	mov	ecx, 32/4
235
	rep	stosd
236
	mov	byte [edx], 1	; version
75 diamond 237
.readroot_loop:
585 mario79 238
	cmp	dword [esi], eax
709 diamond 239
	jz	.readroot_done_static
585 mario79 240
	call	dword [esi]
241
	add	esi, 4
242
	test	eax, eax
243
	jnz	@f
75 diamond 244
.readroot_next:
585 mario79 245
	or	ecx, -1
246
	xchg	esi, edi
247
	repnz	scasb
248
	xchg	esi, edi
249
	jmp	.readroot_loop
75 diamond 250
@@:
585 mario79 251
	xor	eax, eax
252
	inc	dword [edx+8]
253
	dec	dword [esp]
254
	jns	.readroot_next
255
	dec	ebp
256
	js	.readroot_next
257
	inc	dword [edx+4]
258
	mov	dword [edi], 0x10	; attributes: folder
709 diamond 259
	mov	dword [edi+4], ebx	; name type: UNICODE
585 mario79 260
	add	edi, 8
261
	mov	ecx, 40/4-2
262
	rep	stosd
263
	push	edi
75 diamond 264
@@:
585 mario79 265
	lodsb
266
	stosb
267
	test	bl, 1
268
	jz	.ansi
269
	mov	byte [edi], 0
270
	inc	edi
78 diamond 271
.ansi:
585 mario79 272
	test	eax, eax
273
	jnz	@b
274
	pop	edi
275
	add	edi, 520
276
	test	bl, 1
277
	jnz	.readroot_loop
278
	sub	edi, 520-264
279
	jmp	.readroot_loop
709 diamond 280
.readroot_done_static:
281
        mov     esi, fs_additional_handlers-8
282
        sub     esp, 16
283
.readroot_ah_loop:
284
        add     esi, 8
285
        cmp     dword [esi], 0
286
        jz      .readroot_done
287
        xor     eax, eax
288
.readroot_ah_loop2:
289
        push    edi
290
        lea     edi, [esp+4]
291
        call    dword [esi+4]
292
        pop     edi
293
        test    eax, eax
294
        jz      .readroot_ah_loop
295
        inc     dword [edx+8]
296
        dec     dword [esp+16]
297
        jns     .readroot_ah_loop2
298
        dec     ebp
299
        js      .readroot_ah_loop2
300
        push    eax
301
        xor     eax, eax
302
        inc     dword [edx+4]
303
        mov     dword [edi], 0x10       ; attributes: folder
304
        mov     dword [edi+4], ebx
305
        add     edi, 8
306
        mov     ecx, 40/4-2
307
        rep     stosd
308
        push    esi edi
309
        lea     esi, [esp+12]
310
@@:
311
        lodsb
312
        stosb
313
        test    bl, 1
314
        jz      .ansi3
315
        mov     byte [edi], 0
316
        inc     edi
317
.ansi3:
318
        test    al, al
319
        jnz     @b
320
        pop     edi esi eax
321
        add     edi, 520
322
        test    bl, 1
323
        jnz     .readroot_ah_loop2
324
        sub     edi, 520-264
325
        jmp     .readroot_ah_loop2
75 diamond 326
.readroot_done:
709 diamond 327
        add     esp, 16
585 mario79 328
	pop	eax
329
	mov	ebx, [edx+4]
330
	xor	eax, eax
331
	dec	ebp
332
	js	@f
333
	mov	al, ERROR_END_OF_FILE
75 diamond 334
@@:
585 mario79 335
	mov	[image_of_eax], eax
336
	mov	[image_of_ebx], ebx
337
	ret
709 diamond 338
.notfound_try:
339
        mov     edi, fs_additional_handlers
340
@@:
341
        cmp     dword [edi], 0
1270 diamond 342
        jz      .notfound
709 diamond 343
        call    dword [edi]
344
        scasd
345
        scasd
346
        jmp     @b
521 diamond 347
.notfound:
585 mario79 348
	mov	dword [image_of_eax], ERROR_FILE_NOT_FOUND
349
	and	dword [image_of_ebx], 0
350
	ret
75 diamond 351
 
709 diamond 352
.notfounda:
353
        cmp     edi, esp
354
        jnz     .notfound
355
        add     esp, 8
356
        jmp     .notfound
357
 
71 diamond 358
.found1:
585 mario79 359
	pop	eax
360
	cmp	byte [esi], 0
361
	jz	.maindir
709 diamond 362
.found2:
71 diamond 363
; read partition number
585 mario79 364
	xor	ecx, ecx
365
	xor	eax, eax
71 diamond 366
@@:
585 mario79 367
	lodsb
368
	cmp	al, '/'
369
	jz	.done1
370
	test	al, al
371
	jz	.done1
372
	sub	al, '0'
373
	cmp	al, 9
709 diamond 374
	ja	.notfounda
585 mario79 375
	lea	ecx, [ecx*5]
376
	lea	ecx, [ecx*2+eax]
377
	jmp	@b
71 diamond 378
.done1:
709 diamond 379
	jecxz	.notfounda
585 mario79 380
	test	al, al
381
	jnz	@f
382
	dec	esi
71 diamond 383
@@:
585 mario79 384
	cmp	byte [esi], 0
385
	jnz	@f
386
	test	ebp, ebp
387
	jz	@f
388
	mov	esi, ebp
389
	xor	ebp, ebp
521 diamond 390
@@:
75 diamond 391
; now [edi] contains handler address, ecx - partition number,
392
; esi points to ASCIIZ string - rest of name
585 mario79 393
	jmp	dword [edi]
71 diamond 394
 
395
; handlers for devices
75 diamond 396
; in: ecx = 0 => query virtual directory /xxx
71 diamond 397
; in: ecx = partition number
398
;     esi -> relative (for device) name
399
;     ebx -> fileinfo
521 diamond 400
;     ebp = 0 or pointer to rest of name from folder addressed by esi
488 spraid 401
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
71 diamond 402
 
403
fs_OnRamdisk:
585 mario79 404
	cmp	ecx, 1
405
	jnz	file_system_lfn.notfound
406
	mov	eax, [ebx]
407
	cmp	eax, fs_NumRamdiskServices
408
	jae	.not_impl
409
	mov	ecx, [ebx+12]
410
	mov	edx, [ebx+16]
465 serge 411
   ;     add     edx, std_application_base_address
585 mario79 412
	add	ebx, 4
413
	call	dword [fs_RamdiskServices + eax*4]
414
	mov	[image_of_eax], eax
415
	mov	[image_of_ebx], ebx
416
	ret
71 diamond 417
.not_impl:
585 mario79 418
	mov	dword [image_of_eax], 2       ; not implemented
419
	ret
71 diamond 420
 
86 diamond 421
fs_NotImplemented:
585 mario79 422
	mov	eax, 2
423
	ret
86 diamond 424
 
71 diamond 425
fs_RamdiskServices:
585 mario79 426
	dd	fs_RamdiskRead
427
	dd	fs_RamdiskReadFolder
428
	dd	fs_RamdiskRewrite
429
	dd	fs_RamdiskWrite
430
	dd	fs_RamdiskSetFileEnd
431
	dd	fs_RamdiskGetFileInfo
432
	dd	fs_RamdiskSetFileInfo
433
	dd	0
434
	dd	fs_RamdiskDelete
435
	dd	fs_RamdiskCreateFolder
83 diamond 436
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
71 diamond 437
 
438
fs_OnHd0:
585 mario79 439
	call	reserve_hd1
440
	mov	[hdbase], 0x1F0
441
	mov	[hdid], 0
442
	push	1
443
	jmp	fs_OnHd
71 diamond 444
fs_OnHd1:
585 mario79 445
	call	reserve_hd1
446
	mov	[hdbase], 0x1F0
447
	mov	[hdid], 0x10
448
	push	2
449
	jmp	fs_OnHd
71 diamond 450
fs_OnHd2:
585 mario79 451
	call	reserve_hd1
452
	mov	[hdbase], 0x170
453
	mov	[hdid], 0
454
	push	3
455
	jmp	fs_OnHd
71 diamond 456
fs_OnHd3:
585 mario79 457
	call	reserve_hd1
458
	mov	[hdbase], 0x170
459
	mov	[hdid], 0x10
460
	push	4
71 diamond 461
fs_OnHd:
585 mario79 462
	call	reserve_hd_channel
463
	pop	eax
464
	mov	[hdpos], eax
465
	cmp	ecx, 0x100
709 diamond 466
	jae	fs_OnHdAndBd.nf
585 mario79 467
	cmp	cl, [DRIVE_DATA+1+eax]
709 diamond 468
fs_OnHdAndBd:
585 mario79 469
	jbe	@f
75 diamond 470
.nf:
585 mario79 471
	call	free_hd_channel
472
	and	[hd1_status], 0
473
	mov	dword [image_of_eax], 5       ; not found
474
	ret
71 diamond 475
@@:
1378 turbanoff 476
	mov	[known_part], ecx ;	mov	[fat32part], ecx
585 mario79 477
	push	ebx esi
478
	call	choice_necessity_partition_1
479
	pop	esi ebx
480
	mov	ecx, [ebx+12]
481
	mov	edx, [ebx+16]
465 serge 482
    ;    add     edx, std_application_base_address
585 mario79 483
	mov	eax, [ebx]
484
	cmp	eax, fs_NumHdServices
485
	jae	.not_impl
486
	add	ebx, 4
487
	call	dword [fs_HdServices + eax*4]
488
	call	free_hd_channel
489
	and	[hd1_status], 0
490
	mov	[image_of_eax], eax
491
	mov	[image_of_ebx], ebx
492
	ret
75 diamond 493
.not_impl:
585 mario79 494
	call	free_hd_channel
495
	and	[hd1_status], 0
496
	mov	dword [image_of_eax], 2       ; not implemented
497
	ret
71 diamond 498
 
499
fs_HdServices:
585 mario79 500
	dd	fs_HdRead
501
	dd	fs_HdReadFolder
502
	dd	fs_HdRewrite
503
	dd	fs_HdWrite
504
	dd	fs_HdSetFileEnd
505
	dd	fs_HdGetFileInfo
506
	dd	fs_HdSetFileInfo
507
	dd	0
508
	dd	fs_HdDelete
509
	dd	fs_HdCreateFolder
83 diamond 510
fs_NumHdServices = ($ - fs_HdServices)/4
75 diamond 511
 
87 mario79 512
 
75 diamond 513
fs_HasRamdisk:
585 mario79 514
	mov	al, 1	; we always have ramdisk
515
	ret
75 diamond 516
 
517
fs_HasFloppy:
585 mario79 518
	cmp	byte [DRIVE_DATA], 0
519
	setnz	al
520
	ret
75 diamond 521
 
522
fs_HasHd0:
585 mario79 523
	mov	al, [DRIVE_DATA+1]
524
	and	al, 11000000b
525
	cmp	al, 01000000b
526
	setz	al
527
	ret
75 diamond 528
fs_HasHd1:
585 mario79 529
	mov	al, [DRIVE_DATA+1]
530
	and	al, 00110000b
531
	cmp	al, 00010000b
532
	setz	al
533
	ret
75 diamond 534
fs_HasHd2:
585 mario79 535
	mov	al, [DRIVE_DATA+1]
536
	and	al, 00001100b
537
	cmp	al, 00000100b
538
	setz	al
539
	ret
75 diamond 540
fs_HasHd3:
585 mario79 541
	mov	al, [DRIVE_DATA+1]
542
	and	al, 00000011b
543
	cmp	al, 00000001b
544
	setz	al
545
	ret
75 diamond 546
 
87 mario79 547
;*******************************************************
548
fs_HasCd0:
585 mario79 549
	mov	al, [DRIVE_DATA+1]
550
	and	al, 11000000b
551
	cmp	al, 10000000b
552
	setz	al
553
	ret
87 mario79 554
fs_HasCd1:
585 mario79 555
	mov	al, [DRIVE_DATA+1]
556
	and	al, 00110000b
557
	cmp	al, 00100000b
558
	setz	al
559
	ret
87 mario79 560
fs_HasCd2:
585 mario79 561
	mov	al, [DRIVE_DATA+1]
562
	and	al, 00001100b
563
	cmp	al, 00001000b
564
	setz	al
565
	ret
87 mario79 566
fs_HasCd3:
585 mario79 567
	mov	al, [DRIVE_DATA+1]
568
	and	al, 00000011b
569
	cmp	al, 00000010b
570
	setz	al
571
	ret
237 serge 572
;*******************************************************
87 mario79 573
 
75 diamond 574
; fs_NextXXX functions:
575
; in: eax = partition number, from which start to scan
576
; out: CF=1 => no more partitions
577
;      CF=0 => eax=next partition number
578
 
579
fs_NextRamdisk:
580
; we always have /rd/1
585 mario79 581
	test	eax, eax
582
	stc
583
	jnz	@f
584
	mov	al, 1
585
	clc
75 diamond 586
@@:
585 mario79 587
	ret
75 diamond 588
 
589
fs_NextFloppy:
381 serge 590
; we have /fd/1 iff (([DRIVE_DATA] and 0xF0) != 0) and /fd/2 iff (([DRIVE_DATA] and 0x0F) != 0)
585 mario79 591
	test	byte [DRIVE_DATA], 0xF0
592
	jz	.no1
593
	test	eax, eax
594
	jnz	.no1
595
	inc	eax
596
	ret	; CF cleared
75 diamond 597
.no1:
585 mario79 598
	test	byte [DRIVE_DATA], 0x0F
599
	jz	.no2
600
	cmp	al, 2
601
	jae	.no2
602
	mov	al, 2
603
	clc
604
	ret
75 diamond 605
.no2:
585 mario79 606
	stc
607
	ret
75 diamond 608
 
609
; on hdx, we have partitions from 1 to [0x40002+x]
610
fs_NextHd0:
585 mario79 611
	push	0
612
	jmp	fs_NextHd
75 diamond 613
fs_NextHd1:
585 mario79 614
	push	1
615
	jmp	fs_NextHd
75 diamond 616
fs_NextHd2:
585 mario79 617
	push	2
618
	jmp	fs_NextHd
75 diamond 619
fs_NextHd3:
585 mario79 620
	push	3
75 diamond 621
fs_NextHd:
585 mario79 622
	pop	ecx
623
	movzx	ecx, byte [DRIVE_DATA+2+ecx]
624
	cmp	eax, ecx
625
	jae	fs_NextFloppy.no2
626
	inc	eax
627
	clc
628
	ret
237 serge 629
 
87 mario79 630
;*******************************************************
631
fs_NextCd:
632
; we always have /cdX/1
585 mario79 633
	test	eax, eax
634
	stc
635
	jnz	@f
636
	mov	al, 1
637
	clc
87 mario79 638
@@:
585 mario79 639
	ret
87 mario79 640
;*******************************************************
641
 
709 diamond 642
; Additional FS handlers.
643
; This handler gets the control each time when fn 70 is called
644
; with unknown item of root subdirectory.
645
; in: esi -> name
646
;     ebp = 0 or rest of name relative to esi
647
; out: if the handler processes path, he must not return in file_system_lfn,
648
;      but instead pop return address and return directly to the caller
649
;      otherwise simply return
650
 
651
; here we test for /bd/... - BIOS disks
652
biosdisk_handler:
653
        cmp     [NumBiosDisks], 0
654
        jz      .ret
655
        mov     al, [esi]
656
        or      al, 20h
657
        cmp     al, 'b'
658
        jnz     .ret
659
        mov     al, [esi+1]
660
        or      al, 20h
661
        cmp     al, 'd'
662
        jnz     .ret
663
        push    esi
664
        inc     esi
665
        inc     esi
666
        cmp     byte [esi], '0'
667
        jb      .ret2
668
        cmp     byte [esi], '9'
669
        ja      .ret2
670
        xor     edx, edx
671
@@:
672
        lodsb
673
        test    al, al
674
        jz      .ok
675
        cmp     al, '/'
676
        jz      .ok
677
        sub     al, '0'
678
        cmp     al, 9
679
        ja      .ret2
680
        lea     edx, [edx*5]
681
        lea     edx, [edx*2+eax]
682
        jmp     @b
683
.ret2:
684
        pop     esi
685
.ret:
686
        ret
687
.ok:
688
        cmp     al, '/'
689
        jz      @f
690
        dec     esi
691
@@:
692
        add     dl, 80h
693
        xor     ecx, ecx
694
@@:
695
        cmp     dl, [BiosDisksData+ecx*4]
696
        jz      .ok2
697
        inc     ecx
698
        cmp     ecx, [NumBiosDisks]
699
        jb      @b
700
        jmp     .ret2
701
.ok2:
702
        add     esp, 8
703
        test    al, al
704
        jnz     @f
705
        mov     esi, fs_BdNext
706
        jmp     file_system_lfn.maindir_noesi
707
@@:
708
        push    ecx
709
        push    fs_OnBd
710
        mov     edi, esp
711
        jmp     file_system_lfn.found2
712
 
713
fs_BdNext:
714
        cmp     eax, [BiosDiskPartitions+ecx*4]
715
	inc	eax
716
	cmc
717
	ret
718
 
719
fs_OnBd:
720
        pop     edx edx
721
; edx = disk number, ecx = partition number
722
; esi+ebp = name
723
	call	reserve_hd1
724
	add     edx, 0x80
725
	mov     [hdpos], edx
726
	cmp     ecx, [BiosDiskPartitions+(edx-0x80)*4]
727
	jmp     fs_OnHdAndBd
728
 
729
; This handler is called when virtual root is enumerated
730
; and must return all items which can be handled by this.
731
; It is called several times, first time with eax=0
732
; in: eax = 0 for first call, previously returned value for subsequent calls
733
; out: eax = 0 => no more items
734
;      eax != 0 => buffer pointed to by edi contains name of item
735
 
736
; here we enumerate existing BIOS disks /bd
737
biosdisk_enum_root:
738
        cmp     eax, [NumBiosDisks]
739
        jae     .end
740
        push    eax
741
        movzx   eax, byte [BiosDisksData+eax*4]
742
        sub     al, 80h
743
        push    eax
744
        mov     al, 'b'
745
        stosb
746
        mov     al, 'd'
747
        stosb
748
        pop     eax
749
        cmp     al, 10
750
        jae     .big
751
        add     al, '0'
752
        stosb
753
        mov     byte [edi], 0
754
        pop     eax
755
        inc     eax
756
        ret
757
.end:
758
        xor     eax, eax
759
        ret
760
.big:
1689 art_zh 761
        push    ecx edx
709 diamond 762
        push    -'0'
763
        mov     ecx, 10
764
@@:
765
        xor     edx, edx
766
        div     ecx
767
        push    edx
768
        test    eax, eax
769
        jnz     @b
770
        xchg    eax, edx
771
@@:
772
        pop     eax
773
        add     al, '0'
774
        stosb
775
        jnz     @b
1689 art_zh 776
        pop     edx ecx
709 diamond 777
        pop     eax
778
        inc     eax
779
        ret
780
 
521 diamond 781
process_replace_file_name:
585 mario79 782
	mov	ebp, [full_file_name_table]
783
	mov	edi, [full_file_name_table.size]
784
	dec	edi
785
	shl	edi, 7
786
	add	edi, ebp
521 diamond 787
.loop:
585 mario79 788
	cmp	edi, ebp
789
	jb	.notfound
790
	push	esi edi
521 diamond 791
@@:
585 mario79 792
	cmp	byte [edi], 0
793
	jz	.dest_done
794
	lodsb
795
	test	al, al
796
	jz	.cont
797
	or	al, 20h
798
	scasb
799
	jz	@b
800
	jmp	.cont
521 diamond 801
.dest_done:
585 mario79 802
	cmp	byte [esi], 0
803
	jz	.found
804
	cmp	byte [esi], '/'
805
	jnz	.cont
806
	inc	esi
807
	jmp	.found
521 diamond 808
.cont:
585 mario79 809
	pop	edi esi
810
	sub	edi, 128
811
	jmp	.loop
521 diamond 812
.found:
585 mario79 813
	pop	edi eax
814
	mov	ebp, esi
815
	cmp	byte [esi], 0
816
	lea	esi, [edi+64]
817
	jnz	.ret
521 diamond 818
.notfound:
585 mario79 819
	xor	ebp, ebp
521 diamond 820
.ret:
585 mario79 821
	ret
521 diamond 822
 
823
sys_current_directory:
1304 Lrz 824
;	mov	esi, [current_slot]
825
;	mov	esi, [esi+APPDATA.cur_dir]
826
;	mov	edx, esi
827
 
1305 diamond 828
;get length string of appdata.cur_dir
829
	mov	eax, [current_slot]
830
	mov	edi, [eax+APPDATA.cur_dir]
1304 Lrz 831
 
832
	dec	ebx
585 mario79 833
	jz	.set
1304 Lrz 834
	dec	ebx
585 mario79 835
	jz	.get
836
	ret
521 diamond 837
.get:
838
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
839
; for our code: ebx->buffer,ecx=len
1304 Lrz 840
max_cur_dir	equ	0x1000
841
 
842
	mov	ebx,edi
843
 
844
	push	ecx
845
	push	edi
846
 
847
	xor	eax,eax
848
	mov	ecx,max_cur_dir
849
 
850
	repne	scasb		;find zerro at and string
1305 diamond 851
	jnz     .error		; no zero in cur_dir: internal error, should not happen
1304 Lrz 852
 
853
	sub	edi,ebx		;lenght for copy
854
	inc	edi
855
        mov	[esp+32+8],edi	;return in eax
856
 
1305 diamond 857
	cmp	edx, edi
858
	jbe     @f
859
	mov     edx, edi
860
@@:
861
;source string
1304 Lrz 862
	pop	esi
863
;destination string
864
	pop	edi
1305 diamond 865
	cmp	edx, 1
866
	jbe	.ret
1304 Lrz 867
 
868
	mov	al,'/'		;start string with '/'
585 mario79 869
	stosb
1304 Lrz 870
	mov	ecx,edx
871
	rep	movsb           ;copy string
872
.ret:	ret
873
 
874
.error: add	esp,8
875
	or	dword [esp+32],-1	;error not found zerro at string ->[eax+APPDATA.cur_dir]
585 mario79 876
	ret
521 diamond 877
.set:
878
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
879
; for our code: ebx->string to set
1289 diamond 880
; use generic resolver with APPDATA.cur_dir as destination
1304 Lrz 881
	push	max_cur_dir	;0x1000
882
	push	edi	;destination
883
	mov	ebx,ecx
1289 diamond 884
	call	get_full_file_name
885
	ret
886
 
887
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
888
; destroys all registers except ebp,esp
889
get_full_file_name:
890
	push	ebp
891
	mov	esi, [current_slot]
892
	mov	esi, [esi+APPDATA.cur_dir]
893
	mov	edx, esi
521 diamond 894
@@:
585 mario79 895
	inc	esi
896
	cmp	byte [esi-1], 0
897
	jnz	@b
898
	dec	esi
899
	cmp	byte [ebx], '/'
900
	jz	.set_absolute
521 diamond 901
; string gives relative path
1289 diamond 902
	mov	edi, [esp+8]	; destination
521 diamond 903
.relative:
585 mario79 904
	cmp	byte [ebx], 0
905
	jz	.set_ok
906
	cmp	word [ebx], '.'
907
	jz	.set_ok
908
	cmp	word [ebx], './'
909
	jnz	@f
910
	add	ebx, 2
911
	jmp	.relative
521 diamond 912
@@:
585 mario79 913
	cmp	word [ebx], '..'
914
	jnz	.doset_relative
915
	cmp	byte [ebx+2], 0
916
	jz	@f
917
	cmp	byte [ebx+2], '/'
918
	jnz	.doset_relative
521 diamond 919
@@:
585 mario79 920
	dec	esi
921
	cmp	byte [esi], '/'
922
	jnz	@b
923
	add	ebx, 3
924
	jmp	.relative
1289 diamond 925
.set_ok:
926
	cmp	edx, edi	; is destination equal to APPDATA.cur_dir?
927
	jz	.set_ok.cur_dir
928
	sub	esi, edx
929
	cmp	esi, [esp+12]
930
	jb	.set_ok.copy
931
.fail:
932
	mov	byte [edi], 0
933
	xor	eax, eax	; fail
934
	pop	ebp
935
	ret	8
936
.set_ok.copy:
937
	mov	ecx, esi
938
	mov	esi, edx
939
	rep	movsb
940
	mov	byte [edi], 0
941
.ret.ok:
942
	mov	al, 1	; ok
943
	pop	ebp
944
	ret	8
945
.set_ok.cur_dir:
946
	mov	byte [esi], 0
947
	jmp	.ret.ok
521 diamond 948
.doset_relative:
1289 diamond 949
	cmp	edx, edi
950
	jz	.doset_relative.cur_dir
951
	sub	esi, edx
952
	cmp	esi, [esp+12]
953
	jae	.fail
954
	mov	ecx, esi
955
	mov	esi, edx
956
	mov	edx, edi
957
	rep	movsb
958
	jmp	.doset_relative.copy
959
.doset_relative.cur_dir:
960
	mov	edi, esi
961
.doset_relative.copy:
962
	add	edx, [esp+12]
963
	mov	byte [edi], '/'
964
	inc	edi
965
	cmp	edi, edx
966
	jae	.overflow
521 diamond 967
@@:
585 mario79 968
	mov	al, [ebx]
969
	inc	ebx
1289 diamond 970
	stosb
585 mario79 971
	test	al, al
1289 diamond 972
	jz	.ret.ok
973
	cmp	edi, edx
585 mario79 974
	jb	@b
1289 diamond 975
.overflow:
976
	dec	edi
977
	jmp	.fail
521 diamond 978
.set_absolute:
585 mario79 979
	lea	esi, [ebx+1]
980
	call	process_replace_file_name
1289 diamond 981
	mov	edi, [esp+8]
982
	mov	edx, [esp+12]
983
	add	edx, edi
521 diamond 984
.set_copy:
585 mario79 985
	lodsb
986
	stosb
987
	test	al, al
988
	jz	.set_part2
521 diamond 989
.set_copy_cont:
585 mario79 990
	cmp	edi, edx
991
	jb	.set_copy
1289 diamond 992
	jmp	.overflow
521 diamond 993
.set_part2:
585 mario79 994
	mov	esi, ebp
995
	xor	ebp, ebp
996
	test	esi, esi
1289 diamond 997
	jz	.ret.ok
585 mario79 998
	mov	byte [edi-1], '/'
1379 turbanoff 999
	jmp	.set_copy_cont
1664 art_zh 1000
 
1001
; ===============  moved from fs/iso9660.inc
1002
 
1003
char_todown:
1004
; convert character to uppercase, using cp866 encoding
1005
; in: al=symbol
1006
; out: al=converted symbol
1007
	cmp	al, 'A'
1008
	jb	.ret
1009
	cmp	al, 'Z'
1010
	jbe	.az
1011
	cmp	al, ''
1012
	jb	.ret
1013
	cmp	al, ''
1014
	jb	.rus1
1015
	cmp	al, ''
1016
	ja	.ret
1017
; 0x90-0x9F -> 0xE0-0xEF
1018
	add	al, ''-''
1019
.ret:
1020
	ret
1021
.rus1:
1022
; 0x80-0x8F -> 0xA0-0xAF
1023
.az:
1024
	add	al, 0x20
1025
	ret
1026
 
1027
uni2ansi_char:
1028
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
1029
; in: ax=UNICODE character
1030
; out: al=converted ANSI character
1031
	cmp	ax, 0x80
1032
	jb	.ascii
1033
	cmp	ax, 0x401
1034
	jz	.yo1
1035
	cmp	ax, 0x451
1036
	jz	.yo2
1037
	cmp	ax, 0x410
1038
	jb	.unk
1039
	cmp	ax, 0x440
1040
	jb	.rus1
1041
	cmp	ax, 0x450
1042
	jb	.rus2
1043
.unk:
1044
	mov	al, '_'
1045
	jmp	.doit
1046
.yo1:
1047
	mov	al, ''
1048
	jmp	.doit
1049
.yo2:
1050
	mov	al, ''
1051
	jmp	.doit
1052
.rus1:
1053
; 0x410-0x43F -> 0x80-0xAF
1054
	add	al, 0x70
1055
	jmp	.doit
1056
.rus2:
1057
; 0x440-0x44F -> 0xE0-0xEF
1058
	add	al, 0xA0
1059
.ascii:
1060
.doit:
1061
	ret