Subversion Repositories Kolibri OS

Rev

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

Rev 6522 Rev 6558
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2013-2016. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2013-2016. 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 6522 $
8
$Revision: 6558 $
9
 
9
 
10
; EXT external functions
10
; EXT external functions
11
;   in:
11
;   in:
Line 162... Line 162...
162
sectorsPerBlock     dd  ?
162
sectorsPerBlock     dd  ?
163
dwordsPerBlock      dd  ?
163
dwordsPerBlock      dd  ?
164
dwordsPerBranch     dd  ?   ; dwordsPerBlock ^ 2
164
dwordsPerBranch     dd  ?   ; dwordsPerBlock ^ 2
165
mainBlockBuffer     dd  ?
165
mainBlockBuffer     dd  ?
166
tempBlockBuffer     dd  ?
166
tempBlockBuffer     dd  ?
167
align 512
167
align0  rb  200h-EXTFS.align0
168
superblock          SUPERBLOCK
168
superblock          SUPERBLOCK
169
align 1024
169
align1  rb  400h-EXTFS.align1
170
rootInodeBuffer     INODE
170
rootInodeBuffer     INODE
171
align 1024
171
align2  rb  600h-EXTFS.align2
172
mainInodeBuffer     INODE
172
inodeBuffer         INODE
173
align 1024
-
 
174
tempInodeBuffer     INODE
173
align3  rb  800h-EXTFS.align3
175
ends
174
ends
Line 176... Line 175...
176
 
175
 
177
; mount if it's a valid EXT partition
176
; mount if it's a valid EXT partition
178
ext2_create_partition:
177
ext2_create_partition:
Line 202... Line 201...
202
        ja      .fail
201
        ja      .fail
203
        cmp     [ebx+SUPERBLOCK.blocksPerGroup], 0
202
        cmp     [ebx+SUPERBLOCK.blocksPerGroup], 0
204
        je      .fail
203
        je      .fail
205
        cmp     [ebx+SUPERBLOCK.inodesPerGroup], 0
204
        cmp     [ebx+SUPERBLOCK.inodesPerGroup], 0
206
        je      .fail
205
        je      .fail
-
 
206
        movi    eax, sizeof.EXTFS
207
        stdcall kernel_alloc, 1000h
207
        call    malloc
208
        test    eax, eax
208
        test    eax, eax
209
        jz      .fail
209
        jz      .fail
210
        mov     ecx, dword [ebp+PARTITION.FirstSector]
210
        mov     ecx, dword [ebp+PARTITION.FirstSector]
211
        mov     dword [eax+EXTFS.FirstSector], ecx
211
        mov     dword [eax+EXTFS.FirstSector], ecx
212
        mov     ecx, dword [ebp+PARTITION.FirstSector+4]
212
        mov     ecx, dword [ebp+PARTITION.FirstSector+4]
Line 265... Line 265...
265
        ret
265
        ret
Line 266... Line 266...
266
 
266
 
267
@@:
267
@@:
268
        stdcall kernel_free, [ebp+EXTFS.mainBlockBuffer]
268
        stdcall kernel_free, [ebp+EXTFS.mainBlockBuffer]
-
 
269
.error:
269
.error:
270
        mov     eax, ebp
270
        stdcall kernel_free, ebp
271
        call    free
271
        pop     edi esi ebp
272
        pop     edi esi ebp
272
.fail:
273
.fail:
273
        pop     ebx
274
        pop     ebx
274
        xor     eax, eax
275
        xor     eax, eax
Line 277... Line 278...
277
; unmount EXT partition
278
; unmount EXT partition
278
ext_free:
279
ext_free:
279
; in: eax -> EXTFS structure
280
; in: eax -> EXTFS structure
280
        push    eax
281
        push    eax
281
        stdcall kernel_free, [eax+EXTFS.mainBlockBuffer]
282
        stdcall kernel_free, [eax+EXTFS.mainBlockBuffer]
282
        call    kernel_free
283
        pop     eax
283
        ret
284
        jmp     free
Line 284... Line 285...
284
 
285
 
285
extfsWriteBlock:
286
extfsWriteBlock:
286
        push    fs_write64_sys
287
        push    fs_write64_sys
287
        jmp     @f
288
        jmp     @f
Line 416... Line 417...
416
.complete:
417
.complete:
417
        inc     eax
418
        inc     eax
418
        ret
419
        ret
Line 419... Line 420...
419
 
420
 
420
inodeBlockAlloc:
421
inodeBlockAlloc:
421
; in: esi -> inode
422
; in: esi -> inode, eax = inode number
422
; out: ebx = block number
-
 
423
; TODO: fix to have correct preference.
-
 
424
        mov     eax, ROOT_INODE
423
; out: ebx = block number
425
        call    extfsBlockAlloc
424
        call    extfsBlockAlloc
426
        jc      @f
425
        jc      @f
427
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
426
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
428
        add     [esi+INODE.sectorsUsed], eax
427
        add     [esi+INODE.sectorsUsed], eax
Line 601... Line 600...
601
        movi    eax, ERROR_FS_FAIL
600
        movi    eax, ERROR_FS_FAIL
602
        stc
601
        stc
603
        ret
602
        ret
Line 604... Line 603...
604
 
603
 
605
.get_indirect_block:
-
 
606
        push    edx ebx
604
.get_indirect_block:
607
        mov     eax, [esi+INODE.addressBlock]
605
        mov     eax, [esi+INODE.addressBlock]
608
        test    eax, eax
606
        test    eax, eax
609
        jz      .fail3
607
        jz      .noBlock
610
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
608
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
611
        call    extfsReadBlock
609
        call    extfsReadBlock
612
        jc      @f
610
        jc      .fail2
613
        mov     ecx, [ebx+ecx*4]
-
 
614
@@:
611
        mov     ecx, [ebx+ecx*4]
615
        pop     ebx edx
612
        pop     ebx edx
Line 616... Line 613...
616
        ret
613
        ret
617
 
614
 
Line 621... Line 618...
621
        ret
618
        ret
Line 622... Line 619...
622
 
619
 
623
.listTreeSearch:
620
.listTreeSearch:
624
        cmp     ecx, 12
621
        cmp     ecx, 12
-
 
622
        jb      .get_direct_block
625
        jb      .get_direct_block
623
        push    edx ebx
626
        sub     ecx, 12
624
        sub     ecx, 12
627
        cmp     ecx, [ebp+EXTFS.dwordsPerBlock]
625
        cmp     ecx, [ebp+EXTFS.dwordsPerBlock]
628
        jb      .get_indirect_block
626
        jb      .get_indirect_block
629
        sub     ecx, [ebp+EXTFS.dwordsPerBlock]
627
        sub     ecx, [ebp+EXTFS.dwordsPerBlock]
630
        cmp     ecx, [ebp+EXTFS.dwordsPerBranch]
628
        cmp     ecx, [ebp+EXTFS.dwordsPerBranch]
631
        jb      .get_double_indirect_block
