Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5363 yogev_ezra 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 6333 $
9
 
2889 turbanoff 10
ERROR_SUCCESS        = 0
11
ERROR_DISK_BASE      = 1
12
ERROR_UNSUPPORTED_FS = 2
13
ERROR_UNKNOWN_FS     = 3
14
ERROR_PARTITION      = 4
15
ERROR_FILE_NOT_FOUND = 5
16
ERROR_END_OF_FILE    = 6
17
ERROR_MEMORY_POINTER = 7
18
ERROR_DISK_FULL      = 8
19
ERROR_FAT_TABLE      = 9 ;deprecated
20
ERROR_FS_FAIL        = 9
21
ERROR_ACCESS_DENIED  = 10
22
ERROR_DEVICE         = 11
5994 pathoswith 23
ERROR_OUT_OF_MEMORY  = 12
2288 clevermous 24
 
25
image_of_eax EQU esp+32
26
image_of_ebx EQU esp+20
27
 
28
; System function 70 - files with long names (LFN)
29
; diamond, 2006
30
 
31
iglobal
32
; in this table names must be in lowercase
33
rootdirs:
34
;**********************************************
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
4700 mario79 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
2288 clevermous 71
;***********************************************
72
        db      0
73
 
74
 
75
virtual_root_query:
76
;**********************************************
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
4700 mario79 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
2288 clevermous 101
;**********************************************
102
        dd      0
103
endg
3296 clevermous 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
 
2288 clevermous 115
file_system_lfn:
116
; in: ebx->fileinfo block
117
; operation codes:
118
; 0 : read file
119
; 1 : read folder
120
; 2 : create/rewrite file
121
; 3 : write/append to file
122
; 4 : set end of file
123
; 5 : get file/directory attributes structure
124
; 6 : set file/directory attributes structure
125
; 7 : start application
126
; 8 : delete file
127
; 9 : create directory
128
 
129
; parse file name
130
        lea     esi, [ebx+20]
131
        lodsb
132
        test    al, al
133
        jnz     @f
134
        mov     esi, [esi]
135
        lodsb
136
@@:
6333 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
@@:
2288 clevermous 146
        cmp     al, '/'
147
        jz      .notcurdir
148
        dec     esi
149
        mov     ebp, esi
150
        test    al, al
151
        jnz     @f
152
        xor     ebp, ebp
153
@@:
154
        mov     esi, [current_slot]
155
        mov     esi, [esi+APPDATA.cur_dir]
156
        jmp     .parse_normal
157
.notcurdir:
158
        cmp     byte [esi], 0
159
        jz      .rootdir
160
        call    process_replace_file_name
161
.parse_normal:
162
        mov     edi, rootdirs-8
163
        xor     ecx, ecx
164
        push    esi
165
.scan1:
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
175
@@:
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
187
; directory /xxx
188
.maindir:
189
        mov     esi, [edi+4]
190
.maindir_noesi:
191
        cmp     dword [ebx], 1
192
        jnz     .access_denied
193
        xor     eax, eax
4700 mario79 194
        mov     ebp, [ebx+12] ;the number of blocks to read
195
        mov     edx, [ebx+16] ;where to write the result
2288 clevermous 196
    ;    add     edx, std_application_base_address
197
        push    dword [ebx+4]   ; first block
198
        mov     ebx, [ebx+8]    ; flags
199
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
200
        mov     edi, edx
201
        push    ecx
202
        mov     ecx, 32/4
203
        rep stosd
204
        pop     ecx
205
        mov     byte [edx], 1   ; version
206
.maindir_loop:
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
226
; convert number in eax to decimal UNICODE string
227
        push    edi
228
        push    ecx
229
        push    -'0'
230
        mov     ecx, 10
231
@@:
232
        xor     edx, edx
233
        div     ecx
234
        push    edx
235
        test    eax, eax
236
        jnz     @b
237
@@:
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
245
.ansi2:
246
        test    al, al
247
        jnz     @b
248
        mov     byte [edi-1], 0
249
        pop     ecx
250
        pop     edi
251
; UNICODE name length is 520 bytes, ANSI - 264
252
        add     edi, 520
253
        test    bl, 1
254
        jnz     @f
255
        sub     edi, 520-264
256
@@:
257
        pop     edx eax
258
        jmp     .maindir_loop
259
.maindir_done:
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
266
@@:
267
        mov     [image_of_eax], eax
268
        mov     [image_of_ebx], ebx
269
        ret
