Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5565 serge 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 6317 $
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
6078 serge 23
ERROR_OUT_OF_MEMORY  = 12
593 mikedld 24
 
1491 Lrz 25
image_of_eax EQU esp+32
26
image_of_ebx EQU esp+20
488 spraid 27
 
72 diamond 28
; System function 70 - files with long names (LFN)
71 diamond 29
; diamond, 2006
30
 
31
iglobal
32
; in this table names must be in lowercase
33
rootdirs:
87 mario79 34
;**********************************************
2434 Serge 35
        db      3,'cd0'
36
        dd      fs_OnCd0
37
        dd      fs_NextCd
38
        db      3,'cd1'
39
        dd      fs_OnCd1
40
        dd      fs_NextCd
41
        db      3,'cd2'
42
        dd      fs_OnCd2
43
        dd      fs_NextCd
44
        db      3,'cd3'
45
        dd      fs_OnCd3
46
        dd      fs_NextCd
5201 serge 47
        db      3,'cd4'
48
        dd      fs_OnCd4
49
        dd      fs_NextCd
50
        db      3,'cd5'
51
        dd      fs_OnCd5
52
        dd      fs_NextCd
53
        db      3,'cd6'
54
        dd      fs_OnCd6
55
        dd      fs_NextCd
56
        db      3,'cd7'
57
        dd      fs_OnCd7
58
        dd      fs_NextCd
59
        db      3,'cd8'
60
        dd      fs_OnCd8
61
        dd      fs_NextCd
62
        db      3,'cd9'
63
        dd      fs_OnCd9
64
        dd      fs_NextCd
65
        db      4,'cd10'
66
        dd      fs_OnCd10
67
        dd      fs_NextCd
68
        db      4,'cd11'
69
        dd      fs_OnCd11
70
        dd      fs_NextCd
237 serge 71
;***********************************************
2434 Serge 72
        db      0
75 diamond 73
 
87 mario79 74
 
75 diamond 75
virtual_root_query:
87 mario79 76
;**********************************************
2434 Serge 77
        dd      fs_HasCd0
78
        db      'cd0',0
79
        dd      fs_HasCd1
80
        db      'cd1',0
81
        dd      fs_HasCd2
82
        db      'cd2',0
83
        dd      fs_HasCd3
84
        db      'cd3',0
5201 serge 85
        dd      fs_HasCd4
86
        db      'cd4',0
87
        dd      fs_HasCd5
88
        db      'cd5',0
89
        dd      fs_HasCd6
90
        db      'cd6',0
91
        dd      fs_HasCd7
92
        db      'cd7',0
93
        dd      fs_HasCd8
94
        db      'cd8',0
95
        dd      fs_HasCd9
96
        db      'cd9',0
97
        dd      fs_HasCd10
98
        db      'cd10',0
99
        dd      fs_HasCd11
100
        db      'cd11',0
87 mario79 101
;**********************************************
2434 Serge 102
        dd      0
71 diamond 103
endg
3500 Serge 104
 
105
file_system_lfn_protected:
106
        pushad
107
        call    protect_from_terminate
108
        call    file_system_lfn
109
        call    unprotect_from_terminate
110
        popad
111
        mov     [image_of_eax], eax
112
        mov     [image_of_ebx], ebx
113
        ret
114
 
71 diamond 115
file_system_lfn:
1491 Lrz 116
; in: ebx->fileinfo block
71 diamond 117
; operation codes:
72 diamond 118
; 0 : read file
75 diamond 119
; 1 : read folder
83 diamond 120
; 2 : create/rewrite file
133 diamond 121
; 3 : write/append to file
122
; 4 : set end of file
86 diamond 123
; 5 : get file/directory attributes structure
124
; 6 : set file/directory attributes structure
91 diamond 125
; 7 : start application
171 diamond 126
; 8 : delete file
321 diamond 127
; 9 : create directory
71 diamond 128
 
1379 turbanoff 129
; parse file name
2434 Serge 130
        lea     esi, [ebx+20]
131
        lodsb
132
        test    al, al
133
        jnz     @f
134
        mov     esi, [esi]
135
        lodsb
84 diamond 136
@@:
6317 serge 137
        lea     ebp, [esi-1]
138
        cmp     dword [ebx], 7
139
        jne     @F