629
        jb      .get_double_indirect_block
632
; triply-indirect blocks
630
; triply-indirect blocks
633
        sub     ecx, [ebp+EXTFS.dwordsPerBranch]
-
 
634
        push    edx ebx
631
        sub     ecx, [ebp+EXTFS.dwordsPerBranch]
-
 
632
        mov     eax, [esi+INODE.tripleAddress]
-
 
633
        test    eax, eax
635
        mov     eax, [esi+INODE.tripleAddress]
634
        jz      .noBlock
636
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
635
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
637
        call    extfsReadBlock
636
        call    extfsReadBlock
638
        jc      .fail2
637
        jc      .fail2
639
        xor     edx, edx
638
        xor     edx, edx
640
        mov     eax, ecx
639
        mov     eax, ecx
641
        div     [ebp+EXTFS.dwordsPerBranch]
640
        div     [ebp+EXTFS.dwordsPerBranch]
642
; eax = number in triply-indirect block, edx = number in branch
641
; eax = number in triply-indirect block, edx = number in branch
643
        mov     eax, [ebx+eax*4]
642
        mov     eax, [ebx+eax*4]
644
        test    eax, eax
643
        test    eax, eax
645
        jz      .fail3
644
        jz      .noBlock
646
        call    extfsReadBlock
645
        call    extfsReadBlock
647
        jc      .fail2
646
        jc      .fail2
648
        mov     eax, edx
647
        mov     eax, edx
Line -... Line 648...
-
 
648
        jmp     @f
-
 
649
 
649
        jmp     @f
650
.noBlock:
650
 
651
        xor     ecx, ecx
651
.fail3:
-
 
652
        pop     ebx edx
-
 
653
        movi    eax, ERROR_FS_FAIL
652
.fail2:
Line 654... Line 653...
654
        stc
653
        pop     ebx edx
655
        ret
-
 
656
 
654
        ret
657
.get_double_indirect_block:
655
 
658
        push    edx ebx
656
.get_double_indirect_block:
659
        mov     eax, [esi+INODE.doubleAddress]
657
        mov     eax, [esi+INODE.doubleAddress]
660
        test    eax, eax
658
        test    eax, eax
661
        jz      .fail3
659
        jz      .noBlock
662
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
660
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
663
        call    extfsReadBlock
661
        call    extfsReadBlock
664
        jc      .fail2
662
        jc      .fail2
665
        mov     eax, ecx
663
        mov     eax, ecx
666
@@:
664
@@:
667
        xor     edx, edx
665
        xor     edx, edx
668
        div     [ebp+EXTFS.dwordsPerBlock]
666
        div     [ebp+EXTFS.dwordsPerBlock]
669
; eax = number in doubly-indirect block, edx = number in indirect block
667
; eax = number in doubly-indirect block, edx = number in indirect block
670
        mov     eax, [ebx+eax*4]
668
        mov     eax, [ebx+eax*4]
671
        test    eax, eax
669
        test    eax, eax
672
        jz      .fail3
670
        jz      .noBlock
673
        call    extfsReadBlock
-
 
674
        jc      .fail2
671
        call    extfsReadBlock
675
        mov     ecx, [ebx+edx*4]
672
        jc      .fail2
Line 676... Line 673...
676
.fail2:
673
        mov     ecx, [ebx+edx*4]
677
        pop     ebx edx
674
        pop     ebx edx
678
        ret
675
        ret
679
 
676
 
-
 
677
extfsSetFileBlock:
680
extfsSetFileBlock:
678
;   in:
681
;   in:
679
; ecx = file block number
682
; ecx = file block number
680
; edi = block number
683
; edi = block number
681
; edx = inode number
684
; esi -> inode
682
; esi -> inode
Line 694... Line 692...
694
; triple indirect blocks
692
; triple indirect blocks
695
        sub     ecx, [ebp+EXTFS.dwordsPerBranch]
693
        sub     ecx, [ebp+EXTFS.dwordsPerBranch]
696
        mov     eax, [esi+INODE.tripleAddress]
694
        mov     eax, [esi+INODE.tripleAddress]
697
        test    eax, eax
695
        test    eax, eax
698
        jnz     @f
696
        jnz     @f
-
 
697
        mov     eax, edx
699
        call    inodeBlockAlloc
698
        call    inodeBlockAlloc
700
        jc      .ret
699
        jc      .ret
701
        mov     [esi+INODE.tripleAddress], ebx
700
        mov     [esi+INODE.tripleAddress], ebx
702
        mov     eax, ebx
701
        mov     eax, ebx
703
@@:
702
@@:
Line 711... Line 710...
711
; eax = number in triply-indirect block, edx = number in branch
710
; eax = number in triply-indirect block, edx = number in branch
712
        lea     ecx, [ebx+eax*4]
711
        lea     ecx, [ebx+eax*4]
713
        mov     eax, [ebx+eax*4]
712
        mov     eax, [ebx+eax*4]
714
        test    eax, eax
713
        test    eax, eax
715
        jnz     @f
714
        jnz     @f
-
 
715
        mov     eax, [esp+4]
716
        call    inodeBlockAlloc
716
        call    inodeBlockAlloc
717
        jc      .fail_alloc_4
717
        jc      .fail_alloc_4
718
        mov     [ecx], ebx
718
        mov     [ecx], ebx
719
        mov     eax, [esp]
719
        mov     eax, [esp]
720
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
720
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
Line 730... Line 730...
730
 
730
 
731
.double_indirect_block:
731
.double_indirect_block:
732
        mov     eax, [esi+INODE.doubleAddress]
732
        mov     eax, [esi+INODE.doubleAddress]
733
        test    eax, eax
733
        test    eax, eax
-
 
734
        jnz     .double_indirect_present
734
        jnz     .double_indirect_present
735
        mov     eax, edx
735
        call    inodeBlockAlloc
736
        call    inodeBlockAlloc
736
        jc      .ret
737
        jc      .ret
737
        mov     [esi+INODE.doubleAddress], ebx
738
        mov     [esi+INODE.doubleAddress], ebx
738
        mov     eax, ebx
739
        mov     eax, ebx
Line 749... Line 750...
749
        lea     ecx, [ebx+edx*4]
750
        lea     ecx, [ebx+edx*4]
750
        push    ecx
751
        push    ecx
751
        lea     ecx, [ebx+eax*4]
752
        lea     ecx, [ebx+eax*4]
752
        cmp     dword[ecx], 0
753
        cmp     dword[ecx], 0
753
        jne     @f
754
        jne     @f
-
 
755
        mov     eax, [esp+8]
754
        call    inodeBlockAlloc
756
        call    inodeBlockAlloc
755
        jc      .fail_alloc_8
757
        jc      .fail_alloc_8
756
        mov     [ecx], ebx
758
        mov     [ecx], ebx
757
        mov     eax, [esp+4]
759
        mov     eax, [esp+4]
758
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
760
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
Line 770... Line 772...
770
 
772
 
