Subversion Repositories Kolibri OS

Rev

Rev 3742 | Rev 5089 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3742 Rev 4273
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  FAT32.INC                                                      ;;
6
;;  FAT32.INC                                                      ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  FAT16/32 functions for KolibriOS                               ;;
8
;;  FAT functions for KolibriOS                                    ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it          ;;
10
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it          ;;
11
;;                                                                 ;;
11
;;                                                                 ;;
12
;;  See file COPYING for details                                   ;;
12
;;  See file COPYING for details                                   ;;
13
;;  04.02.2007 LFN create folder - diamond                         ;;
13
;;  04.02.2007 LFN create folder - diamond                         ;;
Line 42... Line 42...
42
;;  20.5.2002  Hd status check - VT                                ;;
42
;;  20.5.2002  Hd status check - VT                                ;;
43
;;  29.6.2002  Improved fat32 verification - VT                    ;;
43
;;  29.6.2002  Improved fat32 verification - VT                    ;;
44
;;                                                                 ;;
44
;;                                                                 ;;
45
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 46... Line 46...
46
 
46
 
Line 47... Line 47...
47
$Revision: 3742 $
47
$Revision: 4273 $
Line 48... Line 48...
48
 
48
 
Line 92... Line 92...
92
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
92
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
93
longname_sec2        dd 0       ; directory sectors for delete long filename
93
longname_sec2        dd 0       ; directory sectors for delete long filename
Line 94... Line 94...
94
 
94
 
Line -... Line 95...
-
 
95
fat_in_cache         dd -1
-
 
96
 
-
 
97
; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT.
-
 
98
; For FAT12, the entire FAT structure is read
-
 
99
; and unpacked from 12bit per cluster to word per cluster.
-
 
100
;
-
 
101
; Note: work with unpacked copy of FAT12 means
-
 
102
; additional memory and additional code for packing/unpacking.
95
fat_in_cache         dd -1
103
; I'm not sure that the economy justifies the cost, but anyway,
-
 
104
; there is how work was done before my edits, and I'm just keeping the principle.
96
 
105
fat_cache_ptr        dd ?
97
fat_cache            rb 512
106
fat12_unpacked_ptr   dd ?
98
buffer               rb 512
107
buffer               rb 512
Line 99... Line 108...
99
fsinfo_buffer        rb 512
108
fsinfo_buffer        rb 512
Line 118... Line 127...
118
endg
127
endg
Line 119... Line 128...
119
 
128
 
120
iglobal
129
iglobal
121
align 4
130
align 4
122
fat_user_functions:
131
fat_user_functions:
123
        dd      free
132
        dd      fat_free
124
        dd      (fat_user_functions_end - fat_user_functions - 4) / 4
133
        dd      (fat_user_functions_end - fat_user_functions - 4) / 4
125
        dd      fat_Read
134
        dd      fat_Read
126
        dd      fat_ReadFolder
135
        dd      fat_ReadFolder
127
        dd      fat_Rewrite
136
        dd      fat_Rewrite
Line 212... Line 221...
212
@@:
221
@@:
213
        mov     [ebp+FAT.SECTORS_PER_FAT], eax
222
        mov     [ebp+FAT.SECTORS_PER_FAT], eax
Line 214... Line 223...
214
 
223
 
215
        movzx   eax, byte [ebx+0x10]    ; number of fats
224
        movzx   eax, byte [ebx+0x10]    ; number of fats
216
        mov     [ebp+FAT.NUMBER_OF_FATS], eax
225
        mov     [ebp+FAT.NUMBER_OF_FATS], eax
-
 
226
        mul     [ebp+FAT.SECTORS_PER_FAT]
-
 
227
        test    edx, edx
217
        imul    eax, [ebp+FAT.SECTORS_PER_FAT]
228
        jnz     .free_return0
-
 
229
        add     eax, [ebp+FAT.FAT_START]
218
        add     eax, [ebp+FAT.FAT_START]
230
        jc      .free_return0
219
        mov     [ebp+FAT.ROOT_START], eax       ; rootdir = fat_start + fat_size * fat_count
231
        mov     [ebp+FAT.ROOT_START], eax       ; rootdir = fat_start + fat_size * fat_count
-
 
232
        add     eax, [ebp+FAT.ROOT_SECTORS]     ; rootdir sectors should be 0 on fat32
220
        add     eax, [ebp+FAT.ROOT_SECTORS]     ; rootdir sectors should be 0 on fat32
233
        jc      .free_return0
Line 221... Line 234...
221
        mov     [ebp+FAT.DATA_START], eax       ; data area = rootdir + rootdir_size
234
        mov     [ebp+FAT.DATA_START], eax       ; data area = rootdir + rootdir_size
222
 
235
 
223
        movzx   eax, word [ebx+0x13]    ; total sector count <65536
236
        movzx   eax, word [ebx+0x13]    ; total sector count <65536
224
        test    eax, eax
237
        test    eax, eax
225
        jnz     @f
238
        jnz     @f
-
 
239
        mov     eax, [ebx+0x20]         ; total sector count
-
 
240
@@:
-
 
241
; total sector count must not exceed partition size
-
 
242
        cmp     dword [ebp+FAT.Length+4], 0
-
 
243
        jnz     @f
-
 
244
        cmp     eax, dword [ebp+FAT.Length]
226
        mov     eax, [ebx+0x20]         ; total sector count
245
        ja      .free_return0
227
@@:
246
@@:
228
        mov     dword [ebp+FAT.Length], eax
247
        mov     dword [ebp+FAT.Length], eax
-
 
248
        and     dword [ebp+FAT.Length+4], 0
229
        and     dword [ebp+FAT.Length+4], 0
249
        sub     eax, [ebp+FAT.DATA_START]       ; eax = count of data sectors
230
        sub     eax, [ebp+FAT.DATA_START]       ; eax = count of data sectors
250
        jc      .free_return0
231
        xor     edx, edx
251
        xor     edx, edx
232
        div     [ebp+FAT.SECTORS_PER_CLUSTER]
252
        div     [ebp+FAT.SECTORS_PER_CLUSTER]
233
        inc     eax
253
        inc     eax
-
 
254
        mov     [ebp+FAT.LAST_CLUSTER], eax
234
        mov     [ebp+FAT.LAST_CLUSTER], eax
255
        dec     eax                     ; cluster count
Line 235... Line 256...
235
        dec     eax                     ; cluster count
256
        jz      .free_return0
236
        mov     [ebp+FAT.fatStartScan], 2
257
        mov     [ebp+FAT.fatStartScan], 2
237
 
258
 
238
        ; limits by Microsoft Hardware White Paper v1.03
259
        ; limits by Microsoft Hardware White Paper v1.03
239
        cmp     eax, 4085               ; 0xff5
260
        cmp     eax, 4085               ; 0xff5
240
        jb      .free_return0           ; fat12 not supported
261
        jb      .fat12
241
        cmp     eax, 65525              ; 0xfff5
262
        cmp     eax, 65525              ; 0xfff5
242
        jb      .fat16
263
        jb      .fat16
Line 259... Line 280...
259
        mov     [ebp+FAT.fatRESERVED], 0x0FFFFFF6
280
        mov     [ebp+FAT.fatRESERVED], 0x0FFFFFF6
260
        mov     [ebp+FAT.fatBAD], 0x0FFFFFF7
281
        mov     [ebp+FAT.fatBAD], 0x0FFFFFF7
261
        mov     [ebp+FAT.fatEND], 0x0FFFFFF8
282
        mov     [ebp+FAT.fatEND], 0x0FFFFFF8
262
        mov     [ebp+FAT.fatMASK], 0x0FFFFFFF
283
        mov     [ebp+FAT.fatMASK], 0x0FFFFFFF
263
        mov     al, 32
284
        mov     al, 32
-
 
285
.fat_not_12_finalize:
264
        mov     [ebp+FAT.fs_type], al
286
        mov     [ebp+FAT.fs_type], al
-
 
287
; For FAT16 and FAT32, allocate 512 bytes for FAT cache.
-
 
288
        mov     eax, 512
-
 
289
        call    malloc
-
 
290
        test    eax, eax
-
 
291
        jz      .free_return0
-
 
292
        mov     [ebp+FAT.fat_cache_ptr], eax
265
        mov     eax, ebp
293
        mov     eax, ebp
266
        pop     ebp
294
        pop     ebp
267
        ret
295
        ret
268
.fat16:
296
.fat16:
269
        and     [ebp+FAT.ROOT_CLUSTER], 0
297
        and     [ebp+FAT.ROOT_CLUSTER], 0
270
        mov     [ebp+FAT.fatRESERVED], 0x0000FFF6
298
        mov     [ebp+FAT.fatRESERVED], 0x0000FFF6
271
        mov     [ebp+FAT.fatBAD], 0x0000FFF7
299
        mov     [ebp+FAT.fatBAD], 0x0000FFF7
272
        mov     [ebp+FAT.fatEND], 0x0000FFF8
300
        mov     [ebp+FAT.fatEND], 0x0000FFF8
273
        mov     [ebp+FAT.fatMASK], 0x0000FFFF
301
        mov     [ebp+FAT.fatMASK], 0x0000FFFF
274
        mov     al, 16
302
        mov     al, 16
-
 
303
        jmp     .fat_not_12_finalize
-
 
304
.fat12:
-
 
305
        and     [ebp+FAT.ROOT_CLUSTER], 0
-
 
306
        mov     [ebp+FAT.fatRESERVED], 0xFF6
-
 
307
        mov     [ebp+FAT.fatBAD], 0xFF7
-
 
308
        mov     [ebp+FAT.fatEND], 0xFFF
-
 
309
        mov     [ebp+FAT.fatMASK], 0xFFF
-
 
310
        mov     al, 12
275
        mov     [ebp+FAT.fs_type], al
311
        mov     [ebp+FAT.fs_type], al
-
 
312
; For FAT12, allocate&read data for entire table:
-
 
