Subversion Repositories Kolibri OS

Rev

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

Rev 6575 Rev 6643
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: 6575 $
8
$Revision: 6643 $
9
 
9
 
10
; EXT external functions
10
; EXT external functions
11
;   in:
11
;   in:
Line 375... Line 375...
375
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
375
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
376
        call    extfsWriteBlock
376
        call    extfsWriteBlock
377
        jc      @f
377
        jc      @f
378
        inc     [ebp+EXTFS.superblock.blocksFree+ecx*4]
378
        inc     [ebp+EXTFS.superblock.blocksFree+ecx*4]
379
@@:
379
@@:
-
 
380
        xor     eax, eax
380
        pop     edx ebx
381
        pop     edx ebx
381
        ret
382
        ret
Line 382... Line 383...
382
 
383
 
383
.fail2:
384
.fail2:
384
        pop     eax
385
        pop     eax
385
.fail:
386
.fail:
386
        pop     eax
-
 
387
        movi    eax, ERROR_DEVICE
387
        pop     eax
Line 388... Line -...
388
        jmp     @b
-
 
389
 
-
 
390
freeDoublyIndirectBlock:
-
 
391
; in: eax = doubly-indirect block number
-
 
392
; out: eax=1 -> finished
-
 
393
        test    eax, eax
-
 
394
        jz      .complete
-
 
395
        push    eax
-
 
396
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
397
        call    extfsReadBlock
-
 
398
        pop     eax
-
 
399
        jc      .ret
-
 
400
        xor     ecx, ecx
-
 
401
        call    extfsResourceFree
-
 
402
        mov     edx, ebx
-
 
403
        add     edx, [ebp+EXTFS.bytesPerBlock]
-
 
404
@@:
-
 
405
        mov     eax, [ebx]
-
 
406
        test    eax, eax
-
 
407
        jz      .complete
-
 
408
        call    extfsResourceFree
-
 
409
        add     ebx, 4
-
 
410
        cmp     ebx, edx
-
 
411
        jb      @b
-
 
412
.ret:
-
 
413
        xor     eax, eax
-
 
414
        ret
-
 
415
 
-
 
416
.complete:
-
 
417
        inc     eax
-
 
418
        ret
-
 
419
 
-
 
420
inodeBlockAlloc:    ; also erases
-
 
421
; in: esi -> inode, eax = inode number
-
 
422
; out: ebx = block number
-
 
423
        xor     ebx, ebx
-
 
424
        call    extfsResourceAlloc
-
 
425
        jc      @f
-
 
426
        push    ebx ecx edi
-
 
427
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
428
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
-
 
429
        mov     ebx, edi
-
 
430
        xor     eax, eax
-
 
431
        rep stosd
-
 
432
        pop     edi ecx eax
-
 
433
        push    eax
-
 
434
        call    extfsWriteBlock
-
 
435
        pop     ebx
-
 
436
        jc      @f
-
 
437
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
-
 
438
        add     [esi+INODE.sectorsUsed], eax
-
 
439
        xor     eax, eax
-
 
440
@@:
-
 
441
        ret
388
        jmp     @b
442
 
-
 
443
extfsResourceAlloc:
389
 
444
;   in:
-
 
445
; eax = inode number
-
 
446
; ebx=0 -> block, ebx=1 -> inode
390
extfsInodeAlloc:
447
;   out:
391
; in: eax = parent inode number
448
; ebx = block/inode number
392
; out: ebx = allocated inode number
449
        push    ecx edx esi edi
393
        push    ecx edx esi edi
450
        dec     eax
394
        dec     eax
451
        xor     edx, edx
395
        xor     edx, edx
452
        div     [ebp+EXTFS.superblock.inodesPerGroup]
396
        div     [ebp+EXTFS.superblock.inodesPerGroup]
453
        push    eax eax
397
        push    eax eax
454
        mov     esi, .forward   ; search forward, then backward
398
        mov     esi, .forward   ; search forward, then backward
455
.test_block_group:
399
.test_block_group:
456
        call    extfsReadDescriptor
400
        call    extfsReadDescriptor
457
        jc      .fail
401
        jc      .fail
458
        dec     [eax+BGDESCR.blocksFree+ebx*2]
402
        dec     [eax+BGDESCR.inodesFree]
459
        js      .next
403
        js      .next
460
        mov     edx, [eax+BGDESCR.blockBitmap+ebx*4]
404
        mov     edx, [eax+BGDESCR.inodeBitmap]
461
        mov     eax, [esp]
405
        mov     eax, [esp]
462
        call    extfsWriteDescriptor
-
 
463
        jc      .fail
406
        call    extfsWriteDescriptor
464
        push    ebx
407
        jc      .fail
465
        mov     eax, edx
408
        mov     eax, edx
466
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
409
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
467
        mov     edi, ebx
-
 
468
        call    extfsReadBlock
410
        mov     edi, ebx
469
        pop     ebx
411
        call    extfsReadBlock
470
        jc      .fail
412
        jc      .fail
471
        mov     ecx, [ebp+EXTFS.superblock.blocksPerGroup+ebx*8]
413
        mov     ecx, [ebp+EXTFS.superblock.inodesPerGroup]
472
        or      eax, -1
-
 
473
        shr     ecx, 5
414
        or      eax, -1
474
        jz      .next
415
        shr     ecx, 5
475
        repz scasd
416
        repz scasd
476
        jz      .next
417
        jz      .next
477
        sub     edi, 4
418
        sub     edi, 4
Line 482... Line 423...
482
        sub     edi, [ebp+EXTFS.tempBlockBuffer]
423
        sub     edi, [ebp+EXTFS.tempBlockBuffer]
483
        shl     edi, 3
424
        shl     edi, 3
484
        add     eax, edi
425
        add     eax, edi
485
        mov     ecx, eax
426
        mov     ecx, eax
486
        mov     eax, edx
427
        mov     eax, edx
487
        push    ebx
-
 
488
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
489
        call    extfsWriteBlock
428
        call    extfsWriteBlock
490
        pop     ebx
-
 
491
        jc      .fail
429
        jc      .fail
492
        pop     eax
430
        pop     eax
493
        mul     [ebp+EXTFS.superblock.blocksPerGroup+ebx*8]
431
        mul     [ebp+EXTFS.superblock.inodesPerGroup]
494
        add     eax, ecx
432
        add     eax, ecx
495
        dec     [ebp+EXTFS.superblock.blocksFree+ebx*4]
433
        dec     [ebp+EXTFS.superblock.inodesFree]
496
        mov     ebx, eax
434
        mov     ebx, eax
497
        pop     eax
435
        pop     eax
498
        xor     eax, eax
436
        xor     eax, eax
499
@@:
437
@@:
500
        pop     edi esi edx ecx
438
        pop     edi esi edx ecx
Line 509... Line 447...
509
        jmp     esi
447
        jmp     esi
Line 510... Line 448...
510
 
448
 
511
.forward:
449
.forward:
512
        inc     dword[esp]
450
        inc     dword[esp]
513
        mov     eax, [esp]
451
        mov     eax, [esp]
514
        mul     [ebp+EXTFS.superblock.blocksPerGroup+ebx*8]
-
 
515
        neg     ebx
452
        mul     [ebp+EXTFS.superblock.inodesPerGroup]
516
        cmp     eax, [ebp+EXTFS.superblock.blocksTotal+ebx*4]
453
        cmp     eax, [ebp+EXTFS.superblock.inodesTotal]
517
        ja      @f
-
 
518
        neg     ebx
454
        ja      @f
519
        mov     eax, [esp]
455
        mov     eax, [esp]
Line 520... Line 456...
520
        jmp     .test_block_group
456
        jmp     .test_block_group
521
 
-
 
522
@@:
457
 
523
        neg     ebx
458
@@:
524
        mov     eax, [esp+4]
459
        mov     eax, [esp+4]
525
        mov     [esp], eax
460
        mov     [esp], eax
526
        mov     esi, .backward
461
        mov     esi, .backward
