Subversion Repositories Kolibri OS

Rev

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

Rev 3935 Rev 4066
Line 6... Line 6...
6
;; Distributed under the terms of the new BSD license.          ;;
6
;; Distributed under the terms of the new BSD license.          ;;
7
;;                                                              ;;
7
;;                                                              ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 9... Line 9...
9
 
9
 
10
include 'ext2.inc'
10
include 'ext2.inc'
11
include 'blocks.asm'
11
include 'blocks.inc'
12
include 'inode.asm'
12
include 'inode.inc'
Line 13... Line 13...
13
include 'resource.asm'
13
include 'resource.inc'
14
 
14
 
15
iglobal
15
iglobal
16
align 4
16
align 4
Line 195... Line 195...
195
        call    ext2_inode_read
195
        call    ext2_inode_read
Line 196... Line 196...
196
 
196
 
197
        test    eax, eax
197
        test    eax, eax
Line -... Line 198...
-
 
198
        jnz     .error
-
 
199
 
-
 
200
        ;call    ext2_sb_update
-
 
201
        ; Sync the disk.
-
 
202
        ;mov     esi, [ebp + PARTITION.Disk]
198
        jnz     .error
203
        ;call    disk_sync                       ; eax contains error code, if any.
199
 
204
 
200
        mov     eax, ebp                        ; Return pointer to EXTFS.
205
        mov     eax, ebp                        ; Return pointer to EXTFS.
Line 201... Line 206...
201
        pop     edi esi ebp ebx
206
        pop     edi esi ebp ebx
Line 250... Line 255...
250
;               ebx = pointer to parameters from sysfunc 70.
255
;               ebx = pointer to parameters from sysfunc 70.
251
; Output:       ebx = blocks read (or 0xFFFFFFFF, folder not found)
256
; Output:       ebx = blocks read (or 0xFFFFFFFF, folder not found)
252
;               eax = error code (0 implies no error)
257
;               eax = error code (0 implies no error)
253
;---------------------------------------------------------------------
258
;---------------------------------------------------------------------
254
ext2_ReadFolder:
259
ext2_ReadFolder:
-
 
260
        ;DEBUGF  1, "Reading folder.\n"
255
        call    ext2_lock
261
        call    ext2_lock
256
        cmp     byte [esi], 0
262
        cmp     byte [esi], 0
257
        jz      .root_folder
263
        jz      .root_folder
Line 258... Line 264...
258
 
264
 
Line 304... Line 310...
304
        
310
        
305
        mov     edi, esp                                ; edi = pointer to local variables.
311
        mov     edi, esp                                ; edi = pointer to local variables.
Line 306... Line 312...
306
        add     edx, 32                                 ; edx = mem to return.
312
        add     edx, 32                                 ; edx = mem to return.
307
 
313
 
308
        xor     ecx, ecx                                ; Get number of first block.
314
        xor     ecx, ecx                                ; Get number of first block.
309
        call    ext2_get_inode_block
315
        call    ext2_inode_get_block
Line 310... Line 316...
310
        test    eax, eax
316
        test    eax, eax
311
        jnz     .error_get_block
317
        jnz     .error_get_block
Line 353... Line 359...
353
        inc     dword [edi]                             ; Number of blocks read.
359
        inc     dword [edi]                             ; Number of blocks read.
Line 354... Line 360...
354
        
360
        
355
        ; Read the next block.
361
        ; Read the next block.
356
        push    ecx
362
        push    ecx
357
        mov     ecx, [edi]
363
        mov     ecx, [edi]
358
        call    ext2_get_inode_block
364
        call    ext2_inode_get_block
359
        test    eax, eax
365
        test    eax, eax
Line 360... Line 366...
360
        jnz     .error_get_block
366
        jnz     .error_get_block
361
 
367
 
Line 480... Line 486...
480
        
486
        
481
        xor     eax, eax                                ; Reserved in current implementation.
487
        xor     eax, eax                                ; Reserved in current implementation.
482
        lea     edi, [edx + 12]
488
        lea     edi, [edx + 12]
483
        mov     ecx, 20 / 4
489
        mov     ecx, 20 / 4
-
 
490
        rep stosd
-
 
491
 
484
        rep stosd
492
        ;DEBUGF  1, "Returning with: %x.\n", eax
Line 485... Line 493...
485
        ret
493
        ret
486
 
494
 
Line 495... Line 503...
495
    .error_ret:
503
    .error_ret:
496
        or      ebx, -1
504
        or      ebx, -1
497
        push    eax
505
        push    eax
498
        call    ext2_unlock
506
        call    ext2_unlock
499
        pop     eax
