Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
6462 pathoswith 3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
2288 clevermous 5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 6468 $
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_FS_FAIL        = 9
20
ERROR_ACCESS_DENIED  = 10
21
ERROR_DEVICE         = 11
5994 pathoswith 22
ERROR_OUT_OF_MEMORY  = 12
2288 clevermous 23
 
6468 pathoswith 24
maxPathLength = 1000h
25
 
2288 clevermous 26
image_of_eax EQU esp+32
27
image_of_ebx EQU esp+20
28
 
6464 pathoswith 29
; System function 70
2288 clevermous 30
 
3296 clevermous 31
file_system_lfn_protected:
32
        pushad
33
        call    protect_from_terminate
34
        call    file_system_lfn
35
        call    unprotect_from_terminate
36
        popad
37
        mov     [image_of_eax], eax
38
        mov     [image_of_ebx], ebx
39
        ret
40
 
2288 clevermous 41
file_system_lfn:
6464 pathoswith 42
; in: ebx -> parameter structure
43
;   operation codes:
44
; 0 = read file
45
; 1 = read folder
46
; 2 = create/rewrite file
47
; 3 = write/append to file
48
; 4 = set file end
49
; 5 = get file info
50
; 6 = set file info
51
; start application
52
; 8 = delete file/folder
53
; 9 = create folder
6468 pathoswith 54
        lea     ebp, [ebx+20]
55
        cmp     byte [ebp], 0
2288 clevermous 56
        jnz     @f
6468 pathoswith 57
        mov     ebp, [ebx+21]
2288 clevermous 58
@@:
6464 pathoswith 59
        cmp     dword[ebx], 7   ; start application
60
        jne     @f
6333 serge 61
        mov     edx, [ebx+4]
62
        mov     ebx, [ebx+8]
6464 pathoswith 63
        call    fs_execute      ; ebp, ebx, edx
6333 serge 64
        mov     [image_of_eax], eax
65
        ret
6464 pathoswith 66
 
6333 serge 67
@@:
6468 pathoswith 68
        cmp     word [ebp], '/'
2288 clevermous 69
        jz      .rootdir
6468 pathoswith 70
        stdcall kernel_alloc, maxPathLength
71
        push    ebx
72
        mov     ebx, ebp
73
        mov     ebp, eax
74
        push    maxPathLength
75
        push    eax
76
        call    get_full_file_name
77
        pop     ebx
78
        mov     esi, ebp
79
        mov     ax, [ebp]
6464 pathoswith 80
        or      ax, 2020h
81
        cmp     ax, 'cd'
82
        jz      .CD
83
        call    dyndisk_handler ; not returns if success
84
.notfound:
6468 pathoswith 85
        stdcall kernel_free, ebp
6464 pathoswith 86
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
87
        ret
88
 
89
.CD:
90
        add     esi, 2
91
        xor     eax, eax
92
        lodsb       ; disk number
93
        sub     eax, '0'
94
        cmp     eax, 10
95
        jnc     .notfound
96
        mov     edi, eax
2288 clevermous 97
        lodsb
6464 pathoswith 98
        test    eax, eax
99
        jz      .maindir
2288 clevermous 100
        cmp     al, '/'
6464 pathoswith 101
        jnz     .notfound
102
        lodsb       ; partition number
103
        test    eax, eax
104
        jz      .maindir
105
        cmp     al, '1'
106
        jnz     .notfound
107
        cmp     byte [esi], '/'
108
        jnz     @f
109
        inc     esi
110
@@:
111
        call    reserve_cd
112
        mov     eax, edi
113
        bt      eax, 0
114
        setc    [DiskNumber]
115
        bt      eax, 1
116
        setc    [ChannelNumber]
117
        inc     [ChannelNumber]
118
        inc     eax
119
        mov     [cdpos], eax
120
        call    reserve_cd_channel
121
        mov     eax, edi
122
        not     eax
123
        and     eax, 3
124
        shl     eax, 1
125
        inc     eax
126
        shr     edi, 2
127
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
128
        bt      [edi*5+DRIVE_DATA+1], ax
129
        jnc     @f
130
        mov     ecx, [ebx+12]
131
        mov     edx, [ebx+16]
132
        mov     eax, [ebx]
133
        mov     dword[image_of_eax], ERROR_UNSUPPORTED_FS
134
        cmp     eax, fs_NumCdServices
135
        jae     @f