527
.backward:
462
.backward:
528
        sub     dword[esp], 1
463
        sub     dword[esp], 1
529
        jc      .fail
464
        jc      .fail
Line -... Line 465...
-
 
465
        mov     eax, [esp]
-
 
466
        jmp     .test_block_group
-
 
467
 
-
 
468
extfsExtentAlloc:
-
 
469
;   in:
-
 
470
; eax = parent inode number
-
 
471
; ecx = blocks max
-
 
472
;   out:
-
 
473
; ebx = first block number
-
 
474
; ecx = blocks allocated
-
 
475
        push    edx esi edi ecx
-
 
476
        dec     eax
-
 
477
        xor     edx, edx
-
 
478
        div     [ebp+EXTFS.superblock.inodesPerGroup]
-
 
479
        push    eax eax
-
 
480
.test_block_group:
-
 
481
        call    extfsReadDescriptor
-
 
482
        jc      .fail
-
 
483
        dec     [eax+BGDESCR.blocksFree]
-
 
484
        js      .next
-
 
485
        mov     eax, [eax+BGDESCR.blockBitmap]
-
 
486
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
487
        mov     edx, eax
-
 
488
        mov     edi, ebx
-
 
489
        call    extfsReadBlock
-
 
490
        jc      .fail
-
 
491
        mov     ecx, [ebp+EXTFS.superblock.blocksPerGroup]
-
 
492
        shr     ecx, 5
-
 
493
        or      eax, -1
-
 
494
        repz scasd
-
 
495
        jz      .next
-
 
496
        mov     esi, edi
-
 
497
        sub     esi, 4
-
 
498
        push    edx ecx
-
 
499
        mov     eax, [esi]
-
 
500
        not     eax
-
 
501
        bsf     ecx, eax
-
 
502
        not     eax
-
 
503
        shr     eax, cl
-
 
504
        shl     eax, cl
-
 
505
        mov     ebx, 32
-
 
506
        bsf     ebx, eax
-
 
507
        sub     ebx, ecx
-
 
508
        mov     eax, [esp+16]
-
 
509
        cmp     ebx, eax
-
 
510
        jc      @f
-
 
511
        mov     ebx, eax
-
 
512
@@:
-
 
513
        xchg    ebx, ecx
-
 
514
        or      eax, -1
-
 
515
        shl     eax, cl
-
 
516
        not     eax
-
 
517
        xchg    ebx, ecx
-
 
518
        shl     eax, cl
-
 
519
        or      [esi], eax
-
 
520
        sub     esi, [ebp+EXTFS.tempBlockBuffer]
-
 
521
        shl     esi, 3
-
 
522
        add     esi, ecx
-
 
523
        mov     eax, [esp+16]
-
 
524
        sub     eax, ebx
-
 
525
        mov     [esp+16], ebx
-
 
526
        add     ebx, ecx
-
 
527
        pop     ecx
-
 
528
        test    eax, eax
-
 
529
        jz      .done
-
 
530
        cmp     ebx, 32
-
 
531
        jnz     .done
-
 
532
        jecxz   .done
-
 
533
        mov     ebx, eax
-
 
534
        shr     eax, 5
-
 
535
        inc     eax
-
 
536
        and     ebx, 31
-
 
537
        cmp     ecx, eax
-
 
538
        jnc     @f
-
 
539
        mov     eax, ecx
-
 
540
        mov     bl, 32
-
 
541
@@:
-
 
542
        mov     ecx, eax
-
 
543
        shl     eax, 5
-
 
544
        add     [esp+12], eax
-
 
545
        xor     eax, eax
-
 
546
        push    edi
-
 
547
        repz scasd
-
 
548
        jz      @f
-
 
549
        mov     eax, [edi-4]
-
 
550
        bsf     eax, eax
-
 
551
        xchg    eax, ebx
-
 
552
        test    ecx, ecx
-
 
553
        jnz     @f
-
 
554
        cmp     ebx, eax
-
 
555
        jc      @f
-
 
556
        mov     ebx, eax
-
 
557
@@:
-
 
558
        inc     ecx
-
 
559
        shl     ecx, 5
-
 
560
        sub     ecx, ebx
-
 
561
        sub     [esp+16], ecx
-
 
562
        mov     ecx, edi
-
 
563
        pop     edi
-
 
564
        sub     ecx, edi
-
 
565
        shr     ecx, 2
-
 
566
        dec     ecx
-
 
567
        or      eax, -1
-
 
568
        rep stosd
-
 
569
        mov     ecx, ebx
-
 
570
        shl     eax, cl
-
 
571
        not     eax
-
 
572
        or      [edi], eax
-
 
573
.done:
-
 
574
        pop     eax
-
 
575
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
576
        call    extfsWriteBlock
-
 
577
        jc      .fail
-
 
578
        mov     eax, [esp]
-
 
579
        call    extfsReadDescriptor
-
 
580
        jc      .fail
-
 
581
        mov     ecx, [esp+8]
-
 
582
        sub     [eax+BGDESCR.blocksFree], cx
-
 
583
        jc      .fail
-
 
584
        sub     [ebp+EXTFS.superblock.blocksFree], ecx
-
 
585
        mov     eax, [esp]
-
 
586
        call    extfsWriteDescriptor
-
 
587
        jc      .fail
-
 
588
        pop     eax ebx
-
 
589
        mul     [ebp+EXTFS.superblock.blocksPerGroup]
-
 
590
        mov     ebx, eax
-
 
591
        add     ebx, esi
-
 
592
        xor     eax, eax
-
 
593
        pop     ecx
-
 
594
.ret:
-
 
595
        pop     edi esi edx
-
 
596
        ret
-
 
597
 
-
 
598
.fail:
-
 
599
        pop     eax eax
-
 
600
        movi    eax, ERROR_DEVICE
-
 
601
        xor     ecx, ecx
-
 
602
        jmp     .ret
-
 
603
 
-
 
604
.next:      ; search forward, then backward
-
 
605
        pop     eax
-
 
606
        cmp     eax, [esp]
-
 
607
        jc      .backward
-
 
608
        inc     eax
-
 
609
        push    eax
-
 
610
        mul     [ebp+EXTFS.superblock.blocksPerGroup]
-
 
611
        cmp     eax, [ebp+EXTFS.superblock.blocksTotal]
-
 
612
        ja      @f
-
 
613
        mov     eax, [esp]
-
 
614
        jmp     .test_block_group
-
 
615
 
-
 
616
@@:
-
 
617
        pop     eax eax
-
 
618
        push    eax
-
 
619
.backward:
-
 
620
        dec     eax
-
 
621
        push    eax
-
 
622
        jns     .test_block_group
-
 
623
        pop     eax eax
-
 
624
        movi    eax, ERROR_DISK_FULL
530
        mov     eax, [esp]
625
        xor     ecx, ecx
531
        jmp     .test_block_group
626
        jmp     .ret
532
 
627
 
533
extfsGetFileBlock:
628
extfsGetFileBlock:
534
; in: esi -> inode, ecx = file block number
629
; in: esi -> inode, ecx = file block number
Line 664... Line 759...
664
        jc      .fail2
759
        jc      .fail2
665
        mov     ecx, [ebx+edx*4]
760
        mov     ecx, [ebx+edx*4]
666
        pop     ebx edx
761
        pop     ebx edx
667
        ret
762
        ret
Line 668... Line -...
668
 
-
 
669
extfsSetFileBlock:
-
 
670
;   in:
-
 
671
; ecx = file block number
-
 
672
; edi = block number
-
 
673
; edx = inode number
-
 
674
; esi -> inode
-
 
675
        push    ebx ecx edx
-
 
676
        cmp     ecx, 12
-
 
677
        jb      .direct_block
-
 
678
        sub     ecx, 12
-
 
679
        cmp     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
680
        jb      .indirect_block
-
 
681
        sub     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
682
        cmp     ecx, [ebp+EXTFS.dwordsPerBranch]
-
 
683
        jb      .double_indirect_block