771
.indirect_block:
773
.indirect_block:
772
        mov     eax, [esi+INODE.addressBlock]
774
        mov     eax, [esi+INODE.addressBlock]
773
        test    eax, eax
775
        test    eax, eax
-
 
776
        jnz     @f
774
        jnz     @f
777
        mov     eax, edx
775
        call    inodeBlockAlloc
778
        call    inodeBlockAlloc
776
        jc      .ret
779
        jc      .ret
777
        mov     [esi+INODE.addressBlock], ebx
780
        mov     [esi+INODE.addressBlock], ebx
778
        mov     eax, ebx
781
        mov     eax, ebx
Line 803... Line 806...
803
 
806
 
804
extfsEraseFileBlock:    ; also allocates
807
extfsEraseFileBlock:    ; also allocates
805
;   in:
808
;   in:
806
; edx = inode number
809
; edx = inode number
807
; eax = file block number
810
; eax = file block number
808
; [ebp+EXTFS.tempInodeBuffer] = inode
811
; [ebp+EXTFS.inodeBuffer] = inode
809
        push    ebx ecx edx edi esi
812
        push    ebx ecx edx edi esi
810
        mov     edi, eax
813
        mov     edi, eax
811
        mov     ecx, eax
814
        mov     ecx, eax
812
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
815
        lea     esi, [ebp+EXTFS.inodeBuffer]
813
        call    extfsGetFileBlock
816
        call    extfsGetFileBlock
814
        jc      @f
817
        jc      @f
815
        test    ecx, ecx
818
        test    ecx, ecx
816
        jz      .allocate
819
        jz      .allocate
Line 828... Line 831...
828
        mov     eax, edx
831
        mov     eax, edx
829
        call    extfsBlockAlloc
832
        call    extfsBlockAlloc
830
        jc      @f
833
        jc      @f
831
        mov     ecx, edi
834
        mov     ecx, edi
832
        mov     edi, ebx
835
        mov     edi, ebx
833
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
836
        lea     esi, [ebp+EXTFS.inodeBuffer]
834
        call    extfsSetFileBlock
837
        call    extfsSetFileBlock
835
        jc      @f
838
        jc      @f
836
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
839
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
837
        add     [esi+INODE.sectorsUsed], eax
840
        add     [esi+INODE.sectorsUsed], eax
838
        xor     eax, eax
841
        xor     eax, eax
Line 841... Line 844...
841
        ret
844
        ret
Line 842... Line 845...
842
 
845
 
843
extfsFreeFileBlock:
846
extfsFreeFileBlock:
844
;   in:
847
;   in:
845
; eax = file block number
848
; eax = file block number
846
; [ebp+EXTFS.tempInodeBuffer] = inode
849
; [ebp+EXTFS.inodeBuffer] = inode
847
        push    ebx ecx edi esi
850
        push    ebx ecx edx edi esi
848
        mov     edi, eax
851
        mov     edi, eax
849
        mov     ecx, eax
852
        mov     ecx, eax
850
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
853
        lea     esi, [ebp+EXTFS.inodeBuffer]
851
        call    extfsGetFileBlock
854
        call    extfsGetFileBlock
852
        jc      @f
855
        jc      @f
853
        test    ecx, ecx
856
        test    ecx, ecx
854
        jz      @f
857
        jz      @f
855
        mov     eax, ecx
858
        mov     eax, ecx
856
        xor     ecx, ecx
859
        xor     ecx, ecx
857
        call    extfsResourceFree
860
        call    extfsResourceFree
858
        mov     ecx, edi
861
        mov     ecx, edi
-
 
862
        xor     edi, edi
859
        xor     edi, edi
863
        movi    edx, ROOT_INODE
860
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
864
        lea     esi, [ebp+EXTFS.inodeBuffer]
861
        call    extfsSetFileBlock
865
        call    extfsSetFileBlock
862
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
866
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
863
        sub     [esi+INODE.sectorsUsed], eax
867
        sub     [esi+INODE.sectorsUsed], eax
864
        xor     eax, eax
868
        xor     eax, eax
865
@@:
869
@@:
866
        pop     esi edi ecx ebx
870
        pop     esi edi edx ecx ebx
Line 867... Line 871...
867
        ret
871
        ret
868
 
872
 
869
extfsReadFileBlock:
873
extfsReadFileBlock:
870
;   in:
874
;   in:
871
; eax = file block number
875
; eax = file block number
872
; [ebp+EXTFS.tempInodeBuffer] = inode
876
; [ebp+EXTFS.inodeBuffer] = inode
873
;   out:
877
;   out:
874
; [ebp+EXTFS.mainBlockBuffer] -> block
878
; [ebp+EXTFS.mainBlockBuffer] -> block
875
        push    ebx ecx edx esi
879
        push    ebx ecx edx esi
876
        mov     ecx, eax
880
        mov     ecx, eax
877
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
881
        lea     esi, [ebp+EXTFS.inodeBuffer]
878
        call    extfsGetFileBlock
882
        call    extfsGetFileBlock
879
        jc      .ret
883
        jc      .ret
880
        test    ecx, ecx
884
        test    ecx, ecx
Line 892... Line 896...
892
        jmp     .ret
896
        jmp     .ret
Line 893... Line 897...
893
 
897
 
894
extfsWriteFileBlock:
898
extfsWriteFileBlock:
895
;   in:
899
;   in:
896
; eax = file block number
900
; eax = file block number
897
; [ebp+EXTFS.tempInodeBuffer] = inode
901
; [ebp+EXTFS.inodeBuffer] = inode
898
; [ebp+EXTFS.mainBlockBuffer] -> block to write
902
; [ebp+EXTFS.mainBlockBuffer] -> block to write
899
        push    ebx ecx edx esi
903
        push    ebx ecx edx esi
900
        mov     ecx, eax
904
        mov     ecx, eax
901
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
905
        lea     esi, [ebp+EXTFS.inodeBuffer]
902
        call    extfsGetFileBlock
906
        call    extfsGetFileBlock
903
        jc      @f
907
        jc      @f
904
        test    ecx, ecx
908
        test    ecx, ecx
905
        jz      @b
909
        jz      @b
Line 997... Line 1001...
997
        pop     ebx ecx esi edi edx
1001
        pop     ebx ecx esi edi edx
998
        ret
1002
        ret
Line 999... Line 1003...
999
 
1003
 
1000
extfsExtendFile:
1004
extfsExtendFile:
-
 
1005
;   in:
1001
;   in:
1006
; [ebp+EXTFS.inodeBuffer] = inode
1002
; eax = inode number
1007
; eax = inode number
1003
; ecx = new size
1008
; ecx = new size
1004
        push    ebx ecx edx esi edi eax
1009
        push    ebx ecx edx esi edi eax
1005
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
-
 
1006
        call    readInode
-
 
1007
        jc      .ret
1010
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1008
        cmp     [ebx+INODE.fileSize], ecx
1011
        cmp     [ebx+INODE.fileSize], ecx
1009
        jnc     .ret