136
        add     ebx, 4
137
        call    dword[fs_CdServices + eax*4]
138
        mov     [image_of_eax], eax
139
        mov     [image_of_ebx], ebx
140
@@:
141
        call    free_cd_channel
142
        and     [cd_status], 0
6468 pathoswith 143
        stdcall kernel_free, ebp
6464 pathoswith 144
        ret
145
 
146
.nextCD:
147
        test    eax, eax    ; partition number
148
        stc
149
        jnz     @f      ; no more partitions
150
        mov     al, 1   ; /cdX/1
151
        clc
152
@@:
153
        ret
154
 
155
.maindir:   ; list partitions
156
        mov     esi, .nextCD
157
.maindir_noesi:     ; backjump from dyndisk_handler
6468 pathoswith 158
        push    ebp
159
        mov     ebp, ecx
160
        call    kernel_free
6464 pathoswith 161
        cmp     dword[ebx], 1
162
        jnz     .access_denied  ; read folder?
6468 pathoswith 163
        push    ebp
164
        pushd   [ebx+4]         ; first block
6464 pathoswith 165
        mov     ebp, [ebx+12]   ; the number of blocks to read
6468 pathoswith 166
        mov     edx, [ebx+16]   ; buffer
2288 clevermous 167
        mov     ebx, [ebx+8]    ; flags
6464 pathoswith 168
        mov     ecx, 32/4
2288 clevermous 169
        mov     edi, edx
6464 pathoswith 170
        xor     eax, eax
2288 clevermous 171
        rep stosd
172
        mov     byte [edx], 1   ; version
173
.maindir_loop:
174
        call    esi
175
        jc      .maindir_done
6464 pathoswith 176
        inc     dword[edx+8]
177
        dec     dword[esp]
2288 clevermous 178
        jns     .maindir_loop
179
        dec     ebp
180
        js      .maindir_loop
6464 pathoswith 181
        inc     dword[edx+4]
182
        mov     dword[edi], 16      ; attributes: folder
183
        mov     dword[edi+4], ebx   ; name encoding
2288 clevermous 184
        push    eax
6464 pathoswith 185
        mov     ecx, 32/4
186
        add     edi, 8
2288 clevermous 187
        xor     eax, eax
188
        rep stosd
189
        pop     eax
6464 pathoswith 190
        push    eax edx edi
191
; convert number in eax to decimal string
2288 clevermous 192
        push    -'0'
193
        mov     ecx, 10
194
@@:
195
        xor     edx, edx
196
        div     ecx
197
        push    edx
198
        test    eax, eax
199
        jnz     @b
6464 pathoswith 200
        cmp     ebx, 1
201
        jz      .uni
2288 clevermous 202
@@:
203
        pop     eax
6464 pathoswith 204
        add     eax, '0'
2288 clevermous 205
        stosb
6464 pathoswith 206
        test    eax, eax
2288 clevermous 207
        jnz     @b
6464 pathoswith 208
        pop     edi edx eax
209
        add     edi, 264
210
        jmp     .maindir_loop
211
 
212
.uni:
213
        pop     eax
214
        add     eax, '0'
215
        stosw
216
        test    eax, eax
217
        jnz     .uni
218
        pop     edi edx eax
2288 clevermous 219
        add     edi, 520
220
        jmp     .maindir_loop
6464 pathoswith 221
 
2288 clevermous 222
.maindir_done:
6464 pathoswith 223
        pop     eax eax
2288 clevermous 224
        mov     ebx, [edx+4]
225
        xor     eax, eax
226
        dec     ebp
227
        js      @f
228
        mov     al, ERROR_END_OF_FILE
229
@@:
230
        mov     [image_of_eax], eax
231
        mov     [image_of_ebx], ebx
232
        ret
6464 pathoswith 233
 
2288 clevermous 234
.access_denied:
6464 pathoswith 235
        mov     dword[image_of_eax], ERROR_ACCESS_DENIED
2288 clevermous 236
        ret
237
 
6464 pathoswith 238
.rootdir:   ; / - virtual root folder
239
        cmp     dword[ebx], 1   ; read folder?
240
        jnz     .access_denied
241
        mov     ebp, [ebx+12]   ; number of blocks
242
        mov     edx, [ebx+16]   ; return area
243
        push    dword[ebx+4]    ; first block
2288 clevermous 244
        mov     ebx, [ebx+8]    ; flags
