Subversion Repositories Kolibri OS

Rev

Rev 133 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 133 Rev 384
Line 10... Line 10...
10
 
10
 
Line 11... Line 11...
11
calculatefatchain:
11
calculatefatchain:
Line 12... Line 12...
12
 
12
 
13
   pushad
13
   pushad
Line 14... Line 14...
14
 
14
 
15
   mov  esi,0x100000+512
15
   mov  esi,RAMDISK+512
16
   mov  edi,0x280000
16
   mov  edi,RAMDISK_FAT
17
 
17
 
Line 36... Line 36...
36
   mov  dword [edi+8],ecx
36
   mov  dword [edi+8],ecx
37
   mov  dword [edi+12],edx
37
   mov  dword [edi+12],edx
38
   add  edi,16
38
   add  edi,16
39
   add  esi,12
39
   add  esi,12
Line 40... Line 40...
40
 
40
 
41
   cmp  edi,0x280000+2856*2   ;2849 clusters
41
   cmp  edi,RAMDISK_FAT+2856*2   ;2849 clusters
Line 42... Line 42...
42
   jnz  fcnew
42
   jnz  fcnew
43
 
43
 
Line 44... Line 44...
44
   popad
44
   popad
Line 45... Line 45...
45
   ret
45
   ret
Line 46... Line 46...
46
 
46
 
47
 
47
 
Line 48... Line 48...
48
restorefatchain:   ; restore fat chain
48
restorefatchain:   ; restore fat chain
49
 
49
 
50
   pushad
50
   pushad
51
 
51
 
Line 64... Line 64...
64
   mov  dword [edi],eax
64
   mov  dword [edi],eax
65
   mov  word [edi+4],bx
65
   mov  word [edi+4],bx
66
   add  edi,6
66
   add  edi,6
67
   add  esi,8
67
   add  esi,8
Line 68... Line 68...
68
 
68
 
69
   cmp  edi,0x100000+512+4278     ;4274 bytes - all used FAT
69
   cmp  edi,RAMDISK+512+4278     ;4274 bytes - all used FAT
Line 70... Line 70...
70
   jb   fcnew2
70
   jb   fcnew2
71
 
71
 
72
   mov  esi,0x100000+512           ; duplicate fat chain
72
   mov  esi,RAMDISK+512           ; duplicate fat chain
73
   mov  edi,0x100000+512+0x1200
73
   mov  edi,RAMDISK+512+0x1200
74
   mov  ecx,1069        ;4274/4
74
   mov  ecx,1069        ;4274/4
Line 75... Line 75...
75
   cld
75
   cld
Line 86... Line 86...
86
; rewr.by Mihasik
86
; rewr.by Mihasik
87
;---------------------------------------------
87
;---------------------------------------------
Line 88... Line 88...
88
 
88
 
Line 89... Line 89...
89
        push   eax ebx ecx
89
        push   eax ebx ecx
90
 
90
 
91
        mov  edi,0x280000 ;start of FAT
91
        mov  edi,RAMDISK_FAT ;start of FAT
92
        xor  ax,ax    ;Free cluster=0x0000 in FAT
92
        xor  ax,ax    ;Free cluster=0x0000 in FAT
93
        xor  ebx,ebx  ;counter
93
        xor  ebx,ebx  ;counter
94
        mov  ecx,2849 ;2849 clusters
94
        mov  ecx,2849 ;2849 clusters
Line 200... Line 200...
200
        jbe    fr_do1
200
        jbe    fr_do1
201
        sub    edx,14
201
        sub    edx,14
202
        sub    ecx,edx
202
        sub    ecx,edx
203
      fr_do1:
203
      fr_do1:
204
        shl    ebx,9
204
        shl    ebx,9
205
        mov    esi,0x100000+512*19
205
        mov    esi,RAMDISK+512*19
206
        add    esi,ebx
206
        add    esi,ebx
207
        shl    ecx,7
207
        shl    ecx,7
208
        cld
208
        cld
209
        rep    movsd
209
        rep    movsd
210
        popf
210
        popf
Line 244... Line 244...
244
 
244
 
Line 245... Line 245...
245
      frnew:
245
      frnew:
246
 
246
 
247
        add    eax,31                   ;bootsector+2*fat+filenames
247
        add    eax,31                   ;bootsector+2*fat+filenames
248
        shl    eax,9                    ;*512
248
        shl    eax,9                    ;*512
249
        add    eax,0x100000             ;image base
249
        add    eax,RAMDISK             ;image base
Line 250... Line 250...
250
        mov    ebx,[esp+8]
250
        mov    ebx,[esp+8]
251
        mov    ecx,512                  ;[esp+4]
251
        mov    ecx,512                  ;[esp+4]
Line 258... Line 258...
258
        je     frnoread
258
        je     frnoread
259
        jmp    frfl8
259
        jmp    frfl8
260
      frfl7:
260
      frfl7:
261
        dec    dword [esp+16]
261
        dec    dword [esp+16]
262
      frfl8:
262
      frfl8:
263
        movzx  eax,word [edi*2+0x280000]	; find next cluster from FAT
263
        movzx  eax,word [edi*2+RAMDISK_FAT]        ; find next cluster from FAT
264
        mov    edi,eax
264
        mov    edi,eax
265
        cmp    edi,4095                 ;eof  - cluster
265
        cmp    edi,4095                 ;eof  - cluster
266
        jz     frnoread2
266
        jz     frnoread2
Line 267... Line 267...
267
 
267
 
Line 324... Line 324...
324
        mov    edi,eax                  ;edi = cluster
324
        mov    edi,eax                  ;edi = cluster
Line 325... Line 325...
325
 
325
 
Line 326... Line 326...
326
      frnewd:
326
      frnewd:
327
 
327
 
328
        shl    edi,1                    ;find next cluster from FAT
328
        shl    edi,1                    ;find next cluster from FAT
329
        add    edi,0x280000
329
        add    edi,RAMDISK_FAT
330
        movzx  eax,word [edi]
330
        movzx  eax,word [edi]
331
        mov    [edi],word 0x0           ;clear fat chain cluster