1012
        jnc     .ret
1010
        mov     eax, [ebx+INODE.fileSize]
1013
        mov     eax, [ebx+INODE.fileSize]
1011
        push    eax
1014
        push    eax
Line 1033... Line 1036...
1033
        pop     ecx eax
1036
        pop     ecx eax
1034
        call    extfsWriteFileBlock
1037
        call    extfsWriteFileBlock
1035
        jc      .error_inode_size
1038
        jc      .error_inode_size
1036
        add     [esp], esi
1039
        add     [esp], esi
1037
        sub     ecx, esi
1040
        sub     ecx, esi
1038
        jz      .write_inode
1041
        jz      .done
1039
.start_aligned:
1042
.start_aligned:
1040
        cmp     ecx, [ebp+EXTFS.bytesPerBlock]
1043
        cmp     ecx, [ebp+EXTFS.bytesPerBlock]
1041
        jb      @f
1044
        jb      @f
1042
        mov     eax, [esp]
1045
        mov     eax, [esp]
1043
        xor     edx, edx
1046
        xor     edx, edx
Line 1050... Line 1053...
1050
        add     [esp], eax
1053
        add     [esp], eax
1051
        jmp     .start_aligned
1054
        jmp     .start_aligned
Line 1052... Line 1055...
1052
 
1055
 
1053
@@: ; handle the remaining bytes
1056
@@: ; handle the remaining bytes
1054
        test    ecx, ecx
1057
        test    ecx, ecx
1055
        jz      .write_inode
1058
        jz      .done
1056
        mov     eax, [esp]
1059
        mov     eax, [esp]
1057
        xor     edx, edx
1060
        xor     edx, edx
1058
        div     [ebp+EXTFS.bytesPerBlock]
1061
        div     [ebp+EXTFS.bytesPerBlock]
1059
        mov     edx, [esp+4]
1062
        mov     edx, [esp+4]
1060
        call    extfsEraseFileBlock
1063
        call    extfsEraseFileBlock
1061
        jc      .error_inode_size
1064
        jc      .error_inode_size
1062
        add     [esp], ecx
1065
        add     [esp], ecx
1063
.write_inode:
1066
.done:
1064
        xor     eax, eax
1067
        xor     eax, eax
1065
.error_inode_size:
1068
.error_inode_size:
1066
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1069
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1067
        pop     [ebx+INODE.fileSize]
-
 
1068
        push    eax
-
 
1069
        mov     eax, [esp+4]
-
 
1070
        call    writeInode
-
 
1071
        pop     ebx
-
 
1072
        jc      .ret
-
 
1073
        xchg    eax, ebx
-
 
1074
        cmp     ebx, eax    ; set CF
1070
        pop     [ebx+INODE.fileSize]
1075
.ret:
1071
.ret:
1076
        pop     edi edi esi edx ecx ebx
1072
        pop     edi edi esi edx ecx ebx
Line 1077... Line 1073...
1077
        ret
1073
        ret
1078
 
1074
 
1079
extfsTruncateFile:
1075
extfsTruncateFile:
1080
;   in:
1076
;   in:
1081
; eax = inode number
1077
; [ebp+EXTFS.inodeBuffer] = inode
1082
; ecx = new size
1078
; ecx = new size
1083
        push    ebx ecx edx esi edi eax
-
 
1084
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
-
 
1085
        call    readInode
1079
        push    ebx ecx edx esi edi
1086
        jc      .ret
1080
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1087
        cmp     ecx, [ebx+INODE.fileSize]
1081
        cmp     ecx, [ebx+INODE.fileSize]
1088
        jnc     .ret
1082
        jnc     .ret
1089
        mov     eax, [ebx+INODE.fileSize]
1083
        mov     eax, [ebx+INODE.fileSize]
Line 1112... Line 1106...
1112
        rep stosb
1106
        rep stosb
1113
        pop     ecx eax
1107
        pop     ecx eax
1114
        call    extfsWriteFileBlock
1108
        call    extfsWriteFileBlock
1115
        jc      .error_inode_size
1109
        jc      .error_inode_size
1116
        sub     [esp], ecx
1110
        sub     [esp], ecx
1117
        jmp     .write_inode
1111
        jmp     .done
Line 1118... Line 1112...
1118
 
1112
 
1119
@@:
1113
@@:
1120
        call    extfsFreeFileBlock
1114
        call    extfsFreeFileBlock
1121
        sub     [esp], esi
1115
        sub     [esp], esi
1122
        sub     ecx, esi
1116
        sub     ecx, esi
1123
        jz      .write_inode
1117
        jz      .done
1124
.start_aligned:
1118
.start_aligned:
1125
        cmp     ecx, [ebp+EXTFS.bytesPerBlock]
1119
        cmp     ecx, [ebp+EXTFS.bytesPerBlock]
1126
        jb      @f
1120
        jb      @f
1127
        mov     eax, [esp]
1121
        mov     eax, [esp]
Line 1134... Line 1128...
1134
        sub     [esp], eax
1128
        sub     [esp], eax
1135
        jmp     .start_aligned
1129
        jmp     .start_aligned
Line 1136... Line 1130...
1136
 
1130
 
1137
@@: ; handle the remaining bytes
1131
@@: ; handle the remaining bytes
1138
        test    ecx, ecx
1132
        test    ecx, ecx
1139
        jz      .write_inode
1133
        jz      .done
1140
        mov     eax, [esp]
1134
        mov     eax, [esp]
1141
        xor     edx, edx
1135
        xor     edx, edx
1142
        div     [ebp+EXTFS.bytesPerBlock]
1136
        div     [ebp+EXTFS.bytesPerBlock]
1143
        dec     eax
1137
        dec     eax
Line 1154... Line 1148...
1154
        rep stosb
1148
        rep stosb
1155
        pop     ecx eax
1149
        pop     ecx eax
1156
        call    extfsWriteFileBlock
1150
        call    extfsWriteFileBlock
1157
        jc      .error_inode_size
1151
        jc      .error_inode_size
1158
        sub     [esp], ecx
1152
        sub     [esp], ecx
1159
.write_inode:
1153
.done:
1160
        xor     eax, eax
1154
        xor     eax, eax
1161
.error_inode_size:
1155
.error_inode_size:
1162
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1156
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1163
        pop     [ebx+INODE.fileSize]
1157
        pop     [ebx+INODE.fileSize]
1164
        push    eax
-
 
1165
        mov     eax, [esp+4]
-
 
1166
        call    writeInode
-
 
1167
        pop     ebx
-
 
1168
        jc      .ret
-
 
1169
        xchg    eax, ebx
-
 
1170
        cmp     ebx, eax    ; set CF
-
 
1171
.ret:
1158
.ret:
1172
        pop     edi edi esi edx ecx ebx
1159
        pop     edi esi edx ecx ebx
1173
        ret
1160
        ret
Line 1174... Line 1161...
1174
 
1161
 
1175
linkInode:
1162
linkInode:
1176
;   in:
1163
;   in:
Line 1181... Line 1168...
1181
        push    esi edi ebx ecx eax edx