507
        pop     eax
500
 
-
 
-
 
508
        ;DEBUGF  1, "Returning with: %x.\n", eax
501
        ret
509
        ret
Line 502... Line 510...
502
        
510
        
503
    .error_empty_dir:                                   ; inode of folder without blocks.
511
    .error_empty_dir:                                   ; inode of folder without blocks.
504
    .error_root:                                        ; Root has to be a folder.
512
    .error_root:                                        ; Root has to be a folder.
Line 516... Line 524...
516
;               ebp = pointer to EXTFS structure.
524
;               ebp = pointer to EXTFS structure.
517
; Output:       ebx = bytes read (0xFFFFFFFF -> file not found)
525
; Output:       ebx = bytes read (0xFFFFFFFF -> file not found)
518
;               eax = error code (0 implies no error)
526
;               eax = error code (0 implies no error)
519
;---------------------------------------------------------------------
527
;---------------------------------------------------------------------
520
ext2_Read:
528
ext2_Read:
-
 
529
        ;DEBUGF  1, "Attempting read.\n"
521
        call    ext2_lock
530
        call    ext2_lock
522
        cmp     byte [esi], 0
531
        cmp     byte [esi], 0
523
        jnz     @F
532
        jnz     @F
Line 524... Line 533...
524
 
533
 
Line 605... Line 614...
605
 
614
 
Line 606... Line 615...
606
        push    eax                                     ; Save block counter to stack.
615
        push    eax                                     ; Save block counter to stack.
607
        
616
        
608
        push    ecx
617
        push    ecx
609
        mov     ecx, eax
618
        mov     ecx, eax
610
        call    ext2_get_inode_block
619
        call    ext2_inode_get_block
Line 611... Line 620...
611
        test    eax, eax
620
        test    eax, eax
612
        jnz     .error_at_first_block
621
        jnz     .error_at_first_block
Line 649... Line 658...
649
        test    edi, edi
658
        test    edi, edi
650
        jz      .finish_block
659
        jz      .finish_block
Line 651... Line 660...
651
        
660
        
652
        inc     dword [esp]
661
        inc     dword [esp]
653
        mov     ecx, [esp]
662
        mov     ecx, [esp]
Line 654... Line 663...
654
        call    ext2_get_inode_block
663
        call    ext2_inode_get_block
655
 
664
 
Line 656... Line 665...
656
        test    eax, eax
665
        test    eax, eax
Line 672... Line 681...
672
        test    edx, edx
681
        test    edx, edx
673
        jz      .end_read
682
        jz      .end_read
Line 674... Line 683...
674
 
683
 
675
        pop     ecx                                     ; Pop block counter in ECX.
684
        pop     ecx                                     ; Pop block counter in ECX.
676
        inc     ecx
685
        inc     ecx
Line 677... Line 686...
677
        call    ext2_get_inode_block
686
        call    ext2_inode_get_block
678
        
687
        
Line 679... Line 688...
679
        test    eax, eax
688
        test    eax, eax
Line 703... Line 712...
703
 
712
 
704
        mov     eax, ERROR_END_OF_FILE
713
        mov     eax, ERROR_END_OF_FILE
705
        ret
714
        ret
706
    @@:
715
    @@:
-
 
716
        xor     eax, eax
707
        xor     eax, eax
717
        ;DEBUGF  1, "Returning with: %x.\n", eax
Line 708... Line 718...
708
        ret
718
        ret
709
        
719
        
710
    .only_one_block:
720
    .only_one_block:
Line 720... Line 730...
720
        pop     ecx edx
730
        pop     ecx edx
721
        or      ebx, -1
731
        or      ebx, -1
722
        push    eax
732
        push    eax
723
        call    ext2_unlock
733
        call    ext2_unlock
724
        pop     eax
734
        pop     eax
-
 
735
 
-
 
736
        ;DEBUGF  1, "Returning with: %x.\n", eax
725
        ret
737
        ret
Line 726... Line 738...
726
 
738
 
727
;---------------------------------------------------------------------
739
;---------------------------------------------------------------------
728
; Read file information from block device.
740
; Read file information from block device.
729
; Input:        esi + [esp + 4] = file name.
741
; Input:        esi + [esp + 4] = file name.
730
;               ebx = pointer to paramteres from sysfunc 70.
742
;               ebx = pointer to paramteres from sysfunc 70.
731
;               ebp = pointer to EXTFS structure.
743
;               ebp = pointer to EXTFS structure.
732
; Output:       eax = error code.
744
; Output:       eax = error code.
733
;---------------------------------------------------------------------
745
;---------------------------------------------------------------------
-
 