-
 
684
; triple indirect blocks
-
 
685
        sub     ecx, [ebp+EXTFS.dwordsPerBranch]
-
 
686
        mov     eax, [esi+INODE.tripleAddress]
-
 
687
        test    eax, eax
-
 
688
        jnz     @f
-
 
689
        mov     eax, edx
-
 
690
        call    inodeBlockAlloc
-
 
691
        jc      .ret
-
 
692
        mov     [esi+INODE.tripleAddress], ebx
-
 
693
        mov     eax, ebx
-
 
694
@@:
-
 
695
        push    eax
-
 
696
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
697
        call    extfsReadBlock
-
 
698
        jc      .fail_alloc_4
-
 
699
        xor     edx, edx
-
 
700
        mov     eax, ecx
-
 
701
        div     [ebp+EXTFS.dwordsPerBranch]
-
 
702
; eax = number in triply-indirect block, edx = number in branch
-
 
703
        lea     ecx, [ebx+eax*4]
-
 
704
        mov     eax, [ebx+eax*4]
-
 
705
        test    eax, eax
-
 
706
        jnz     @f
-
 
707
        mov     eax, [esp+4]
-
 
708
        call    inodeBlockAlloc
-
 
709
        jc      .fail_alloc_4
-
 
710
        mov     [ecx], ebx
-
 
711
        mov     eax, [esp]
-
 
712
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
713
        call    extfsWriteBlock
-
 
714
        jc      .fail_alloc_4
-
 
715
        mov     eax, [ecx]
-
 
716
@@:
-
 
717
        mov     [esp], eax
-
 
718
        call    extfsReadBlock
-
 
719
        jc      .fail_alloc_4
-
 
720
        mov     eax, edx
-
 
721
        jmp     @f
-
 
722
 
-
 
723
.double_indirect_block:
-
 
724
        mov     eax, [esi+INODE.doubleAddress]
-
 
725
        test    eax, eax
-
 
726
        jnz     .double_indirect_present
-
 
727
        mov     eax, edx
-
 
728
        call    inodeBlockAlloc
-
 
729
        jc      .ret
-
 
730
        mov     [esi+INODE.doubleAddress], ebx
-
 
731
        mov     eax, ebx
-
 
732
.double_indirect_present:
-
 
733
        push    eax
-
 
734
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
735
        call    extfsReadBlock
-
 
736
        jc      .fail_alloc_4
-
 
737
        mov     eax, ecx
-
 
738
@@:
-
 
739
        xor     edx, edx
-
 
740
        div     [ebp+EXTFS.dwordsPerBlock]
-
 
741
; eax = number in doubly-indirect block, edx = number in indirect block
-
 
742
        lea     ecx, [ebx+edx*4]
-
 
743
        push    ecx
-
 
744
        lea     ecx, [ebx+eax*4]
-
 
745
        cmp     dword[ecx], 0
-
 
746
        jne     @f
-
 
747
        mov     eax, [esp+8]
-
 
748
        call    inodeBlockAlloc
-
 
749
        jc      .fail_alloc_8
-
 
750
        mov     [ecx], ebx
-
 
751
        mov     eax, [esp+4]
-
 
752
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
753
        call    extfsWriteBlock
-
 
754
        jc      .fail_alloc_8
-
 
755
@@:
-
 
756
        mov     eax, [ecx]
-
 
757
        push    eax
-
 
758
        call    extfsReadBlock
-
 
759
        jc      .fail_alloc_12
-
 
760
        pop     eax ecx edx
-
 
761
        mov     [ecx], edi
-
 
762
        call    extfsWriteBlock
-
 
763
        jmp     .ret
-
 
764
 
-
 
765
.indirect_block:
-
 
766
        mov     eax, [esi+INODE.addressBlock]
-
 
767
        test    eax, eax
-
 
768
        jnz     @f
-
 
769
        mov     eax, edx
-
 
770
        call    inodeBlockAlloc
-
 
771
        jc      .ret
-
 
772
        mov     [esi+INODE.addressBlock], ebx
-
 
773
        mov     eax, ebx
-
 
774
@@:
-
 
775
        push    eax
-
 
776
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
777
        call    extfsReadBlock
-
 
778
        jc      .fail_alloc_4
-
 
779
        mov     [ebx+ecx*4], edi
-
 
780
        pop     eax
-
 
781
        call    extfsWriteBlock
-
 
782
        jmp     .ret
-
 
783
 
-
 
784
.direct_block:
-
 
785
        mov     [esi+INODE.blockNumbers+ecx*4], edi
-
 
786
        xor     eax, eax
-
 
787
.ret:
-
 
788
        pop     edx ecx ebx
-
 
789
        ret
-
 
790
 
-
 
791
.fail_alloc_12:
-
 
792
        pop     ebx
-
 
793
.fail_alloc_8:
-
 
794
        pop     ebx
-
 
795
.fail_alloc_4:
-
 
796
        pop     ebx
-
 
797
        jmp     .ret
-
 
798
 
-
 
799
extfsFileBlockAlloc:
-
 
800
;   in:
-
 
801
; esi -> inode
-
 
802
; edx = inode number
-
 
803
; eax = file block number
-
 
804
;   out:
-
 
805
; edi = allocated block number
-
 
806
        push    ebx ecx
-
 
807
        mov     ecx, eax
-
 
808
        mov     eax, edx
-
 
809
        xor     ebx, ebx
-
 
810
        call    extfsResourceAlloc
-
 
811
        jc      @f
-
 
812
        mov     edi, ebx
-
 
813
        call    extfsSetFileBlock
-
 
814
        jc      @f
-
 
815
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
-
 
816
        add     [esi+INODE.sectorsUsed], eax
-
 
817
        xor     eax, eax
-
 
818
@@:
-
 
819
        pop     ecx ebx
-
 
820
        ret
-
 
821
 
763
 
822
extfsReadFileBlock:
764
extfsReadFileBlock:
823
;   in:
765
;   in:
824
; eax = file block number
766
; eax = file block number
825
; [ebp+EXTFS.inodeBuffer] = inode
767
; [ebp+EXTFS.inodeBuffer] = inode
Line 941... Line 883...
941
        xor     eax, eax
883
        xor     eax, eax
942
@@:
884
@@:
943
        pop     ebx ecx esi edi edx
885
        pop     ebx ecx esi edi edx
944
        ret
886
        ret
Line -... Line 887...
-
 
887
 
-
 
888
indirectBlockAlloc:
-
 
889
;   in:
-
 
890
; edi -> indirect block number
-
 
891
; ebx = starting extent block
-
 
892
; ecx = extent size
-
 
893
; edx = starting file block
-
 
894
        mov     eax, [edi]
-
 
895
        test    eax, eax
-
 
896
        jz      .newBlock
-
 
897
        push    edi ebx ecx
-
 
898
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
899
        call    extfsReadBlock
-
 
900
        jc      .err2
-
 
901
        lea     edi, [ebx+edx*4]
-
 
902
        test    edx, edx
-
 
903
        jz      @f
-
 
904
        cmp     dword[edi-4], 0
-
 
905
        jnz     @f
-
 
906
        pop     ecx ebx edi
-
 
907
.err:
-
 
908
        mov     al, ERROR_FS_FAIL
-
 
909
        stc
-
 
910
        ret
-
 
911
 
-
 
912
.err2:
-
 
913
        pop     ecx ebx edi
-
 
914
        ret
-
 
915
 
-
 
916
.newBlock:
-
 
917
        test    edx, edx
-
 
918
        jnz     .err
-
 
919
        mov     [edi], ebx
-
 
920
        inc     ebx
-
 
921
        dec     ecx
-
 
922
        push    edi ebx ecx
-
 
923
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
924
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
-
 
925
        push    edi
-
 
926
        rep stosd
-
 
927
        pop     edi
-
 
928
@@:
-
 
929
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
930
        sub     ecx, edx
-
 
931
        pop     ebx eax
-
 
932
        sub     ebx, ecx
