Subversion Repositories Kolibri OS

Rev

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

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