270
; directory /
271
.rootdir:
272
        cmp     dword [ebx], 1  ; read folder?
273
        jz      .readroot
274
.access_denied:
275
        mov     dword [image_of_eax], 10      ; access denied
276
        ret
277
 
278
.readroot:
279
; virtual root folder - special handler
280
        mov     ebp, [ebx+12]
281
        mov     edx, [ebx+16]
282
    ;    add     edx, std_application_base_address
283
        push    dword [ebx+4]   ; first block
284
        mov     ebx, [ebx+8]    ; flags
285
        xor     eax, eax
286
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
287
        mov     edi, edx
288
        mov     ecx, 32/4
289
        rep stosd
290
        mov     byte [edx], 1   ; version
4277 clevermous 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
2288 clevermous 333
.readroot_loop:
334
        cmp     dword [esi], eax
4277 clevermous 335
        jz      .readroot_done
2288 clevermous 336
        call    dword [esi]
337
        add     esi, 4
338
        test    eax, eax
339
        jnz     @f
340
.readroot_next:
341
        or      ecx, -1
342
        xchg    esi, edi
343
        repnz scasb
344
        xchg    esi, edi
345
        jmp     .readroot_loop
346
@@:
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
360
@@:
361
        lodsb
362
        stosb
363
        test    bl, 1
364
        jz      .ansi
365
        mov     byte [edi], 0
366
        inc     edi
367
.ansi:
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
376
.readroot_done:
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
383
@@:
384
        mov     [image_of_eax], eax
385
        mov     [image_of_ebx], ebx
386
        ret
387
.notfound_try:
4277 clevermous 388
        call    dyndisk_handler
2288 clevermous 389
.notfound:
390
        mov     dword [image_of_eax], ERROR_FILE_NOT_FOUND
391
        and     dword [image_of_ebx], 0
392
        ret
393
 
394
.notfounda:
395
        cmp     edi, esp
396
        jnz     .notfound
397
        call    dword [edi+4]
398
        add     esp, 16
399
        jmp     .notfound
400
 
401
.found1:
402
        pop     eax
403
        cmp     byte [esi], 0
404
        jz      .maindir
405
.found2:
406
; read partition number
407
        xor     ecx, ecx
408
        xor     eax, eax
409
@@:
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
421
.done1:
422
        jecxz   .notfounda
423
        test    al, al
424
        jnz     @f
425
        dec     esi
426
@@:
427
        cmp     byte [esi], 0
428
        jnz     @f
429
        test    ebp, ebp
430
        jz      @f
431
        mov     esi, ebp
432
        xor     ebp, ebp
433
@@:
434
; now [edi] contains handler address, ecx - partition number,
435
; esi points to ASCIIZ string - rest of name
436
        jmp     dword [edi]
437
 
438
; handlers for devices
439
; in: ecx = 0 => query virtual directory /xxx
440
; in: ecx = partition number
441
;     esi -> relative (for device) name
442
;     ebx -> fileinfo
443
;     ebp = 0 or pointer to rest of name from folder addressed by esi
444
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
445
 
446
fs_NotImplemented:
447
        mov     eax, 2
448
        ret
4700 mario79 449
;-----------------------------------------------------------------------------
2288 clevermous 450
fs_OnCd0:
451
        call    reserve_cd
452
        mov     [ChannelNumber], 1
453
        mov     [DiskNumber], 0
454
        push    6
455
        push    1
456
        jmp     fs_OnCd
4700 mario79 457
;-----------------------------------------------------------------------------
2288 clevermous 458
fs_OnCd1:
459
        call    reserve_cd
460
        mov     [ChannelNumber], 1
461
        mov     [DiskNumber], 1
462
        push    4
463
        push    2
464
        jmp     fs_OnCd
4700 mario79 465
;-----------------------------------------------------------------------------
2288 clevermous 466
fs_OnCd2:
467
        call    reserve_cd
468
        mov     [ChannelNumber], 2
469
        mov     [DiskNumber], 0
470
        push    2
471
        push    3
472
        jmp     fs_OnCd
4700 mario79 473
;-----------------------------------------------------------------------------
2288 clevermous 474
fs_OnCd3:
475
        call    reserve_cd
476
        mov     [ChannelNumber], 2
477
        mov     [DiskNumber], 1
478
        push    0
479
        push    4
4700 mario79 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
;-----------------------------------------------------------------------------
2288 clevermous 545
fs_OnCd:
546
        pop     eax
547
        mov     [cdpos], eax