140
        mov     edx, [ebx+4]
141
        mov     ebx, [ebx+8]
142
        call    fs_execute; ebp, ebx, edx
143
        mov     [image_of_eax], eax
144
        ret
145
@@:
2434 Serge 146
        cmp     al, '/'
147
        jz      .notcurdir
148
        dec     esi
149
        mov     ebp, esi
150
        test    al, al
151
        jnz     @f
152
        xor     ebp, ebp
521 diamond 153
@@:
2434 Serge 154
        mov     esi, [current_slot]
155
        mov     esi, [esi+APPDATA.cur_dir]
156
        jmp     .parse_normal
521 diamond 157
.notcurdir:
2434 Serge 158
        cmp     byte [esi], 0
159
        jz      .rootdir
160
        call    process_replace_file_name
521 diamond 161
.parse_normal:
2434 Serge 162
        mov     edi, rootdirs-8
163
        xor     ecx, ecx
164
        push    esi
71 diamond 165
.scan1:
2434 Serge 166
        pop     esi
167
        add     edi, ecx
168
        scasd
169
        scasd
170
        mov     cl, byte [edi]
171
        test    cl, cl
172
        jz      .notfound_try
173
        inc     edi
174
        push    esi
71 diamond 175
@@:
2434 Serge 176
        lodsb
177
        or      al, 20h
178
        scasb
179
        loopz   @b
180
        jnz     .scan1
181
        lodsb
182
        cmp     al, '/'
183
        jz      .found1
184
        test    al, al
185
        jnz     .scan1
186
        pop     eax
71 diamond 187
; directory /xxx
188
.maindir:
2434 Serge 189
        mov     esi, [edi+4]
709 diamond 190
.maindir_noesi:
2434 Serge 191
        cmp     dword [ebx], 1
192
        jnz     .access_denied
193
        xor     eax, eax
5201 serge 194
        mov     ebp, [ebx+12] ;the number of blocks to read
195
        mov     edx, [ebx+16] ;where to write the result
465 serge 196
    ;    add     edx, std_application_base_address
2434 Serge 197
        push    dword [ebx+4]   ; first block
198
        mov     ebx, [ebx+8]    ; flags
78 diamond 199
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
2434 Serge 200
        mov     edi, edx
201
        push    ecx
202
        mov     ecx, 32/4
203
        rep stosd
204
        pop     ecx
205
        mov     byte [edx], 1   ; version
75 diamond 206
.maindir_loop:
2434 Serge 207
        call    esi
208
        jc      .maindir_done
209
        inc     dword [edx+8]
210
        dec     dword [esp]
211
        jns     .maindir_loop
212
        dec     ebp
213
        js      .maindir_loop
214
        inc     dword [edx+4]
215
        mov     dword [edi], 0x10       ; attributes: folder
216
        mov     dword [edi+4], 1        ; name type: UNICODE
217
        push    eax
218
        xor     eax, eax
219
        add     edi, 8
220
        push    ecx
221
        mov     ecx, 40/4-2
222
        rep stosd
223
        pop     ecx
224
        pop     eax
225
        push    eax edx
75 diamond 226
; convert number in eax to decimal UNICODE string
2434 Serge 227
        push    edi
228
        push    ecx
229
        push    -'0'
230
        mov     ecx, 10
75 diamond 231
@@:
2434 Serge 232
        xor     edx, edx
233
        div     ecx
234
        push    edx
235
        test    eax, eax
236
        jnz     @b
75 diamond 237
@@:
2434 Serge 238
        pop     eax
239
        add     al, '0'
240
        stosb
241
        test    bl, 1           ; UNICODE name?
242
        jz      .ansi2
243
        mov     byte [edi], 0
244
        inc     edi
78 diamond 245
.ansi2:
2434 Serge 246
        test    al, al
247
        jnz     @b
248
        mov     byte [edi-1], 0
249
        pop     ecx
250
        pop     edi
78 diamond 251
; UNICODE name length is 520 bytes, ANSI - 264
2434 Serge 252
        add     edi, 520
253
        test    bl, 1
254
        jnz     @f
255
        sub     edi, 520-264
78 diamond 256
@@:
2434 Serge 257
        pop     edx eax
258
        jmp     .maindir_loop
75 diamond 259
.maindir_done:
2434 Serge 260
        pop     eax