1168
        push    esi edi ebx ecx eax edx
1182
        call    strlen
1169
        call    strlen
1183
        add     ecx, 8  ; directory entry size
1170
        add     ecx, 8  ; directory entry size
1184
        push    esi ebx ecx
1171
        push    esi ebx ecx
1185
        xor     ecx, ecx
1172
        xor     ecx, ecx
1186
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
1173
        lea     esi, [ebp+EXTFS.inodeBuffer]
1187
        mov     ebx, esi
1174
        mov     ebx, esi
1188
        call    readInode
1175
        call    readInode
1189
        jc      .error_inode_read
1176
        jc      .error_inode_read
1190
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
1177
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
1191
        mov     eax, [esi+INODE.sectorsUsed]
1178
        mov     eax, [esi+INODE.sectorsUsed]
1192
        shr     eax, cl
1179
        shr     eax, cl
1193
        xor     ecx, ecx
1180
        xor     ecx, ecx
1194
        push    eax     ; maximum file block number
-
 
1195
        push    ecx     ; current file block number
-
 
1196
.searchBlock:
1181
.searchBlock:
-
 
1182
        push    eax     ; blocks total
-
 
1183
        push    ecx     ; current file block number
-
 
1184
        cmp     eax, ecx
-
 
1185
        jz      .alloc_block
1197
        call    extfsGetFileBlock
1186
        call    extfsGetFileBlock
1198
        jc      .error_get_inode_block
1187
        jc      .error_get_inode_block
1199
        test    ecx, ecx
1188
        test    ecx, ecx
1200
        jz      .alloc_block
1189
        jz      .alloc_block
1201
        push    ecx
1190
        push    ecx
1202
        mov     eax, ecx
1191
        mov     eax, ecx
1203
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1192
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1204
        call    extfsReadBlock
1193
        call    extfsReadBlock
1205
        jc      .error_block_read
1194
        jc      .error_block_read
1206
        mov     ecx, [esp+8]
1195
        mov     ecx, [esp+12]
1207
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
1196
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
1208
        mov     edx, edi
1197
        mov     edx, edi
1209
        add     edx, [ebp+EXTFS.bytesPerBlock]
1198
        add     edx, [ebp+EXTFS.bytesPerBlock]
1210
.searchSpace:
1199
.searchSpace:
1211
        movzx   eax, [edi+DIRENTRY.entryLength]
1200
        movzx   eax, [edi+DIRENTRY.entryLength]
Line 1231... Line 1220...
1231
        jge     .found
1220
        jge     .found
1232
.nextEntry:
1221
.nextEntry:
1233
        add     edi, eax
1222
        add     edi, eax
1234
        cmp     edi, edx
1223
        cmp     edi, edx
1235
        jb      .searchSpace
1224
        jb      .searchSpace
-
 
1225
        pop     ecx ecx eax
-
 
1226
        inc     ecx
1236
        jmp     .nextBlock
1227
        jmp     .searchBlock
Line 1237... Line 1228...
1237
 
1228
 
1238
.zeroLength:
1229
.zeroLength:
1239
        mov     [edi+DIRENTRY.entryLength], cx
1230
        mov     [edi+DIRENTRY.entryLength], cx
1240
        mov     eax, edx
1231
        mov     eax, edx
Line 1255... Line 1246...
1255
        test    ecx, ecx
1246
        test    ecx, ecx
1256
        jz      .alloc_block
1247
        jz      .alloc_block
1257
        push    ecx
1248
        push    ecx
1258
        jmp     .prepare_block
1249
        jmp     .prepare_block
Line 1259... Line -...
1259
 
-
 
1260
.nextBlock:
-
 
1261
        add     esp, 4
-
 
1262
        inc     dword[esp]
-
 
1263
        mov     ecx, [esp]
-
 
1264
        cmp     ecx, [esp+4]
-
 
1265
        jbe     .searchBlock
1250
 
1266
.alloc_block:
1251
.alloc_block:
-
 
1252
        mov     eax, [esp+24]
1267
        mov     eax, [esp+12]
1253
        mov     edx, eax
1268
        call    extfsBlockAlloc
1254
        call    extfsBlockAlloc
1269
        jc      .error_get_inode_block
1255
        jc      .error_get_inode_block
1270
        mov     ecx, [esp]
1256
        mov     ecx, [esp]
1271
        mov     edi, ebx
1257
        mov     edi, ebx
Line 1304... Line 1290...
1304
        mov     eax, edx
1290
        mov     eax, edx
1305
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1291
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1306
        call    extfsWriteBlock
1292
        call    extfsWriteBlock
1307
        jc      .error_block_write
1293
        jc      .error_block_write
1308
        mov     eax, [esp]
1294
        mov     eax, [esp]
1309
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1295
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1310
        call    readInode
1296
        call    readInode
1311
        jc      .error_block_write
1297
        jc      .error_block_write
1312
        pop     eax
1298
        pop     eax
1313
        inc     [ebx+INODE.linksCount]
1299
        inc     [ebx+INODE.linksCount]
1314
        call    writeInode
1300
        call    writeInode
Line 1333... Line 1319...
1333
; eax = inode from which to unlink
1319
; eax = inode from which to unlink
1334
; ebx = inode to unlink
1320
; ebx = inode to unlink
1335
;   out:
1321
;   out:
1336
; eax = current number of links to inode, -1 = error
1322
; eax = current number of links to inode, -1 = error
1337
        push    edx ebx
1323
        push    edx ebx
1338
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1324
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1339
        call    readInode
1325
        call    readInode
1340
        jc      .fail
1326
        jc      .fail
1341
        push    eax
1327
        push    eax
1342
        lea     esi, [ebp+EXTFS.tempInodeBuffer]
1328
        lea     esi, [ebp+EXTFS.inodeBuffer]
1343
.loop:
1329
.loop:
1344
        mov     ecx, [esp]
1330
        mov     ecx, [esp]
1345
        call    extfsGetFileBlock
1331
        call    extfsGetFileBlock
1346
        jc      .fail_loop
1332
        jc      .fail_loop
1347
        test    ecx, ecx
1333
        test    ecx, ecx
Line 1399... Line 1385...
1399
        mov     eax, edi
1385
        mov     eax, edi
1400
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1386
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1401
        call    extfsWriteBlock
1387
        call    extfsWriteBlock
1402
        jc      .fail
1388
        jc      .fail
1403
        mov     eax, [esp]
1389
        mov     eax, [esp]
1404
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1390
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1405
        call    readInode
1391
        call    readInode
1406
        jc      .fail
1392
        jc      .fail
1407
        dec     word [ebx+INODE.linksCount]
1393
        dec     word [ebx+INODE.linksCount]
1408
        mov     eax, [esp]
1394
        mov     eax, [esp]
1409
        call    writeInode
1395
        call    writeInode