331
        mov    [edi],word 0x0           ;clear fat chain cluster
332
        mov    edi,eax
332
        mov    edi,eax
Line 373... Line 373...
373
 
373
 
Line 374... Line 374...
374
      rd_do_save:
374
      rd_do_save:
Line 375... Line 375...
375
 
375
 
376
        push   eax ebx ecx edx esi edi
376
        push   eax ebx ecx edx esi edi
377
 
377
 
378
        mov    edi,0x100000+512*18+512  ;Point at directory
378
        mov    edi,RAMDISK+512*18+512  ;Point at directory
379
        mov    edx,224 +1
379
        mov    edx,224 +1
380
        ; find an empty spot for filename in the root dir
380
        ; find an empty spot for filename in the root dir
Line 405... Line 405...
405
call get_date_for_file   ; from FAT32.INC
405
call get_date_for_file   ; from FAT32.INC
406
mov [edi+24],ax          ; date
406
mov [edi+24],ax          ; date
407
call get_time_for_file   ; from FAT32.INC
407
call get_time_for_file   ; from FAT32.INC
408
mov [edi+22],ax          ; time
408
mov [edi+22],ax          ; time
409
; End
409
; End
410
        mov    edi,0x280000            ;pointer to first cluster
410
        mov    edi,RAMDISK_FAT            ;pointer to first cluster
411
        mov    ecx,2849
411
        mov    ecx,2849
412
        cld
412
        cld
413
      frnewds:
413
      frnewds:
414
        xor    ax,ax
414
        xor    ax,ax
415
        repne  scasw
415
        repne  scasw
Line 421... Line 421...
421
        dec    edx
421
        dec    edx
422
        call   fdc_filesave
422
        call   fdc_filesave
423
        pusha                           ; move save to floppy cluster
423
        pusha                           ; move save to floppy cluster
424
        add    ebx,31
424
        add    ebx,31
425
        shl    ebx,9
425
        shl    ebx,9
426
        add    ebx,0x100000
426
        add    ebx,RAMDISK
427
        mov    eax,[esp+32+16]
427
        mov    eax,[esp+32+16]
428
        mov    ecx,512
428
        mov    ecx,512
429
        call   memmove
429
        call   memmove
430
        popa
430
        popa
Line 456... Line 456...
456
 
456
 
457
   rd_findfile:
457
   rd_findfile:
458
   ;by Mihasik
458
   ;by Mihasik
Line 459... Line 459...
459
   ;IN: eax - pointer to filename OUT: filestring+11 in edi or notZero in flags and fnf in eax,ebx
459
   ;IN: eax - pointer to filename OUT: filestring+11 in edi or notZero in flags and fnf in eax,ebx
460
 
460
 
461
        mov    edi,0x100000+512*18+512  ;Point at directory
461
        mov    edi,RAMDISK+512*18+512  ;Point at directory
462
        cld
462
        cld
463
    rd_newsearch:
463
    rd_newsearch:
464
        mov    esi,eax
464
        mov    esi,eax
465
        mov    ecx,11
465
        mov    ecx,11
466
        rep    cmpsb
466
        rep    cmpsb
467
        je     rd_ff
467
        je     rd_ff
468
        add    cl,21
468
        add    cl,21
469
        add    edi,ecx
469
        add    edi,ecx
470
        cmp    edi,0x100000+512*33
470
        cmp    edi,RAMDISK+512*33
471
        jb     rd_newsearch
471
        jb     rd_newsearch
472
        mov    eax,5      ;if file not found - eax=5
472
        mov    eax,5      ;if file not found - eax=5
473
        xor    ebx,ebx
473
        xor    ebx,ebx
Line 597... Line 597...
597
        ret
597
        ret
598
@@:
598
@@:
599
        cmp     byte [edi+11], 0xF
599
        cmp     byte [edi+11], 0xF
600
        jz      .longname
600
        jz      .longname
601
        push    ecx
601
        push    ecx
602
        mov     ecx, 8
-
 
603
        push    edi ebp ecx
602
        push    edi ebp
604
        test    byte [ebp-4], 1
603
        test    byte [ebp-4], 1
605
        jnz     .unicode_short
604
        jnz     .unicode_short
-
 
605
 
-
 
606
        mov     eax, [edi]
-
 
607
        mov     ecx, [edi+4]
-
 
608
        mov     [ebp], eax
-
 
609
        mov     [ebp+4], ecx
-
 
610
 
-
 
611
        mov     ecx, 8
606
@@:
612
@@:
607
        mov     al, [edi]
-
 
608
        inc     edi
-
 
609
        mov     [ebp], al
613
        cmp     byte [ebp+ecx-1], ' '
610
        inc     ebp
-
 
611
        loop    @b
614
        loope    @b
-
 
615
 
612
        pop     ecx
616
        mov     eax, [edi+8]
613
@@:
-
 
614
        cmp     byte [ebp-1], ' '
617
        cmp     al, ' '
615
        jnz     @f
618
        je      .done
616
        dec     ebp
619
        shl     eax, 8
617
        loop    @b
620
        mov     al, '.'
618
@@:
621
 
619
        mov     byte [ebp], '.'
622
        lea ebp, [ebp+ecx+1]
620
        inc     ebp
623
        mov     [ebp], eax
621
        mov     ecx, 3
624
        mov     ecx, 3
622
        push    ecx
-
 
623
@@:
-
 
624
        mov     al, [edi]
-
 
625
        inc     edi
-
 
626
        mov     [ebp], al
-
 
627
        inc     ebp
-
 
628
        loop    @b
-
 
629
        pop     ecx
-
 
630
@@:
625
@@:
631
        cmp     byte [ebp-1], ' '
626
        rol eax, 8
632
        jnz     @f
627
        cmp al, ' '
633
        dec     ebp
628
        jne .done
634
        loop    @b
629
        loop   @b
635
        dec     ebp
630
        dec ebp
636
@@:
631
.done:
637
        and     byte [ebp], 0	; CF=0
632
        and     byte [ebp+ecx+1], 0   ; CF=0