-
 
933
        jnc     @f
-
 
934
        add     ecx, ebx
-
 
935
        xor     ebx, ebx
-
 
936
@@:
-
 
937
        jecxz   .done
-
 
938
        add     edx, ecx
-
 
939
@@:
-
 
940
        stosd
-
 
941
        inc     eax
-
 
942
        loop    @b
-
 
943
.done:
-
 
944
        pop     edi
-
 
945
        push    eax ebx
-
 
946
        mov     eax, [edi]
-
 
947
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
948
        call    extfsWriteBlock
-
 
949
        pop     ecx ebx
-
 
950
        ret
-
 
951
 
-
 
952
doublyIndirectBlockAlloc:
-
 
953
;   in:
-
 
954
; edi -> indirect block number
-
 
955
; edx = starting file block
-
 
956
; ebx = starting extent block
-
 
957
; ecx = extent size
-
 
958
; [esp+4] = rest of size
-
 
959
; [esp+8] = parent inode number
-
 
960
        mov     eax, [edi]
-
 
961
        test    eax, eax
-
 
962
        jz      .newBlock
-
 
963
        push    edi ecx ebx
-
 
964
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
965
        call    extfsReadBlock
-
 
966
        jc      .err2
-
 
967
        mov     eax, edx
-
 
968
        xor     edx, edx
-
 
969
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
970
        div     ecx
-
 
971
        lea     edi, [ebx+eax*4]
-
 
972
        pop     ebx
-
 
973
        test    eax, eax
-
 
974
        jz      @f
-
 
975
        cmp     dword[edi-4], 0
-
 
976
        jnz     @f
-
 
977
        pop     ecx edi
-
 
978
.err:
-
 
979
        mov     al, ERROR_FS_FAIL
-
 
980
        stc
-
 
981
        ret
-
 
982
 
-
 
983
.err2:
-
 
984
        pop     ebx ecx edi
-
 
985
        ret
-
 
986
 
-
 
987
.newBlock:
-
 
988
        test    edx, edx
-
 
989
        jnz     .err
-
 
990
        mov     [edi], ebx
-
 
991
        inc     ebx
-
 
992
        dec     ecx
-
 
993
        inc     dword[esp+4]
-
 
994
        push    edi ecx
-
 
995
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
996
        mov     edi, [ebp+EXTFS.mainBlockBuffer]
-
 
997
        push    ecx edi
-
 
998
        rep stosd
-
 
999
        pop     edi ecx
-
 
1000
@@:
-
 
1001
        sub     ecx, eax
-
 
1002
        xchg    [esp], ecx
-
 
1003
.loop:
-
 
1004
        cmp     dword[edi], 0
-
 
1005
        jnz     @f
-
 
1006
        inc     dword[esp+12]
-
 
1007
@@:
-
 
1008
        jecxz   .extentAlloc
-
 
1009
        call    indirectBlockAlloc
-
 
1010
        jc      .end
-
 
1011
        cmp     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1012
        jnz     @b
-
 
1013
        add     edi, 4
-
 
1014
        xor     edx, edx
-
 
1015
        dec     dword[esp]
-
 
1016
        jnz     .loop
-
 
1017
.end:
-
 
1018
        pop     edi edi
-
 
1019
        push    ebx eax
-
 
1020
        mov     eax, [edi]
-
 
1021
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
1022
        call    extfsWriteBlock
-
 
1023
        pop     ebx
-
 
1024
        add     eax, ebx
-
 
1025
        xor     ebx, ebx
-
 
1026
        cmp     ebx, eax
-
 
1027
        pop     ebx
-
 
1028
        ret
-
 
1029
 
-
 
1030
.extentAlloc:
-
 
1031
        mov     ecx, [esp+12]
-
 
1032
        xor     eax, eax
-
 
1033
        jecxz   .end
-
 
1034
        mov     eax, [esp+16]
-
 
1035
        call    extfsExtentAlloc
-
 
1036
        jc      .end
-
 
1037
        sub     [esp+12], ecx
-
 
1038
        mov     eax, ecx
-
 
1039
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1040
        add     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
-
 
1041
        jmp     @b
945
 
1042
 
946
extfsExtendFile:
1043
extfsExtendFile:
947
;   in:
1044
;   in:
948
; [ebp+EXTFS.inodeBuffer] = inode
1045
; [ebp+EXTFS.inodeBuffer] = inode
949
; eax = inode number
1046
; eax = inode number
950
; ecx = new size
1047
; ecx = new size
951
        push    ebx ecx edx esi edi eax
1048
        push    ebx ecx edx esi edi eax
952
        lea     esi, [ebp+EXTFS.inodeBuffer]
-
 
953
        mov     eax, [esi+INODE.fileSize]
-
 
954
        sub     ecx, eax
-
 
955
        jna     .ret
-
 
956
        mov     ebx, eax
-
 
957
        xor     edx, edx
-
 
958
        div     [ebp+EXTFS.bytesPerBlock]
-
 
959
        test    edx, edx
-
 
960
        jz      .start_aligned
-
 
961
        mov     eax, [ebp+EXTFS.bytesPerBlock]
-
 
962
        sub     eax, edx
-
 
963
        cmp     eax, ecx
-
 
964
        jbe     @f
1049
        lea     esi, [ebp+EXTFS.inodeBuffer]
-
 
1050
        mov     eax, ecx
-
 
1051
        mov     edx, [esi+INODE.fileSize]
-
 
1052
        cmp     edx, eax
-
 
1053
        jnc     .ret
-
 
1054
        mov     [esi+INODE.fileSize], eax
-
 
1055
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
-
 
1056
        add     ecx, 9
-
 
1057
        dec     eax
-
 
1058
        shr     eax, cl
-
 
1059
        inc     eax
-
 
1060
        sub     edx, 1
-
 
1061
        jc      @f
965
        mov     eax, ecx
1062
        shr     edx, cl
-
 
1063
@@:
966
@@:
1064
        inc     edx
-
 
1065
        sub     eax, edx
-
 
1066
        jz      .ret
-
 
1067
        push    eax
-
 
1068
@@:
-
 
1069
        mov     ecx, [esp]
967
        add     ebx, eax
1070
        mov     eax, [esp+4]
968
        sub     ecx, eax
1071
        test    ecx, ecx
-
 
1072
        jz      .done
-
 
1073
        call    extfsExtentAlloc
-
 
1074
        jc      .errDone
-
 
1075
        sub     [esp], ecx
-
 
1076
        mov     eax, ecx
-
 
1077
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1078
        add     [esi+INODE.sectorsUsed], eax
-
 
1079
        cmp     edx, 12
-
 
1080
        jc      .directBlocks
-
 
1081
        sub     edx, 12
-
 
1082
        cmp     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1083
        jc      .indirectBlocks
-
 
1084
        sub     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1085
        cmp     edx, [ebp+EXTFS.dwordsPerBranch]
-
 
1086
        jc      .doublyIndirectBlock
-
 
1087
        sub     edx, [ebp+EXTFS.dwordsPerBranch]
-
 
1088
        jmp     .triplyIndirectBlock
-
 
1089
 
-
 
1090
.newExtent:
-
 
1091
        jmp     @b
969
        jz      .done
1092
 
-
 
1093
.directBlocks:
-
 
1094
        lea     edi, [esi+INODE.blockNumbers+edx*4]
-
 
1095
        test    edx, edx
-
 
1096
        jz      @f
-
 
1097
        cmp     dword[edi-4], 0
-
 
1098
        jz      .errDone
970
.start_aligned:
1099
@@:
-
 
1100
        mov     eax, ebx
-
 
1101
        mov     ebx, ecx
-
 
1102
        mov     ecx, 12
-
 
1103
        sub     ecx, edx
-
 
1104
        sub     ebx, ecx
-
 
1105
        jnc     @f
-
 
1106
        add     ecx, ebx
-
 
1107
        xor     ebx, ebx
-
 
1108
@@:
-
 
1109
        add     edx, ecx
-
 