4700 mario79 548
        call    reserve_cd_channel
2288 clevermous 549
        pop     eax
550
        cmp     ecx, 0x100
551
        jae     .nf
552
        push    ecx ebx
553
        mov     cl, al
4700 mario79 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
 
2288 clevermous 563
        shr     bl, cl
564
        test    bl, 2
565
        pop     ebx ecx
566
 
567
        jnz     @f
568
.nf:
569
        call    free_cd_channel
570
        and     [cd_status], 0
571
        mov     dword [image_of_eax], 5       ; not found
572
        ret
573
@@:
574
        mov     ecx, [ebx+12]
575
        mov     edx, [ebx+16]
576
    ;    add     edx, std_application_base_address
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
587
.not_impl:
588
        call    free_cd_channel
589
        and     [cd_status], 0
590
        mov     dword [image_of_eax], 2       ; not implemented
591
        ret
4700 mario79 592
;-----------------------------------------------------------------------------
2288 clevermous 593
fs_CdServices:
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
604
fs_NumCdServices = ($ - fs_CdServices)/4
4700 mario79 605
;-----------------------------------------------------------------------------
2288 clevermous 606
fs_HasCd0:
3627 Serge 607
        test    byte [DRIVE_DATA+1], 10000000b
608
        setnz   al
2288 clevermous 609
        ret
4700 mario79 610
;--------------------------------------
2288 clevermous 611
fs_HasCd1:
3627 Serge 612
        test    byte [DRIVE_DATA+1], 00100000b
613
        setnz   al
2288 clevermous 614
        ret
4700 mario79 615
;--------------------------------------
2288 clevermous 616
fs_HasCd2:
3627 Serge 617
        test    byte [DRIVE_DATA+1], 00001000b
618
        setnz   al
2288 clevermous 619
        ret
4700 mario79 620
;--------------------------------------
2288 clevermous 621
fs_HasCd3:
3627 Serge 622
        test    byte [DRIVE_DATA+1], 00000010b
623
        setnz   al
2288 clevermous 624
        ret
4700 mario79 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
;
2288 clevermous 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
4700 mario79 671
;
672
;-----------------------------------------------------------------------------
2288 clevermous 673
fs_NextCd:
674
; we always have /cdX/1
675
        test    eax, eax
676
        stc
677
        jnz     @f
678
        mov     al, 1
679
        clc
680
@@:
681
        ret
3689 mario79 682
;-----------------------------------------------------------------------------
2288 clevermous 683
process_replace_file_name:
3663 mario79 684
; in
685
; esi - path with filename(f.70)
686
;
687
; out
688
; ebp - full filename
3689 mario79 689
        pushfd
690
        cli
2288 clevermous 691
        mov     ebp, [full_file_name_table]
3689 mario79 692
        xor     edi, edi
2288 clevermous 693
.loop:
3711 clevermous 694
        cmp     edi, [full_file_name_table.size]
3689 mario79 695
        jae     .notfound
2288 clevermous 696
        push    esi edi
3689 mario79 697
        shl     edi, 7 ; edi*128
698
        add     edi, ebp
2288 clevermous 699
@@:
3689 mario79 700
        cmp     byte [edi], 0 ; end of dir_name
2288 clevermous 701
        jz      .dest_done
702
        lodsb
703
        test    al, al
704
        jz      .cont
3689 mario79 705
        or      al, 20h ; 32 - space char
2288 clevermous 706
        scasb
707
        jz      @b
708
        jmp     .cont
709
.dest_done:
710
        cmp     byte [esi], 0
711
        jz      .found
712
        cmp     byte [esi], '/'
713
        jnz     .cont
714
        inc     esi
715
        jmp     .found
716
.cont:
717
        pop     edi esi
3689 mario79 718
        inc     edi
2288 clevermous 719
        jmp     .loop
720
.found:
721
        pop     edi eax
3689 mario79 722
        shl     edi, 7 ; edi*128
723
        add     edi, ebp
2288 clevermous 724
        mov     ebp, esi
725
        cmp     byte [esi], 0
726
        lea     esi, [edi+64]
727
        jnz     .ret
728
.notfound:
729
        xor     ebp, ebp
730
.ret:
3689 mario79 731
        popfd
2288 clevermous 732
        ret
3689 mario79 733
;-----------------------------------------------------------------------------
3663 mario79 734
uglobal
735
lock_flag_for_f30_3 rb 1
736
endg
737
 