6464 pathoswith 245
        mov     ecx, 32/4
246
        mov     edi, edx
2288 clevermous 247
        xor     eax, eax
248
        rep stosd
249
        mov     byte [edx], 1   ; version
4277 clevermous 250
        sub     esp, 16
6464 pathoswith 251
.rootdir_loop:
4277 clevermous 252
        push    edi
253
        lea     edi, [esp+4]
254
        call    dyndisk_enum_root
255
        pop     edi
256
        test    eax, eax
6464 pathoswith 257
        jz      .rootdirCD
258
        inc     dword[edx+8]
259
        dec     dword[esp+16]
260
        jns     .rootdir_loop
4277 clevermous 261
        dec     ebp
6464 pathoswith 262
        js      .rootdir_loop
263
        inc     dword[edx+4]
264
        mov     dword[edi], 16      ; attributes: folder
265
        mov     dword[edi+4], ebx   ; name encoding
4277 clevermous 266
        push    eax
6464 pathoswith 267
        mov     ecx, 32/4
268
        add     edi, 8
4277 clevermous 269
        xor     eax, eax
270
        rep stosd
6468 pathoswith 271
        push    edi
272
        lea     esi, [esp+8]
6464 pathoswith 273
        cmp     ebx, 1
274
        jz      .uni2
4277 clevermous 275
@@:
276
        lodsb
277
        stosb
6464 pathoswith 278
        test    eax, eax
4277 clevermous 279
        jnz     @b
6468 pathoswith 280
        pop     edi eax
6464 pathoswith 281
        add     edi, 264
282
        jmp     .rootdir_loop
283
 
284
.uni2:
285
        lodsb
286
        stosw
287
        test    eax, eax
288
        jnz     .uni2
6468 pathoswith 289
        pop     edi eax
4277 clevermous 290
        add     edi, 520
6464 pathoswith 291
        jmp     .rootdir_loop
292
 
293
.rootdirCD:
4277 clevermous 294
        add     esp, 16
6464 pathoswith 295
        or      esi, -1
296
.rootdirCD_loop:
297
        inc     esi
298
        cmp     esi, 10
299
        jnc     .rootdir_done
300
        mov     eax, esi
301
        not     eax
302
        and     eax, 3
303
        shl     eax, 1
304
        inc     eax
305
        mov     ecx, esi
306
        shr     ecx, 2
307
        bt      [ecx*5+DRIVE_DATA+1], ax
308
        jnc     .rootdirCD_loop
309
        inc     dword[edx+8]
310
        dec     dword[esp]
311
        jns     .rootdirCD_loop
2288 clevermous 312
        dec     ebp
6464 pathoswith 313
        js      .rootdirCD_loop
314
        inc     dword[edx+4]
315
        mov     dword[edi], 16      ; attributes: folder
316
        mov     dword[edi+4], ebx   ; name encoding
317
        mov     ecx, 32/4
2288 clevermous 318
        add     edi, 8
6464 pathoswith 319
        xor     eax, eax
2288 clevermous 320
        rep stosd
6464 pathoswith 321
        mov     eax, esi
322
        add     eax, '0'
323
        cmp     ebx, 1
324
        jz      @f
325
        mov     word [edi], 'cd'
326
        mov     [edi+2], ax
327
        add     edi, 264
328
        jmp     .rootdirCD_loop
329
 
2288 clevermous 330
@@:
6464 pathoswith 331
        mov     dword[edi], 640063h
332
        mov     [edi+4], eax
2288 clevermous 333
        add     edi, 520
6464 pathoswith 334
        jmp     .rootdirCD_loop
335
 
336
.rootdir_done:
2288 clevermous 337
        pop     eax
338
        mov     ebx, [edx+4]
339
        xor     eax, eax
340
        dec     ebp
341
        js      @f
342
        mov     al, ERROR_END_OF_FILE
343
@@:
344
        mov     [image_of_eax], eax
345
        mov     [image_of_ebx], ebx
346
        ret
347
 
4700 mario79 348
;-----------------------------------------------------------------------------
2288 clevermous 349
process_replace_file_name:
6464 pathoswith 350
; in: [esi] = virtual path
351
; out: [esi]+[ebp] = physical path
3689 mario79 352
        pushfd
353
        cli
2288 clevermous 354
        mov     ebp, [full_file_name_table]
3689 mario79 355
        xor     edi, edi