638
        pop     ebp edi ecx
633
        pop     ebp edi ecx
639
        ret
634
        ret
640
.unicode_short:
635
.unicode_short:
-
 
636
        mov     ecx, 8
-
 
637
        push    ecx
641
@@:
638
@@:
642
        mov     al, [edi]
639
        mov     al, [edi]
643
        inc     edi
640
        inc     edi
644
        call    ansi2uni_char
641
        call    ansi2uni_char
645
        mov     [ebp], ax
642
        mov     [ebp], ax
Line 903... Line 900...
903
        call    bdfe_to_fat_date
900
        call    bdfe_to_fat_date
904
        mov     [edi+24], ax            ; last write date
901
        mov     [edi+24], ax            ; last write date
905
        ret
902
        ret
Line 906... Line 903...
906
 
903
 
907
ramdisk_root_first:
904
ramdisk_root_first:
908
        mov     edi, 0x100000+512*19
905
        mov     edi, RAMDISK+512*19
909
        clc
906
        clc
910
        ret
907
        ret
911
ramdisk_root_next:
908
ramdisk_root_next:
912
        add     edi, 0x20
909
        add     edi, 0x20
913
        cmp     edi, 0x100000+512*33
910
        cmp     edi, RAMDISK+512*33
914
        cmc
911
        cmc
Line 915... Line 912...
915
        ret
912
        ret
916
 
913
 
917
ramdisk_root_extend_dir:
914
ramdisk_root_extend_dir:
Line -... Line 915...
-
 
915
        stc
-
 
916
        ret
-
 
917
 
-
 
918
uglobal
-
 
919
; this is for delete support
-
 
920
rd_prev_sector          dd      ?
918
        stc
921
rd_prev_prev_sector     dd      ?
919
        ret
922
endg
920
 
923
 
921
ramdisk_notroot_next:
924
ramdisk_notroot_next:
922
        add     edi, 0x20
925
        add     edi, 0x20
923
        test    edi, 0x1FF
926
        test    edi, 0x1FF
924
        jz      ramdisk_notroot_next_sector
927
        jz      ramdisk_notroot_next_sector
925
        ret     ; CF=0
928
        ret     ; CF=0
-
 
929
ramdisk_notroot_next_sector:
-
 
930
        push    ecx
-
 
931
        mov     ecx, [eax]
926
ramdisk_notroot_next_sector:
932
        push    [rd_prev_sector]
927
        push    ecx
933
        pop     [rd_prev_prev_sector]
928
        mov     ecx, [eax]
934
        mov     [rd_prev_sector], ecx
929
        mov     ecx, [ecx*2+0x280000]
935
        mov     ecx, [ecx*2+RAMDISK_FAT]
930
        and     ecx, 0xFFF
936
        and     ecx, 0xFFF
931
        cmp     ecx, 2849
937
        cmp     ecx, 2849
Line 937... Line 943...
937
        cmp     eax, 2
943
        cmp     eax, 2
938
        jb      .err
944
        jb      .err
939
        cmp     eax, 2849
945
        cmp     eax, 2849
940
        jae     .err
946
        jae     .err
941
        shl     eax, 9
947
        shl     eax, 9
942
        lea     edi, [eax+(31 shl 9)+0x100000]
948
        lea     edi, [eax+(31 shl 9)+RAMDISK]
943
        clc
949
        clc
944
        ret
950
        ret
945
.err2:
951
.err2:
946
        pop     ecx
952
        pop     ecx
947
.err:
953
.err:
Line 954... Line 960...
954
        ret
960
        ret
Line 955... Line 961...
955
 
961
 
956
ramdisk_notroot_extend_dir:
962
ramdisk_notroot_extend_dir:
957
        pusha
963
        pusha
958
        xor     eax, eax
964
        xor     eax, eax
959
        mov     edi, 0x280000
965
        mov     edi, RAMDISK_FAT
960
        mov     ecx, 2849
966
        mov     ecx, 2849
961
        repnz   scasw
967
        repnz   scasw
962
        jnz     .notfound
968
        jnz     .notfound
963
        mov     word [edi-2], 0xFFF
969
        mov     word [edi-2], 0xFFF
964
        sub     edi, 0x280000
970
        sub     edi, RAMDISK_FAT
965
        shr     edi, 1
971
        shr     edi, 1
966
        dec     edi
972
        dec     edi
967
        mov     eax, [esp+28]
973
        mov     eax, [esp+28]
968
        mov     ecx, [eax]
974
        mov     ecx, [eax]
969
        mov     [0x280000+ecx*2], di
975
        mov     [RAMDISK_FAT+ecx*2], di
970
        mov     [eax], edi
976
        mov     [eax], edi
971
        shl     edi, 9
977
        shl     edi, 9
972
        add     edi, (31 shl 9)+0x100000
978
        add     edi, (31 shl 9)+RAMDISK
973
        mov     [esp], edi
979
        mov     [esp], edi
974
        xor     eax, eax
980
        xor     eax, eax
975
        mov     ecx, 128
981
        mov     ecx, 128
976
        rep     stosd
982
        rep     stosd
Line 1071... Line 1077...
1071
        jz      .eof
1077
        jz      .eof
1072
        cmp     edi, 0xFF8
1078
        cmp     edi, 0xFF8
1073
        jae     .eof
1079
        jae     .eof
1074
        lea     eax, [edi+31]           ; bootsector+2*fat+filenames
1080
        lea     eax, [edi+31]           ; bootsector+2*fat+filenames
1075
        shl     eax, 9                  ; *512
1081
        shl     eax, 9                  ; *512
1076
        add     eax, 0x100000           ; image base
1082
        add     eax, RAMDISK           ; image base
1077
; now eax points to data of cluster
1083
; now eax points to data of cluster
1078
        sub     ebx, 512
1084
        sub     ebx, 512
1079
        jae     .skip
1085
        jae     .skip
1080
        lea     eax, [eax+ebx+512]
1086
        lea     eax, [eax+ebx+512]
1081
        neg     ebx
1087
        neg     ebx
Line 1089... Line 1095...
1089
        add     edx, ecx
