Subversion Repositories Kolibri OS

Rev

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