1110
@@:
-
 
1111
        stosd
-
 
1112
        inc     eax
-
 
1113
        loop    @b
-
 
1114
        mov     ecx, ebx
-
 
1115
        mov     ebx, eax
971
        mov     eax, ebx
1116
        jecxz   .newExtent
-
 
1117
        xor     edx, edx
-
 
1118
.indirectBlocks:
-
 
1119
        lea     edi, [esi+INODE.addressBlock]
-
 
1120
        cmp     dword[edi], 0
-
 
1121
        jnz     @f
-
 
1122
        inc     dword[esp]
-
 
1123
@@:
-
 
1124
        call    indirectBlockAlloc
-
 
1125
        jc      .errDone
-
 
1126
        add     edx, 12
-
 
1127
        jecxz   .newExtent
-
 
1128
        xor     edx, edx
-
 
1129
.doublyIndirectBlock:
-
 
1130
        lea     edi, [esi+INODE.doubleAddress]
-
 
1131
        call    doublyIndirectBlockAlloc
-
 
1132
        jc      .errDone
972
        xor     edx, edx
1133
        mov     edx, [ebp+EXTFS.dwordsPerBranch]
-
 
1134
        add     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1135
        add     edx, 12
-
 
1136
        jecxz   .newExtent
-
 
1137
        xor     edx, edx
-
 
1138
.triplyIndirectBlock:
-
 
1139
        push    ecx ebx edx
-
 
1140
        stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
-
 
1141
        pop     edx
-
 
1142
        mov     esi, eax
-
 
1143
        mov     eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
-
 
1144
        test    eax, eax
973
        div     [ebp+EXTFS.bytesPerBlock]
1145
        jz      .newBlock
974
        mov     edx, [esp]
1146
        mov     ebx, esi
-
 
1147
        call    extfsReadBlock
975
        call    extfsFileBlockAlloc
1148
        pop     ebx ecx
-
 
1149
        jc      .errFree
-
 
1150
        mov     eax, edx
976
        jc      .error
1151
        xor     edx, edx
-
 
1152
        div     [ebp+EXTFS.dwordsPerBranch]
977
        mov     eax, [ebp+EXTFS.bytesPerBlock]
1153
        lea     edi, [esi+eax*4]
-
 
1154
        test    eax, eax
-
 
1155
        jz      @f
-
 
1156
        cmp     dword[edi-4], 0
-
 
1157
        jnz     @f
-
 
1158
        mov     al, ERROR_FS_FAIL
978
        add     ebx, eax
1159
.errFree:
-
 
1160
        push    ecx eax
979
        sub     ecx, eax
1161
        stdcall kernel_free, esi
-
 
1162
        pop     eax ecx
-
 
1163
.errDone:
-
 
1164
        imul    ecx, [ebp+EXTFS.sectorsPerBlock]
-
 
1165
        sub     [ebp+EXTFS.inodeBuffer.sectorsUsed], ecx
-
 
1166
        pop     ebx
980
        ja      .start_aligned
1167
        imul    ebx, [ebp+EXTFS.sectorsPerBlock]
-
 
1168
        add     ebx, ecx
-
 
1169
        shl     ebx, 9
-
 
1170
        sub     [ebp+EXTFS.inodeBuffer.fileSize], ebx
-
 
1171
        stc
-
 
1172
        jmp     .ret
-
 
1173
 
-
 
1174
.newBlock:
-
 
1175
        pop     ebx ecx
-
 
1176
        mov     al, ERROR_FS_FAIL
-
 
1177
        test    edx, edx
-
 
1178
        jnz     .errFree
-
 
1179
        mov     [ebp+EXTFS.inodeBuffer.tripleAddress], ebx
-
 
1180
        inc     ebx
-
 
1181
        dec     ecx
-
 
1182
        inc     dword[esp]
-
 
1183
        push    ecx
-
 
1184
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
1185
        mov     edi, esi
-
 
1186
        xor     eax, eax
-
 
1187
        rep stosd
-
 
1188
        mov     edi, esi
-
 
1189
        pop     ecx
-
 
1190
@@:
-
 
1191
        jecxz   .extentAlloc
-
 
1192
        call    doublyIndirectBlockAlloc
-
 
1193
        jc      .errSave
-
 
1194
        add     edi, 4
-
 
1195
        jmp     @b
-
 
1196
 
-
 
1197
.extentAlloc:
-
 
1198
        mov     ecx, [esp]
-
 
1199
        mov     eax, [esp+4]
-
 
1200
        jecxz   @f
-
 
1201
        call    extfsExtentAlloc
-
 
1202
        jc      .errSave
-
 
1203
        sub     [esp], ecx
-
 
1204
        mov     eax, ecx
-
 
1205
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1206
        add     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
-
 
1207
        jmp     @b
-
 
1208
 
-
 
1209
@@:
-
 
1210
        mov     eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
-
 
1211
        mov     ebx, esi
-
 
1212
        call    extfsWriteBlock
981
        add     ebx, ecx
1213
        stdcall kernel_free, esi
982
.done:
1214
.done:
983
        xor     eax, eax
-
 
984
.error:
1215
        xor     eax, eax
985
        mov     [esi+INODE.fileSize], ebx
1216
        pop     edi
986
.ret:
1217
.ret:
987
        pop     edi edi esi edx ecx ebx
1218
        pop     edi edi esi edx ecx ebx
Line -... Line 1219...
-
 
1219
        ret
-
 
1220
 
-
 
1221
.errSave:
-
 
1222
        push    eax
-
 
1223
        mov     eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
-
 
1224
        mov     ebx, esi
-
 
1225
        call    extfsWriteBlock
-
 
1226
        pop     eax
-
 
1227
        jmp     .errFree
-
 
1228
 
-
 
1229
freeIndirectBlock:
-
 
1230
; in: edi -> indirect block number, edx = starting block
-
 
1231
; out: edi = edi+4, eax=-1 -> done, eax=0 -> end
-
 
1232
        pushd   ecx 0 edi edx
-
 
1233
        mov     eax, [edi]
-
 
1234
        test    eax, eax
-
 
1235
        jz      .ret
-
 
1236
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
1237
        call    extfsReadBlock
-
 
1238
        jc      .ret
-
 
1239
        lea     edi, [ebx+edx*4]
-
 
1240
        neg     edx
-
 
1241
        add     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1242
        xor     ecx, ecx
-
 
1243
@@:
-
 
1244
        mov     eax, [edi]
-
 
1245
        test    eax, eax
-
 
1246
        jz      .end
-
 
1247
        call    extfsResourceFree
-
 
1248
        stosd
-
 
1249
        dec     edx
-
 
1250
        jnz     @b
-
 
1251
        dec     dword[esp+8]
-
 
1252
.end:
-
 
1253
        pop     edx edi
-
 
1254
        mov     eax, [edi]
-
 
1255
        test    edx, edx
-
 
1256
        jnz     @f
-
 
1257
        call    extfsResourceFree
-
 
1258
        stosd
-
 
1259
        jmp     .done
-
 
1260
 
-
 
1261
@@:
-
 
1262
        call    extfsWriteBlock
-
 
1263
        add     edi, 4
-
 
1264
.done:
-
 
1265
        pop     eax ecx
-
 
1266
        xor     edx, edx
-
 
1267
        ret
-
 
1268
 
-
 
1269
.ret:
-
 
1270
        pop     edi edi edx ecx
-
 
1271
        ret
-
 
1272
 
-
 
1273
freeDoublyIndirectBlock:
-
 
1274
; in: edi -> doubly-indirect block number, edx = starting block
-
 
1275
; out: edi = edi+4, eax=-1 -> done, eax=0 -> end
-
 
1276
        mov     eax, [edi]
-
 
1277
        test    eax, eax
-
 
1278
        jz      .ret
-
 
1279
        push    ecx eax edx
-
 
1280
        stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
-
 
1281
        mov     ebx, eax
-
 
1282
        pop     edx eax
-
 
1283
        pushd   0 ebx edx