746
ext2_GetFileInfo:
734
ext2_GetFileInfo:
747
        ;DEBUGF  1, "Calling for file info.\n"
735
        call    ext2_lock
748
        call    ext2_lock
736
        mov     edx, [ebx + 16]
749
        mov     edx, [ebx + 16]
737
        cmp     byte [esi], 0
750
        cmp     byte [esi], 0
Line 747... Line 760...
747
        jz      @F
760
        jz      @F
Line 748... Line 761...
748
 
761
 
749
        push    eax
762
        push    eax
750
        call    ext2_unlock
763
        call    ext2_unlock
-
 
764
        pop     eax
-
 
765
 
751
        pop     eax
766
        ;DEBUGF  1, "Returning with: %x.\n", eax
Line 752... Line 767...
752
        ret
767
        ret
753
 
768
 
754
    .is_root:      
769
    .is_root:      
Line 799... Line 814...
799
        adc     edx, 2
814
        adc     edx, 2
800
        call    ntfs_datetime_to_bdfe.sec
815
        call    ntfs_datetime_to_bdfe.sec
Line 801... Line 816...
801
 
816
 
802
        call    ext2_unlock
817
        call    ext2_unlock
-
 
818
        xor     eax, eax
803
        xor     eax, eax
819
        ;DEBUGF  1, "Returning with: %x.\n", eax
Line 804... Line 820...
804
        ret
820
        ret
805
 
821
 
806
;---------------------------------------------------------------------
822
;---------------------------------------------------------------------
807
; Set file information for block device.
823
; Set file information for block device.
808
; Input:        esi + [esp + 4] = file name.
824
; Input:        esi + [esp + 4] = file name.
809
;               ebx = pointer to paramteres from sysfunc 70.
825
;               ebx = pointer to paramteres from sysfunc 70.
810
;               ebp = pointer to EXTFS structure.
826
;               ebp = pointer to EXTFS structure.
811
; Output:       eax = error code.
827
; Output:       eax = error code.
-
 
828
;---------------------------------------------------------------------
-
 
829
ext2_SetFileInfo:
-
 
830
        test    [ebp + EXTFS.partition_flags], EXT2_RO
-
 
831
        jz      @F
-
 
832
 
-
 
833
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
834
        ret
812
;---------------------------------------------------------------------
835
 
813
ext2_SetFileInfo:
836
    @@:    
814
        push    edx esi edi ebx
837
        push    edx esi edi ebx
Line 815... Line 838...
815
        call    ext2_lock
838
        call    ext2_lock
Line 886... Line 909...
886
;               ebx = pointer to paramteres from sysfunc 70.
909
;               ebx = pointer to paramteres from sysfunc 70.
887
;               ebp = pointer to EXTFS structure.
910
;               ebp = pointer to EXTFS structure.
888
; Output:       eax = error code.
911
; Output:       eax = error code.
889
;---------------------------------------------------------------------
912
;---------------------------------------------------------------------
890
ext2_Delete:
913
ext2_Delete:
-
 
914
        ;DEBUGF  1, "Attempting Delete.\n"
-
 
915
        test    [ebp + EXTFS.partition_flags], EXT2_RO
-
 
916
        jz      @F
-
 
917
 
-
 
918
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
919
        ret
-
 
920
 
-
 
921
    @@:    
891
        push    ebx ecx edx esi edi
922
        push    ebx ecx edx esi edi
892
        call    ext2_lock
923
        call    ext2_lock
Line 893... Line 924...
893
 
924
 
Line 969... Line 1000...
969
        mov     esi, [ebp + EXTFS.ext2_save_inode]
1000
        mov     esi, [ebp + EXTFS.ext2_save_inode]
970
        xor     ecx, ecx
1001
        xor     ecx, ecx
Line 971... Line 1002...
971
 
1002
 
972
    @@:
1003
    @@:
973
        push    ecx
1004
        push    ecx
974
        call    ext2_get_inode_block
1005
        call    ext2_inode_get_block
975
        test    eax, eax
1006
        test    eax, eax
976
        jnz     .error_stack8
1007
        jnz     .error_stack8
977
        mov     eax, ecx
1008
        mov     eax, ecx
Line 987... Line 1018...
987
 
1018
 
988
        inc     ecx
1019
        inc     ecx
Line 989... Line 1020...
989
        jmp     @B
1020
        jmp     @B
-
 
1021
 
-
 
1022
    @@:
-
 
1023
        ; Free indirect blocks.
-
 
1024
        call    ext2_inode_free_indirect_blocks
-
 
1025
        test    eax, eax
990
 
1026
        jnz     .error_stack4