Line 1416... Line 1402...
1416
findInode:
1402
findInode:
1417
; in: esi -> path string in UTF-8
1403
; in: esi -> path string in UTF-8
1418
;   out:
1404
;   out:
1419
; edi -> file name in UTF-8
1405
; edi -> file name in UTF-8
1420
; esi = last inode number
1406
; esi = last inode number
1421
; [ebp+EXTFS.mainInodeBuffer] = last inode
1407
; [ebp+EXTFS.inodeBuffer] = last inode
1422
; ecx = parent inode number
1408
; ecx = parent inode number
1423
; CF=1 -> file not found, edi=0 -> error
1409
; CF=1 -> file not found, edi=0 -> error
1424
        push    esi
1410
        push    esi
1425
        lea     esi, [ebp+EXTFS.rootInodeBuffer]
1411
        lea     esi, [ebp+EXTFS.rootInodeBuffer]
1426
        lea     edi, [ebp+EXTFS.mainInodeBuffer]
1412
        lea     edi, [ebp+EXTFS.inodeBuffer]
1427
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
1413
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
1428
        mov     edx, esi
1414
        mov     edx, esi
1429
        rep movsb
1415
        rep movsb
1430
        pop     esi
1416
        pop     esi
1431
        pushd   0 ROOT_INODE
1417
        pushd   0 ROOT_INODE
-
 
1418
        mov     edi, esi
1432
        cmp     [edx+INODE.sectorsUsed], 0
1419
        cmp     [edx+INODE.sectorsUsed], 0
1433
        jz      .not_found
1420
        jz      .not_found
1434
        cmp     byte [esi], 0
1421
        cmp     byte [esi], 0
1435
        jnz     .next_path_part
1422
        jnz     .next_path_part
1436
        xor     eax, eax
1423
        xor     eax, eax
1437
        mov     edi, esi
-
 
1438
        pop     esi ecx
1424
        pop     esi ecx
1439
        ret
1425
        ret
Line 1440... Line 1426...
1440
 
1426
 
1441
@@:
1427
@@:
Line 1499... Line 1485...
1499
 
1485
 
1500
@@:
1486
@@:
1501
        pop     eax
1487
        pop     eax
1502
        mov     [esp], eax
1488
        mov     [esp], eax
1503
        mov     eax, [ebx+DIRENTRY.inodeNumber]
1489
        mov     eax, [ebx+DIRENTRY.inodeNumber]
1504
        lea     ebx, [ebp+EXTFS.mainInodeBuffer]
1490
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1505
        push    eax
1491
        push    eax
1506
        call    readInode
1492
        call    readInode
1507
        jc      .error
1493
        jc      .error
1508
        cmp     byte [esi], 0
1494
        cmp     byte [esi], 0
Line 1511... Line 1497...
1511
        movzx   eax, [ebx+INODE.accessMode]
1497
        movzx   eax, [ebx+INODE.accessMode]
1512
        and     eax, TYPE_MASK
1498
        and     eax, TYPE_MASK
1513
        cmp     eax, DIRECTORY
1499
        cmp     eax, DIRECTORY
1514
        jz      .next_path_part
1500
        jz      .next_path_part
1515
        xor     edi, edi        ; path folder is a file
1501
        xor     edi, edi    ; path folder is a file
-
 
1502
        jmp     @f
-
 
1503
 
1516
.not_found:
1504
.not_found:
-
 
1505
        mov     esi, edi
-
 
1506
        call    strlen
-
 
1507
        mov     al, '/'
-
 
1508
        repnz scasb
-
 
1509
        mov     edi, esi
-
 
1510
        jnz     @f
-
 
1511
        xor     edi, edi    ; path folder not found
-
 
1512
@@:
1517
        movi    eax, ERROR_FILE_NOT_FOUND
1513
        movi    eax, ERROR_FILE_NOT_FOUND
1518
        stc
1514
        stc
1519
.ret:
1515
.ret:
1520
        pop     esi ecx
1516
        pop     esi ecx
1521
        ret
1517
        ret
Line 1555... Line 1551...
1555
        jz      .root_folder
1551
        jz      .root_folder
1556
        push    ebx
1552
        push    ebx
1557
        call    findInode
1553
        call    findInode
1558
        pop     ebx
1554
        pop     ebx
1559
        jc      .error_ret
1555
        jc      .error_ret
1560
        lea     esi, [ebp+EXTFS.mainInodeBuffer]
1556
        lea     esi, [ebp+EXTFS.inodeBuffer]
1561
        test    [esi+INODE.accessMode], FLAG_FILE
1557
        test    [esi+INODE.accessMode], FLAG_FILE
1562
        jnz     .error_not_found
1558
        jnz     .error_not_found
1563
        jmp     @f
1559
        jmp     @f
Line 1564... Line 1560...
1564
 
1560
 
1565
.root_folder:
1561
.root_folder:
1566
        lea     esi, [ebp+EXTFS.rootInodeBuffer]
1562
        lea     esi, [ebp+EXTFS.rootInodeBuffer]
1567
        lea     edi, [ebp+EXTFS.mainInodeBuffer]
1563
        lea     edi, [ebp+EXTFS.inodeBuffer]
1568
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
1564
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
1569
        shr     ecx, 2
1565
        shr     ecx, 2
1570
        push    edi
1566
        push    edi
1571
        rep movsd
1567
        rep movsd
Line 1639... Line 1635...
1639
        jecxz   .wanted_end
1635
        jecxz   .wanted_end
1640
        cmp     [ebx+DIRENTRY.inodeNumber], 0
1636
        cmp     [ebx+DIRENTRY.inodeNumber], 0
1641
        jz      .empty_rec
1637
        jz      .empty_rec
1642
        inc     dword [edi+8]
1638
        inc     dword [edi+8]
1643
        inc     dword [edi+4]
1639
        inc     dword [edi+4]
1644
        push    ebx edi ecx esi edx
1640
        push    ebx edi ecx esi edx edi
1645
        pushd   [edi+12]
1641
        pushd   [edi+12]
1646
        mov     edi, edx
1642
        mov     edi, edx
1647
        xor     eax, eax
1643
        xor     eax, eax
1648
        mov     ecx, 40 / 4
1644
        mov     ecx, 40 / 4
1649
        rep stosd
1645
        rep stosd
1650
        popd    [edx+4]
1646
        popd    [edx+4] edi
1651
        mov     eax, [ebx+DIRENTRY.inodeNumber]
1647
        mov     eax, [ebx+DIRENTRY.inodeNumber]
1652
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
1648
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1653
        call    readInode
1649
        call    readInode
1654
        jc      .error_read_subinode
1650
        jc      .error_read_subinode
1655
        mov     esi, ebx
1651
        mov     esi, ebx
1656
        lea     edi, [edx+8]
1652
        lea     edi, [edx+8]
1657
        mov     eax, [ebx+INODE.inodeModified]
1653
        mov     eax, [ebx+INODE.inodeModified]
Line 1763... Line 1759...
1763
        mov     [esp], ebx
1759
        mov     [esp], ebx