1095
        add     edx, ecx
1090
        sub     [esp], ecx
1096
        sub     [esp], ecx
1091
        pop     ecx
1097
        pop     ecx
1092
        xor     ebx, ebx
1098
        xor     ebx, ebx
1093
.skip:
1099
.skip:
1094
        movzx   edi, word [edi*2+0x280000]      ; find next cluster from FAT
1100
        movzx   edi, word [edi*2+RAMDISK_FAT]      ; find next cluster from FAT
1095
        jmp     .new
1101
        jmp     .new
1096
.eof:
1102
.eof:
1097
        mov     ebx, edx
1103
        mov     ebx, edx
1098
        pop     eax edx ecx
1104
        pop     eax edx ecx
1099
        sub     ebx, edx
1105
        sub     ebx, edx
Line 1160... Line 1166...
1160
        pop     ecx eax
1166
        pop     ecx eax
1161
        mov     esi, edi        ; esi points to block of data of folder entry (BDFE)
1167
        mov     esi, edi        ; esi points to block of data of folder entry (BDFE)
1162
.main_loop:
1168
.main_loop:
1163
        mov     edi, eax
1169
        mov     edi, eax
1164
        shl     edi, 9
1170
        shl     edi, 9
1165
        add     edi, 0x100000
1171
        add     edi, RAMDISK
1166
        push    eax
1172
        push    eax
1167
.l1:
1173
.l1:
1168
        call    fat_get_name
1174
        call    fat_get_name
1169
        jc      .l2
1175
        jc      .l2
1170
        cmp     byte [edi+11], 0xF
1176
        cmp     byte [edi+11], 0xF
Line 1176... Line 1182...
1176
        inc     eax
1182
        inc     eax
1177
        dec     byte [esp+262*2+16]
1183
        dec     byte [esp+262*2+16]
1178
        jz      .done
1184
        jz      .done
1179
        jns     @f
1185
        jns     @f
1180
; read next sector from FAT
1186
; read next sector from FAT
1181
        mov     eax, [(eax-31-1)*2+0x280000]
1187
        mov     eax, [(eax-31-1)*2+RAMDISK_FAT]
1182
        and     eax, 0xFFF
1188
        and     eax, 0xFFF
1183
        cmp     eax, 0xFF8
1189
        cmp     eax, 0xFF8
1184
        jae     .done
1190
        jae     .done
1185
        add     eax, 31
1191
        add     eax, 31
1186
        mov     byte [esp+262*2+16], 0
1192
        mov     byte [esp+262*2+16], 0
1187
@@:
1193
@@:
1188
        mov     edi, eax
1194
        mov     edi, eax
1189
        shl     edi, 9
1195
        shl     edi, 9
1190
        add     edi, 0x100000
1196
        add     edi, RAMDISK
1191
        push    eax
1197
        push    eax
1192
.do_bdfe:
1198
.do_bdfe:
1193
        inc     dword [edx+8]   ; new file found
1199
        inc     dword [edx+8]   ; new file found
1194
        dec     ebx
1200
        dec     ebx
1195
        jns     .l2
1201
        jns     .l2
Line 1205... Line 1211...
1205
        inc     eax
1211
        inc     eax
1206
        dec     byte [esp+262*2+16]
1212
        dec     byte [esp+262*2+16]
1207
        jz      .done
1213
        jz      .done
1208
        jns     @f
1214
        jns     @f
1209
; read next sector from FAT
1215
; read next sector from FAT
1210
        mov     eax, [(eax-31-1)*2+0x280000]
1216
        mov     eax, [(eax-31-1)*2+RAMDISK_FAT]
1211
        and     eax, 0xFFF
1217
        and     eax, 0xFFF
1212
        cmp     eax, 0xFF8
1218
        cmp     eax, 0xFF8
1213
        jae     .done
1219
        jae     .done
1214
        add     eax, 31
1220
        add     eax, 31
1215
        mov     byte [esp+262*2+16], 0
1221
        mov     byte [esp+262*2+16], 0
Line 1458... Line 1464...
1458
        popad
1464
        popad
1459
        ret
1465
        ret
Line 1460... Line 1466...
1460
 
1466
 
1461
;----------------------------------------------------------------
1467
;----------------------------------------------------------------
1462
;
1468
;
-
 
1469
;  fs_RamdiskRewrite - LFN variant for writing ramdisk
1463
;  fs_RamdiskRewrite - LFN variant for writing sys floppy
1470
;  fs_RamdiskCreateFolder - create folder on ramdisk
1464
;
1471
;
1465
;  esi  points to filename
1472
;  esi  points to file/folder name
1466
;  ebx  ignored (reserved)
1473
;  ebx  ignored (reserved)
1467
;  ecx  number of bytes to write, 0+
1474
;  ecx  number of bytes to write, 0+ (ignored for folders)
1468
;  edx  mem location to data
1475
;  edx  mem location to data (ignored for folders)
1469
;
1476
;
1470
;  ret ebx = number of written bytes
1477
;  ret ebx = number of written bytes
1471
;      eax = 0 ok read or other = errormsg
1478
;      eax = 0 ok read or other = errormsg
1472
;
1479
;
1473
;--------------------------------------------------------------
1480
;--------------------------------------------------------------
1474
@@:
1481
@@:
1475
        mov     eax, ERROR_ACCESS_DENIED
1482
        mov     eax, ERROR_ACCESS_DENIED
1476
        xor     ebx, ebx
1483
        xor     ebx, ebx
Line -... Line 1484...
-
 
1484
        ret
-
 
1485
 
-
 
1486
fs_RamdiskCreateFolder:
-
 
1487
        mov     al, 1           ; create folder
1477
        ret
1488
        jmp     fs_RamdiskRewrite.common
-
 
1489
 
-
 
1490
fs_RamdiskRewrite:
1478
 
1491
        xor     eax, eax        ; create file
1479
fs_RamdiskRewrite:
1492
.common:
1480
        cmp     byte [esi], 0
1493
        cmp     byte [esi], 0
1481
        jz      @b
1494
        jz      @b