991
    @@:
1027
 
992
        ; Clear the inode, and add deletion time.
1028
        ; Clear the inode, and add deletion time.
993
        mov     edi, [ebp + EXTFS.ext2_save_inode]
1029
        mov     edi, [ebp + EXTFS.ext2_save_inode]
994
        xor     eax, eax
1030
        xor     eax, eax
Line 1045... Line 1081...
1045
        push    eax
1081
        push    eax
1046
        call    ext2_unlock
1082
        call    ext2_unlock
1047
        pop     eax
1083
        pop     eax
Line 1048... Line 1084...
1048
 
1084
 
-
 
1085
        pop     edi esi edx ecx ebx
1049
        pop     edi esi edx ecx ebx
1086
        ;DEBUGF  1, "And returning with: %x.\n", eax
Line 1050... Line 1087...
1050
        ret
1087
        ret
1051
 
1088
 
1052
    .error_stack8:
1089
    .error_stack8:
Line 1069... Line 1106...
1069
;               ebx = pointer to paramteres from sysfunc 70.
1106
;               ebx = pointer to paramteres from sysfunc 70.
1070
;               ebp = pointer to EXTFS structure.
1107
;               ebp = pointer to EXTFS structure.
1071
; Output:       eax = error code.
1108
; Output:       eax = error code.
1072
;---------------------------------------------------------------------
1109
;---------------------------------------------------------------------
1073
ext2_CreateFolder:
1110
ext2_CreateFolder:
-
 
1111
        ;DEBUGF  1, "Attempting to create folder.\n"
-
 
1112
        test    [ebp + EXTFS.partition_flags], EXT2_RO
-
 
1113
        jz      @F
-
 
1114
 
-
 
1115
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
1116
        ret
-
 
1117
 
-
 
1118
    @@:    
1074
        push    ebx ecx edx esi edi
1119
        push    ebx ecx edx esi edi
1075
        call    ext2_lock
1120
        call    ext2_lock
Line 1076... Line 1121...
1076
 
1121
 
Line 1077... Line 1122...
1077
        add     esi, [esp + 20 + 4]
1122
        add     esi, [esp + 20 + 4]
1078
 
1123
 
1079
        ; Can't create root, but for CreateFile already existing directory is success.
1124
        ; Can't create root, but for CreateFolder already existing directory is success.
Line 1080... Line 1125...
1080
        cmp     byte [esi], 0
1125
        cmp     byte [esi], 0
1081
        jz      .success
1126
        jz      .success
Line 1192... Line 1237...
1192
        push    eax
1237
        push    eax
1193
        call    ext2_unlock
1238
        call    ext2_unlock
1194
        pop     eax
1239
        pop     eax
Line 1195... Line 1240...
1195
 
1240
 
-
 
1241
        pop     edi esi edx ecx ebx
1196
        pop     edi esi edx ecx ebx
1242
        ;DEBUGF  1, "Returning with: %x.\n", eax
Line 1197... Line 1243...
1197
        ret
1243
        ret
1198
 
1244
 
Line 1208... Line 1254...
1208
 
1254
 
1209
    .error_full:
1255
    .error_full:
1210
        mov     eax, ERROR_DISK_FULL
1256
        mov     eax, ERROR_DISK_FULL
Line 1211... Line 1257...
1211
        jmp     .return
1257
        jmp     .return
1212
 
1258
 
Line -... Line 1259...
-
 
1259
self_link   db ".", 0
-
 
1260
parent_link db "..", 0
-
 
1261
 
-
 
1262
;---------------------------------------------------------------------
-
 
1263
; Rewrite a file.
-
 
1264
; Input:        esi + [esp + 4] = file name.
-
 
1265
;               ebx = pointer to paramteres from sysfunc 70.
-
 
1266
;               ebp = pointer to EXTFS structure.
1213
self_link:   db ".", 0
1267
; Output:       eax = error code.
-
 
1268
;               ebx = bytes written.
-
 
1269
;---------------------------------------------------------------------
-
 
1270
ext2_Rewrite:
-
 
1271
        ;DEBUGF  1, "Attempting Rewrite.\n"
-
 
1272
        test    [ebp + EXTFS.partition_flags], EXT2_RO
-
 
1273
        jz      @F
-
 
1274
 
-
 
1275
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
1276
        ret
-
 
1277
 
-
 
1278
    @@:
-
 
1279
        push    ecx edx esi edi
-
 
1280
        pushad
-
 
1281
 
-
 
1282
        call    ext2_lock
-
 
1283
 
-
 
1284
        add     esi, [esp + 16 + 32 + 4]
-
 