261
        mov     ebx, [edx+4]
262
        xor     eax, eax
263
        dec     ebp
264
        js      @f
265
        mov     al, ERROR_END_OF_FILE
75 diamond 266
@@:
2434 Serge 267
        mov     [image_of_eax], eax
268
        mov     [image_of_ebx], ebx
269
        ret
71 diamond 270
; directory /
271
.rootdir:
2434 Serge 272
        cmp     dword [ebx], 1  ; read folder?
273
        jz      .readroot
75 diamond 274
.access_denied:
2434 Serge 275
        mov     dword [image_of_eax], 10      ; access denied
276
        ret
71 diamond 277
 
75 diamond 278
.readroot:
279
; virtual root folder - special handler
2434 Serge 280
        mov     ebp, [ebx+12]
281
        mov     edx, [ebx+16]
465 serge 282
    ;    add     edx, std_application_base_address
2434 Serge 283
        push    dword [ebx+4]   ; first block
284
        mov     ebx, [ebx+8]    ; flags
285
        xor     eax, eax
78 diamond 286
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
2434 Serge 287
        mov     edi, edx
288
        mov     ecx, 32/4
289
        rep stosd
290
        mov     byte [edx], 1   ; version
4287 Serge 291
        sub     esp, 16
292
.readroot_ah_loop2:
293
        push    edi
294
        lea     edi, [esp+4]
295
        call    dyndisk_enum_root
296
        pop     edi
297
        test    eax, eax
298
        jz      .readroot_done_dynamic
299
        inc     dword [edx+8]
300
        dec     dword [esp+16]
301
        jns     .readroot_ah_loop2
302
        dec     ebp
303
        js      .readroot_ah_loop2
304
        push    eax
305
        xor     eax, eax
306
        inc     dword [edx+4]
307
        mov     dword [edi], 0x10       ; attributes: folder
308
        mov     dword [edi+4], ebx
309
        add     edi, 8
310
        mov     ecx, 40/4-2
311
        rep stosd
312
        push    esi edi
313
        lea     esi, [esp+12]
314
@@:
315
        lodsb
316
        stosb
317
        test    bl, 1
318
        jz      .ansi3
319
        mov     byte [edi], 0
320
        inc     edi
321
.ansi3:
322
        test    al, al
323
        jnz     @b
324
        pop     edi esi eax
325
        add     edi, 520
326
        test    bl, 1
327
        jnz     .readroot_ah_loop2
328
        sub     edi, 520-264
329
        jmp     .readroot_ah_loop2
330
.readroot_done_dynamic:
331
        add     esp, 16
332
        mov     esi, virtual_root_query
75 diamond 333
.readroot_loop:
2434 Serge 334
        cmp     dword [esi], eax
4287 Serge 335
        jz      .readroot_done
2434 Serge 336
        call    dword [esi]
337
        add     esi, 4
338
        test    eax, eax
339
        jnz     @f
75 diamond 340
.readroot_next:
2434 Serge 341
        or      ecx, -1
342
        xchg    esi, edi
343
        repnz scasb
344
        xchg    esi, edi
345
        jmp     .readroot_loop
75 diamond 346
@@:
2434 Serge 347
        xor     eax, eax
348
        inc     dword [edx+8]
349
        dec     dword [esp]
350
        jns     .readroot_next
351
        dec     ebp
352
        js      .readroot_next
353
        inc     dword [edx+4]
354
        mov     dword [edi], 0x10       ; attributes: folder
355
        mov     dword [edi+4], ebx      ; name type: UNICODE
356
        add     edi, 8
357
        mov     ecx, 40/4-2
358
        rep stosd
359
        push    edi
75 diamond 360
@@:
2434 Serge 361
        lodsb
362
        stosb
363
        test    bl, 1
364
        jz      .ansi
365
        mov     byte [edi], 0
366
        inc     edi
78 diamond 367
.ansi:
2434 Serge 368
        test    eax, eax
369
        jnz     @b
370
        pop     edi
371
        add     edi, 520
372
        test    bl, 1
373
        jnz     .readroot_loop
374
        sub     edi, 520-264
375
        jmp     .readroot_loop
75 diamond 376
.readroot_done:
2434 Serge 377
        pop     eax
378
        mov     ebx, [edx+4]