1482
        pushad
1495
        pushad
Line 1499... Line 1512...
1499
        push    ebp
1512
        push    ebp
1500
        push    ramdisk_root_first
1513
        push    ramdisk_root_first
1501
        push    ramdisk_root_next
1514
        push    ramdisk_root_next
1502
        jmp     .common1
1515
        jmp     .common1
1503
.noroot:
1516
.noroot:
-
 
1517
        mov     eax, ERROR_ACCESS_DENIED
-
 
1518
        cmp     byte [ebp+1], 0
-
 
1519
        jz      .ret1
1504
; check existence
1520
; check existence
1505
        mov     byte [ebp], 0
1521
        mov     byte [ebp], 0
1506
        call    rd_find_lfn
1522
        call    rd_find_lfn
1507
        mov     byte [ebp], '/'
1523
        mov     byte [ebp], '/'
1508
        lea     esi, [ebp+1]
1524
        lea     esi, [ebp+1]
Line 1529... Line 1545...
1529
        push    ramdisk_notroot_first
1545
        push    ramdisk_notroot_first
1530
        push    ramdisk_notroot_next
1546
        push    ramdisk_notroot_next
1531
.common1:
1547
.common1:
1532
        call    fat_find_lfn
1548
        call    fat_find_lfn
1533
        jc      .notfound
1549
        jc      .notfound
1534
; found; must not be directory
1550
; found
1535
        test    byte [edi+11], 10h
1551
        test    byte [edi+11], 10h
-
 
1552
        jz      .exists_file
-
 
1553
; found directory; if we are creating directory, return OK,
-
 
1554
;                  if we are creating file, say "access denied"
-
 
1555
        add     esp, 20
-
 
1556
        popad
-
 
1557
        test    al, al
-
 
1558
        mov     eax, ERROR_ACCESS_DENIED
-
 
1559
        jz      @f
-
 
1560
        mov     al, 0
-
 
1561
@@:
-
 
1562
        xor     ebx, ebx
-
 
1563
        ret
-
 
1564
.exists_file:
-
 
1565
; found file; if we are creating directory, return "access denied",
-
 
1566
;             if we are creating file, delete existing file and continue
-
 
1567
        cmp     byte [esp+20+28], 0
1536
        jz      @f
1568
        jz      @f
1537
        add     esp, 20
1569
        add     esp, 20
1538
        popad
1570
        popad
1539
        mov     eax, ERROR_ACCESS_DENIED
1571
        mov     eax, ERROR_ACCESS_DENIED
1540
        xor     ebx, ebx
1572
        xor     ebx, ebx
Line 1548... Line 1580...
1548
        test    eax, eax
1580
        test    eax, eax
1549
        jz      .done1
1581
        jz      .done1
1550
@@:
1582
@@:
1551
        cmp     eax, 0xFF8
1583
        cmp     eax, 0xFF8
1552
        jae     .done1
1584
        jae     .done1
1553
        lea     edi, [0x280000 + eax*2] ; position in FAT
1585
        lea     edi, [RAMDISK_FAT + eax*2] ; position in FAT
1554
        xor     eax, eax
1586
        xor     eax, eax
1555
        xchg    ax, [edi]
1587
        xchg    ax, [edi]
1556
        jmp     @b
1588
        jmp     @b
1557
.done1:
1589
.done1:
1558
        pop     edi
1590
        pop     edi
Line 1740... Line 1772...
1740
        mov     [edi+24], ax            ; last write date
1772
        mov     [edi+24], ax            ; last write date
1741
        mov     [edi+18], ax            ; last access date
1773
        mov     [edi+18], ax            ; last access date
1742
        and     word [edi+20], 0        ; high word of cluster
1774
        and     word [edi+20], 0        ; high word of cluster
1743
        and     word [edi+26], 0        ; low word of cluster - to be filled
1775
        and     word [edi+26], 0        ; low word of cluster - to be filled
1744
        and     dword [edi+28], 0       ; file size - to be filled
1776
        and     dword [edi+28], 0       ; file size - to be filled
-
 
1777
        cmp     byte [esp+20+28], 0
-
 
1778
        jz      .doit
-
 
1779
; create directory
-
 
1780
        mov     byte [edi+11], 10h         ; attributes: folder
-
 
1781
        mov     ecx, 32*2
-
 
1782
        mov     edx, edi
1745
.doit:
1783
.doit:
1746
        push    edx
1784
        push    edx
1747
        push    ecx
1785
        push    ecx
1748
        push    edi
1786
        push    edi
1749
        add     edi, 26         ; edi points to low word of cluster
1787
        add     edi, 26         ; edi points to low word of cluster
1750
        push    edi
1788
        push    edi
1751
        jecxz   .done
1789
        jecxz   .done
1752
        mov     ecx, 2849
1790
        mov     ecx, 2849
1753
        mov     edi, 0x280000
1791
        mov     edi, RAMDISK_FAT
1754
.write_loop:
1792
.write_loop:
1755
; allocate new cluster
1793
; allocate new cluster
1756
        xor     eax, eax
1794
        xor     eax, eax
1757
        repnz   scasw
1795
        repnz   scasw
1758
        jnz     .disk_full2
1796
        jnz     .disk_full2
1759
        dec     edi
1797
        dec     edi
1760
        dec     edi
1798
        dec     edi
1761
        lea     eax, [edi-0x280000]
1799
        lea     eax, [edi-(RAMDISK_FAT)]
1762
        shr     eax, 1                  ; eax = cluster
1800
        shr     eax, 1                  ; eax = cluster
1763
        mov     word [edi], 0xFFF       ; mark as last cluster
1801
        mov     word [edi], 0xFFF       ; mark as last cluster
1764
        xchg    edi, [esp]
1802
        xchg    edi, [esp]
1765
        stosw
1803
        stosw
1766
        pop     edi
1804
        pop     edi
1767
        push    edi
1805
        push    edi
1768
        inc     ecx
1806
        inc     ecx
1769
; write data
1807
; write data
-
 
1808
        cmp     byte [esp+16+20+28], 0
-
 