1285
        ; Can't create root.
-
 
1286
        cmp     byte [esi], 0
-
 
1287
        jz      .error_access_denied
-
 
1288
 
-
 
1289
        push    esi 
-
 
1290
        stdcall ext2_inode_find, 0
-
 
1291
        pop     esi
-
 
1292
 
-
 
1293
        ; If the file is there, delete it.
-
 
1294
        test    eax, eax
-
 
1295
        jnz     @F
-
 
1296
 
-
 
1297
        pushad
-
 
1298
 
-
 
1299
        push    eax
-
 
1300
        call    ext2_unlock
-
 
1301
        pop     eax
-
 
1302
 
-
 
1303
        push    dword 0x00000000
-
 
1304
        call    ext2_Delete
-
 
1305
        add     esp, 4
-
 
1306
 
-
 
1307
        push    eax
-
 
1308
        call    ext2_lock
-
 
1309
        pop     eax
-
 
1310
 
-
 
1311
        test    eax, eax
-
 
1312
        jnz     .error_access_denied_delete
-
 
1313
 
-
 
1314
        popad
-
 
1315
    @@:
-
 
1316
        ; Find parent.
-
 
1317
        call    ext2_inode_find_parent
-
 
1318
        test    eax, eax
-
 
1319
        jnz     .error_access_denied
-
 
1320
 
-
 
1321
        ; Inode ID for preference.
-
 
1322
        mov     eax, esi
-
 
1323
        call    ext2_inode_alloc
-
 
1324
        test    eax, eax
-
 
1325
        jnz     .error_full
-
 
1326
 
-
 
1327
        ; Save allocated inode in EDX; filename is in EDI; parent ID in ESI.
-
 
1328
        mov     edx, ebx
-
 
1329
 
-
 
1330
        push    edi
-
 
1331
 
-
 
1332
        xor     al, al
-
 
1333
        mov     edi, [ebp + EXTFS.ext2_temp_inode]
-
 
1334
        mov     ecx, [ebp + EXTFS.inode_size]
-
 
1335
        rep stosb
-
 
1336
 
-
 
1337
        mov     edi, [ebp + EXTFS.ext2_temp_inode]
-
 
1338
        add     edi, EXT2_INODE_STRUC.i_atime
-
 
1339
        call    current_unix_time
-
 
1340
 
-
 
1341
        add     edi, 8
-
 
1342
        call    current_unix_time
-
 
1343
 
-
 
1344
        pop     edi
-
 
1345
 
-
 
1346
        mov     ebx, [ebp + EXTFS.ext2_temp_inode]
-
 