1764
        call    findInode
1760
        call    findInode
1765
        pop     ebx
1761
        pop     ebx
1766
        jc      .error_eax
1762
        jc      .error_eax
1767
        push    ERROR_ACCESS_DENIED
1763
        push    ERROR_ACCESS_DENIED
1768
        lea     esi, [ebp+EXTFS.mainInodeBuffer]
1764
        lea     esi, [ebp+EXTFS.inodeBuffer]
1769
        mov     ax, [esi+INODE.accessMode]
1765
        mov     ax, [esi+INODE.accessMode]
1770
        and     ax, TYPE_MASK
1766
        and     ax, TYPE_MASK
1771
        cmp     ax, FLAG_FILE
1767
        cmp     ax, FLAG_FILE
1772
        jnz     .error  ; not a file
1768
        jnz     .error  ; not a file
1773
        pop     eax
1769
        pop     eax
Line 1891... Line 1887...
1891
        cmp     byte [esi], 0
1887
        cmp     byte [esi], 0
1892
        jz      .is_root
1888
        jz      .is_root
1893
        push    edx
1889
        push    edx
1894
        call    findInode
1890
        call    findInode
1895
        pop     edx
1891
        pop     edx
1896
        lea     esi, [ebp+EXTFS.mainInodeBuffer]
1892
        lea     esi, [ebp+EXTFS.inodeBuffer]
1897
        jnc     @f
1893
        jnc     @f
1898
        push    eax
1894
        push    eax
1899
        call    ext_unlock
1895
        call    ext_unlock
1900
        pop     eax
1896
        pop     eax
1901
        ret
1897
        ret
Line 1945... Line 1941...
1945
        call    findInode
1941
        call    findInode
1946
        pop     edx
1942
        pop     edx
1947
        jc      @f
1943
        jc      @f
1948
        push    esi     ; inode number
1944
        push    esi     ; inode number
1949
        lea     esi, [edx+16]
1945
        lea     esi, [edx+16]
1950
        lea     edi, [ebp+EXTFS.mainInodeBuffer]
1946
        lea     edi, [ebp+EXTFS.inodeBuffer]
1951
        call    fsCalculateTime
1947
        call    fsCalculateTime
1952
        add     eax, 978307200  ; 01.01.1970-01.01.2001 = (365*31+8)*24*60*60
1948
        add     eax, 978307200  ; 01.01.1970-01.01.2001 = (365*31+8)*24*60*60
1953
        mov     [edi+INODE.accessedTime], eax
1949
        mov     [edi+INODE.accessedTime], eax
Line 1954... Line 1950...
1954
 
1950
 
Line 1976... Line 1972...
1976
        call    findInode
1972
        call    findInode
1977
        mov     ebx, esi
1973
        mov     ebx, esi
1978
        push    eax
1974
        push    eax
1979
        jc      .ret
1975
        jc      .ret
1980
        pop     eax
1976
        pop     eax
1981
        lea     edx, [ebp+EXTFS.mainInodeBuffer]
1977
        lea     edx, [ebp+EXTFS.inodeBuffer]
1982
        movzx   edx, [edx+INODE.accessMode]
1978
        movzx   edx, [edx+INODE.accessMode]
1983
        and     edx, TYPE_MASK
1979
        and     edx, TYPE_MASK
1984
        cmp     edx, DIRECTORY
1980
        cmp     edx, DIRECTORY
1985
        jne     .file
1981
        jne     .file
1986
        push    ebx ecx edx 0
1982
        push    ebx ecx edx 0
1987
        lea     esi, [ebp+EXTFS.mainInodeBuffer]
1983
        lea     esi, [ebp+EXTFS.inodeBuffer]
1988
.checkDirectory:
1984
.checkDirectory:
1989
        mov     ecx, [esp]
1985
        mov     ecx, [esp]
1990
        call    extfsGetFileBlock
1986
        call    extfsGetFileBlock
1991
        jc      .not_empty_eax
1987
        jc      .not_empty_eax
1992
        test    ecx, ecx
1988
        test    ecx, ecx
Line 2032... Line 2028...
2032
        jnz     .error_stack4_eax   ; hardlinks
2028
        jnz     .error_stack4_eax   ; hardlinks
2033
        mov     eax, [esp]
2029
        mov     eax, [esp]
2034
        call    unlinkInode
2030
        call    unlinkInode
2035
@@:
2031
@@:
2036
        mov     eax, [esp]
2032
        mov     eax, [esp]
2037
        lea     ebx, [ebp+EXTFS.mainInodeBuffer]
2033
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2038
        call    readInode
2034
        call    readInode
2039
        jc      .error_stack4_eax
2035
        jc      .error_stack4_eax
2040
; free file's data
2036
; free file's data
2041
        lea     esi, [ebp+EXTFS.mainInodeBuffer]
2037
        lea     esi, [ebp+EXTFS.inodeBuffer]
2042
        xor     ecx, ecx
2038
        xor     ecx, ecx
2043
@@:
2039
@@:
2044
        push    ecx
2040
        push    ecx
2045
        call    extfsGetFileBlock
2041
        call    extfsGetFileBlock
2046
        jc      .error_stack8_eax
2042
        jc      .error_stack8_eax
Line 2054... Line 2050...
2054
        jmp     @b
2050
        jmp     @b
Line 2055... Line 2051...
2055
 
2051
 
2056
@@: ; free indirect blocks
2052
@@: ; free indirect blocks
2057
        pop     ecx
2053
        pop     ecx
2058
        push    edx
2054
        push    edx
2059
        lea     edi, [ebp+EXTFS.mainInodeBuffer]
2055
        lea     edi, [ebp+EXTFS.inodeBuffer]
2060
        mov     eax, [edi+INODE.addressBlock]
2056
        mov     eax, [edi+INODE.addressBlock]
2061
        test    eax, eax
2057
        test    eax, eax
2062
        jz      .success
2058
        jz      .success
2063
        xor     ecx, ecx
2059
        xor     ecx, ecx
Line 2093... Line 2089...
2093
        jb      @b
2089
        jb      @b
2094
.success:   ; clear the inode, and add deletion time
2090
.success:   ; clear the inode, and add deletion time
2095
        xor     eax, eax
2091
        xor     eax, eax
2096
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2092
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2097
        rep stosb
2093
        rep stosb
2098
        lea     edi, [ebp+EXTFS.mainInodeBuffer]
2094
        lea     edi, [ebp+EXTFS.inodeBuffer]
2099
        call    fsGetTime
2095
        call    fsGetTime
2100
        pop     edx
2096
        pop     edx
2101
        add     eax, 978307200
2097
        add     eax, 978307200
2102
        mov     [edi+INODE.deletedTime], eax
2098
        mov     [edi+INODE.deletedTime], eax
2103
        mov     eax, [esp]
2099
        mov     eax, [esp]
Line 2163... Line 2159...
2163
        call    extfsResourceAlloc
2159
        call    extfsResourceAlloc
2164
        jc      .error
2160
        jc      .error