313
; calculate A = ALIGN_UP(NUM_CLUSTERS, 8),
-
 
314
; calculatefatchain/restorefatchain will process A items,
-
 
315
; allocate ALIGN_UP(A*3/2, 512) bytes for FAT table plus A*2 bytes for unpacked data.
-
 
316
        mov     eax, [ebp+FAT.LAST_CLUSTER]
-
 
317
        and     eax, not 7
-
 
318
        add     eax, 8
-
 
319
        mov     edx, eax
-
 
320
        lea     eax, [eax*3]
-
 
321
        add     eax, 512*2-1
-
 
322
        shr     eax, 10
-
 
323
        shl     eax, 9
-
 
324
        lea     eax, [eax+edx*2]
-
 
325
        call    malloc
-
 
326
        test    eax, eax
-
 
327
        jz      .free_return0
-
 
328
; Read ALIGN_UP(NUM_CLUSTERS*3/2, 512) bytes.
-
 
329
; Note that this can be less than allocated, this is ok,
-
 
330
; overallocation simplifies calculatefatchain/restorefatchain.
-
 
331
        push    ebx
-
 
332
        mov     [ebp+FAT.fat_cache_ptr], eax
-
 
333
        mov     edx, [ebp+FAT.LAST_CLUSTER]
-
 
334
        lea     edx, [(edx+1)*3 + 512*2-1]
-
 
335
        shr     edx, 10
-
 
336
        xchg    eax, ebx
-
 
337
        xor     eax, eax
-
 
338
.read_fat:
-
 
339
        push    eax
-
 
340
        add     eax, [ebp+FAT.FAT_START]
-
 
341
        call    fs_read32_sys
-
 
342
        test    eax, eax
-
 
343
        pop     eax
-
 
344
        jz      @f
-
 
345
        dbgstr 'Failed to read FAT table'
-
 
346
        mov     eax, [ebp+FAT.fat_cache_ptr]
-
 
347
        call    free
-
 
348
        pop     ebx
-
 
349
        jmp     .free_return0
-
 
350
@@:
-
 
351
        add     ebx, 512
-
 
352
        inc     eax
-
 
353
        cmp     eax, edx
-
 
354
        jb      .read_fat
-
 
355
        mov     [ebp+FAT.fat12_unpacked_ptr], ebx
-
 
356
        call    calculatefatchain
-
 
357
        pop     ebx
276
        mov     eax, ebp
358
        mov     eax, ebp
277
        pop     ebp
359
        pop     ebp
278
        ret
360
        ret
Line -... Line 361...
-
 
361
 
-
 
362
fat_free:
-
 
363
        push    eax
-
 
364
        mov     eax, [eax+FAT.fat_cache_ptr]
-
 
365
        call    free
-
 
366
        pop     eax
-
 
367
        jmp     free
-
 
368
 
-
 
369
calculatefatchain:
-
 
370
 
-
 
371
        pushad
-
 
372
 
-
 
373
        mov     esi, [ebp+FAT.fat_cache_ptr]
-
 
374
        mov     edi, [ebp+FAT.fat12_unpacked_ptr]
-
 
375
 
-
 
376
        mov     edx, [ebp+FAT.LAST_CLUSTER]
-
 
377
        and     edx, not 7
-
 
378
        lea     edx, [edi+(edx+8)*2]
-
 
379
        push    edx
-
 
380
 
-
 
381
 fcnew:
-
 
382
        mov     eax, dword [esi]
-
 
383
        mov     ebx, dword [esi+4]
-
 
384
        mov     ecx, dword [esi+8]
-
 
385
        mov     edx, ecx
-
 
386
        shr     edx, 4;8 ok
-
 
387
        shr     dx, 4;7 ok
-
 
388
        xor     ch, ch
-
 
389
        shld    ecx, ebx, 20;6 ok
-
 
390
        shr     cx, 4;5 ok
-
 
391
        shld    ebx, eax, 12
-
 
392
        and     ebx, 0x0fffffff;4 ok
-
 
393
        shr     bx, 4;3 ok
-
 
394
        shl     eax, 4
-
 
395
        and     eax, 0x0fffffff;2 ok
-
 
396
        shr     ax, 4;1 ok
-
 
397
        mov     dword [edi], eax
-
 
398
        mov     dword [edi+4], ebx
-
 
399
        mov     dword [edi+8], ecx
-
 
400
        mov     dword [edi+12], edx
-
 
401
        add     edi, 16
-
 
402
        add     esi, 12
-
 
403
 
-
 
404
        cmp     edi, [esp]
-
 
405
        jnz     fcnew
-
 
406
        pop     eax
-
 
407
 
-
 
408
        popad
-
 
409
        ret
-
 
410
 
-
 
411
 
-
 
412
restorefatchain:   ; restore fat chain
-
 
413
 
-
 
414
        pushad
-
 
415
 
-
 
416
        mov     esi, [ebp+FAT.fat12_unpacked_ptr]
-
 
417
        mov     edi, [ebp+FAT.fat_cache_ptr]
-
 
418
 
-
 
419
        mov     edx, [ebp+FAT.LAST_CLUSTER]
-
 
420
        and     edx, not 7
-
 
421
        lea     edx, [esi+(edx+8)*2]
-
 
422
 
-
 
423
  fcnew2:
-
 
424
        mov     eax, dword [esi]
-
 
425
        mov     ebx, dword [esi+4]
-
 
426
        shl     ax, 4
-
 
427
        shl     eax, 4
-
 
428
        shl     bx, 4
-
 
429
        shr     ebx, 4
-
 
430
        shrd    eax, ebx, 8
-
 
431
        shr     ebx, 8
-
 
432
        mov     dword [edi], eax
-
 
433
        mov     word [edi+4], bx
-
 
434
        add     edi, 6
-
 
435
        add     esi, 8
-
 
436
 
-
 
437
        cmp     esi, edx
-
 
438
        jb      fcnew2
-
 
439
 
-
 
440
        mov     esi, [ebp+FAT.NUMBER_OF_FATS]
-
 
441
        mov     edx, [ebp+FAT.LAST_CLUSTER]
-
 
442
        lea     edx, [(edx+1)*3 + 512*2-1]
-
 
443
        shr     edx, 10
-
 
444
        push    [ebp+FAT.FAT_START]
-
 
445
 
-
 
446
.write_fats:
-
 
447
        xor     eax, eax
-
 
448
        mov     ebx, [ebp+FAT.fat_cache_ptr]
-
 
449
.loop1:
-
 
450
        push    eax
-
 
451
        add     eax, [esp+4]
-
 
452
        call    fs_write32_sys
-
 
453
        test    eax, eax
-
 
454
        pop     eax
-
 
455
        jnz     .fail
-
 
456
        add     ebx, 512
-
 
457
        inc     eax
-
 
458
        cmp     eax, edx
-
 
459
        jb      .loop1
-
 
460
        pop     eax
-
 
461
        add     eax, [ebp+FAT.SECTORS_PER_FAT]
-
 
462
        push    eax
-
 
463
        dec     esi
-
 
464
        jnz     .write_fats
-
 
465
        pop     eax
-
 
466
 
-
 
467
        popad
-
 
468
        ret
-
 
469
.fail:
-
 
470
        dbgstr 'Failed to save FAT'
-
 
471
        popad
-
 
472
        ret
-
 
473
 
-
 
474
iglobal
-
 
475
label fat_legal_chars byte
-
 
476
; 0 = not allowed
-
 
477
; 1 = allowed only in long names
-
 
478
; 3 = allowed
-
 
479
        times 32 db 0
-
 
480
;                 ! " # $ % & ' ( ) * + , - . /
-
 
481
        db      1,3,0,3,3,3,3,3,3,3,0,1,1,3,3,0
-
 
482
;               0 1 2 3 4 5 6 7 8 9 : ; < = > ?
-
 
483
        db      3,3,3,3,3,3,3,3,3,3,0,1,0,1,0,0
-
 
484
;               @ A B C D E F G H I J K L M N O
-
 
485
        db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
-
 
486
;               P Q R S T U V W X Y Z [ \ ] ^ _
-
 
487
        db      3,3,3,3,3,3,3,3,3,3,3,1,0,1,3,3
-
 