1347
        mov     [ebx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG
-
 
1348
        mov     eax, edx
-
 
1349
        call    ext2_inode_write
-
 
1350
        test    eax, eax
-
 
1351
        jnz     .error
-
 
1352
 
-
 
1353
        ; Link parent to child.
-
 
1354
        mov     eax, esi
-
 
1355
        mov     ebx, edx
-
 
1356
        mov     esi, edi
-
 
1357
        mov     dl, EXT2_FT_REG_FILE
-
 
1358
        call    ext2_inode_link
-
 
1359
        test    eax, eax
-
 
1360
        jnz     .error
-
 
1361
 
-
 
1362
        popad
-
 
1363
        push    eax
-
 
1364
        call    ext2_unlock
-
 
1365
        pop     eax
-
 
1366
 
-
 
1367
        push    dword 0x00000000
-
 
1368
        call    ext2_Write
-
 
1369
        add     esp, 4
-
 
1370
 
-
 
1371
        push    eax
-
 
1372
        call    ext2_lock
-
 
1373
        pop     eax
-
 
1374
 
-
 
1375
    .success:
-
 
1376
        push    eax
-
 
1377
        call    ext2_sb_update
-
 
1378
 
-
 
1379
        ; Sync the disk.
-
 
1380
        mov     esi, [ebp + PARTITION.Disk]
-
 
1381
        call    disk_sync                       ; eax contains error code, if any.
-
 
1382
        pop     eax
-
 
1383
 
-
 
1384
    .return:
-
 
1385
        push    eax
-
 
1386
        call    ext2_unlock
-
 
1387
        pop     eax
-
 
1388
 
-
 
1389
        pop     edi esi edx ecx
-
 
1390
 
-
 
1391
        ;DEBUGF  1, "And returning with: %x.\n", eax
-
 
1392
        ret
-
 
1393
 
-
 
1394
    .error:       
-
 
1395
        mov     eax, ERROR_ACCESS_DENIED
-
 
1396
        jmp     .success
-
 
1397
 
-
 
1398
    .error_access_denied_delete:
-
 
1399
        popad
-
 
1400
 
-
 
1401
    .error_access_denied:
-
 
1402
        popad
-
 
1403
        xor     ebx, ebx
-
 
1404
 
-
 
1405
        mov     eax, ERROR_ACCESS_DENIED
-
 
1406
        jmp     .return
-
 
1407
 
-
 
1408
    .error_full:
-
 
1409
        popad
-
 
1410
        xor     ebx, ebx
-
 
1411
 
-
 
1412
        mov     eax, ERROR_DISK_FULL
-
 
1413
        jmp     .return
-
 
1414
 
-
 
1415
;---------------------------------------------------------------------
-
 
1416
; Write to a file.
-
 
1417
; Input:        esi + [esp + 4] = file name.
-
 
1418
;               ebx = pointer to paramteres from sysfunc 70.
-
 
1419
;               ebp = pointer to EXTFS structure.
1214
parent_link: db "..", 0
1420
; Output:       eax = error code.
-
 
1421
;               ebx = number of bytes written.
-
 
1422
;---------------------------------------------------------------------
-
 
1423
ext2_Write:
-
 
1424
        ;DEBUGF 1, "Attempting write, "
-
 
1425
        test    [ebp + EXTFS.partition_flags], EXT2_RO
-
 
1426
        jz      @F
-
 
1427
 
-
 
1428
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
1429
        ret
-
 
1430
 
-
 
1431
    @@:    
-
 
1432
        push    ecx edx esi edi
-
 
1433
        call    ext2_lock
-
 
1434
 
-
 
1435
        add     esi, [esp + 16 + 4]
-
 
1436
 
-
 
1437
        ; Can't write to root.
-
 
1438
        cmp     byte [esi], 0
-
 
1439
        jz      .error
-
 
1440
 
-
 
1441
        push    ebx ecx edx
-
 
1442
        stdcall ext2_inode_find, 0
-
 
1443
        pop     edx ecx ebx
-
 
1444
        ; If file not there, error.
-
 
1445
        xor     ecx, ecx
-
 
1446
        test    eax, eax
-
 
1447
        jnz     .error_file_not_found
-
 
1448
 
-
 
1449
        ; Save the inode.
-
 
1450
        push    esi
-
 
1451
 
-
 
1452
        ; Check if it's a file.
-
 
1453
        mov     edx, [ebp + EXTFS.ext2_save_inode]
-
 
1454
        cmp     [edx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG
-
 
1455
        jne     .error
-
 
1456
 
-
 
1457
        mov     eax, esi
-
 
1458
        mov     ecx, [ebx + 4]
-
 
1459
 
-
 
1460
        call    ext2_inode_extend
-
 
1461
        xor     ecx, ecx
-
 
1462
        test    eax, eax
-
 
1463
        jnz     .error_device
-
 
1464
 
-
 
1465
        ; ECX contains the size to write, and ESI points to it.
-
 
1466
        mov     ecx, [ebx + 0x0C]
-
 
1467
        mov     esi, [ebx + 0x10]
-
 
1468
 
-
 
1469
        ; Save the size of the inode.
-
 
1470
        mov     eax, [edx + EXT2_INODE_STRUC.i_size]
-
 
1471
        push    eax
-
 
1472
 
-
 
1473
        xor     edx, edx
-
 
1474
        div     [ebp + EXTFS.block_size]
-
 
1475
 
-
 
1476
        test    edx, edx
-
 
1477
        jz      .start_aligned
-
 
1478
 
-
 
1479
        ; Start isn't aligned, so deal with the non-aligned bytes.
-
 
1480
        mov     ebx, [ebp + EXTFS.block_size]
-
 
1481
        sub     ebx, edx
-
 
1482
 
-
 
1483
        cmp     ebx, ecx
-
 
1484
        jbe     @F
-
 
1485
 
-
 
1486
        ; If the size to copy fits in current block, limit to that, instead of the entire block.
-
 
1487
        mov     ebx, ecx
-
 
1488
 
-
 
1489
    @@:
-
 
1490
        ; Copy EBX bytes, in EAX indexed block.
-
 
1491
        push    eax
-
 
1492
        call    ext2_inode_read_entry
-
 
1493
        test    eax, eax
-
 
1494
        pop     eax
-
 
1495
        jnz     .error_inode_size
-
 
1496
 
-
 
1497
        push    ecx
-
 
1498
        
-
 
1499
        mov     ecx, ebx
-
 
1500
        mov     edi, ebx
-
 
1501
        add     edi, edx
-
 
1502
        rep movsb
-
 
1503
 
-
 
1504
        pop     ecx
-
 
1505
 
-
 
1506
        ; Write the block.
-
 
1507
        call    ext2_inode_write_entry
-
 
1508
        test    eax, eax
-
 
1509
        jnz     .error_inode_size
-
 
1510
 
-
 
1511
        add     [esp], ebx
-
 
1512
        sub     ecx, ebx
-
 
1513
        jz      .write_inode
-
 
1514
 
-
 
1515
    .start_aligned:
-
 
1516
        cmp     ecx, [ebp + EXTFS.block_size]
-
 
1517
        jb      @F
-
 
1518
 
-
 
1519
        mov     eax, [esp]
-
 
1520
        xor     edx, edx
-
 
1521
        div     [ebp + EXTFS.block_size]
-
 
1522
 
-
 
1523
        push    eax
-
 
1524
        mov     edx, [esp + 8]
-
 
1525
        call    ext2_inode_blank_entry
-
 
1526
        test    eax, eax
-
 
1527
        pop     eax
-
 
1528
        jnz     .error_inode_size
-
 
1529
 
-
 
1530
        push    ecx
-
 
1531
 
-
 
1532
        mov     ecx, [ebp + EXTFS.block_size]
-
 
1533
        mov     edi, [ebp + EXTFS.ext2_save_block]
-
 
1534
        rep movsb
-
 
1535
 
-
 
1536
        pop     ecx
-
 
1537
 
-
 
1538
        call    ext2_inode_write_entry
-
 
1539
        test    eax, eax
-
 
1540
        jnz     .error_inode_size
-
 
1541
 
-
 
1542
        mov     eax, [ebp + EXTFS.block_size]
-
 
1543
        sub     ecx, eax
-
 
1544
        add     [esp], eax
-
 
1545
        jmp     .start_aligned        
-
 
1546
 
-
 
1547
    ; Handle the remaining bytes.
-
 
1548
    @@:
-
 
1549
        test    ecx, ecx
-
 
1550
        jz      .write_inode
-
 
1551
 
-
 
1552
        mov     eax, [esp]
-
 
1553
        xor     edx, edx
-
 
1554
        div     [ebp + EXTFS.block_size]
-
 
1555
 
-
 
1556
        push    eax
-
 
1557
        call    ext2_inode_read_entry
-
 
1558
        test    eax, eax
-
 
1559
        pop     eax
-
 
1560
        jz      @F
-
 
1561
 
-
 
1562
        push    eax
-
 
1563
        mov     edx, [esp + 8]
-
 
1564
 
-
 
1565
        call    ext2_inode_blank_entry
-
 
1566
        test    eax, eax
-
 
1567
        pop     eax
-
 
1568
        jnz     .error_inode_size
-
 
1569
 
-
 
1570
    @@:
-
 
1571
        push    ecx
-
 
1572
        mov     edi, [ebp + EXTFS.ext2_save_block]
-
 
1573
        rep movsb
-
 
1574
        pop     ecx
-
 
1575
 
-
 
1576
        call    ext2_inode_write_entry
-
 
1577
        test    eax, eax
-
 
1578
        jnz     .error_inode_size
-
 
1579
 
-
 
1580
        add     [esp], ecx
-
 
1581
        xor     ecx, ecx
-
 
1582
 
-
 
1583
    .write_inode:
-
 
1584
        mov     ebx, [ebp + EXTFS.ext2_temp_inode]
-
 
1585
        pop     eax
-
 
1586
        mov     [ebx + EXT2_INODE_STRUC.i_size], eax
-
 
1587
        mov     eax, [esp]
-
 
1588
 
-
 
1589
        call    ext2_inode_write
-
 
1590
        test    eax, eax
-
 
1591
        jnz     .error_device
-
 
1592
 
-
 
1593
    .success:
-
 
1594
        call    ext2_sb_update
-
 
1595
 
-
 
1596
        ; Sync the disk.
-
 
1597
        mov     esi, [ebp + PARTITION.Disk]
-
 
1598
        call    disk_sync                       ; eax contains error code, if any.
-
 
1599
 
-
 
1600
    .return:
-
 
1601
        push    eax
-
 
1602
        call    ext2_unlock
-
 
1603
        pop     eax
-
 
1604
 
-
 
1605
        add     esp, 4
-
 
1606
 
-
 
1607
        mov     ebx, [esp + 12]
-
 
1608
        sub     ebx, ecx
-
 
1609
        pop     edi esi edx ecx
-
 
1610
 
-
 
1611
        ;DEBUGF  1, "and returning with: %x.\n", eax
-
 
1612
        ret
-
 
1613
 
-
 
1614
    .error:
-
 
1615
        mov     eax, ERROR_ACCESS_DENIED
-
 
1616
        jmp     .return
-
 
1617
 
-
 
1618
    .error_file_not_found:
-
 
1619
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1620
        jmp     .return
-
 
1621
 
-
 
1622
    .error_inode_size:
-
 
1623
        mov     ebx, [ebp + EXTFS.ext2_temp_inode]
-
 
1624
        pop     eax
-
 
1625
        mov     [ebx + EXT2_INODE_STRUC.i_size], eax
-
 
1626
        mov     eax, [esp]
-
 
1627
 
-
 
1628
        call    ext2_inode_write
-
 
1629
 
-
 
1630
    .error_device:        
-
 
1631
        call    ext2_sb_update
-
 
1632
 
-
 
1633
        ; Sync the disk.
-
 
1634
        mov     esi, [ebp + PARTITION.Disk]
-
 
1635
        call    disk_sync                       ; eax contains error code, if any.
-
 
1636
 
-
 
1637
        mov     eax, ERROR_DEVICE
-
 
1638
        jmp     .return
-
 
1639
 
-
 
1640
;---------------------------------------------------------------------
-
 
1641
; Set the end of a file.
-
 
1642
; Input:        esi + [esp + 4] = file name.
-
 
1643
;               ebx = pointer to paramteres from sysfunc 70.
1215
 
1644
;               ebp = pointer to EXTFS structure.
-
 
1645
; Output:       eax = error code.
1216
ext2_Rewrite:
1646
;---------------------------------------------------------------------
-
 
1647
ext2_SetFileEnd:
1217
ext2_Write:
1648
        test    [ebp + EXTFS.partition_flags], EXT2_RO
1218
ext2_SetFileEnd:
1649
        jz      @F
-
 
1650
 
-
 
1651
        mov     eax, ERROR_UNSUPPORTED_FS
-
 
1652
        ret
-
 
1653
 
-
 
1654
    @@:    
-
 
1655
        push    ebx ecx edx esi edi
-
 
1656
        call    ext2_lock
-
 
1657
 
-
 
1658
        add     esi, [esp + 20 + 4]
-
 
1659
 
-
 
1660
        ; Can't write to root.
-
 
1661
        cmp     byte [esi], 0
-
 
1662
        jz      .error
-
 
1663
 
-
 
1664
        stdcall ext2_inode_find, 0
-
 
1665
        ; If file not there, error.
-
 
1666
        test    eax, eax
-
 
1667
        jnz     .error_file_not_found
-
 
1668
 
-
 
1669
        ; Check if it's a file.
-
 
1670
        mov     edx, [ebp + EXTFS.ext2_save_inode]
-
 
1671
        cmp     [edx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG
-
 
1672
        jne     .error
-
 
1673
 
-
 
1674
        mov     eax, esi
-
 
1675
        mov     ecx, [ebx + 4]
-
 
1676
        call    ext2_inode_extend
-
 
1677
        test    eax, eax
-
 
1678
        jnz     .error_disk_full
-
 
1679
 
-
 
1680
        mov     eax, esi
-
 
1681
        call    ext2_inode_truncate
-
 
1682
        test    eax, eax
-
 
1683
        jnz     .error_disk_full
-
 
1684
 
-
 
1685
        mov     eax, esi
-
 
1686
        mov     ebx, [ebp + EXTFS.ext2_temp_inode]
-
 
1687
        call    ext2_inode_write
-
 
1688
 
-
 
1689
        call    ext2_sb_update
-
 
1690
 
-
 
1691
        ; Sync the disk.
-
 
1692
        mov     esi, [ebp + PARTITION.Disk]
-
 
1693
        call    disk_sync                       ; eax contains error code, if any.
-
 
1694
 
-
 
1695
    .return:
-
 
1696
        push    eax
-
 
1697
        call    ext2_unlock
-
 
1698
        pop     eax
-
 
1699
 
-
 
1700
        pop     edi esi edx ecx ebx
-
 
1701
        ret
-
 
1702
 
-
 
1703
    .error:
-
 
1704
        mov     eax, ERROR_ACCESS_DENIED
-
 
1705
        jmp     .return
-
 
1706
 
-
 
1707
    .error_file_not_found:
-
 
1708
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1709
        jmp     .return
-
 
1710
 
-
 
1711
    .error_disk_full:        
-
 
1712
        call    ext2_sb_update
-
 
1713
 
-
 
1714
        ; Sync the disk.
-
 
1715
        mov     esi, [ebp + PARTITION.Disk]
-
 
1716
        call    disk_sync                       ; eax contains error code, if any.