379
        xor     eax, eax
380
        dec     ebp
381
        js      @f
382
        mov     al, ERROR_END_OF_FILE
75 diamond 383
@@:
2434 Serge 384
        mov     [image_of_eax], eax
385
        mov     [image_of_ebx], ebx
386
        ret
709 diamond 387
.notfound_try:
4287 Serge 388
        call    dyndisk_handler
521 diamond 389
.notfound:
2434 Serge 390
        mov     dword [image_of_eax], ERROR_FILE_NOT_FOUND
391
        and     dword [image_of_ebx], 0
392
        ret
75 diamond 393
 
709 diamond 394
.notfounda:
395
        cmp     edi, esp
396
        jnz     .notfound
2130 serge 397
        call    dword [edi+4]
398
        add     esp, 16
709 diamond 399
        jmp     .notfound
400
 
71 diamond 401
.found1:
2434 Serge 402
        pop     eax
403
        cmp     byte [esi], 0
404
        jz      .maindir
709 diamond 405
.found2:
71 diamond 406
; read partition number
2434 Serge 407
        xor     ecx, ecx
408
        xor     eax, eax
71 diamond 409
@@:
2434 Serge 410
        lodsb
411
        cmp     al, '/'
412
        jz      .done1
413
        test    al, al
414
        jz      .done1
415
        sub     al, '0'
416
        cmp     al, 9
417
        ja      .notfounda
418
        lea     ecx, [ecx*5]
419
        lea     ecx, [ecx*2+eax]
420
        jmp     @b
71 diamond 421
.done1:
2434 Serge 422
        jecxz   .notfounda
423
        test    al, al
424
        jnz     @f
425
        dec     esi
71 diamond 426
@@:
2434 Serge 427
        cmp     byte [esi], 0
428
        jnz     @f
429
        test    ebp, ebp
430
        jz      @f
431
        mov     esi, ebp
432
        xor     ebp, ebp
521 diamond 433
@@:
75 diamond 434
; now [edi] contains handler address, ecx - partition number,
435
; esi points to ASCIIZ string - rest of name
2434 Serge 436
        jmp     dword [edi]
71 diamond 437
 
438
; handlers for devices
75 diamond 439
; in: ecx = 0 => query virtual directory /xxx
71 diamond 440
; in: ecx = partition number
441
;     esi -> relative (for device) name
442
;     ebx -> fileinfo
521 diamond 443
;     ebp = 0 or pointer to rest of name from folder addressed by esi
488 spraid 444
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
71 diamond 445
 
86 diamond 446
fs_NotImplemented:
2434 Serge 447
        mov     eax, 2
448
        ret
5201 serge 449
;-----------------------------------------------------------------------------
87 mario79 450
fs_OnCd0:
2434 Serge 451
        call    reserve_cd
452
        mov     [ChannelNumber], 1
453
        mov     [DiskNumber], 0
454
        push    6
455
        push    1
456
        jmp     fs_OnCd
5201 serge 457
;-----------------------------------------------------------------------------
87 mario79 458
fs_OnCd1:
2434 Serge 459
        call    reserve_cd
460
        mov     [ChannelNumber], 1
461
        mov     [DiskNumber], 1
462
        push    4
463
        push    2
464
        jmp     fs_OnCd
5201 serge 465
;-----------------------------------------------------------------------------
87 mario79 466
fs_OnCd2:
2434 Serge 467
        call    reserve_cd
468
        mov     [ChannelNumber], 2
469
        mov     [DiskNumber], 0
470
        push    2
471
        push    3
472
        jmp     fs_OnCd
5201 serge 473
;-----------------------------------------------------------------------------
87 mario79 474
fs_OnCd3:
2434 Serge 475
        call    reserve_cd
476
        mov     [ChannelNumber], 2
477
        mov     [DiskNumber], 1
478
        push    0
479
        push    4
5201 serge 480
        jmp     fs_OnCd
481
;-----------------------------------------------------------------------------
482
fs_OnCd4:
483
        call    reserve_cd
484
        mov     [ChannelNumber], 1
485
        mov     [DiskNumber], 0
486
        push    6
487
        push    5
488
        jmp     fs_OnCd
489
;-----------------------------------------------------------------------------
490
fs_OnCd5:
491
        call    reserve_cd