1809
        jnz     .writedir
1770
        shl     eax, 9
1810
        shl     eax, 9
1771
        add     eax, 0x100000+31*512
1811
        add     eax, RAMDISK+31*512
-
 
1812
.writefile:
1772
        mov     ebx, edx
1813
        mov     ebx, edx
1773
        xchg    eax, ebx
1814
        xchg    eax, ebx
1774
        push    ecx
1815
        push    ecx
1775
        mov     ecx, 512
1816
        mov     ecx, 512
1776
        cmp     dword [esp+12], ecx
1817
        cmp     dword [esp+12], ecx
Line 1801... Line 1842...
1801
        mov     [esp+16], ebx
1842
        mov     [esp+16], ebx
1802
        popad
1843
        popad
1803
        push    ERROR_DISK_FULL
1844
        push    ERROR_DISK_FULL
1804
        pop     eax
1845
        pop     eax
1805
        ret
1846
        ret
-
 
1847
.writedir:
-
 
1848
        mov     edi, eax
-
 
1849
        shl     edi, 9
-
 
1850
        add     edi, RAMDISK+31*512
-
 
1851
        mov     esi, edx
-
 
1852
        mov     ecx, 32/4
-
 
1853
        push    ecx
-
 
1854
        rep     movsd
-
 
1855
        mov     dword [edi-32], '.   '
-
 
1856
        mov     dword [edi-32+4], '    '
-
 
1857
        mov     dword [edi-32+8], '    '
-
 
1858
        mov     byte [edi-32+11], 10h
-
 
1859
        mov     word [edi-32+26], ax
-
 
1860
        mov     esi, edx
-
 
1861
        pop     ecx
-
 
1862
        rep     movsd
-
 
1863
        mov     dword [edi-32], '..  '
-
 
1864
        mov     dword [edi-32+4], '    '
-
 
1865
        mov     dword [edi-32+8], '    '
-
 
1866
        mov     byte [edi-32+11], 10h
-
 
1867
        mov     eax, [esp+16+8]
-
 
1868
        mov     word [edi-32+26], ax
-
 
1869
        pop     edi edi ecx edx
-
 
1870
        add     esp, 20
-
 
1871
        popad
-
 
1872
        xor     eax, eax
-
 
1873
        xor     ebx, ebx
-
 
1874
        ret
Line 1806... Line 1875...
1806
 
1875
 
1807
.read_symbol:
1876
.read_symbol:
1808
        or      ax, -1
1877
        or      ax, -1
1809
        test    esi, esi
1878
        test    esi, esi
Line 1922... Line 1991...
1922
        jbe     @f
1991
        jbe     @f
1923
        mov     ecx, ebx
1992
        mov     ecx, ebx
1924
@@:
1993
@@:
1925
        mov     eax, edi
1994
        mov     eax, edi
1926
        shl     eax, 9
1995
        shl     eax, 9
1927
        add     eax, 0x100000+31*512+0x200
1996
        add     eax, RAMDISK+31*512+0x200
1928
        sub     eax, ebx
1997
        sub     eax, ebx
1929
        mov     ebx, eax
1998
        mov     ebx, eax
1930
        mov     eax, edx
1999
        mov     eax, edx
1931
        call    memmove
2000
        call    memmove
1932
        xor     ebx, ebx
2001
        xor     ebx, ebx
1933
        add     edx, ecx
2002
        add     edx, ecx
1934
        sub     [esp], ecx
2003
        sub     [esp], ecx
1935
        pop     ecx
2004
        pop     ecx
1936
        jz      .ret
2005
        jz      .ret
1937
.next_cluster:
2006
.next_cluster:
1938
        movzx   edi, word [edi*2+0x280000]
2007
        movzx   edi, word [edi*2+RAMDISK_FAT]
1939
        jmp     .write_loop
2008
        jmp     .write_loop
Line 1940... Line 2009...
1940
 
2009
 
1941
ramdisk_extend_file.zero_size:
2010
ramdisk_extend_file.zero_size:
1942
        xor     eax, eax
2011
        xor     eax, eax
Line 1953... Line 2022...
1953
        mov     ecx, [edi+28]
2022
        mov     ecx, [edi+28]
1954
        jecxz   .zero_size
2023
        jecxz   .zero_size
1955
@@:
2024
@@:
1956
        sub     ecx, 0x200
2025
        sub     ecx, 0x200
1957
        jbe     @f
2026
        jbe     @f
1958
        mov     eax, [eax*2+0x280000]
2027
        mov     eax, [eax*2+RAMDISK_FAT]
1959
        and     eax, 0xFFF
2028
        and     eax, 0xFFF
1960
        jz      .fat_err
2029
        jz      .fat_err
1961
        cmp     eax, 0xFF8
2030
        cmp     eax, 0xFF8
1962
        jb      @b
2031
        jb      @b
1963
.fat_err:
2032
.fat_err:
Line 1966... Line 2035...
1966
        pop     eax
2035
        pop     eax
1967
        stc
2036
        stc
1968
        ret
2037
        ret
1969
@@:
2038
@@:
1970
        push    eax
2039
        push    eax
1971
        mov     eax, [eax*2+0x280000]
2040
        mov     eax, [eax*2+RAMDISK_FAT]
1972
        and     eax, 0xFFF
2041
        and     eax, 0xFFF
1973
        cmp     eax, 0xFF8
2042
        cmp     eax, 0xFF8
1974
        pop     eax
2043
        pop     eax
1975
        jb      .fat_err
2044
        jb      .fat_err
1976
; set length to full number of sectors and make sure that last sector is zero-padded
2045
; set length to full number of sectors and make sure that last sector is zero-padded
1977
        sub     [edi+28], ecx
2046
        sub     [edi+28], ecx
1978
        push    eax edi
2047
        push    eax edi
1979
        mov     edi, eax
2048
        mov     edi, eax
1980
        shl     edi, 9
2049
        shl     edi, 9
1981
        lea     edi, [edi+0x100000+31*512+0x200+ecx]
2050
        lea     edi, [edi+RAMDISK+31*512+0x200+ecx]