-
 
1284
        call    extfsReadBlock
-
 
1285
        jc      .err
-
 
1286
        mov     eax, edx
-
 
1287
        xor     edx, edx
-
 
1288
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
1289
        div     ecx
-
 
1290
        sub     ecx, eax
-
 
1291
        push    edi
-
 
1292
        lea     edi, [ebx+eax*4]
-
 
1293
@@:
-
 
1294
        call    freeIndirectBlock
-
 
1295
        test    eax, eax
-
 
1296
        jz      .end
-
 
1297
        dec     ecx
-
 
1298
        jnz     @b
-
 
1299
        dec     dword[esp+12]
-
 
1300
.end:
-
 
1301
        pop     edi edx
-
 
1302
        mov     eax, [edi]
-
 
1303
        test    edx, edx
-
 
1304
        jnz     @f
-
 
1305
        xor     ecx, ecx
-
 
1306
        call    extfsResourceFree
-
 
1307
        stosd
-
 
1308
        jmp     .done
-
 
1309
 
-
 
1310
@@:
-
 
1311
        mov     ebx, [esp]
-
 
1312
        call    extfsWriteBlock
-
 
1313
        add     edi, 4
-
 
1314
        jmp     .done
-
 
1315
 
-
 
1316
.err:
-
 
1317
        mov     [esp+8], eax
-
 
1318
        pop     eax
-
 
1319
.done:
-
 
1320
        call    kernel_free
-
 
1321
        pop     eax ecx
-
 
1322
.ret:
-
 
1323
        xor     edx, edx
988
        ret
1324
        ret
989
 
1325
 
990
extfsTruncateFile:
1326
extfsTruncateFile:
991
;   in:
1327
;   in:
992
; [ebp+EXTFS.inodeBuffer] = inode
1328
; [ebp+EXTFS.inodeBuffer] = inode
993
; ecx = new size
1329
; ecx = new size
994
        push    ebx ecx edx esi edi
1330
        push    ebx ecx edx esi edi
995
        lea     esi, [ebp+EXTFS.inodeBuffer]
-
 
996
        mov     eax, [esi+INODE.fileSize]
1331
        lea     esi, [ebp+EXTFS.inodeBuffer]
-
 
1332
        cmp     ecx, [esi+INODE.fileSize]
-
 
1333
        jnc     .ret
-
 
1334
        mov     [esi+INODE.fileSize], ecx
-
 
1335
        mov     edx, ecx
-
 
1336
        jecxz   .directBlocks
-
 
1337
        dec     edx
-
 
1338
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
-
 
1339
        add     ecx, 9
-
 
1340
        shr     edx, cl
-
 
1341
        inc     edx
-
 
1342
        cmp     edx, 12
-
 
1343
        jc      .directBlocks
-
 
1344
        sub     edx, 12
-
 
1345
        cmp     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1346
        jc      .indirectBlocks
-
 
1347
        sub     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1348
        cmp     edx, [ebp+EXTFS.dwordsPerBranch]
-
 
1349
        jc      .doublyIndirectBlock
-
 
1350
        sub     edx, [ebp+EXTFS.dwordsPerBranch]
-
 
1351
        jmp     .triplyIndirectBlock
-
 
1352
 
997
        sub     ecx, eax
1353
.directBlocks:
-
 
1354
        lea     edi, [esi+INODE.blockNumbers+edx*4]
-
 
1355
        neg     edx
-
 
1356
        add     edx, 12
-
 
1357
        xor     ecx, ecx
-
 
1358
@@:
-
 
1359
        mov     eax, [edi]
-
 
1360
        test    eax, eax
-
 
1361
        jz      .ret
-
 
1362
        call    extfsResourceFree
-
 
1363
        stosd
-
 
1364
        dec     edx
-
 
1365
        jnz     @b
-
 
1366
.indirectBlocks:
-
 
1367
        lea     edi, [esi+INODE.addressBlock]
-
 
1368
        call    freeIndirectBlock
-
 
1369
        test    eax, eax
-
 
1370
        jz      .ret
-
 
1371
.doublyIndirectBlock:
-
 
1372
        lea     edi, [esi+INODE.doubleAddress]
-
 
1373
        call    freeDoublyIndirectBlock
-
 
1374
        test    eax, eax
-
 
1375
        jz      .ret
-
 
1376
.triplyIndirectBlock:
-
 
1377
        mov     eax, [esi+INODE.tripleAddress]
-
 
1378
        test    eax, eax
-
 
1379
        jz      .ret
998
        jnc     .ret
1380
        push    eax edx
-
 
1381
        stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
-
 
1382
        mov     ebx, eax
-
 
1383
        pop     edx eax
-
 
1384
        push    ebx eax edx
-
 
1385
        call    extfsReadBlock
999
        neg     ecx
1386
        jc      .err
1000
        mov     ebx, eax
1387
        mov     eax, edx
-
 
1388
        xor     edx, edx
-
 
1389
        div     [ebp+EXTFS.dwordsPerBranch]
-
 
1390
        mov     ecx, [ebp+EXTFS.dwordsPerBlock]
-
 
1391
        sub     ecx, eax
-
 
1392
        lea     edi, [ebx+eax*4]
-
 
1393
@@:
-
 
1394
        call    freeDoublyIndirectBlock
-
 
1395
        test    eax, eax
-
 
1396
        jz      .end
-
 
1397
        dec     ecx
-
 
1398
        jnz     @b
1001
        xor     edx, edx
1399
.end:
1002
        div     [ebp+EXTFS.bytesPerBlock]
1400
        pop     edx eax
1003
        test    edx, edx
-
 
1004
        jnz     @f
-
 
1005
.start_aligned:
-
 
1006
        mov     edx, [ebp+EXTFS.bytesPerBlock]
-
 
1007
        dec     eax
-
 
1008
@@:
-
 
1009
        cmp     ecx, edx
-
 
1010
        jc      .tail
-
 
1011
        push    ecx edx
-
 
1012
        mov     edi, eax
-
 
1013
        mov     ecx, eax
-
 
1014
        call    extfsGetFileBlock
-
 
1015
        jc      .error
-
 
1016
        test    ecx, ecx
-
 
1017
        jz      @f
1401
        test    edx, edx
1018
        mov     eax, ecx
1402
        jnz     @f
1019
        xor     ecx, ecx
1403
        xor     ecx, ecx
1020
        call    extfsResourceFree
1404
        call    extfsResourceFree
1021
        mov     ecx, edi
-
 
1022
        xor     edi, edi
-
 
1023
        movi    edx, ROOT_INODE
-
 
1024
        call    extfsSetFileBlock
-
 
-
 
1405
        mov     [esi+INODE.tripleAddress], eax
1025
        mov     eax, [ebp+EXTFS.sectorsPerBlock]
1406
        jmp     .done
1026
        sub     [esi+INODE.sectorsUsed], eax
-
 
1027
@@:
1407
 
1028
        pop     edx ecx
1408
@@:
1029
        sub     ebx, edx
1409
        mov     ebx, [esp]
1030
        sub     ecx, edx
-
 
1031
        jz      .done
-
 
1032
        mov     eax, ebx
-
 
1033
        xor     edx, edx
-
 
Line 1034... Line 1410...
1034
        div     [ebp+EXTFS.bytesPerBlock]
1410
        call    extfsWriteBlock
1035
        jmp     .start_aligned
1411
        jmp     .done
1036
 
1412
 
1037
.tail:      ; handle the remaining bytes
1413
.err:
1038
        sub     ebx, ecx
-
 
1039
.done:
-
 
1040
        xor     eax, eax
1414
        pop     eax eax
1041
@@:
1415
.done:
1042
        mov     [esi+INODE.fileSize], ebx
1416
        call    kernel_free
Line 1043... Line -...
1043
.ret:
-
 
1044
        pop     edi esi edx ecx ebx
-
 
1045
        ret
-
 
1046
 
-
 
1047
.error:
-
 
1048
        pop     edx ecx