2288 clevermous 356
.loop:
3711 clevermous 357
        cmp     edi, [full_file_name_table.size]
3689 mario79 358
        jae     .notfound
2288 clevermous 359
        push    esi edi
6464 pathoswith 360
        shl     edi, 7
3689 mario79 361
        add     edi, ebp
2288 clevermous 362
@@:
6464 pathoswith 363
        cmp     byte [edi], 0
2288 clevermous 364
        jz      .dest_done
365
        lodsb
366
        test    al, al
367
        jz      .cont
6464 pathoswith 368
        or      al, 20h
2288 clevermous 369
        scasb
370
        jz      @b
6464 pathoswith 371
.cont:
372
        pop     edi esi
373
        inc     edi
374
        jmp     .loop
375
 
2288 clevermous 376
.dest_done:
377
        cmp     byte [esi], 0
378
        jz      .found
379
        cmp     byte [esi], '/'
380
        jnz     .cont
381
        inc     esi
382
.found:
383
        pop     edi eax
6464 pathoswith 384
        shl     edi, 7
3689 mario79 385
        add     edi, ebp
2288 clevermous 386
        mov     ebp, esi
387
        cmp     byte [esi], 0
388
        lea     esi, [edi+64]
389
        jnz     .ret
390
.notfound:
391
        xor     ebp, ebp
392
.ret:
3689 mario79 393
        popfd
2288 clevermous 394
        ret
6464 pathoswith 395
 
3689 mario79 396
;-----------------------------------------------------------------------------
3663 mario79 397
uglobal
398
lock_flag_for_f30_3 rb 1
399
endg
6338 serge 400
 
6464 pathoswith 401
sys_current_directory:  ; sysfunction 30
2288 clevermous 402
        mov     eax, [current_slot]
403
        mov     edi, [eax+APPDATA.cur_dir]
404
        dec     ebx
405
        jz      .set
406
        dec     ebx
407
        jz      .get
3663 mario79 408
        dec     ebx
409
        jz      .mount_additional_directory
2288 clevermous 410
        ret
3663 mario79 411
 
412
.mount_additional_directory:
6464 pathoswith 413
; in: ecx -> dir name+dir path (128)
414
        cmp     [lock_flag_for_f30_3], 1    ; check lock
3663 mario79 415
        je      @f
416
        mov     esi, ecx
417
        mov     edi, sysdir_name1
418
        mov     ecx, 63
3711 clevermous 419
        pushfd
420
        cli
3663 mario79 421
        cld
6464 pathoswith 422
        rep movsb   ; copying fake directory name
3663 mario79 423
        inc     esi
424
        xor     eax, eax
6464 pathoswith 425
        stosb       ; terminator of name, in case if we get the inlet trash
3663 mario79 426
        mov     ecx, 63
6464 pathoswith 427
        rep movsb   ; copying real directory path for mounting
3663 mario79 428
        xor     eax, eax
429
        stosb
6338 serge 430
; increase the pointer of inputs for procedure "process_replace_file_name"
3663 mario79 431
        mov     [full_file_name_table.size], 2
6464 pathoswith 432
        mov     [lock_flag_for_f30_3], 1    ; lock
3711 clevermous 433
        popfd
3663 mario79 434
@@:
435
        ret
6338 serge 436
 
6464 pathoswith 437
.get:       ; in: ecx -> buffer, edx = length
438
        mov     ebx, edi    ; buffer
2288 clevermous 439
        push    ecx
440
        push    edi
441
        xor     eax, eax
6468 pathoswith 442
        mov     ecx, maxPathLength
6464 pathoswith 443
        repne scasb
444
        jnz     .error
445
        sub     edi, ebx
2288 clevermous 446
        inc     edi
6464 pathoswith 447
        mov     [esp+32+8], edi ; return in eax
2288 clevermous 448
        cmp     edx, edi
449
        jbe     @f
450
        mov     edx, edi
451
@@:
452
        pop     esi
453
        pop     edi
454
        cmp     edx, 1
455
        jbe     .ret
6464 pathoswith 456
        mov     al, '/'
2288 clevermous 457
        stosb
458
        mov     ecx, edx
6464 pathoswith 459
        rep movsb
2288 clevermous 460
.ret:
461
        ret
462
 
463
.error:
464
        add     esp, 8
6464 pathoswith 465
        or      dword[esp+32], -1
2288 clevermous 466
        ret
6464 pathoswith 467
 