1982
        neg     ecx
2051
        neg     ecx
1983
        xor     eax, eax
2052
        xor     eax, eax
1984
        rep     stosb
2053
        rep     stosb
1985
        pop     edi eax
2054
        pop     edi eax
1986
.start_extend:
2055
.start_extend:
1987
        pop     ecx
2056
        pop     ecx
1988
; now do extend
2057
; now do extend
1989
        push    edx esi
2058
        push    edx esi
1990
        mov     esi, 0x280000+2*2       ; start scan from cluster 2
2059
        mov     esi, RAMDISK_FAT+2*2       ; start scan from cluster 2
1991
        mov     edx, 2847               ; number of clusters to scan
2060
        mov     edx, 2847               ; number of clusters to scan
1992
.extend_loop:
2061
.extend_loop:
1993
        cmp     [edi+28], ecx
2062
        cmp     [edi+28], ecx
1994
        jae     .extend_done
2063
        jae     .extend_done
1995
; add new sector
2064
; add new sector
Line 2004... Line 2073...
2004
        pop     eax
2073
        pop     eax
2005
        jnz     .disk_full
2074
        jnz     .disk_full
2006
        mov     word [edi-2], 0xFFF
2075
        mov     word [edi-2], 0xFFF
2007
        mov     esi, edi
2076
        mov     esi, edi
2008
        mov     edx, ecx
2077
        mov     edx, ecx
2009
        sub     edi, 0x280000
2078
        sub     edi, RAMDISK_FAT
2010
        shr     edi, 1
2079
        shr     edi, 1
2011
        dec     edi     ; now edi=new cluster
2080
        dec     edi     ; now edi=new cluster
2012
        test    eax, eax
2081
        test    eax, eax
2013
        jz      .first_cluster
2082
        jz      .first_cluster
2014
        mov     [0x280000+eax*2], di
2083
        mov     [RAMDISK_FAT+eax*2], di
2015
        jmp     @f
2084
        jmp     @f
2016
.first_cluster:
2085
.first_cluster:
2017
        pop     eax     ; eax->direntry
2086
        pop     eax     ; eax->direntry
2018
        push    eax
2087
        push    eax
2019
        mov     [eax+26], di
2088
        mov     [eax+26], di
2020
@@:
2089
@@:
2021
        push    edi
2090
        push    edi
2022
        shl     edi, 9
2091
        shl     edi, 9
2023
        add     edi, 0x100000+31*512
2092
        add     edi, RAMDISK+31*512
2024
        xor     eax, eax
2093
        xor     eax, eax
2025
        mov     ecx, 512/4
2094
        mov     ecx, 512/4
2026
        rep     stosd
2095
        rep     stosd
2027
        pop     eax     ; eax=new cluster
2096
        pop     eax     ; eax=new cluster
2028
        pop     edi     ; edi->direntry
2097
        pop     edi     ; edi->direntry
Line 2115... Line 2184...
2115
        jz      .zero_size
2184
        jz      .zero_size
2116
; find new last sector
2185
; find new last sector
2117
@@:
2186
@@:
2118
        sub     eax, 0x200
2187
        sub     eax, 0x200
2119
        jbe     @f
2188
        jbe     @f
2120
        movzx   ecx, word [0x280000+ecx*2]
2189
        movzx   ecx, word [RAMDISK_FAT+ecx*2]
2121
        jmp     @b
2190
        jmp     @b
2122
@@:
2191
@@:
2123
; zero data at the end of last sector
2192
; zero data at the end of last sector
2124
        push    ecx
2193
        push    ecx
2125
        mov     edi, ecx
2194
        mov     edi, ecx
2126
        shl     edi, 9
2195
        shl     edi, 9
2127
        lea     edi, [edi+0x100000+31*512+eax+0x200]
2196
        lea     edi, [edi+RAMDISK+31*512+eax+0x200]
2128
        mov     ecx, eax
2197
        mov     ecx, eax
2129
        neg     ecx
2198
        neg     ecx
2130
        xor     eax, eax
2199
        xor     eax, eax
2131
        rep     stosb
2200
        rep     stosb
2132
        pop     ecx
2201
        pop     ecx
2133
; terminate FAT chain
2202
; terminate FAT chain
2134
        lea     ecx, [0x280000+ecx+ecx]
2203
        lea     ecx, [RAMDISK_FAT+ecx+ecx]
2135
        push    dword [ecx]
2204
        push    dword [ecx]
2136
        mov     word [ecx], 0xFFF
2205
        mov     word [ecx], 0xFFF
2137
        pop     ecx
2206
        pop     ecx
2138
        and     ecx, 0xFFF
2207
        and     ecx, 0xFFF
2139
        jmp     .delete
2208
        jmp     .delete
Line 2142... Line 2211...
2142
.delete:
2211
.delete:
2143
; delete FAT chain starting with ecx
2212
; delete FAT chain starting with ecx
2144
; mark all clusters as free
2213
; mark all clusters as free
2145
        cmp     ecx, 0xFF8
2214
        cmp     ecx, 0xFF8
2146
        jae     .deleted
2215
        jae     .deleted
2147
        lea     ecx, [0x280000+ecx+ecx]
2216
        lea     ecx, [RAMDISK_FAT+ecx+ecx]
2148
        push    dword [ecx]
2217
        push    dword [ecx]
2149
        and     word [ecx], 0
2218
        and     word [ecx], 0
2150
        pop     ecx
2219
        pop     ecx
2151
        and     ecx, 0xFFF
2220
        and     ecx, 0xFFF
2152
        jmp     .delete
2221
        jmp     .delete
Line 2263... Line 2332...
2263
        cmp     dword [eax], 0  ; file size
2332
        cmp     dword [eax], 0  ; file size
2264
        jz      .eof
2333
        jz      .eof
2265
        mov     edx, [eax+4]    ; cluster
2334
        mov     edx, [eax+4]    ; cluster
2266
        lea     esi, [edx+31]
2335
        lea     esi, [edx+31]
2267
        shl     esi, 9
2336
        shl     esi, 9