2165
        inc     ebx
2161
        inc     ebx
2166
        push    ebx esi edi
2162
        push    ebx esi edi
2167
        xor     al, al
2163
        xor     al, al
2168
        lea     edi, [ebp+EXTFS.tempInodeBuffer]
2164
        lea     edi, [ebp+EXTFS.inodeBuffer]
2169
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2165
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2170
        rep stosb
2166
        rep stosb
2171
        lea     edi, [ebp+EXTFS.tempInodeBuffer]
2167
        lea     edi, [ebp+EXTFS.inodeBuffer]
2172
        call    fsGetTime
2168
        call    fsGetTime
2173
        add     eax, 978307200
2169
        add     eax, 978307200
2174
        mov     [edi+INODE.accessedTime], eax
2170
        mov     [edi+INODE.accessedTime], eax
2175
        mov     [edi+INODE.dataModified], eax
2171
        mov     [edi+INODE.dataModified], eax
2176
        mov     ebx, edi
2172
        mov     ebx, edi
Line 2246... Line 2242...
2246
        call    extfsResourceAlloc
2242
        call    extfsResourceAlloc
2247
        jc      .error
2243
        jc      .error
2248
        inc     ebx
2244
        inc     ebx
2249
        push    ebx ebx esi edi
2245
        push    ebx ebx esi edi
2250
        xor     al, al
2246
        xor     al, al
2251
        lea     edi, [ebp+EXTFS.tempInodeBuffer]
2247
        lea     edi, [ebp+EXTFS.inodeBuffer]
2252
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2248
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2253
        rep stosb
2249
        rep stosb
2254
        lea     edi, [ebp+EXTFS.tempInodeBuffer]
2250
        lea     edi, [ebp+EXTFS.inodeBuffer]
2255
        call    fsGetTime
2251
        call    fsGetTime
2256
        add     eax, 978307200
2252
        add     eax, 978307200
2257
        mov     [edi+INODE.accessedTime], eax
2253
        mov     [edi+INODE.accessedTime], eax
2258
        mov     [edi+INODE.dataModified], eax
2254
        mov     [edi+INODE.dataModified], eax
2259
        mov     ebx, edi
2255
        mov     ebx, edi
Line 2274... Line 2270...
2274
        push    ebx esi
2270
        push    ebx esi
2275
        mov     ecx, [ebx+12]
2271
        mov     ecx, [ebx+12]
2276
        jmp     ext_WriteFile.start
2272
        jmp     ext_WriteFile.start
Line 2277... Line 2273...
2277
 
2273
 
2278
.exist:
2274
.exist:
2279
        lea     edx, [ebp+EXTFS.mainInodeBuffer]
2275
        lea     edx, [ebp+EXTFS.inodeBuffer]
2280
        movi    eax, ERROR_ACCESS_DENIED
2276
        movi    eax, ERROR_ACCESS_DENIED
2281
        test    [edx+INODE.accessMode], FLAG_FILE
2277
        test    [edx+INODE.accessMode], FLAG_FILE
2282
        jz      .error  ; not a file
2278
        jz      .error  ; not a file
2283
        pop     ebx
2279
        pop     ebx
2284
        push    ebx esi
-
 
2285
        mov     eax, esi
2280
        push    ebx esi
2286
        mov     ecx, [ebx+12]
2281
        mov     ecx, [ebx+12]
2287
        call    extfsTruncateFile
2282
        call    extfsTruncateFile
2288
        jnc     ext_WriteFile.start
2283
        jnc     ext_WriteFile.start
2289
.error2:
2284
.error2:
Line 2301... Line 2296...
2301
        push    0 ebx
2296
        push    0 ebx
2302
        call    findInode
2297
        call    findInode
2303
        pop     ebx
2298
        pop     ebx
2304
        push    ebx esi
2299
        push    ebx esi
2305
        jc      .error
2300
        jc      .error
2306
        lea     edx, [ebp+EXTFS.mainInodeBuffer]
2301
        lea     edx, [ebp+EXTFS.inodeBuffer]
2307
        movi    eax, ERROR_ACCESS_DENIED
2302
        movi    eax, ERROR_ACCESS_DENIED
2308
        test    [edx+INODE.accessMode], FLAG_FILE
2303
        test    [edx+INODE.accessMode], FLAG_FILE
2309
        jz      .error  ; not a file
2304
        jz      .error  ; not a file
2310
        mov     ecx, [ebx+4]
2305
        mov     ecx, [ebx+4]
2311
        add     ecx, [ebx+12]
2306
        add     ecx, [ebx+12]
Line 2392... Line 2387...
2392
        add     [esp], ecx
2387
        add     [esp], ecx
2393
        xor     ecx, ecx
2388
        xor     ecx, ecx
2394
.error_inode_size:
2389
.error_inode_size:
2395
        mov     [esp+12], eax
2390
        mov     [esp+12], eax
2396
.write_inode:
2391
.write_inode:
2397
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
2392
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2398
        pop     eax eax
2393
        pop     eax eax
2399
        call    writeInode
2394
        call    writeInode
2400
        pop     ebx
2395
        pop     ebx
2401
        mov     ebx, [ebx+12]
2396
        mov     ebx, [ebx+12]
2402
        sub     ebx, ecx
2397
        sub     ebx, ecx
Line 2422... Line 2417...
2422
        call    extfsWritingInit
2417
        call    extfsWritingInit
2423
        pushd   [ebx+4]
2418
        pushd   [ebx+4]
2424
        call    findInode
2419
        call    findInode
2425
        pop     ecx
2420
        pop     ecx
2426
        jc      @f
2421
        jc      @f
2427
        lea     edx, [ebp+EXTFS.mainInodeBuffer]
2422
        lea     edx, [ebp+EXTFS.inodeBuffer]
2428
        movi    eax, ERROR_ACCESS_DENIED
2423
        movi    eax, ERROR_ACCESS_DENIED
2429
        cmp     [edx+INODE.accessMode], FLAG_FILE
2424
        cmp     [edx+INODE.accessMode], FLAG_FILE
2430
        jnz     @f      ; not a file
2425
        jnz     @f      ; not a file
2431
        mov     eax, esi
2426
        mov     eax, esi
2432
        call    extfsExtendFile
2427
        call    extfsExtendFile
2433
        jc      @f
2428
        jc      @f
2434
        mov     eax, esi
-
 
2435
        call    extfsTruncateFile
2429
        call    extfsTruncateFile
2436
        jc      @f
2430
        jc      @f
2437
        mov     eax, esi
2431
        mov     eax, esi
2438
        lea     ebx, [ebp+EXTFS.tempInodeBuffer]
2432
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2439
        call    writeInode
2433
        call    writeInode
2440
@@:
2434
@@:
2441
        push    eax
2435
        push    eax
2442
        call    writeSuperblock
2436
        call    writeSuperblock
2443
        mov     esi, [ebp+PARTITION.Disk]
2437
        mov     esi, [ebp+PARTITION.Disk]