492
        mov     [ChannelNumber], 1
493
        mov     [DiskNumber], 1
494
        push    4
495
        push    6
496
        jmp     fs_OnCd
497
;-----------------------------------------------------------------------------
498
fs_OnCd6:
499
        call    reserve_cd
500
        mov     [ChannelNumber], 2
501
        mov     [DiskNumber], 0
502
        push    2
503
        push    7
504
        jmp     fs_OnCd
505
;-----------------------------------------------------------------------------
506
fs_OnCd7:
507
        call    reserve_cd
508
        mov     [ChannelNumber], 2
509
        mov     [DiskNumber], 1
510
        push    0
511
        push    8
512
        jmp     fs_OnCd
513
;-----------------------------------------------------------------------------
514
fs_OnCd8:
515
        call    reserve_cd
516
        mov     [ChannelNumber], 1
517
        mov     [DiskNumber], 0
518
        push    6
519
        push    9
520
        jmp     fs_OnCd
521
;-----------------------------------------------------------------------------
522
fs_OnCd9:
523
        call    reserve_cd
524
        mov     [ChannelNumber], 1
525
        mov     [DiskNumber], 1
526
        push    4
527
        push    10
528
        jmp     fs_OnCd
529
;-----------------------------------------------------------------------------
530
fs_OnCd10:
531
        call    reserve_cd
532
        mov     [ChannelNumber], 2
533
        mov     [DiskNumber], 0
534
        push    2
535
        push    11
536
        jmp     fs_OnCd
537
;-----------------------------------------------------------------------------
538
fs_OnCd11:
539
        call    reserve_cd
540
        mov     [ChannelNumber], 2
541
        mov     [DiskNumber], 1
542
        push    0
543
        push    12
544
;-----------------------------------------------------------------------------
87 mario79 545
fs_OnCd:
2434 Serge 546
        pop     eax
547
        mov     [cdpos], eax
5201 serge 548
        call    reserve_cd_channel
2434 Serge 549
        pop     eax
550
        cmp     ecx, 0x100
551
        jae     .nf
552
        push    ecx ebx
553
        mov     cl, al
5201 serge 554
 
555
        push    eax
556
        mov     eax, [cdpos]
557
        dec     eax
558
        shr     eax, 2
559
        lea     eax, [eax*5]
560
        mov     bl, [eax+DRIVE_DATA+1]
561
        pop     eax
562
 
2434 Serge 563
        shr     bl, cl
564
        test    bl, 2
565
        pop     ebx ecx
87 mario79 566
 
2434 Serge 567
        jnz     @f
87 mario79 568
.nf:
2434 Serge 569
        call    free_cd_channel
570
        and     [cd_status], 0
571
        mov     dword [image_of_eax], 5       ; not found
572
        ret
87 mario79 573
@@:
2434 Serge 574
        mov     ecx, [ebx+12]
575
        mov     edx, [ebx+16]
465 serge 576
    ;    add     edx, std_application_base_address
2434 Serge 577
        mov     eax, [ebx]
578
        cmp     eax, fs_NumCdServices
579
        jae     .not_impl
580
        add     ebx, 4
581
        call    dword [fs_CdServices + eax*4]
582
        call    free_cd_channel
583
        and     [cd_status], 0
584
        mov     [image_of_eax], eax
585
        mov     [image_of_ebx], ebx
586
        ret
87 mario79 587
.not_impl:
2434 Serge 588
        call    free_cd_channel
589
        and     [cd_status], 0
590
        mov     dword [image_of_eax], 2       ; not implemented
591
        ret
5201 serge 592
;-----------------------------------------------------------------------------
87 mario79 593
fs_CdServices:
2434 Serge 594
        dd      fs_CdRead
595
        dd      fs_CdReadFolder
596
        dd      fs_NotImplemented
597
        dd      fs_NotImplemented
598
        dd      fs_NotImplemented
599
        dd      fs_CdGetFileInfo
600
        dd      fs_NotImplemented
601
        dd      0
602
        dd      fs_NotImplemented
603
        dd      fs_NotImplemented
90 mario79 604
fs_NumCdServices = ($ - fs_CdServices)/4
5201 serge 605
;-----------------------------------------------------------------------------
87 mario79 606
fs_HasCd0:
3626 Serge 607
        test    byte [DRIVE_DATA+1], 10000000b