1417
.ret:
1049
        jmp     @b
1418
        pop     edi esi edx ecx ebx
1050
 
1419
        ret
1051
 
1420
 
1052
linkInode:
1421
linkInode:
Line 1063... Line 1432...
1063
        lea     esi, [ebp+EXTFS.inodeBuffer]
1432
        lea     esi, [ebp+EXTFS.inodeBuffer]
1064
        mov     ebx, esi
1433
        mov     ebx, esi
1065
        call    readInode
1434
        call    readInode
1066
        jc      .error_inode_read
1435
        jc      .error_inode_read
1067
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
1436
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
-
 
1437
        add     ecx, 9
1068
        mov     eax, [esi+INODE.sectorsUsed]
1438
        mov     eax, [esi+INODE.fileSize]
1069
        shr     eax, cl
1439
        shr     eax, cl
1070
        xor     ecx, ecx
1440
        xor     ecx, ecx
1071
.searchBlock:
1441
.searchBlock:
1072
        push    eax     ; blocks total
1442
        push    eax     ; blocks total
1073
        push    ecx     ; current file block number
1443
        push    ecx     ; current file block number
Line 1114... Line 1484...
1114
        jb      .searchSpace
1484
        jb      .searchSpace
1115
        pop     ecx ecx eax
1485
        pop     ecx ecx eax
1116
        inc     ecx
1486
        inc     ecx
1117
        jmp     .searchBlock
1487
        jmp     .searchBlock
Line -... Line 1488...
-
 
1488
 
-
 
1489
.alloc_block:
-
 
1490
        mov     ecx, [esi+INODE.fileSize]
-
 
1491
        add     ecx, [ebp+EXTFS.bytesPerBlock]
-
 
1492
        mov     eax, [esp+24]
-
 
1493
        call    extfsExtendFile
-
 
1494
        jc      .error_get_inode_block
-
 
1495
        mov     eax, [esp+24]
-
 
1496
        mov     ebx, esi
-
 
1497
        call    writeInode
-
 
1498
        jc      .error_get_inode_block
-
 
1499
        jmp     @f
1118
 
1500
 
1119
.zeroLength:
1501
.zeroLength:
1120
        mov     [edi+DIRENTRY.entryLength], cx
1502
        mov     [edi+DIRENTRY.entryLength], cx
1121
        mov     eax, edx
1503
        mov     eax, edx
1122
        sub     eax, edi
1504
        sub     eax, edi
Line 1128... Line 1510...
1128
        pop     eax
1510
        pop     eax
1129
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1511
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1130
        call    extfsWriteBlock
1512
        call    extfsWriteBlock
1131
        jc      .error_get_inode_block
1513
        jc      .error_get_inode_block
1132
        inc     dword[esp]
1514
        inc     dword[esp]
-
 
1515
@@:
1133
        mov     ecx, [esp]
1516
        mov     ecx, [esp]
1134
        call    extfsGetFileBlock
1517
        call    extfsGetFileBlock
1135
        jc      .error_get_inode_block
1518
        jc      .error_get_inode_block
1136
        test    ecx, ecx
1519
        test    ecx, ecx
1137
        jz      .alloc_block
1520
        jz      .alloc_block
1138
        push    ecx
1521
        push    ecx
1139
        jmp     .prepare_block
-
 
1140
 
-
 
1141
.alloc_block:
-
 
1142
        mov     eax, [esp]
-
 
1143
        mov     edx, [esp+24]
-
 
1144
        call    extfsFileBlockAlloc
-
 
1145
        jc      .error_get_inode_block
-
 
1146
        mov     eax, [ebp+EXTFS.bytesPerBlock]
-
 
1147
        add     [esi+INODE.fileSize], eax
-
 
1148
        mov     eax, [esp+24]
-
 
1149
        mov     ebx, esi
-
 
1150
        call    writeInode
-
 
1151
        jc      .error_get_inode_block
-
 
1152
        push    edi     ; save the block we just allocated
-
 
1153
.prepare_block:
-
 
1154
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
1522
        mov     edi, [ebp+EXTFS.tempBlockBuffer]
1155
        mov     eax, [ebp+EXTFS.bytesPerBlock]
1523
        mov     eax, [ebp+EXTFS.bytesPerBlock]
1156
        mov     [edi+DIRENTRY.entryLength], ax
1524
        mov     [edi+DIRENTRY.entryLength], ax
1157
.found:
1525
.found:
1158
        pop     edx ecx ecx ecx ebx esi
1526
        pop     edx ecx ecx ecx ebx esi
Line 1911... Line 2279...
1911
@@:
2279
@@:
1912
        mov     eax, [esp]
2280
        mov     eax, [esp]
1913
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2281
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1914
        call    readInode
2282
        call    readInode
1915
        jc      .error_stack4_eax
2283
        jc      .error_stack4_eax
1916
; free file's data
-
 
1917
        lea     esi, [ebp+EXTFS.inodeBuffer]
-
 
1918
        xor     ecx, ecx
-
 
1919
@@:
-
 
1920
        push    ecx
-
 
1921
        call    extfsGetFileBlock
-
 
1922
        jc      .error_stack8_eax
-
 
1923
        mov     eax, ecx
-
 
1924
        test    eax, eax
-
 
1925
        jz      @f
-
 
1926
        xor     ecx, ecx
-
 
1927
        call    extfsResourceFree
-
 
1928
        pop     ecx
-
 
1929
        inc     ecx
-
 
1930
        jmp     @b
-
 
1931
 
-
 
1932
@@: ; free indirect blocks
-
 
1933
        pop     ecx
-
 
1934
        push    edx
-
 
1935
        lea     edi, [ebp+EXTFS.inodeBuffer]
-
 
1936
        mov     eax, [edi+INODE.addressBlock]
-
 
1937
        test    eax, eax
-
 
1938
        jz      .success
-
 
1939
        xor     ecx, ecx
-
 
1940
        call    extfsResourceFree
-
 
1941
        mov     eax, [edi+INODE.doubleAddress]
-
 
1942
        call    freeDoublyIndirectBlock
-
 
1943
        cmp     eax, 1
-
 
1944
        je      .success
-
 
1945
        mov     eax, [edi+INODE.tripleAddress]
-
 
1946
        test    eax, eax
-
 
1947
        jz      .success
-
 
1948
        xor     edx, edx
-
 
1949
        mov     ecx, eax
-
 
1950
@@:
-
 
1951
        mov     eax, ecx
-
 
1952
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
-
 
1953
        call    extfsReadBlock
-
 
1954
        jc      .error_stack8_eax
-
 
1955
        mov     eax, [ebx+edx]
-
 
1956
        test    eax, eax
-
 
1957
        jz      @f
-
 
1958
        push    ecx edx
-
 
1959
        call    freeDoublyIndirectBlock
-
 
1960
        pop     edx ecx
-
 
1961
        cmp     eax, 1
-
 
1962
        je      @f
-
 
1963
        add     edx, 4
-
 
1964
        cmp     edx, [ebp+EXTFS.bytesPerBlock]
-
 
1965
        jb      @b
-
 
1966
@@:
-
 
1967
        mov     eax, ecx
-
 
1968
        xor     ecx, ecx
2284
        xor     ecx, ecx
1969
        call    extfsResourceFree
2285
        call    extfsTruncateFile   ; free file's data
1970
.success:   ; clear the inode, and add deletion time
-
 
1971
        xor     eax, eax
2286
        xor     eax, eax
1972
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2287
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
1973
        rep stosb
2288
        rep stosb
1974
        lea     edi, [ebp+EXTFS.inodeBuffer]
2289
        lea     edi, [ebp+EXTFS.inodeBuffer]
-
 
2290
        push    edx
1975
        call    fsGetTime
2291
        call    fsGetTime
1976
        pop     edx
2292
        pop     edx
1977
        add     eax, 978307200
2293
        add     eax, 978307200
1978
        mov     [edi+INODE.deletedTime], eax
2294
        mov     [edi+INODE.deletedTime], eax