2288 clevermous 468
.set:
6464 pathoswith 469
        pop     eax
6468 pathoswith 470
        push    maxPathLength
6464 pathoswith 471
        push    edi
472
        push    eax
2288 clevermous 473
        mov     ebx, ecx
474
get_full_file_name:
6464 pathoswith 475
; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
476
; destroys all registers
2288 clevermous 477
        push    ebp
478
        cmp     byte [ebx], '/'
6468 pathoswith 479
        jnz     .set_relative
480
        lea     esi, [ebx+1]
481
        call    process_replace_file_name
6464 pathoswith 482
        mov     edi, [esp+8]
6468 pathoswith 483
        mov     edx, [esp+12]
484
        add     edx, edi
485
.set_copy:
486
        lodsb
487
        stosb
488
        test    al, al
489
        jz      .set_part2
490
.set_copy_cont:
491
        cmp     edi, edx
492
        jb      .set_copy
493
.overflow:
494
        dec     edi
495
.fail:
496
        mov     byte [edi], 0
497
        xor     eax, eax
498
        pop     ebp
499
        ret     8
500
 
501
.set_part2:
502
        mov     esi, ebp
503
        xor     ebp, ebp
504
        test    esi, esi
505
        jz      .ret.ok
506
        mov     byte [edi-1], '/'
507
        jmp     .set_copy_cont
508
 
509
.set_relative:
510
        mov     edi, [current_slot]
511
        mov     edi, [edi+APPDATA.cur_dir]
512
        mov     edx, edi
513
        mov     ecx, [esp+12]
514
        xor     eax, eax
515
        repnz scasb
516
        mov     esi, edi
517
        dec     esi
518
        mov     edi, [esp+8]
519
        jecxz   .fail
2288 clevermous 520
.relative:
521
        cmp     byte [ebx], 0
522
        jz      .set_ok
523
        cmp     word [ebx], '.'
524
        jz      .set_ok
525
        cmp     word [ebx], './'
526
        jnz     @f
527
        add     ebx, 2
528
        jmp     .relative
6464 pathoswith 529
 
2288 clevermous 530
@@:
531
        cmp     word [ebx], '..'
532
        jnz     .doset_relative
533
        cmp     byte [ebx+2], 0
534
        jz      @f
535
        cmp     byte [ebx+2], '/'
536
        jnz     .doset_relative
537
@@:
538
        dec     esi
539
        cmp     byte [esi], '/'
540
        jnz     @b
541
        add     ebx, 3
542
        jmp     .relative
6464 pathoswith 543
 
2288 clevermous 544
.set_ok:
545
        cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
6468 pathoswith 546
        jz      @f
2288 clevermous 547
        mov     ecx, esi
6468 pathoswith 548
        sub     ecx, edx
2288 clevermous 549
        mov     esi, edx
550
        rep movsb
551
        mov     byte [edi], 0
552
.ret.ok:
6464 pathoswith 553
        mov     al, 1
2288 clevermous 554
        pop     ebp
555
        ret     8
6464 pathoswith 556
 
6468 pathoswith 557
@@:
2288 clevermous 558
        mov     byte [esi], 0
559
        jmp     .ret.ok
6464 pathoswith 560
 
2288 clevermous 561
.doset_relative:
562
        cmp     edx, edi
563
        jz      .doset_relative.cur_dir
564
        mov     ecx, esi
6468 pathoswith 565
        sub     ecx, edx
2288 clevermous 566
        mov     esi, edx
567
        mov     edx, edi
568
        rep movsb
569
        jmp     .doset_relative.copy
6464 pathoswith 570
 
2288 clevermous 571
.doset_relative.cur_dir:
572
        mov     edi, esi
573
.doset_relative.copy:
574
        add     edx, [esp+12]
575
        mov     byte [edi], '/'
576
        inc     edi
577
        cmp     edi, edx
578
        jae     .overflow
579
@@:
580
        mov     al, [ebx]
581
        inc     ebx
582
        stosb
583
        test    al, al
584
        jz      .ret.ok
585
        cmp     edi, edx
586
        jb      @b
587
        jmp     .overflow
6464 pathoswith 588
 
6462 pathoswith 589
include "parse_fn.inc"
590
include "fs_common.inc"
591
include "iso9660.inc"   ; read for CD filesystem
592
include "fat.inc"
593
include "ntfs.inc"
594
include "ext.inc"
595
include "xfs.asm"