608
        setnz   al
2434 Serge 609
        ret
5201 serge 610
;--------------------------------------
87 mario79 611
fs_HasCd1:
3626 Serge 612
        test    byte [DRIVE_DATA+1], 00100000b
613
        setnz   al
2434 Serge 614
        ret
5201 serge 615
;--------------------------------------
87 mario79 616
fs_HasCd2:
3626 Serge 617
        test    byte [DRIVE_DATA+1], 00001000b
618
        setnz   al
2434 Serge 619
        ret
5201 serge 620
;--------------------------------------
87 mario79 621
fs_HasCd3:
3626 Serge 622
        test    byte [DRIVE_DATA+1], 00000010b
623
        setnz   al
2434 Serge 624
        ret
5201 serge 625
;--------------------------------------
626
fs_HasCd4:
627
        test    byte [DRIVE_DATA+6], 10000000b
628
        setnz   al
629
        ret
630
;--------------------------------------
631
fs_HasCd5:
632
        test    byte [DRIVE_DATA+6], 00100000b
633
        setnz   al
634
        ret
635
;--------------------------------------
636
fs_HasCd6:
637
        test    byte [DRIVE_DATA+6], 00001000b
638
        setnz   al
639
        ret
640
;--------------------------------------
641
fs_HasCd7:
642
        test    byte [DRIVE_DATA+6], 00000010b
643
        setnz   al
644
        ret
645
;--------------------------------------
646
fs_HasCd8:
647
        test    byte [DRIVE_DATA+11], 10000000b
648
        setnz   al
649
        ret
650
;--------------------------------------
651
fs_HasCd9:
652
        test    byte [DRIVE_DATA+11], 00100000b
653
        setnz   al
654
        ret
655
;--------------------------------------
656
fs_HasCd10:
657
        test    byte [DRIVE_DATA+11], 00001000b
658
        setnz   al
659
        ret
660
;--------------------------------------
661
fs_HasCd11:
662
        test    byte [DRIVE_DATA+11], 00000010b
663
        setnz   al
664
        ret
665
;-----------------------------------------------------------------------------
666
;
75 diamond 667
; fs_NextXXX functions:
668
; in: eax = partition number, from which start to scan
669
; out: CF=1 => no more partitions
670
;      CF=0 => eax=next partition number
5201 serge 671
;
672
;-----------------------------------------------------------------------------
87 mario79 673
fs_NextCd:
674
; we always have /cdX/1
2434 Serge 675
        test    eax, eax
676
        stc
677
        jnz     @f
678
        mov     al, 1
679
        clc
87 mario79 680
@@:
2434 Serge 681
        ret
3725 Serge 682
;-----------------------------------------------------------------------------
521 diamond 683
process_replace_file_name:
3725 Serge 684
; in
685
; esi - path with filename(f.70)
686
;
687
; out
688
; ebp - full filename
689
        pushfd
690
        cli
2434 Serge 691
        mov     ebp, [full_file_name_table]
3725 Serge 692
        xor     edi, edi
521 diamond 693
.loop:
3725 Serge 694
        cmp     edi, [full_file_name_table.size]
695
        jae     .notfound
2434 Serge 696
        push    esi edi
3725 Serge 697
        shl     edi, 7 ; edi*128
698
        add     edi, ebp
521 diamond 699
@@:
3725 Serge 700
        cmp     byte [edi], 0 ; end of dir_name
2434 Serge 701
        jz      .dest_done
702
        lodsb
703
        test    al, al
704
        jz      .cont
3725 Serge 705
        or      al, 20h ; 32 - space char
2434 Serge 706
        scasb
707
        jz      @b
708
        jmp     .cont
521 diamond 709
.dest_done:
2434 Serge 710
        cmp     byte [esi], 0
711
        jz      .found
712
        cmp     byte [esi], '/'
713
        jnz     .cont
714
        inc     esi
715
        jmp     .found
521 diamond 716
.cont:
2434 Serge 717
        pop     edi esi
3725 Serge 718
        inc     edi
2434 Serge 719
        jmp     .loop
521 diamond 720
.found:
2434 Serge 721
        pop     edi eax
3725 Serge 722
        shl     edi, 7 ; edi*128