1979
        mov     eax, [esp]
2295
        mov     eax, [esp]
Line 2008... Line 2324...
2008
        xor     ebx, ebx
2324
        xor     ebx, ebx
2009
        pop     eax
2325
        pop     eax
2010
        ret
2326
        ret
Line 2011... Line 2327...
2011
 
2327
 
2012
.not_empty:
2328
.not_empty:
2013
        pop     eax
2329
        pop     eax eax
2014
.error_stack8:
2330
.error_stack8:
2015
        pop     eax eax
2331
        pop     eax eax
2016
        push    ERROR_ACCESS_DENIED
2332
        push    ERROR_ACCESS_DENIED
Line 2017... Line 2333...
2017
        jmp     .disk_sync
2333
        jmp     .disk_sync
2018
 
-
 
2019
.not_empty_eax:
-
 
2020
        pop     ebx
2334
 
2021
.error_stack8_eax:
2335
.not_empty_eax:
2022
        pop     ebx
2336
        add     esp, 12
2023
.error_stack4_eax:
-
 
2024
        pop     ebx
2337
.error_stack4_eax:
2025
.error:
2338
        pop     ebx
Line 2026... Line 2339...
2026
        push    eax
2339
        push    eax
2027
        jmp     .disk_sync
2340
        jmp     .disk_sync
Line 2032... Line 2345...
2032
        call    findInode
2345
        call    findInode
2033
        jnc     .success    ; exist
2346
        jnc     .success    ; exist
2034
        test    edi, edi
2347
        test    edi, edi
2035
        jz      .error
2348
        jz      .error
2036
        mov     eax, esi
2349
        mov     eax, esi
2037
        xor     ebx, ebx
-
 
2038
        inc     ebx
-
 
2039
        call    extfsResourceAlloc
2350
        call    extfsInodeAlloc
2040
        jc      .error
2351
        jc      .error
2041
        inc     ebx
2352
        inc     ebx
2042
        push    ebx esi edi
2353
        push    ebx esi edi
2043
        xor     al, al
2354
        xor     al, al
2044
        lea     edi, [ebp+EXTFS.inodeBuffer]
2355
        lea     edi, [ebp+EXTFS.inodeBuffer]
Line 2115... Line 2426...
2115
        call    findInode
2426
        call    findInode
2116
        jnc     .exist
2427
        jnc     .exist
2117
        test    edi, edi
2428
        test    edi, edi
2118
        jz      .error
2429
        jz      .error
2119
        mov     eax, esi
2430
        mov     eax, esi
2120
        xor     ebx, ebx
-
 
2121
        inc     ebx
-
 
2122
        call    extfsResourceAlloc
2431
        call    extfsInodeAlloc
2123
        jc      .error
2432
        jc      .error
2124
        inc     ebx
2433
        inc     ebx
2125
        push    ebx ebx esi edi
2434
        push    ebx ebx esi edi
2126
        xor     al, al
2435
        xor     al, al
2127
        lea     edi, [ebp+EXTFS.inodeBuffer]
2436
        lea     edi, [ebp+EXTFS.inodeBuffer]
Line 2158... Line 2467...
2158
        jz      .error  ; not a file
2467
        jz      .error  ; not a file
2159
        pop     ebx
2468
        pop     ebx
2160
        push    ebx esi
2469
        push    ebx esi
2161
        mov     ecx, [ebx+12]
2470
        mov     ecx, [ebx+12]
2162
        call    extfsTruncateFile
2471
        call    extfsTruncateFile
2163
        jnc     ext_WriteFile.start
2472
        jmp     ext_WriteFile.start
-
 
2473
 
2164
.error2:
2474
.error2:
2165
        pop     ebx
2475
        pop     ebx
2166
.error:
2476
.error:
2167
        push    eax
2477
        push    eax
2168
        call    ext_unlock
2478
        call    ext_unlock
Line 2185... Line 2495...
2185
        mov     ecx, [ebx+4]
2495
        mov     ecx, [ebx+4]
2186
        add     ecx, [ebx+12]
2496
        add     ecx, [ebx+12]
2187
.start:
2497
.start:
2188
        mov     eax, esi
2498
        mov     eax, esi
2189
        call    extfsExtendFile
2499
        call    extfsExtendFile
2190
        jc      .error
-
 
2191
        mov     eax, [ebx+4]
-
 
2192
        mov     ecx, [ebx+12]
2500
        mov     ecx, [ebx+12]
-
 
2501
        push    eax
-
 
2502
        jc      .error_inode_size
-
 
2503
        pop     eax
-
 
2504
        mov     eax, [ebx+4]
2193
        mov     ebx, [ebx+16]
2505
        mov     ebx, [ebx+16]
2194
        push    eax
2506
        push    eax
2195
        xor     edx, edx
2507
        xor     edx, edx
2196
        div     [ebp+EXTFS.bytesPerBlock]
2508
        div     [ebp+EXTFS.bytesPerBlock]
2197
        test    edx, edx
2509
        test    edx, edx
Line 2279... Line 2591...
2279
;----------------------------------------------------------------
2591
;----------------------------------------------------------------
2280
ext_SetFileEnd:
2592
ext_SetFileEnd:
2281
        call    extfsWritingInit
2593
        call    extfsWritingInit
2282
        pushd   [ebx+4]
2594
        pushd   [ebx+4]
2283
        call    findInode
2595
        call    findInode
2284
        jc      .error
2596
        jc      .error2
2285
        lea     edi, [ebp+EXTFS.inodeBuffer]
2597
        lea     edi, [ebp+EXTFS.inodeBuffer]
2286
        movi    eax, ERROR_ACCESS_DENIED
2598
        movi    eax, ERROR_ACCESS_DENIED
2287
        cmp     [edi+INODE.accessMode], FLAG_FILE
2599
        cmp     [edi+INODE.accessMode], FLAG_FILE
2288
        jnz     .error  ; not a file
2600
        jnz     .error2 ; not a file
2289
        pop     ecx
2601
        pop     ecx
2290
        push    esi
2602
        push    esi
2291
        mov     ebx, [edi+INODE.fileSize]
2603
        mov     ebx, [edi+INODE.fileSize]
2292
        mov     eax, esi
2604
        mov     eax, esi
2293
        cmp     ebx, ecx
2605
        cmp     ebx, ecx
2294
        jc      @f
2606
        jc      @f
2295
        call    extfsTruncateFile
2607
        call    extfsTruncateFile
2296
        jc      .error
-
 
2297
        jmp     .done
2608
        jmp     .done
Line 2298... Line 2609...
2298
 
2609
 
2299
@@:
2610
@@:
2300
        call    extfsExtendFile
2611
        call    extfsExtendFile
Line 2347... Line 2658...
2347
        call    extfsWriteFileBlock
2658
        call    extfsWriteFileBlock
2348
        jc      .error
2659
        jc      .error
2349
        inc     edi
2660
        inc     edi
2350
        loop    @b
2661
        loop    @b
2351
.done:
2662
.done:
-
 
2663
        xor     eax, eax
-
 
2664
.error:
2352
        mov     eax, [esp]
2665
        xchg    eax, [esp]
2353
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2666
        lea     ebx, [ebp+EXTFS.inodeBuffer]
2354
        call    writeInode
2667
        call    writeInode
2355
        jc      .error
2668
        jnc     @f
-
 
2669
        mov     [esp], eax
-
 
2670
@@:
2356
        call    writeSuperblock
2671
        call    writeSuperblock
2357
        mov     esi, [ebp+PARTITION.Disk]
2672
        mov     esi, [ebp+PARTITION.Disk]
2358
        call    disk_sync
2673
        call    disk_sync
2359
        xor     eax, eax
2674
        mov     eax, [esp]
2360
.error:
2675
.error2:
2361
        mov     [esp], eax
2676
        mov     [esp], eax
2362
        call    ext_unlock
2677
        call    ext_unlock
2363
        pop     eax
2678
        pop     eax
2364
        ret
2679
        ret