Subversion Repositories Kolibri OS

Rev

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

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