723
        add     edi, ebp
2434 Serge 724
        mov     ebp, esi
725
        cmp     byte [esi], 0
726
        lea     esi, [edi+64]
727
        jnz     .ret
521 diamond 728
.notfound:
2434 Serge 729
        xor     ebp, ebp
521 diamond 730
.ret:
3725 Serge 731
        popfd
2434 Serge 732
        ret
3725 Serge 733
;-----------------------------------------------------------------------------
734
uglobal
735
lock_flag_for_f30_3 rb 1
736
endg
3908 Serge 737
 
521 diamond 738
sys_current_directory:
2434 Serge 739
;       mov     esi, [current_slot]
740
;       mov     esi, [esi+APPDATA.cur_dir]
741
;       mov     edx, esi
1304 Lrz 742
 
1305 diamond 743
;get length string of appdata.cur_dir
2434 Serge 744
        mov     eax, [current_slot]
745
        mov     edi, [eax+APPDATA.cur_dir]
1304 Lrz 746
 
2434 Serge 747
        dec     ebx
748
        jz      .set
749
        dec     ebx
750
        jz      .get
3725 Serge 751
        dec     ebx
752
        jz      .mount_additional_directory
2434 Serge 753
        ret
3725 Serge 754
 
755
.mount_additional_directory:
756
; sysfunction 30.2: [for app] eax=30,ebx=3,ecx->dir name+dir path (128)
757
; for our code: nothing
758
 
759
; check lock of the function
760
        cmp     [lock_flag_for_f30_3], 1
761
        je      @f
762
 
763
        mov     esi, ecx
764
        mov     edi, sysdir_name1
765
; copying fake directory name
766
        mov     ecx, 63
767
        pushfd
768
        cli
769
        cld
770
        rep movsb
771
; terminator of name, in case if we get the inlet trash
772
        inc     esi
773
        xor     eax, eax
774
        stosb
775
; copying real directory path for mounting
776
        mov     ecx, 63
777
        rep movsb
778
; terminator of name, in case if we get the inlet trash
779
        xor     eax, eax
780
        stosb
781
; increase the pointer of inputs for procedure "process_replace_file_name"
782
        mov     [full_file_name_table.size], 2
783
; block the ability to call f.30.3 because for one session is necessary
784
; for us only once
785
        mov     [lock_flag_for_f30_3], 1
786
        popfd
787
@@:
788
        ret
789
 
521 diamond 790
.get:
791
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
792
; for our code: ebx->buffer,ecx=len
2434 Serge 793
max_cur_dir     equ     0x1000
1304 Lrz 794
 
2434 Serge 795
        mov     ebx, edi
1304 Lrz 796
 
2434 Serge 797
        push    ecx
798
        push    edi
1304 Lrz 799
 
2434 Serge 800
        xor     eax, eax
801
        mov     ecx, max_cur_dir
1304 Lrz 802
 
2434 Serge 803
        repne scasb             ;find zerro at and string
804
        jnz     .error          ; no zero in cur_dir: internal error, should not happen
1304 Lrz 805
 
2434 Serge 806
        sub     edi, ebx        ;lenght for copy
807
        inc     edi
808
        mov     [esp+32+8], edi ;return in eax
1304 Lrz 809
 
2434 Serge 810
        cmp     edx, edi
811
        jbe     @f
812
        mov     edx, edi
1305 diamond 813
@@:
814
;source string
2434 Serge 815
        pop     esi
1304 Lrz 816
;destination string
2434 Serge 817
        pop     edi
818
        cmp     edx, 1
819
        jbe     .ret
1304 Lrz 820
 
2434 Serge 821
        mov     al, '/'         ;start string with '/'
822
        stosb
823
        mov     ecx, edx
824
        rep movsb               ;copy string
825
.ret:
826
        ret
1304 Lrz 827
 
2434 Serge 828
.error:
829
        add     esp, 8
830
        or      dword [esp+32], -1      ;error not found zerro at string ->[eax+APPDATA.cur_dir]
831
        ret
521 diamond 832
.set:
833
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
834
; for our code: ebx->string to set
1289 diamond 835
; use generic resolver with APPDATA.cur_dir as destination
2434 Serge 836
        push    max_cur_dir     ;0x1000
837
        push    edi     ;destination
838
        mov     ebx, ecx
