Subversion Repositories Kolibri OS

Rev

Rev 1378 | Rev 1491 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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