488
;               ` a b c d e f g h i j k l m n o
-
 
489
        db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
-
 
490
;               p q r s t u v w x y z { | } ~
-
 
491
        db      3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,0
-
 
492
endg
-
 
493
 
-
 
494
fat_name_is_legal:
-
 
495
; in: esi->(long) name
-
 
496
; out: CF set <=> legal
-
 
497
; destroys eax
-
 
498
        push    esi
-
 
499
        xor     eax, eax
-
 
500
@@:
-
 
501
        lodsb
-
 
502
        test    al, al
-
 
503
        jz      .done
-
 
504
        cmp     al, 80h
-
 
505
        jae     .big
-
 
506
        test    [fat_legal_chars+eax], 1
-
 
507
        jnz     @b
-
 
508
.err:
-
 
509
        pop     esi
-
 
510
        clc
-
 
511
        ret
-
 
512
.big:
-
 
513
; 0x80-0xAF, 0xE0-0xEF
-
 
514
        cmp     al, 0xB0
-
 
515
        jb      @b
-
 
516
        cmp     al, 0xE0
-
 
517
        jb      .err
-
 
518
        cmp     al, 0xF0
-
 
519
        jb      @b
-
 
520
        jmp     .err
-
 
521
.done:
-
 
522
        sub     esi, [esp]
-
 
523
        cmp     esi, 257
-
 
524
        pop     esi
-
 
525
        ret
-
 
526
 
-
 
527
fat_next_short_name:
-
 
528
; in: edi->8+3 name
-
 
529
; out: name corrected
-
 
530
;      CF=1 <=> error
-
 
531
        pushad
-
 
532
        mov     ecx, 8
-
 
533
        mov     al, '~'
-
 
534
        std
-
 
535
        push    edi
-
 
536
        add     edi, 7
-
 
537
        repnz scasb
-
 
538
        pop     edi
-
 
539
        cld
-
 
540
        jz      .tilde
-
 
541
; tilde is not found, insert "~1" at end
-
 
542
        add     edi, 6
-
 
543
        cmp     word [edi], '  '
-
 
544
        jnz     .insert_tilde
-
 
545
@@:
-
 
546
        dec     edi
-
 
547
        cmp     byte [edi], ' '
-
 
548
        jz      @b
-
 
549
        inc     edi
-
 
550
.insert_tilde:
-
 
551
        mov     word [edi], '~1'
-
 
552
        popad
-
 
553
        clc
-
 
554
        ret
-
 
555
.tilde:
-
 
556
        push    edi
-
 
557
        add     edi, 7
-
 
558
        xor     ecx, ecx
-
 
559
@@:
-
 
560
; after tilde may be only digits and trailing spaces
-
 
561
        cmp     byte [edi], '~'
-
 
562
        jz      .break
-
 
563
        cmp     byte [edi], ' '
-
 
564
        jz      .space
-
 
565
        cmp     byte [edi], '9'
-
 
566
        jnz     .found
-
 
567
        dec     edi
-
 
568
        jmp     @b
-
 
569
.space:
-
 
570
        dec     edi
-
 
571
        inc     ecx
-
 
572
        jmp     @b
-
 
573
.found:
-
 
574
        inc     byte [edi]
-
 
575
        add     dword [esp], 8
-
 
576
        jmp     .zerorest
-
 
577
.break:
-
 
578
        jecxz   .noplace
-
 
579
        inc     edi
-
 
580
        mov     al, '1'
-
 
581
@@:
-
 
582
        xchg    al, [edi]
-
 
583
        inc     edi
-
 
584
        cmp     al, ' '
-
 
585
        mov     al, '0'
-
 
586
        jnz     @b
-
 
587
.succ:
-
 
588
        pop     edi
-
 
589
        popad
-
 
590
        clc
-
 
591
        ret
-
 
592
.noplace:
-
 
593
        dec     edi
-
 
594
        cmp     edi, [esp]
-
 
595
        jz      .err
-
 
596
        add     dword [esp], 8
-
 
597
        mov     word [edi], '~1'
-
 
598
        inc     edi
-
 
599
        inc     edi
-
 
600
@@:
-
 
601
        mov     byte [edi], '0'
-
 
602
.zerorest:
-
 
603
        inc     edi
-
 
604
        cmp     edi, [esp]
-
 
605
        jb      @b
-
 
606
        pop     edi
-
 
607
        popad
-
 
608
        ;clc    ; automatically
-
 
609
        ret
-
 
610
.err:
-
 
611
        pop     edi
-
 
612
        popad
-
 
613
        stc
-
 
614
        ret
-
 
615
 
-
 
616
fat_gen_short_name:
-
 
617
; in: esi->long name
-
 
618
;     edi->buffer (8+3=11 chars)
-
 
619
; out: buffer filled
-
 
620
        pushad
-
 
621
        mov     eax, '    '
-
 
622
        push    edi
-
 
623
        stosd
-
 
624
        stosd
-
 
625
        stosd
-
 
626
        pop     edi
-
 
627
        xor     eax, eax
-
 
628
        movi    ebx, 8
-
 
629
        lea     ecx, [edi+8]
-
 
630
.loop:
-
 
631
        lodsb
-
 
632
        test    al, al
-
 
633
        jz      .done
-
 
634
        call    char_toupper
-
 
635
        cmp     al, ' '
-
 
636
        jz      .space
-
 
637
        cmp     al, 80h
-
 
638
        ja      .big
-
 
639
        test    [fat_legal_chars+eax], 2
-
 
640
        jnz     .symbol
-
 
641
.inv_symbol:
-
 
642
        mov     al, '_'
-
 
643
        or      bh, 1
-
 
644
.symbol:
-
 
645
        cmp     al, '.'
-
 
646
        jz      .dot
-
 
647
.normal_symbol:
-
 
648
        dec     bl
-
 
649
        jns     .store
-
 
650
        mov     bl, 0
-
 
651
.space:
-
 
652
        or      bh, 1
-
 
653
        jmp     .loop
-
 
654
.store:
-
 
655
        stosb
-
 
656
        jmp     .loop
-
 
657
.big:
-
 
658
        cmp     al, 0xB0
-
 
659
        jb      .normal_symbol
-
 
660
        cmp     al, 0xE0
-
 
661
        jb      .inv_symbol
-
 
662
        cmp     al, 0xF0
-
 
663
        jb      .normal_symbol
-
 
664
        jmp     .inv_symbol
-
 
665
.dot:
-
 
666
        test    bh, 2
-
 
667
        jz      .firstdot
-
 
668
        pop     ebx
-
 
669
        add     ebx, edi
-
 
670
        sub     ebx, ecx
-
 
671
        push    ebx
-
 
672
        cmp     ebx, ecx
-
 
673
        jb      @f
-
 
674
        pop     ebx
-
 
675
        push    ecx
-
 
676
@@:
-
 
677
        cmp     edi, ecx
-
 
678
        jbe     .skip
-
 
679
@@:
-
 
680
        dec     edi
-
 
681
        mov     al, [edi]
-
 
682
        dec     ebx
-
 
683
        mov     [ebx], al
-
 
684
        mov     byte [edi], ' '
-
 
685
        cmp     edi, ecx
-
 
686
        ja      @b
-
 
687
.skip:
-
 
688
        mov     bh, 3
-
 
689
        jmp     @f
-
 
690
.firstdot:
-
 
691
        cmp     bl, 8
-
 
692
        jz      .space
-
 
693
        push    edi
-
 
694
        or      bh, 2
-
 
695
@@:
-
 
696
        mov     edi, ecx
-
 
697
        mov     bl, 3
-
 
698
        jmp     .loop
-
 
699
.done:
-
 
700
        test    bh, 2
-
 
701
        jz      @f
-
 
702
        pop     edi
-
 
703
@@:
-
 
704
        lea     edi, [ecx-8]
-
 
705
        test    bh, 1
-
 
706
        jz      @f
-
 
707
        call    fat_next_short_name
-
 
708
@@:
-
 
709
        popad
-
 
710
        ret
-
 
711
 
-
 
712
fat12_free_space:
-
 
713
;---------------------------------------------
-
 
714
;
-
 
715
; returns free space in edi
-
 
716
; rewr.by Mihasik
-
 
717
;---------------------------------------------
-
 
718
 
-
 
719
        push    eax ebx ecx
-
 
720
 
-
 
721
        mov     edi, [ebp+FAT.fat12_unpacked_ptr];start of FAT
-
 
722
        xor     ax, ax;Free cluster=0x0000 in FAT
-
 
723
        xor     ebx, ebx;counter
-
 
724
        mov     ecx, [ebp+FAT.LAST_CLUSTER]
-
 
725
        inc     ecx
-
 
726
        cld
-
 
727
    rdfs1:
-
 
728
        repne scasw
-
 
729
        jnz     rdfs2 ;if last cluster not 0
-
 
730
        inc     ebx
-
 
731
        test    ecx, ecx
-
 
732
        jnz     rdfs1
-
 
733
    rdfs2:
-
 
734
        shl     ebx, 9;free clusters*512
-
 
735
        mov     edi, ebx
-
 
736
 
-
 
737
        pop     ecx ebx eax
-
 
738
        ret
-
 
739
 
-
 
740
 
279
 
741
 
280
set_FAT:
742
set_FAT:
281
;--------------------------------
743
;--------------------------------
282
; input  : EAX = cluster
744
; input  : EAX = cluster
283
;          EDX = value to save
745
;          EDX = value to save
Line 289... Line 751...
289
 
751
 
290
        cmp     eax, 2
752
        cmp     eax, 2
291
        jb      sfc_error
753
        jb      sfc_error
292
        cmp     eax, [ebp+FAT.LAST_CLUSTER]
754
        cmp     eax, [ebp+FAT.LAST_CLUSTER]
-
 
755
        ja      sfc_error
-
 
756
        cmp     [ebp+FAT.fs_type], 12
293
        ja      sfc_error
757
        je      set_FAT12
294
        cmp     [ebp+FAT.fs_type], 16
758
        cmp     [ebp+FAT.fs_type], 16
295
        je      sfc_1
759
        je      sfc_1
296
        add     eax, eax
760
        add     eax, eax
297
  sfc_1:
761
  sfc_1:
298
        add     eax, eax
762
        add     eax, eax
299
        mov     esi, 511
763
        mov     esi, 511
300
        and     esi, eax        ; esi = position in fat sector
764
        and     esi, eax        ; esi = position in fat sector
301
        shr     eax, 9          ; eax = fat sector
765
        shr     eax, 9          ; eax = fat sector
302
        add     eax, [ebp+FAT.FAT_START]
766
        add     eax, [ebp+FAT.FAT_START]
Line 303... Line 767...
303
        lea     ebx, [ebp+FAT.fat_cache]
767
        mov     ebx, [ebp+FAT.fat_cache_ptr]
304
 
768
 
Line 305... Line 769...
305
        cmp     eax, [ebp+FAT.fat_in_cache]; is fat sector already in memory?
769
        cmp     eax, [ebp+FAT.fat_in_cache]; is fat sector already in memory?
Line 347... Line 811...
347
        ret
811
        ret
348
  sfc_error:
812
  sfc_error:
349
        stc
813
        stc
350
        jmp     sfc_return
814
        jmp     sfc_return
Line -... Line 815...
-
 
815
 
-
 
816
  set_FAT12:
-
 
817
        test    edx, 0xF000
-
 
818
        jnz     sfc_error
-
 
819
        mov     ebx, [ebp+FAT.fat12_unpacked_ptr]
-
 
820
        xchg    [ebx+eax*2], dx
-
 
821
        mov     [ebp+FAT.fat_change], 1
-
 
822
        pop     esi ebx eax
-
 
823
        clc
Line 351... Line 824...
351
 
824
        ret
352
 
825
 
353
get_FAT:
826
get_FAT:
354
;--------------------------------
827
;--------------------------------
355
; input  : EAX = cluster
828
; input  : EAX = cluster
356
;          EBP = pointer to FAT structure
829
;          EBP = pointer to FAT structure
357
; output : EAX = next cluster
830
; output : EAX = next cluster
358
;--------------------------------
831
;--------------------------------
Line -... Line 832...
-
 
832
; out: CF set <=> error
-
 
833
        push    ebx esi
-
 
834
 
359
; out: CF set <=> error
835
        cmp     [ebp+FAT.fs_type], 12
360
        push    ebx esi
836
        je      get_FAT12
361
 
837
 
362
        cmp     [ebp+FAT.fs_type], 16
838
        cmp     [ebp+FAT.fs_type], 16
363
        je      gfc_1
839
        je      gfc_1
364
        add     eax, eax
840
        add     eax, eax
365
  gfc_1:
841
  gfc_1:
366
        add     eax, eax
842
        add     eax, eax
367
        mov     esi, 511
843
        mov     esi, 511
368
        and     esi, eax        ; esi = position in fat sector
844
        and     esi, eax        ; esi = position in fat sector
Line 369... Line 845...
369
        shr     eax, 9          ; eax = fat sector
845
        shr     eax, 9          ; eax = fat sector
370
        add     eax, [ebp+FAT.FAT_START]
846
        add     eax, [ebp+FAT.FAT_START]
Line 371... Line 847...
371
        lea     ebx, [ebp+FAT.fat_cache]
847
        mov     ebx, [ebp+FAT.fat_cache_ptr]
Line 392... Line 868...
392
        ret
868
        ret
393
 hd_error_01:
869
 hd_error_01:
394
        stc
870
        stc
395
        jmp     gfc_return
871
        jmp     gfc_return
Line -... Line 872...
-
 
872
 
-
 
873
get_FAT12:
-
 
874
        mov     ebx, [ebp+FAT.fat12_unpacked_ptr]
-
 
875
        movzx   eax, word [ebx+eax*2]
-
 
876
        pop     esi ebx
-
 
877
        clc
-
 
878
        ret
Line 396... Line 879...
396
 
879
 
397
 
880
 
398
get_free_FAT:
881
get_free_FAT:
399
;-----------------------------------------------------------
882
;-----------------------------------------------------------
400
; output : if CARRY=0 EAX = # first cluster found free
883
; output : if CARRY=0 EAX = # first cluster found free
401
;          if CARRY=1 disk full
884
;          if CARRY=1 disk full
402
; Note   : for more speed need to use fat_cache directly
885
; Note   : for more speed need to use fat_cache directly
403
;-----------------------------------------------------------
886
;-----------------------------------------------------------
404
        push    ecx
-
 
405
        mov     ecx, [ebp+FAT.LAST_CLUSTER]; counter for full disk
887
        push    ecx
-
 
888
        mov     ecx, [ebp+FAT.LAST_CLUSTER]; counter for full disk
-
 
889
        mov     eax, [ebp+FAT.fatStartScan]
-
 
890
        cmp     [ebp+FAT.fs_type], 12
406
        sub     ecx, 2
891
        jz      get_free_FAT12
407
        mov     eax, [ebp+FAT.fatStartScan]
892
        dec     ecx
Line 408... Line 893...
408
        cmp     eax, 2
893
        cmp     eax, 2
409
        jb      gff_reset
894
        jb      gff_reset
Line 422... Line 907...
422
        test    eax, eax        ; is it free?
907
        test    eax, eax        ; is it free?
423
        pop     eax
908
        pop     eax
424
        je      gff_found       ; yes
909
        je      gff_found       ; yes
425
        inc     eax             ; next cluster
910
        inc     eax             ; next cluster
426
        dec     ecx             ; is all checked?
911
        dec     ecx             ; is all checked?
427
        jns     gff_test        ; no
912
        jnz     gff_test        ; no
Line 428... Line 913...
428
 
913
 
429
  gff_not_found:
914
  gff_not_found:
430
        pop     ecx             ; yes. disk is full
915
        pop     ecx             ; yes. disk is full
431
        stc
916
        stc
Line 440... Line 925...
440
        mov     [ebp+FAT.fatStartScan], ecx
925
        mov     [ebp+FAT.fatStartScan], ecx
441
        pop     ecx
926
        pop     ecx
442
        clc
927
        clc
443
        ret
928
        ret
Line -... Line 929...
-
 
929
 
-
 
930
get_free_FAT12:
-
 
931
        push    edx edi
-
 
932
        mov     edi, [ebp+FAT.fat12_unpacked_ptr]
-
 
933
        cmp     eax, 2
-
 
934
        jb      .reset
-
 
935
        cmp     eax, ecx
-
 
936
        jbe     @f
-
 
937
.reset:
-
 
938
        mov     eax, 2
-
 
939
@@:
-
 
940
        mov     edx, eax
-
 
941
        lea     edi, [edi+eax*2]
-
 
942
        sub     ecx, eax
-
 
943
        inc     ecx
-
 
944
        xor     eax, eax
-
 
945
        repnz scasw
-
 
946
        jz      .found
-
 
947
        cmp     edx, 2
-
 
948
        jz      .notfound
-
 
949
        mov     edi, [ebp+FAT.fat12_unpacked_ptr]
-
 
950
        lea     ecx, [edx-2]
-
 
951
        repnz scasw
-
 
952
        jnz     .notfound
-
 
953
.found:
-
 
954
        sub     edi, [ebp+FAT.fat12_unpacked_ptr]
-
 
955
        shr     edi, 1
-
 
956
        mov     [ebp+FAT.fatStartScan], edi
-
 
957
        lea     eax, [edi-1]
-
 
958
        pop     edi edx ecx
-
 
959
        ret
-
 
960
.notfound:
-
 
961
        pop     edi edx ecx
-
 
962
        stc
-
 
963
        ret
Line 444... Line 964...
444
 
964
 
445
 
965
 
446
write_fat_sector:
966
write_fat_sector:
447
;-----------------------------------------------------------
967
;-----------------------------------------------------------
Line 451... Line 971...
451
 
971
 
452
        mov     [ebp+FAT.fat_change], 0
972
        mov     [ebp+FAT.fat_change], 0
453
        mov     eax, [ebp+FAT.fat_in_cache]
973
        mov     eax, [ebp+FAT.fat_in_cache]
454
        cmp     eax, -1
974
        cmp     eax, -1
455
        jz      write_fat_not_used
975
        jz      write_fat_not_used
456
        lea     ebx, [ebp+FAT.fat_cache]
976
        mov     ebx, [ebp+FAT.fat_cache_ptr]
Line 457... Line 977...
457
        mov     ecx, [ebp+FAT.NUMBER_OF_FATS]
977
        mov     ecx, [ebp+FAT.NUMBER_OF_FATS]
458
 
978
 
459
  write_next_fat:
979
  write_next_fat:
Line 681... Line 1201...
681
        mov     eax, ERROR_ACCESS_DENIED
1201
        mov     eax, ERROR_ACCESS_DENIED
682
        ret
1202
        ret
683
end if
1203
end if
Line 684... Line 1204...
684
 
1204
 
-
 
1205
update_disk:
-
 
1206
        cmp     [ebp+FAT.fat_change], 0 ; is fat changed?
-
 
1207
        je      upd_no_change
-
 
1208
        cmp     [ebp+FAT.fs_type], 12
685
update_disk:
1209
        jz      .fat12
686
;-----------------------------------------------------------
1210
;-----------------------------------------------------------
687
; write changed fat and cache to disk
1211
; write changed fat and cache to disk
688
;-----------------------------------------------------------
-
 
689
        cmp     [ebp+FAT.fat_change], 0 ; is fat changed?
-
 
Line 690... Line 1212...
690
        je      upd_no_change
1212
;-----------------------------------------------------------
691
 
1213
 
-
 
1214
        call    write_fat_sector
-
 
1215
        jc      update_disk_acces_denied
-
 
1216
        jmp     upd_no_change
-
 
1217
.fat12:
Line 692... Line 1218...
692
        call    write_fat_sector
1218
        call    restorefatchain
Line 693... Line 1219...
693
        jc      update_disk_acces_denied
1219
        mov     [ebp+FAT.fat_change], 0
694
 
1220
 
Line 707... Line 1233...
707
fat_unlock:
1233
fat_unlock:
708
        lea     ecx, [ebp+FAT.Lock]
1234
        lea     ecx, [ebp+FAT.Lock]
709
        jmp     mutex_unlock
1235
        jmp     mutex_unlock
Line 710... Line 1236...
710
 
1236
 
-
 
1237
; \begin{diamond}
-
 
1238
uni2ansi_str:
-
 
1239
; convert UNICODE zero-terminated string to ASCII-string (codepage 866)
-
 
1240
; in: esi->source, edi->buffer (may be esi=edi)
-
 
1241
; destroys: eax,esi,edi
-
 
1242
        lodsw
-
 
1243
        test    ax, ax
-
 
1244
        jz      .done
-
 
1245
        cmp     ax, 0x80
-
 
1246
        jb      .ascii
-
 
1247
        cmp     ax, 0x401
-
 
1248
        jz      .yo1
-
 
1249
        cmp     ax, 0x451
-
 
1250
        jz      .yo2
-
 
1251
        cmp     ax, 0x410
-
 
1252
        jb      .unk
-
 
1253
        cmp     ax, 0x440
-
 
1254
        jb      .rus1
-
 
1255
        cmp     ax, 0x450
-
 
1256
        jb      .rus2
-
 
1257
.unk:
-
 
1258
        mov     al, '_'
-
 
1259
        jmp     .doit
-
 
1260
.yo1:
-
 
1261
        mov     al, 0xF0 ; 'Ё'
-
 
1262
        jmp     .doit
-
 
1263
.yo2:
-
 
1264
        mov     al, 0xF1 ; 'ё'
-
 
1265
        jmp     .doit
-
 
1266
.rus1:
-
 
1267
; 0x410-0x43F -> 0x80-0xAF
-
 
1268
        add     al, 0x70
-
 
1269
        jmp     .doit
-
 
1270
.rus2:
-
 
1271
; 0x440-0x44F -> 0xE0-0xEF
-
 
1272
        add     al, 0xA0
-
 
1273
.ascii:
-
 
1274
.doit:
-
 
1275
        stosb
-
 
1276
        jmp     uni2ansi_str
-
 
1277
.done:
-
 
1278
        mov     byte [edi], 0
-
 
1279
        ret
-
 
1280
 
-
 
1281
ansi2uni_char:
-
 
1282
; convert ANSI character in al to UNICODE character in ax, using cp866 encoding
-
 
1283
        mov     ah, 0
-
 
1284
; 0x00-0x7F - trivial map
-
 
1285
        cmp     al, 0x80
-
 
1286
        jb      .ret
-
 
1287
; 0x80-0xAF -> 0x410-0x43F
-
 
1288
        cmp     al, 0xB0
-
 
1289
        jae     @f
-
 
1290
        add     ax, 0x410-0x80
-
 
1291
.ret:
-
 
1292
        ret
-
 
1293
@@:
-
 
1294
; 0xE0-0xEF -> 0x440-0x44F
-
 
1295
        cmp     al, 0xE0
-
 
1296
        jb      .unk
-
 
1297
        cmp     al, 0xF0
-
 
1298
        jae     @f
-
 
1299
        add     ax, 0x440-0xE0
-
 
1300
        ret
-
 
1301
; 0xF0 -> 0x401
-
 
1302
; 0xF1 -> 0x451
-
 
1303
@@:
-
 
1304
        cmp     al, 0xF0 ; 'Ё'
-
 
1305
        jz      .yo1
-
 
1306
        cmp     al, 0xF1 ; 'ё'
-
 
1307
        jz      .yo2
-
 
1308
.unk:
-
 
1309
        mov     al, '_'         ; ah=0
-
 
1310
        ret
-
 
1311
.yo1:
-
 
1312
        mov     ax, 0x401
-
 
1313
        ret
-
 
1314
.yo2:
-
 
1315
        mov     ax, 0x451
-
 
1316
        ret
-
 
1317
 
-
 
1318
char_toupper:
-
 
1319
; convert character to uppercase, using cp866 encoding
-
 
1320
; in: al=symbol
-
 
1321
; out: al=converted symbol
-
 
1322
        cmp     al, 'a'
-
 
1323
        jb      .ret
-
 
1324
        cmp     al, 'z'
-
 
1325
        jbe     .az
-
 
1326
        cmp     al, 0xF1 ; 'ё'
-
 
1327
        jz      .yo1
-
 
1328
        cmp     al, 0xA0 ; 'а'
-
 
1329
        jb      .ret
-
 
1330
        cmp     al, 0xE0 ; 'р'
-
 
1331
        jb      .rus1
-
 
1332
        cmp     al, 0xEF ; 'я'
-
 
1333
        ja      .ret
-
 
1334
; 0xE0-0xEF -> 0x90-0x9F
-
 
1335
        sub     al, 0xE0-0x90
-
 
1336
.ret:
-
 
1337
        ret
-
 
1338
.rus1:
-
 
1339
; 0xA0-0xAF -> 0x80-0x8F
-
 
1340
.az:
-
 
1341
        and     al, not 0x20
-
 
1342
        ret
-
 
1343
.yo1:
-
 
1344
; 0xF1 -> 0xF0
-
 
1345
        dec     ax
-
 
1346
        ret
-
 
1347
 
-
 
1348
fat_get_name:
-
 
1349
; in: edi->FAT entry
-
 
1350
; out: CF=1 - no valid entry
-
 
1351
; else CF=0 and ebp->ASCIIZ-name
-
 
1352
; (maximum length of filename is 255 (wide) symbols without trailing 0,
-
 
1353
;  but implementation requires buffer 261 words)
-
 
1354
; destroys eax
-
 
1355
        cmp     byte [edi], 0
-
 
1356
        jz      .no
-
 
1357
        cmp     byte [edi], 0xE5
-
 
1358
        jnz     @f
-
 
1359
.no:
-
 
1360
        stc
-
 
1361
        ret
-
 
1362
@@:
-
 
1363
        cmp     byte [edi+11], 0xF
-
 
1364
        jz      .longname
-
 
1365
        test    byte [edi+11], 8
-
 
1366
        jnz     .no
-
 
1367
        push    ecx
-
 
1368
        push    edi ebp
-
 
1369
        test    byte [ebp-4], 1
-
 
1370
        jnz     .unicode_short
-
 
1371
 
-
 
1372
        mov     eax, [edi]
-
 
1373
        mov     ecx, [edi+4]
-
 
1374
        mov     [ebp], eax
-
 
1375
        mov     [ebp+4], ecx
-
 
1376
 
-
 
1377
        mov     ecx, 8
-
 
1378
@@:
-
 
1379
        cmp     byte [ebp+ecx-1], ' '
-
 
1380
        loope   @b
-
 
1381
 
-
 
1382
        mov     eax, [edi+8]
-
 
1383
        cmp     al, ' '
-
 
1384
        je      .done
-
 
1385
        shl     eax, 8
-
 
1386
        mov     al, '.'
-
 
1387
 
-
 
1388
        lea     ebp, [ebp+ecx+1]
-
 
1389
        mov     [ebp], eax
-
 
1390
        mov     ecx, 3
-
 
1391
@@:
-
 
1392
        rol     eax, 8
-
 
1393
        cmp     al, ' '
-
 
1394
        jne     .done
-
 
1395
        loop    @b
-
 
1396
        dec     ebp
-
 
1397
.done:
-
 
1398
        and     byte [ebp+ecx+1], 0   ; CF=0
-
 
1399
        pop     ebp edi ecx
-
 
1400
        ret
-
 
1401
.unicode_short:
-
 
1402
        mov     ecx, 8
-
 
1403
        push    ecx
-
 
1404
@@:
-
 
1405
        mov     al, [edi]
-
 
1406
        inc     edi
-
 
1407
        call    ansi2uni_char
-
 
1408
        mov     [ebp], ax
-
 
1409
        inc     ebp
-
 
1410
        inc     ebp
-
 
1411
        loop    @b
-
 
1412
        pop     ecx
-
 
1413
@@:
-
 
1414
        cmp     word [ebp-2], ' '
-
 
1415
        jnz     @f
-
 
1416
        dec     ebp
-
 
1417
        dec     ebp
-
 
1418
        loop    @b
-
 
1419
@@:
-
 
1420
        mov     word [ebp], '.'
-
 
1421
        inc     ebp
-
 
1422
        inc     ebp
-
 
1423
        mov     ecx, 3
-
 
1424
        push    ecx
-
 
1425
@@:
-
 
1426
        mov     al, [edi]
-
 
1427
        inc     edi
-
 
1428
        call    ansi2uni_char
-
 
1429
        mov     [ebp], ax
-
 
1430
        inc     ebp
-
 
1431
        inc     ebp
-
 
1432
        loop    @b
-
 
1433
        pop     ecx
-
 
1434
@@:
-
 
1435
        cmp     word [ebp-2], ' '
-
 
1436
        jnz     @f
-
 
1437
        dec     ebp
-
 
1438
        dec     ebp
-
 
1439
        loop    @b
-
 
1440
        dec     ebp
-
 
1441
        dec     ebp
-
 
1442
@@:
-
 
1443
        and     word [ebp], 0   ; CF=0
-
 
1444
        pop     ebp edi ecx
-
 
1445
        ret
-
 
1446
.longname:
-
 
1447
; LFN
-
 
1448
        mov     al, byte [edi]
-
 
1449
        and     eax, 0x3F
-
 
1450
        dec     eax
-
 
1451
        cmp     al, 20
-
 
1452
        jae     .no     ; ignore invalid entries
-
 
1453
        mov     word [ebp+260*2], 0     ; force null-terminating for orphans
-
 
1454
        imul    eax, 13*2
-
 
1455
        add     ebp, eax
-
 
1456
        test    byte [edi], 0x40
-
 
1457
        jz      @f
-
 
1458
        mov     word [ebp+13*2], 0
-
 
1459
@@:
-
 
1460
        push    eax
-
 
1461
; now copy name from edi to ebp ...
-
 
1462
        mov     eax, [edi+1]
-
 
1463
        mov     [ebp], eax      ; symbols 1,2
-
 
1464
        mov     eax, [edi+5]
-
 
1465
        mov     [ebp+4], eax    ; 3,4
-
 
1466
        mov     eax, [edi+9]
-
 
1467
        mov     [ebp+8], ax     ; 5
-
 
1468
        mov     eax, [edi+14]
-
 
1469
        mov     [ebp+10], eax   ; 6,7
-
 
1470
        mov     eax, [edi+18]
-
 
1471
        mov     [ebp+14], eax   ; 8,9
-
 
1472
        mov     eax, [edi+22]
-
 
1473
        mov     [ebp+18], eax   ; 10,11
-
 
1474
        mov     eax, [edi+28]
-
 
1475
        mov     [ebp+22], eax   ; 12,13
-
 
1476
; ... done
-
 
1477
        pop     eax
-
 
1478
        sub     ebp, eax
-
 
1479
        test    eax, eax
-
 
1480
        jz      @f
-
 
1481
; if this is not first entry, more processing required
-
 
1482
        stc
-
 
1483
        ret
-
 
1484
@@:
-
 
1485
; if this is first entry:
-
 
1486
        test    byte [ebp-4], 1
-
 
1487
        jnz     .ret
-
 
1488
; buffer at ebp contains UNICODE name, convert it to ANSI
-
 
1489
        push    esi edi
-
 
1490
        mov     esi, ebp
-
 
1491
        mov     edi, ebp
-
 
1492
        call    uni2ansi_str
-
 
1493
        pop     edi esi
-
 
1494
.ret:
-
 
1495
        clc
-
 
1496
        ret
-
 
1497
 
-
 
1498
fat_compare_name:
-
 
1499
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
-
 
1500
; in: esi->name, ebp->name
-
 
1501
; out: if names match: ZF=1 and esi->next component of name
-
 
1502
;      else: ZF=0, esi is not changed
-
 
1503
; destroys eax
-
 
1504
        push    ebp esi
-
 
1505
.loop:
-
 
1506
        mov     al, [ebp]
-
 
1507
        inc     ebp
-
 
1508
        call    char_toupper
-
 
1509
        push    eax
-
 
1510
        lodsb
-
 
1511
        call    char_toupper
-
 
1512
        cmp     al, [esp]
-
 
1513
        jnz     .done
-
 
1514
        pop     eax
-
 
1515
        test    al, al
-
 
1516
        jnz     .loop
-
 
1517
        dec     esi
-
 
1518
        pop     eax
-
 
1519
        pop     ebp
-
 
1520
        xor     eax, eax        ; set ZF flag
-
 
1521
        ret
-
 
1522
.done:
-
 
1523
        cmp     al, '/'
-
 
1524
        jnz     @f
-
 
1525
        cmp     byte [esp], 0
-
 
1526
        jnz     @f
-
 
1527
        mov     [esp+4], esi
-
 
1528
@@:
-
 
1529
        pop     eax
-
 
1530
        pop     esi ebp
-
 
1531
        ret
-
 
1532
 
-
 
1533
fat_find_lfn:
-
 
1534
; in: esi->name
-
 
1535
;     [esp+4] = next
-
 
1536
;     [esp+8] = first
-
 
1537
;     [esp+C]... - possibly parameters for first and next
-
 
1538
; out: CF=1 - file not found, eax=error code
-
 
1539
;      else CF=0, esi->next name component, edi->direntry
-
 
1540
        pusha
-
 
1541
        lea     eax, [esp+0Ch+20h]
-
 
1542
        call    dword [eax-4]
-
 
1543
        jc      .reterr
-
 
1544
        sub     esp, 262*2      ; reserve place for LFN
-
 
1545
        push    0               ; for fat_get_name: read ASCII name
-
 
1546
.l1:
-
 
1547
        lea     ebp, [esp+4]
-
 
1548
        call    fat_get_name
-
 
1549
        jc      .l2
-
 
1550
        call    fat_compare_name
-
 
1551
        jz      .found
-
 
1552
.l2:
-
 
1553
        mov     ebp, [esp+8+262*2+4]
-
 
1554
        lea     eax, [esp+0Ch+20h+262*2+4]
-
 
1555
        call    dword [eax-8]
-
 
1556
        jnc     .l1
-
 
1557
        add     esp, 262*2+4
-
 
1558
.reterr:
-
 
1559
        mov     [esp+28], eax
-
 
1560
        stc
-
 
1561
        popa
-
 
1562
        ret
-
 
1563
.found:
-
 
1564
        add     esp, 262*2+4
-
 
1565
        mov     ebp, [esp+8]
-
 
1566
; if this is LFN entry, advance to true entry
-
 
1567
        cmp     byte [edi+11], 0xF
-
 
1568
        jnz     @f
-
 
1569
        lea     eax, [esp+0Ch+20h]
-
 
1570
        call    dword [eax-8]
-
 
1571
        jc      .reterr
-
 
1572
@@:
-
 
1573
        add     esp, 8          ; CF=0
-
 
1574
        push    esi
-
 
1575
        push    edi
-
 
1576
        popa
-
 
1577
        ret
-
 
1578
 
-
 
1579
fat_time_to_bdfe:
-
 
1580
; in: eax=FAT time
-
 
1581
; out: eax=BDFE time
-
 
1582
        push    ecx edx
-
 
1583
        mov     ecx, eax
-
 
1584
        mov     edx, eax
-
 
1585
        shr     eax, 11
-
 
1586
        shl     eax, 16 ; hours
-
 
1587
        and     edx, 0x1F
-
 
1588
        add     edx, edx
-
 
1589
        mov     al, dl  ; seconds
-
 
1590
        shr     ecx, 5
-
 
1591
        and     ecx, 0x3F
-
 
1592
        mov     ah, cl  ; minutes
-
 
1593
        pop     edx ecx
-
 
1594
        ret
-
 
1595
 
-
 
1596
fat_date_to_bdfe:
-
 
1597
        push    ecx edx
-
 
1598
        mov     ecx, eax
-
 
1599
        mov     edx, eax
-
 
1600
        shr     eax, 9
-
 
1601
        add     ax, 1980
-
 
1602
        shl     eax, 16 ; year
-
 
1603
        and     edx, 0x1F
-
 
1604
        mov     al, dl  ; day
-
 
1605
        shr     ecx, 5
-
 
1606
        and     ecx, 0xF
-
 
1607
        mov     ah, cl  ; month
-
 
1608
        pop     edx ecx
-
 
1609
        ret
-
 
1610
 
-
 
1611
bdfe_to_fat_time:
-
 
1612
        push    edx
-
 
1613
        mov     edx, eax
-
 
1614
        shr     eax, 16
-
 
1615
        and     dh, 0x3F
-
 
1616
        shl     eax, 6
-
 
1617
        or      al, dh
-
 
1618
        shr     dl, 1
-
 
1619
        and     dl, 0x1F
-
 
1620
        shl     eax, 5
-
 
1621
        or      al, dl
-
 
1622
        pop     edx
-
 
1623
        ret
-
 
1624
 
-
 
1625
bdfe_to_fat_date:
-
 
1626
        push    edx
-
 
1627
        mov     edx, eax
-
 
1628
        shr     eax, 16
-
 
1629
        sub     ax, 1980
-
 
1630
        and     dh, 0xF
-
 
1631
        shl     eax, 4
-
 
1632
        or      al, dh
-
 
1633
        and     dl, 0x1F
-
 
1634
        shl     eax, 5
-
 
1635
        or      al, dl
-
 
1636
        pop     edx
-
 
1637
        ret
-
 
1638
 
-
 
1639
fat_entry_to_bdfe:
-
 
1640
; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi
-
 
1641
; destroys eax
-
 
1642
        mov     eax, [ebp-4]
-
 
1643
        mov     [esi+4], eax    ; ASCII/UNICODE name
-
 
1644
fat_entry_to_bdfe2:
-
 
1645
        movzx   eax, byte [edi+11]
-
 
1646
        mov     [esi], eax      ; attributes
-
 
1647
        movzx   eax, word [edi+14]
-
 
1648
        call    fat_time_to_bdfe
-
 
1649
        mov     [esi+8], eax    ; creation time
-
 
1650
        movzx   eax, word [edi+16]
-
 
1651
        call    fat_date_to_bdfe
-
 
1652
        mov     [esi+12], eax   ; creation date
-
 
1653
        and     dword [esi+16], 0       ; last access time is not supported on FAT
-
 
1654
        movzx   eax, word [edi+18]
-
 
1655
        call    fat_date_to_bdfe
-
 
1656
        mov     [esi+20], eax   ; last access date
-
 
1657
        movzx   eax, word [edi+22]
-
 
1658
        call    fat_time_to_bdfe
-
 
1659
        mov     [esi+24], eax   ; last write time
-
 
1660
        movzx   eax, word [edi+24]
-
 
1661
        call    fat_date_to_bdfe
-
 
1662
        mov     [esi+28], eax   ; last write date
-
 
1663
        mov     eax, [edi+28]
-
 
1664
        mov     [esi+32], eax   ; file size (low dword)
-
 
1665
        xor     eax, eax
-
 
1666
        mov     [esi+36], eax   ; file size (high dword)
-
 
1667
        test    ebp, ebp
-
 
1668
        jz      .ret
-
 
1669
        push    ecx edi
-
 
1670
        lea     edi, [esi+40]
-
 
1671
        mov     esi, ebp
-
 
1672
        test    byte [esi-4], 1
-
 
1673
        jz      .ansi
-
 
1674
        mov     ecx, 260/2
-
 
1675
        rep movsd
-
 
1676
        mov     [edi-2], ax
-
 
1677
@@:
-
 
1678
        mov     esi, edi
-
 
1679
        pop     edi ecx
-
 
1680
.ret:
-
 
1681
        ret
-
 
1682
.ansi:
-
 
1683
        mov     ecx, 264/4
-
 
1684
        rep movsd
-
 
1685
        mov     [edi-1], al
-
 
1686
        jmp     @b
-
 
1687
 
-
 
1688
bdfe_to_fat_entry:
-
 
1689
; convert BDFE at edx to FAT entry at edi
-
 
1690
; destroys eax
-
 
1691
; attributes byte
-
 
1692
        test    byte [edi+11], 8        ; volume label?
-
 
1693
        jnz     @f
-
 
1694
        mov     al, [edx]
-
 
1695
        and     al, 0x27
-
 
1696
        and     byte [edi+11], 0x10
-
 
1697
        or      byte [edi+11], al
-
 
1698
@@:
-
 
1699
        mov     eax, [edx+8]
-
 
1700
        call    bdfe_to_fat_time
-
 
1701
        mov     [edi+14], ax            ; creation time
-
 
1702
        mov     eax, [edx+12]
-
 
1703
        call    bdfe_to_fat_date
-
 
1704
        mov     [edi+16], ax            ; creation date
-
 
1705
        mov     eax, [edx+20]
-
 
1706
        call    bdfe_to_fat_date
-
 
1707
        mov     [edi+18], ax            ; last access date
-
 
1708
        mov     eax, [edx+24]
-
 
1709
        call    bdfe_to_fat_time
-
 
1710
        mov     [edi+22], ax            ; last write time
-
 
1711
        mov     eax, [edx+28]
-
 
1712
        call    bdfe_to_fat_date
-
 
1713
        mov     [edi+24], ax            ; last write date
-
 
1714
        ret
711
; \begin{diamond}
1715
 
712
hd_find_lfn:
1716
hd_find_lfn:
713
; in: ebp -> FAT structure
1717
; in: ebp -> FAT structure
714
; in: esi+[esp+4] -> name
1718
; in: esi+[esp+4] -> name
715
; out: CF=1 - file not found, eax=error code
1719
; out: CF=1 - file not found, eax=error code
716
;      else CF=0 and edi->direntry, eax=sector
1720
;      else CF=0 and edi->direntry, eax=sector
717
; destroys eax
1721
; destroys eax
718
        push    esi edi
1722
        push    esi edi
719
        push    0
1723
        push    0
720
        push    0
1724
        push    0
721
        push    fat16_root_first
1725
        push    fat1x_root_first
722
        push    fat16_root_next
1726
        push    fat1x_root_next
723
        mov     eax, [ebp+FAT.ROOT_CLUSTER]
1727
        mov     eax, [ebp+FAT.ROOT_CLUSTER]
724
        cmp     [ebp+FAT.fs_type], 32
1728
        cmp     [ebp+FAT.fs_type], 32
725
        jz      .fat32
1729
        jz      .fat32
-
 
1730
.loop:
-
 
1731
        and     [ebp+FAT.longname_sec1], 0
726
.loop:
1732
        and     [ebp+FAT.longname_sec2], 0
727
        call    fat_find_lfn
1733
        call    fat_find_lfn
728
        jc      .notfound
1734
        jc      .notfound
729
        cmp     byte [esi], 0
1735
        cmp     byte [esi], 0
730
        jz      .found
1736
        jz      .found
Line 764... Line 1770...
764
        add     esp, 20         ; CF=0
1770
        add     esp, 20         ; CF=0
765
        pop     esi
1771
        pop     esi
766
        ret     4
1772
        ret     4
Line 767... Line 1773...
767
 
1773
 
768
;----------------------------------------------------------------
1774
;----------------------------------------------------------------
769
; fat_Read - FAT16/32 implementation of reading a file
1775
; fat_Read - FAT implementation of reading a file
770
; in:  ebp = pointer to FAT structure
1776
; in:  ebp = pointer to FAT structure
771
; in:  esi+[esp+4] = name
1777
; in:  esi+[esp+4] = name
772
; in:  ebx = pointer to parameters from sysfunc 70
1778
; in:  ebx = pointer to parameters from sysfunc 70
773
; out: eax, ebx = return values for sysfunc 70
1779
; out: eax, ebx = return values for sysfunc 70
Line 903... Line 1909...
903
        pop     eax edx
1909
        pop     eax edx
904
        sub     ebx, edx
1910
        sub     ebx, edx
905
        jmp     .reteof
1911
        jmp     .reteof
Line 906... Line 1912...
906
 
1912
 
907
;----------------------------------------------------------------
1913
;----------------------------------------------------------------
908
; fat_ReadFolder - FAT16/32 implementation of reading a folder
1914
; fat_ReadFolder - FAT implementation of reading a folder
909
; in:  ebp = pointer to FAT structure
1915
; in:  ebp = pointer to FAT structure
910
; in:  esi+[esp+4] = name
1916
; in:  esi+[esp+4] = name
911
; in:  ebx = pointer to parameters from sysfunc 70
1917
; in:  ebx = pointer to parameters from sysfunc 70
912
; out: eax, ebx = return values for sysfunc 70
1918
; out: eax, ebx = return values for sysfunc 70
Line 1078... Line 2084...
1078
        call    fat_unlock
2084
        call    fat_unlock
1079
        pop     eax
2085
        pop     eax
1080
        pop     esi edi
2086
        pop     esi edi
1081
        ret
2087
        ret
Line 1082... Line 2088...
1082
 
2088
 
1083
fat16_root_next:
2089
fat1x_root_next:
1084
        push    ecx
2090
        push    ecx
1085
        lea     ecx, [ebp+FAT.buffer+0x200-0x20]
2091
        lea     ecx, [ebp+FAT.buffer+0x200-0x20]
1086
        cmp     edi, ecx
2092
        cmp     edi, ecx
1087
        jae     fat16_root_next_sector
2093
        jae     fat1x_root_next_sector
1088
        pop     ecx
2094
        pop     ecx
1089
        add     edi, 0x20
2095
        add     edi, 0x20
1090
        ret     ; CF=0
2096
        ret     ; CF=0
1091
fat16_root_next_sector:
2097
fat1x_root_next_sector:
1092
; read next sector
2098
; read next sector
1093
        push    [ebp+FAT.longname_sec2]
2099
        push    [ebp+FAT.longname_sec2]
1094
        pop     [ebp+FAT.longname_sec1]
2100
        pop     [ebp+FAT.longname_sec1]
1095
        mov     ecx, [eax+4]
2101
        mov     ecx, [eax+4]
Line 1099... Line 2105...
1099
        pop     ecx
2105
        pop     ecx
1100
        inc     ecx
2106
        inc     ecx
1101
        mov     [eax+4], ecx
2107
        mov     [eax+4], ecx
1102
        cmp     ecx, [ebp+FAT.ROOT_SECTORS]
2108
        cmp     ecx, [ebp+FAT.ROOT_SECTORS]
1103
        pop     ecx
2109
        pop     ecx
1104
        jb      fat16_root_first
2110
        jb      fat1x_root_first
1105
        mov     eax, ERROR_FILE_NOT_FOUND
2111
        mov     eax, ERROR_FILE_NOT_FOUND
1106
        stc
2112
        stc
1107
        ret
2113
        ret
1108
fat16_root_first:
2114
fat1x_root_first:
1109
        mov     eax, [eax+4]
2115
        mov     eax, [eax+4]
1110
        add     eax, [ebp+FAT.ROOT_START]
2116
        add     eax, [ebp+FAT.ROOT_START]
1111
        push    ebx
2117
        push    ebx
1112
        lea     edi, [ebp+FAT.buffer]
2118
        lea     edi, [ebp+FAT.buffer]
1113
        mov     ebx, edi
2119
        mov     ebx, edi
Line 1122... Line 2128...
1122
        ret
2128
        ret
1123
.notfound:
2129
.notfound:
1124
        mov     eax, ERROR_FILE_NOT_FOUND
2130
        mov     eax, ERROR_FILE_NOT_FOUND
1125
        stc
2131
        stc
1126
        ret
2132
        ret
1127
fat16_root_begin_write:
2133
fat1x_root_begin_write:
1128
        push    edi eax
2134
        push    edi eax
1129
        call    fat16_root_first
2135
        call    fat1x_root_first
1130
        pop     eax edi
2136
        pop     eax edi
1131
        ret
2137
        ret
1132
fat16_root_end_write:
2138
fat1x_root_end_write:
1133
        pusha
2139
        pusha
1134
        mov     eax, [eax+4]
2140
        mov     eax, [eax+4]
1135
        add     eax, [ebp+FAT.ROOT_START]
2141
        add     eax, [ebp+FAT.ROOT_START]
1136
        lea     ebx, [ebp+FAT.buffer]
2142
        lea     ebx, [ebp+FAT.buffer]
1137
        call    fs_write32_sys
2143
        call    fs_write32_sys
1138
        popa
2144
        popa
1139
        ret
2145
        ret
1140
fat16_root_next_write:
2146
fat1x_root_next_write:
1141
        push    ecx
2147
        push    ecx
1142
        lea     ecx, [ebp+FAT.buffer+0x200]
2148
        lea     ecx, [ebp+FAT.buffer+0x200]
1143
        cmp     edi, ecx
2149
        cmp     edi, ecx
1144
        jae     @f
2150
        jae     @f
1145
        pop     ecx
2151
        pop     ecx
1146
        ret
2152
        ret
1147
@@:
2153
@@:
1148
        call    fat16_root_end_write
2154
        call    fat1x_root_end_write
1149
        jmp     fat16_root_next_sector
2155
        jmp     fat1x_root_next_sector
1150
fat16_root_extend_dir:
2156
fat1x_root_extend_dir:
1151
        stc
2157
        stc
1152
        ret
2158
        ret
Line 1153... Line 2159...
1153
 
2159
 
1154
fat_notroot_next:
2160
fat_notroot_next:
Line 1306... Line 2312...
1306
        mov     eax, ERROR_ACCESS_DENIED
2312
        mov     eax, ERROR_ACCESS_DENIED
1307
        xor     ebx, ebx
2313
        xor     ebx, ebx
1308
        ret
2314
        ret
Line 1309... Line 2315...
1309
 
2315
 
1310
;----------------------------------------------------------------
2316
;----------------------------------------------------------------
1311
; fat_CreateFolder - FAT16/32 implementation of creating a folder
2317
; fat_CreateFolder - FAT implementation of creating a folder
1312
; in:  ebp = pointer to FAT structure
2318
; in:  ebp = pointer to FAT structure
1313
; in:  esi+[esp+4] = name
2319
; in:  esi+[esp+4] = name
1314
; in:  ebx = pointer to parameters from sysfunc 70
2320
; in:  ebx = pointer to parameters from sysfunc 70
1315
; out: eax, ebx = return values for sysfunc 70
2321
; out: eax, ebx = return values for sysfunc 70
1316
;----------------------------------------------------------------
2322
;----------------------------------------------------------------
1317
fat_CreateFolder:
2323
fat_CreateFolder:
1318
        push    1
2324
        push    1
Line 1319... Line 2325...
1319
        jmp     fat_Rewrite.common
2325
        jmp     fat_Rewrite.common
1320
 
2326
 
1321
;----------------------------------------------------------------
2327
;----------------------------------------------------------------
1322
; fat_Rewrite - FAT16/32 implementation of creating a new file
2328
; fat_Rewrite - FAT implementation of creating a new file
1323
; in:  ebp = pointer to FAT structure
2329
; in:  ebp = pointer to FAT structure
1324
; in:  esi+[esp+4] = name
2330
; in:  esi+[esp+4] = name
1325
; in:  ebx = pointer to parameters from sysfunc 70
2331
; in:  ebx = pointer to parameters from sysfunc 70
Line 1358... Line 2364...
1358
        mov     edx, [ebp+FAT.ROOT_CLUSTER]
2364
        mov     edx, [ebp+FAT.ROOT_CLUSTER]
1359
        cmp     [ebp+FAT.fs_type], 32
2365
        cmp     [ebp+FAT.fs_type], 32
1360
        jz      .pushnotroot
2366
        jz      .pushnotroot
1361
        xor     edx, edx
2367
        xor     edx, edx
1362
        push    edx
2368
        push    edx
1363
        push    fat16_root_extend_dir
2369
        push    fat1x_root_extend_dir
1364
        push    fat16_root_end_write
2370
        push    fat1x_root_end_write
1365
        push    fat16_root_next_write
2371
        push    fat1x_root_next_write
1366
        push    fat16_root_begin_write
2372
        push    fat1x_root_begin_write
1367
        push    edx
2373
        push    edx
1368
        push    edx
2374
        push    edx
1369
        push    fat16_root_first
2375
        push    fat1x_root_first
1370
        push    fat16_root_next
2376
        push    fat1x_root_next
1371
        jmp     .common1
2377
        jmp     .common1
1372
.hasebp:
2378
.hasebp:
1373
        mov     eax, ERROR_ACCESS_DENIED
2379
        mov     eax, ERROR_ACCESS_DENIED
1374
        cmp     byte [edx], 0
2380
        cmp     byte [edx], 0
1375
        jz      .ret1
2381
        jz      .ret1
Line 1656... Line 2662...
1656
        dec     ecx
2662
        dec     ecx
1657
        imul    ecx, 13
2663
        imul    ecx, 13
1658
        add     esi, ecx
2664
        add     esi, ecx
1659
        stosb
2665
        stosb
1660
        mov     cl, 5
2666
        mov     cl, 5
1661
        call    fs_RamdiskRewrite.read_symbols
2667
        call    fat_read_symbols
1662
        mov     ax, 0xF
2668
        mov     ax, 0xF
1663
        stosw
2669
        stosw
1664
        mov     al, [esp+4]
2670
        mov     al, [esp+4]
1665
        stosb
2671
        stosb
1666
        mov     cl, 6
2672
        mov     cl, 6
1667
        call    fs_RamdiskRewrite.read_symbols
2673
        call    fat_read_symbols
1668
        xor     eax, eax
2674
        xor     eax, eax
1669
        stosw
2675
        stosw
1670
        mov     cl, 2
2676
        mov     cl, 2
1671
        call    fs_RamdiskRewrite.read_symbols
2677
        call    fat_read_symbols
1672
        pop     ecx
2678
        pop     ecx
1673
        lea     eax, [esp+8+8+12+8]
2679
        lea     eax, [esp+8+8+12+8]
1674
        call    dword [eax+12]         ; next write
2680
        call    dword [eax+12]         ; next write
1675
        xor     eax, eax
2681
        xor     eax, eax
1676
        loop    .writelfn
2682
        loop    .writelfn
Line 1864... Line 2870...
1864
        mov     word [edi-32+26], cx
2870
        mov     word [edi-32+26], cx
1865
        shr     ecx, 16
2871
        shr     ecx, 16
1866
        mov     [edi-32+20], cx
2872
        mov     [edi-32+20], cx
1867
        jmp     .writedircont
2873
        jmp     .writedircont
Line -... Line 2874...
-
 
2874
 
-
 
2875
fat_read_symbol:
-
 
2876
        or      ax, -1
-
 
2877
        test    esi, esi
-
 
2878
        jz      .retFFFF
-
 
2879
        lodsb
-
 
2880
        test    al, al
-
 
2881
        jnz     ansi2uni_char
-
 
2882
        xor     eax, eax
-
 
2883
        xor     esi, esi
-
 
2884
.retFFFF:
-
 
2885
        ret
-
 
2886
 
-
 
2887
fat_read_symbols:
-
 
2888
        call    fat_read_symbol
-
 
2889
        stosw
-
 
2890
        loop    fat_read_symbols
-
 
2891
        ret
-
 
2892
 
1868
 
2893
 
1869
fat_Write.access_denied:
2894
fat_Write.access_denied:
1870
        push    ERROR_ACCESS_DENIED
2895
        push    ERROR_ACCESS_DENIED
1871
fat_Write.ret0:
2896
fat_Write.ret0:
1872
        pop     eax
2897
        pop     eax
Line 1876... Line 2901...
1876
fat_Write.ret11:
2901
fat_Write.ret11:
1877
        push    ERROR_DEVICE
2902
        push    ERROR_DEVICE
1878
        jmp     fat_Write.ret0
2903
        jmp     fat_Write.ret0
Line 1879... Line 2904...
1879
 
2904
 
1880
;----------------------------------------------------------------
2905
;----------------------------------------------------------------
1881
; fat_Write - FAT16/32 implementation of writing to file
2906
; fat_Write - FAT implementation of writing to file
1882
; in:  ebp = pointer to FAT structure
2907
; in:  ebp = pointer to FAT structure
1883
; in:  esi+[esp+4] = name
2908
; in:  esi+[esp+4] = name
1884
; in:  ebx = pointer to parameters from sysfunc 70
2909
; in:  ebx = pointer to parameters from sysfunc 70
1885
; out: eax, ebx = return values for sysfunc 70
2910
; out: eax, ebx = return values for sysfunc 70
Line 2202... Line 3227...
2202
        pop     eax edx esi
3227
        pop     eax edx esi
2203
        movi    eax, ERROR_DISK_FULL
3228
        movi    eax, ERROR_DISK_FULL
2204
        stc
3229
        stc
2205
        ret
3230
        ret
Line -... Line 3231...
-
 
3231
 
-
 
3232
fat_update_datetime:
-
 
3233
        call    get_time_for_file
-
 
3234
        mov     [edi+22], ax            ; last write time
-
 
3235
        call    get_date_for_file
-
 
3236
        mov     [edi+24], ax            ; last write date
-
 
3237
        mov     [edi+18], ax            ; last access date
-
 
3238
        ret
-
 
3239
 
2206
 
3240
 
2207
;----------------------------------------------------------------
3241
;----------------------------------------------------------------
2208
; fat_SetFileEnd - FAT16/32 implementation of setting end-of-file
3242
; fat_SetFileEnd - FAT implementation of setting end-of-file
2209
; in:  ebp = pointer to FAT structure
3243
; in:  ebp = pointer to FAT structure
2210
; in:  esi+[esp+4] = name
3244
; in:  esi+[esp+4] = name
2211
; in:  ebx = pointer to parameters from sysfunc 70
3245
; in:  ebx = pointer to parameters from sysfunc 70
2212
; out: eax, ebx = return values for sysfunc 70
3246
; out: eax, ebx = return values for sysfunc 70
Line 2443... Line 3477...
2443
        call    fat_unlock
3477
        call    fat_unlock
2444
        movi    eax, ERROR_FAT_TABLE
3478
        movi    eax, ERROR_FAT_TABLE
2445
        ret
3479
        ret
Line 2446... Line 3480...
2446
 
3480
 
2447
;----------------------------------------------------------------
3481
;----------------------------------------------------------------
2448
; fat_GetFileInfo - FAT16/32 implementation of getting file info
3482
; fat_GetFileInfo - FAT implementation of getting file info
2449
; in:  ebp = pointer to FAT structure
3483
; in:  ebp = pointer to FAT structure
2450
; in:  esi+[esp+4] = name
3484
; in:  esi+[esp+4] = name
2451
; in:  ebx = pointer to parameters from sysfunc 70
3485
; in:  ebx = pointer to parameters from sysfunc 70
2452
; out: eax, ebx = return values for sysfunc 70
3486
; out: eax, ebx = return values for sysfunc 70
Line 2477... Line 3511...
2477
        pop     eax
3511
        pop     eax
2478
        pop     edi
3512
        pop     edi
2479
        ret
3513
        ret
Line 2480... Line 3514...
2480
 
3514
 
2481
;----------------------------------------------------------------
3515
;----------------------------------------------------------------
2482
; fat_SetFileInfo - FAT16/32 implementation of setting file info
3516
; fat_SetFileInfo - FAT implementation of setting file info
2483
; in:  ebp = pointer to FAT structure
3517
; in:  ebp = pointer to FAT structure
2484
; in:  esi+[esp+4] = name
3518
; in:  esi+[esp+4] = name
2485
; in:  ebx = pointer to parameters from sysfunc 70
3519
; in:  ebx = pointer to parameters from sysfunc 70
2486
; out: eax, ebx = return values for sysfunc 70
3520
; out: eax, ebx = return values for sysfunc 70
Line 2512... Line 3546...
2512
        pop     eax
3546
        pop     eax
2513
        pop     edi
3547
        pop     edi
2514
        ret
3548
        ret
Line 2515... Line 3549...
2515
 
3549
 
2516
;----------------------------------------------------------------
3550
;----------------------------------------------------------------
2517
; fat_Delete - FAT16/32 implementation of deleting a file/folder
3551
; fat_Delete - FAT implementation of deleting a file/folder
2518
; in:  ebp = pointer to FAT structure
3552
; in:  ebp = pointer to FAT structure
2519
; in:  esi+[esp+4] = name
3553
; in:  esi+[esp+4] = name
2520
; in:  ebx = pointer to parameters from sysfunc 70
3554
; in:  ebx = pointer to parameters from sysfunc 70
2521
; out: eax, ebx = return values for sysfunc 70
3555
; out: eax, ebx = return values for sysfunc 70