839
        call    get_full_file_name
840
        ret
1289 diamond 841
 
842
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
843
; destroys all registers except ebp,esp
844
get_full_file_name:
2434 Serge 845
        push    ebp
846
        mov     esi, [current_slot]
847
        mov     esi, [esi+APPDATA.cur_dir]
848
        mov     edx, esi
521 diamond 849
@@:
2434 Serge 850
        inc     esi
851
        cmp     byte [esi-1], 0
852
        jnz     @b
853
        dec     esi
854
        cmp     byte [ebx], '/'
855
        jz      .set_absolute
521 diamond 856
; string gives relative path
2434 Serge 857
        mov     edi, [esp+8]    ; destination
521 diamond 858
.relative:
2434 Serge 859
        cmp     byte [ebx], 0
860
        jz      .set_ok
861
        cmp     word [ebx], '.'
862
        jz      .set_ok
863
        cmp     word [ebx], './'
864
        jnz     @f
865
        add     ebx, 2
866
        jmp     .relative
521 diamond 867
@@:
2434 Serge 868
        cmp     word [ebx], '..'
869
        jnz     .doset_relative
870
        cmp     byte [ebx+2], 0
871
        jz      @f
872
        cmp     byte [ebx+2], '/'
873
        jnz     .doset_relative
521 diamond 874
@@:
2434 Serge 875
        dec     esi
876
        cmp     byte [esi], '/'
877
        jnz     @b
878
        add     ebx, 3
879
        jmp     .relative
1289 diamond 880
.set_ok:
2434 Serge 881
        cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
882
        jz      .set_ok.cur_dir
883
        sub     esi, edx
884
        cmp     esi, [esp+12]
885
        jb      .set_ok.copy
1289 diamond 886
.fail:
2434 Serge 887
        mov     byte [edi], 0
888
        xor     eax, eax        ; fail
889
        pop     ebp
890
        ret     8
1289 diamond 891
.set_ok.copy:
2434 Serge 892
        mov     ecx, esi
893
        mov     esi, edx
894
        rep movsb
895
        mov     byte [edi], 0
1289 diamond 896
.ret.ok:
2434 Serge 897
        mov     al, 1   ; ok
898
        pop     ebp
899
        ret     8
1289 diamond 900
.set_ok.cur_dir:
2434 Serge 901
        mov     byte [esi], 0
902
        jmp     .ret.ok
521 diamond 903
.doset_relative:
2434 Serge 904
        cmp     edx, edi
905
        jz      .doset_relative.cur_dir
906
        sub     esi, edx
907
        cmp     esi, [esp+12]
908
        jae     .fail
909
        mov     ecx, esi
910
        mov     esi, edx
911
        mov     edx, edi
912
        rep movsb
913
        jmp     .doset_relative.copy
1289 diamond 914
.doset_relative.cur_dir:
2434 Serge 915
        mov     edi, esi
1289 diamond 916
.doset_relative.copy:
2434 Serge 917
        add     edx, [esp+12]
918
        mov     byte [edi], '/'
919
        inc     edi
920
        cmp     edi, edx
921
        jae     .overflow
521 diamond 922
@@:
2434 Serge 923
        mov     al, [ebx]
924
        inc     ebx
925
        stosb
926
        test    al, al
927
        jz      .ret.ok
928
        cmp     edi, edx
929
        jb      @b
1289 diamond 930
.overflow:
2434 Serge 931
        dec     edi
932
        jmp     .fail
521 diamond 933
.set_absolute:
2434 Serge 934
        lea     esi, [ebx+1]
935
        call    process_replace_file_name
936
        mov     edi, [esp+8]
937
        mov     edx, [esp+12]
938
        add     edx, edi
521 diamond 939
.set_copy:
2434 Serge 940
        lodsb
941
        stosb
942
        test    al, al
943
        jz      .set_part2
521 diamond 944
.set_copy_cont:
2434 Serge 945
        cmp     edi, edx
946
        jb      .set_copy
947
        jmp     .overflow
521 diamond 948
.set_part2:
2434 Serge 949
        mov     esi, ebp
950
        xor     ebp, ebp
951
        test    esi, esi
952
        jz      .ret.ok
953
        mov     byte [edi-1], '/'
954
        jmp     .set_copy_cont