2288 clevermous 738
sys_current_directory:
739
;       mov     esi, [current_slot]
740
;       mov     esi, [esi+APPDATA.cur_dir]
741
;       mov     edx, esi
742
 
743
;get length string of appdata.cur_dir
744
        mov     eax, [current_slot]
745
        mov     edi, [eax+APPDATA.cur_dir]
746
 
747
        dec     ebx
748
        jz      .set
749
        dec     ebx
750
        jz      .get
3663 mario79 751
        dec     ebx
752
        jz      .mount_additional_directory
2288 clevermous 753
        ret
3663 mario79 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
3711 clevermous 767
        pushfd
768
        cli
3663 mario79 769
        cld
3711 clevermous 770
        rep movsb
3663 mario79 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
3711 clevermous 777
        rep movsb
3663 mario79 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
3711 clevermous 786
        popfd
3663 mario79 787
@@:
788
        ret
789
 
2288 clevermous 790
.get:
791
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
792
; for our code: ebx->buffer,ecx=len
793
max_cur_dir     equ     0x1000
794
 
795
        mov     ebx, edi
796
 
797
        push    ecx
798
        push    edi
799
 
800
        xor     eax, eax
801
        mov     ecx, max_cur_dir
802
 
803
        repne scasb             ;find zerro at and string
804
        jnz     .error          ; no zero in cur_dir: internal error, should not happen
805
 
806
        sub     edi, ebx        ;lenght for copy
807
        inc     edi
808
        mov     [esp+32+8], edi ;return in eax
809
 
810
        cmp     edx, edi
811
        jbe     @f
812
        mov     edx, edi
813
@@:
814
;source string
815
        pop     esi
816
;destination string
817
        pop     edi
818
        cmp     edx, 1
819
        jbe     .ret
820
 
821
        mov     al, '/'         ;start string with '/'
822
        stosb
823
        mov     ecx, edx
824
        rep movsb               ;copy string
825
.ret:
826
        ret
827
 
828
.error:
829
        add     esp, 8
830
        or      dword [esp+32], -1      ;error not found zerro at string ->[eax+APPDATA.cur_dir]
831
        ret
832
.set:
833
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
834
; for our code: ebx->string to set
835
; use generic resolver with APPDATA.cur_dir as destination
836
        push    max_cur_dir     ;0x1000
837
        push    edi     ;destination
838
        mov     ebx, ecx
839
        call    get_full_file_name
840
        ret
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:
845
        push    ebp
846
        mov     esi, [current_slot]
847
        mov     esi, [esi+APPDATA.cur_dir]
848
        mov     edx, esi
849
@@:
850
        inc     esi
851
        cmp     byte [esi-1], 0
852
        jnz     @b
853
        dec     esi
854
        cmp     byte [ebx], '/'
855
        jz      .set_absolute
856
; string gives relative path
857
        mov     edi, [esp+8]    ; destination
858
.relative:
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
867
@@:
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
874
@@:
875
        dec     esi
876
        cmp     byte [esi], '/'
877
        jnz     @b
878
        add     ebx, 3
879
        jmp     .relative
880
.set_ok:
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
886
.fail:
887
        mov     byte [edi], 0
888
        xor     eax, eax        ; fail
889
        pop     ebp
890
        ret     8
891
.set_ok.copy:
892
        mov     ecx, esi
893
        mov     esi, edx
894
        rep movsb
895
        mov     byte [edi], 0
896
.ret.ok:
897
        mov     al, 1   ; ok
898
        pop     ebp
899
        ret     8
900
.set_ok.cur_dir:
901
        mov     byte [esi], 0
902
        jmp     .ret.ok
903
.doset_relative:
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
914
.doset_relative.cur_dir:
915
        mov     edi, esi
916
.doset_relative.copy:
917
        add     edx, [esp+12]
918
        mov     byte [edi], '/'
919
        inc     edi
920
        cmp     edi, edx
921
        jae     .overflow
922
@@:
923
        mov     al, [ebx]
924
        inc     ebx
925
        stosb
926
        test    al, al
927
        jz      .ret.ok
928
        cmp     edi, edx
929
        jb      @b
930
.overflow:
931
        dec     edi
932
        jmp     .fail
933
.set_absolute:
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
939
.set_copy:
940
        lodsb
941
        stosb
942
        test    al, al
943
        jz      .set_part2
944
.set_copy_cont:
945
        cmp     edi, edx
946
        jb      .set_copy
947
        jmp     .overflow
948
.set_part2:
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