2268
        add     esi, 0x100000
2337
        add     esi, RAMDISK
2269
        mov     ecx, 512/4
2338
        mov     ecx, 512/4
2270
        rep     movsd
2339
        rep     movsd
2271
        mov     ecx, [eax]
2340
        mov     ecx, [eax]
2272
        sub     ecx, 512
2341
        sub     ecx, 512
2273
        jae     @f
2342
        jae     @f
Line 2277... Line 2346...
2277
        xor     eax, eax
2346
        xor     eax, eax
2278
        rep     stosb
2347
        rep     stosb
2279
        pop     eax
2348
        pop     eax
2280
@@:
2349
@@:
2281
        mov     [eax], ecx
2350
        mov     [eax], ecx
2282
        mov     dx, [edx*2+0x280000]
2351
        mov     dx, [edx*2+RAMDISK_FAT]
2283
        mov     [eax+4], dx     ; high word is already zero
2352
        mov     [eax+4], dx     ; high word is already zero
2284
        popad
2353
        popad
2285
        xor     eax, eax
2354
        xor     eax, eax
2286
        ret
2355
        ret
2287
.eof:
2356
.eof:
2288
        popad
2357
        popad
2289
        mov     eax, 6
2358
        mov     eax, 6
2290
        ret
2359
        ret
Line -... Line 2360...
-
 
2360
 
-
 
2361
;----------------------------------------------------------------
-
 
2362
;
-
 
2363
;  fs_RamdiskDelete - delete file or empty folder from ramdisk
-
 
2364
;
-
 
2365
;  esi  points to filename
-
 
2366
;
-
 
2367
;  ret  eax = 0 ok or other = errormsg
-
 
2368
;
-
 
2369
;--------------------------------------------------------------
-
 
2370
fs_RamdiskDelete:
-
 
2371
        cmp     byte [esi], 0
-
 
2372
        jnz     @f
-
 
2373
; cannot delete root!
-
 
2374
.access_denied:
-
 
2375
        push    ERROR_ACCESS_DENIED
-
 
2376
.pop_ret:
-
 
2377
        pop     eax
-
 
2378
        ret
-
 
2379
@@:
-
 
2380
        and     [rd_prev_sector], 0
-
 
2381
        and     [rd_prev_prev_sector], 0
-
 
2382
        push    edi
-
 
2383
        call    rd_find_lfn
-
 
2384
        jnc     .found
-
 
2385
        pop     edi
-
 
2386
        push    ERROR_FILE_NOT_FOUND
-
 
2387
        jmp     .pop_ret
-
 
2388
.found:
-
 
2389
        cmp     dword [edi], '.   '
-
 
2390
        jz      .access_denied2
-
 
2391
        cmp     dword [edi], '..  '
-
 
2392
        jz      .access_denied2
-
 
2393
        test    byte [edi+11], 10h
-
 
2394
        jz      .dodel
-
 
2395
; we can delete only empty folders!
-
 
2396
        movzx   eax, word [edi+26]
-
 
2397
        push    ebx
-
 
2398
        mov     ebx, eax
-
 
2399
        shl     ebx, 9
-
 
2400
        add     ebx, RAMDISK + 31*0x200 + 2*0x20
-
 
2401
.checkempty:
-
 
2402
        cmp     byte [ebx], 0
-
 
2403
        jz      .empty
-
 
2404
        cmp     byte [ebx], 0xE5
-
 
2405
        jnz     .notempty
-
 
2406
        add     ebx, 0x20
-
 
2407
        test    ebx, 0x1FF
-
 
2408
        jnz     .checkempty
-
 
2409
        movzx   eax, word [RAMDISK_FAT + eax*2]
-
 
2410
        test    eax, eax
-
 
2411
        jz      .empty
-
 
2412
        mov     ebx, eax
-
 
2413
        shl     ebx, 9
-
 
2414
        add     ebx, RAMDISK + 31*0x200
-
 
2415
        jmp     .checkempty
-
 
2416
.notempty:
-
 
2417
        pop     ebx
-
 
2418
.access_denied2:
-
 
2419
        pop     edi
-
 
2420
        jmp     .access_denied
-
 
2421
.empty:
-
 
2422
        pop     ebx
-
 
2423
.dodel:
-
 
2424
        movzx   eax, word [edi+26]
-
 
2425
; delete folder entry
-
 
2426
        mov     byte [edi], 0xE5
-
 
2427
; delete LFN (if present)
-
 
2428
.lfndel:
-
 
2429
        test    edi, 0x1FF
-
 
2430
        jnz     @f
-
 
2431
        cmp     [rd_prev_sector], 0
-
 
2432
        jz      @f
-
 
2433
        cmp     [rd_prev_sector], -1
-
 
2434
        jz      .lfndone
-
 
2435
        mov     edi, [rd_prev_sector]
-
 
2436
        push    [rd_prev_prev_sector]
-
 
2437
        pop     [rd_prev_sector]
-
 
2438
        or      [rd_prev_prev_sector], -1
-
 
2439
        shl     edi, 9
-
 
2440
        add     edi, RAMDISK + 31*0x200 + 0x200
-
 
2441
@@:
-
 
2442
        sub     edi, 0x20
-
 
2443
        cmp     byte [edi], 0xE5
-
 
2444
        jz      .lfndone
-
 
2445
        cmp     byte [edi+11], 0xF
-
 
2446
        jnz     .lfndone
-
 
2447
        mov     byte [edi], 0xE5
-
 
2448
        jmp     .lfndel
-
 
2449
.lfndone:
-
 
2450
; delete FAT chain
-
 
2451
        test    eax, eax
-
 
2452
        jz      .done
-
 
2453
        lea     eax, [RAMDISK_FAT + eax*2]
-
 
2454
        push    dword [eax]
-
 
2455
        and     word [eax], 0
-
 
2456
        pop     eax
-
 
2457
        and     eax, 0xFFF
-
 
2458
        jmp     .lfndone
-
 
2459
.done:
-
 
2460
        pop     edi
-
 
2461
        xor     eax, eax
-
 
2462
        ret
2291
 
2463