Subversion Repositories Kolibri OS

Rev

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

Rev 6726 Rev 6756
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: 6726 $
8
$Revision: 6756 $
9
 
9
 
10
; EXT external functions
10
; EXT external functions
11
;   in:
11
;   in:
Line 303... Line 303...
303
@@:
303
@@:
304
        ret
304
        ret
Line 305... Line 305...
305
 
305
 
306
extfsReadDescriptor:
306
extfsReadDescriptor:
-
 
307
; in: eax = block group number
307
; in: eax = block group number
308
; out: ebx -> block group descriptor
308
;   out:
309
        push    ecx edx
-
 
310
        mov     edx, [ebp+EXTFS.superblock.firstGroupBlock]
309
; [ebp+EXTFS.tempBlockBuffer] -> relevant block
311
        inc     edx
310
; eax -> block group descriptor, 0 = error
312
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
311
        push    edx ebx
313
        shl     edx, cl
312
        shl     eax, 5
314
        shl     eax, 5
313
        xor     edx, edx
-
 
314
        div     [ebp+EXTFS.bytesPerBlock]
-
 
315
        add     eax, [ebp+EXTFS.superblock.firstGroupBlock]
315
        mov     ecx, eax
316
        inc     eax
-
 
317
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
318
        call    extfsReadBlock
-
 
319
        jc      .fail
316
        and     ecx, 511
320
        mov     eax, ebx
317
        shr     eax, 9
-
 
318
        add     eax, edx
-
 
319
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
320
        push    ecx
-
 
321
        call    fs_read32_sys
-
 
322
        pop     ecx
-
 
323
        add     ebx, ecx
-
 
324
        test    eax, eax
-
 
325
        jz      @f
-
 
326
        movi    eax, ERROR_DEVICE
321
        add     eax, edx
327
        stc
322
@@:
328
@@:
323
        pop     ebx edx
329
        pop     edx ecx
Line 324... Line -...
324
        ret
-
 
325
 
-
 
326
.fail:
-
 
327
        xor     eax, eax
-
 
328
        stc
-
 
329
        jmp     @b
330
        ret
330
 
-
 
331
extfsWriteDescriptor:
331
 
332
;   in:
-
 
333
; eax = block group number
332
extfsWriteDescriptor:
334
; [ebp+EXTFS.tempBlockBuffer] -> relevant block
333
; in: eax = block group number
335
        push    edx ebx
334
        push    ebx ecx edx
336
        shl     eax, 5
335
        mov     edx, [ebp+EXTFS.superblock.firstGroupBlock]
337
        xor     edx, edx
336
        inc     edx
-
 
337
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
338
        div     [ebp+EXTFS.bytesPerBlock]
338
        shl     edx, cl
339
        add     eax, [ebp+EXTFS.superblock.firstGroupBlock]
339
        shr     eax, 9-5
340
        inc     eax
340
        add     eax, edx
341
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
341
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
342
        call    extfsWriteBlock
342
        call    fs_write32_sys
Line 343... Line 343...
343
        pop     ebx edx
343
        pop     edx ecx ebx
344
        ret
-
 
345
 
344
        ret
346
extfsResourceFree:
-
 
347
;   in:
345
 
348
; ecx=0 -> block, ecx=1 -> inode
346
extfsExtentFree:
349
; eax = block/inode number
347
; in: eax = first block number, ecx = extent size
350
        push    ebx edx
348
        push    ebx edx edi
-
 
349
        sub     eax, [ebp+EXTFS.superblock.firstGroupBlock]
-
 
350
        xor     edx, edx
-
 
351
        mov     ebx, [ebp+EXTFS.superblock.blocksPerGroup]
-
 
352
        div     ebx
351
        sub     eax, [ebp+EXTFS.superblock.firstGroupBlock]
353
        sub     ebx, edx
352
        xor     edx, edx
354
        sub     ebx, ecx
353
        div     [ebp+EXTFS.superblock.blocksPerGroup]
355
        jc      .ret
354
        push    edx eax
356
        push    edx eax
355
        call    extfsReadDescriptor
357
        call    extfsReadDescriptor
356
        jc      .fail2
358
        jc      .fail2
357
        inc     [eax+BGDESCR.blocksFree+ecx*2]
359
        add     [ebx+BGDESCR.blocksFree], cx
358
        mov     edx, [eax+BGDESCR.blockBitmap+ecx*4]
-
 
359
        pop     eax
360
        mov     edx, [ebx+BGDESCR.blockBitmap]
360
        call    extfsWriteDescriptor
361
        pop     eax
361
        jc      .fail
362
        call    extfsWriteDescriptor
362
        mov     eax, edx
363
        mov     eax, edx
363
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
364
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
365
        call    extfsReadBlock
-
 
366
        jc      .fail
-
 
367
        pop     eax
-
 
368
        push    ecx ebx edx
-
 
369
        add     [ebp+EXTFS.superblock.blocksFree], ecx
-
 
370
        mov     edi, eax
-
 
371
        shr     edi, 5
-
 
372
        shl     edi, 2
-
 
373
        add     edi, ebx
-
 
374
        and     eax, 31
-
 
375
        mov     edx, ecx
-
 
376
        mov     ecx, 32
-
 
377
        sub     ecx, eax
-
 
378
        sub     edx, ecx
-
 
379
        jnc     @f
-
 
380
        add     ecx, edx
-
 
381
        xor     edx, edx
364
        call    extfsReadBlock
382
@@:
365
        jc      .fail
383
        or      ebx, -1
-
 
384
        shl     ebx, cl
-
 
385
        not     ebx
-
 
386
        mov     ecx, eax
-
 
387
        shl     ebx, cl
-
 
388
        not     ebx
-
 
389
        and     [edi], ebx
-
 
390
        mov     ecx, edx
-
 
391
        jecxz   @f
-
 
392
        shr     ecx, 5
366
        pop     eax
393
        add     edi, 4
367
        push    edx
394
        xor     eax, eax
368
        mov     edx, eax
395
        rep stosd
369
        and     edx, 31
-
 
370
        shr     eax, 5
-
 
371
        shl     eax, 2
396
        and     edx, 31
372
        add     eax, [ebp+EXTFS.tempBlockBuffer]
-
 
373
        btr     [eax], edx
397
        mov     ecx, edx
374
        pop     eax
398
        jecxz   @f
375
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
376
        call    extfsWriteBlock
399
        not     eax
-
 
400
        shl     eax, cl
-
 
401
        and     [edi], eax
-
 
402
@@:
-
 
403
        pop     eax ebx
-
 
404
        call    extfsWriteBlock
-
 
405
        pop     ecx
-
 
406
        mov     eax, ecx
-
 
407
        mul     [ebp+EXTFS.sectorsPerBlock]
377
        jc      @f
408
        sub     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
378
        inc     [ebp+EXTFS.superblock.blocksFree+ecx*4]
-
 
379
@@:
409
.ret:
Line 380... Line 410...
380
        xor     eax, eax
410
        pop     edi edx ebx
381
        pop     edx ebx
411
        xor     eax, eax
382
        ret
412
        ret
383
 
413
 
384
.fail2:
414
.fail2:
Line 385... Line 415...
385
        pop     eax
415
        pop     eax
386
.fail:
416
.fail:
387
        pop     eax
417
        pop     eax
388
        jmp     @b
418
        jmp     .ret
Line 397... Line 427...
397
        push    eax eax
427
        push    eax eax
398
        mov     esi, .forward   ; search forward, then backward
428
        mov     esi, .forward   ; search forward, then backward
399
.test_block_group:
429
.test_block_group:
400
        call    extfsReadDescriptor
430
        call    extfsReadDescriptor
401
        jc      .fail
431
        jc      .fail
402
        dec     [eax+BGDESCR.inodesFree]
432
        dec     [ebx+BGDESCR.inodesFree]
403
        js      .next
433
        js      .next
404
        mov     edx, [eax+BGDESCR.inodeBitmap]
434
        mov     edx, [ebx+BGDESCR.inodeBitmap]
405
        mov     eax, [esp]
435
        mov     eax, [esp]
406
        call    extfsWriteDescriptor
436
        call    extfsWriteDescriptor
407
        jc      .fail
-
 
408
        mov     eax, edx
437
        mov     eax, edx
409
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
438
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
410
        mov     edi, ebx
439
        mov     edi, ebx
411
        call    extfsReadBlock
440
        call    extfsReadBlock
412
        jc      .fail
441
        jc      .fail
Line 424... Line 453...
424
        shl     edi, 3
453
        shl     edi, 3
425
        add     eax, edi
454
        add     eax, edi
426
        mov     ecx, eax
455
        mov     ecx, eax
427
        mov     eax, edx
456
        mov     eax, edx
428
        call    extfsWriteBlock
457
        call    extfsWriteBlock
429
        jc      .fail
-
 
430
        pop     eax
458
        pop     eax
431
        mul     [ebp+EXTFS.superblock.inodesPerGroup]
459
        mul     [ebp+EXTFS.superblock.inodesPerGroup]
432
        add     eax, ecx
-
 
433
        dec     [ebp+EXTFS.superblock.inodesFree]
460
        dec     [ebp+EXTFS.superblock.inodesFree]
434
        mov     ebx, eax
461
        lea     ebx, [eax+ecx+1]
435
        pop     eax
-
 
436
        xor     eax, eax
462
        xor     eax, eax
437
@@:
463
.ret:
438
        pop     edi esi edx ecx
464
        pop     edi edi esi edx ecx
439
        ret
465
        ret
Line 440... Line -...
440
 
-
 
441
.fail:
-
 
442
        pop     eax eax
-
 
443
        movi    eax, ERROR_DEVICE
-
 
444
        jmp     @b
-
 
445
 
466
 
446
.next:
467
.next:
Line 447... Line 468...
447
        jmp     esi
468
        jmp     esi
448
 
469
 
Line 459... Line 480...
459
        mov     eax, [esp+4]
480
        mov     eax, [esp+4]
460
        mov     [esp], eax
481
        mov     [esp], eax
461
        mov     esi, .backward
482
        mov     esi, .backward
462
.backward:
483
.backward:
463
        sub     dword[esp], 1
484
        sub     dword[esp], 1
464
        jc      .fail
-
 
465
        mov     eax, [esp]
485
        mov     eax, [esp]
466
        jmp     .test_block_group
486
        jnc     .test_block_group
-
 
487
        movi    eax, ERROR_DISK_FULL
-
 
488
.fail:
-
 
489
        pop     edi
-
 
490
        jmp     .ret
Line 467... Line 491...
467
 
491
 
468
extfsExtentAlloc:
-
 
469
;   in:
492
extfsExtentAlloc:
470
; eax = parent inode number
-
 
471
; ecx = blocks max
-
 
472
;   out:
493
; in: eax = parent inode number, ecx = blocks max
473
; ebx = first block number
-
 
474
; ecx = blocks allocated
494
; out: ebx = first block number, ecx = blocks allocated
475
        push    edx esi edi ecx
495
        push    edx esi edi ecx
476
        dec     eax
496
        dec     eax
477
        xor     edx, edx
497
        xor     edx, edx
478
        div     [ebp+EXTFS.superblock.inodesPerGroup]
498
        div     [ebp+EXTFS.superblock.inodesPerGroup]
479
        push    eax eax
499
        push    eax eax
480
.test_block_group:
500
.test_block_group:
481
        call    extfsReadDescriptor
501
        call    extfsReadDescriptor
482
        jc      .fail
502
        jc      .fail
483
        dec     [eax+BGDESCR.blocksFree]
503
        dec     [ebx+BGDESCR.blocksFree]
484
        js      .next
504
        js      .next
485
        mov     eax, [eax+BGDESCR.blockBitmap]
505
        mov     eax, [ebx+BGDESCR.blockBitmap]
486
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
506
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
487
        mov     edx, eax
507
        mov     edx, eax
488
        mov     edi, ebx
508
        mov     edi, ebx
489
        call    extfsReadBlock
509
        call    extfsReadBlock
Line 500... Line 520...
500
        not     eax
520
        not     eax
501
        bsf     ecx, eax
521
        bsf     ecx, eax
502
        not     eax
522
        not     eax
503
        shr     eax, cl
523
        shr     eax, cl
504
        shl     eax, cl
524
        shl     eax, cl
505
        mov     ebx, 32
-
 
506
        bsf     ebx, eax
525
        bsf     ebx, eax
-
 
526
        jnz     @f
-
 
527
        mov     ebx, 32
-
 
528
@@:
507
        sub     ebx, ecx
529
        sub     ebx, ecx
508
        mov     eax, [esp+16]
530
        mov     eax, [esp+16]
509
        cmp     ebx, eax
531
        cmp     ebx, eax
510
        jc      @f
532
        jc      @f
511
        mov     ebx, eax
533
        mov     ebx, eax
Line 572... Line 594...
572
        or      [edi], eax
594
        or      [edi], eax
573
.done:
595
.done:
574
        pop     eax
596
        pop     eax
575
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
597
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
576
        call    extfsWriteBlock
598
        call    extfsWriteBlock
577
        jc      .fail
-
 
578
        mov     eax, [esp]
599
        mov     eax, [esp]
579
        call    extfsReadDescriptor
600
        call    extfsReadDescriptor
580
        jc      .fail
601
        jc      .fail
581
        mov     ecx, [esp+8]
602
        mov     ecx, [esp+8]
582
        sub     [eax+BGDESCR.blocksFree], cx
603
        sub     [ebx+BGDESCR.blocksFree], cx
583
        jc      .fail
604
        jc      .fail
584
        sub     [ebp+EXTFS.superblock.blocksFree], ecx
605
        sub     [ebp+EXTFS.superblock.blocksFree], ecx
585
        mov     eax, [esp]
606
        mov     eax, [esp]
586
        call    extfsWriteDescriptor
607
        call    extfsWriteDescriptor
587
        jc      .fail
-
 
588
        pop     eax ebx
608
        pop     eax ebx
589
        mul     [ebp+EXTFS.superblock.blocksPerGroup]
609
        mul     [ebp+EXTFS.superblock.blocksPerGroup]
590
        mov     ebx, eax
610
        mov     ebx, eax
591
        add     ebx, esi
611
        add     ebx, esi
592
        xor     eax, eax
612
        add     ebx, [ebp+EXTFS.superblock.firstGroupBlock]
593
        pop     ecx
613
        pop     ecx
-
 
614
        mov     eax, ecx
-
 
615
        mul     [ebp+EXTFS.sectorsPerBlock]
-
 
616
        add     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
-
 
617
        xor     eax, eax
594
.ret:
618
.ret:
595
        pop     edi esi edx
619
        pop     edi esi edx
596
        ret
620
        ret
Line 597... Line -...
597
 
-
 
598
.fail:
-
 
599
        pop     eax eax
-
 
600
        movi    eax, ERROR_DEVICE
-
 
601
        xor     ecx, ecx
-
 
602
        jmp     .ret
-
 
603
 
621
 
604
.next:      ; search forward, then backward
622
.next:      ; search forward, then backward
605
        pop     eax
623
        pop     eax
606
        cmp     eax, [esp]
624
        cmp     eax, [esp]
607
        jc      .backward
625
        jc      .backward
Line 618... Line 636...
618
        push    eax
636
        push    eax
619
.backward:
637
.backward:
620
        dec     eax
638
        dec     eax
621
        push    eax
639
        push    eax
622
        jns     .test_block_group
640
        jns     .test_block_group
623
        pop     eax eax
-
 
624
        movi    eax, ERROR_DISK_FULL
641
        movi    eax, ERROR_DISK_FULL
-
 
642
.fail:
-
 
643
        add     esp, 12
625
        xor     ecx, ecx
644
        xor     ecx, ecx
-
 
645
        stc
626
        jmp     .ret
646
        jmp     .ret
Line 627... Line 647...
627
 
647
 
628
extfsGetExtent:
648
extfsGetExtent:
629
; in: ecx = starting file block
649
; in: ecx = starting file block
Line 751... Line 771...
751
        call    extfsReadBlock
771
        call    extfsReadBlock
752
        jc      .fail2
772
        jc      .fail2
753
.calculateExtent:
773
.calculateExtent:
754
        lea     esi, [ebx+edx*4]
774
        lea     esi, [ebx+edx*4]
755
        lodsd
775
        lodsd
-
 
776
        test    eax, eax
-
 
777
        jz      .noBlock
756
        mov     ebx, eax
778
        mov     ebx, eax
757
        sub     ecx, edx
779
        sub     ecx, edx
758
        xor     edx, edx
780
        xor     edx, edx
759
@@:
781
@@:
760
        inc     edx
782
        inc     edx
Line 771... Line 793...
771
        clc
793
        clc
772
        ret
794
        ret
Line 773... Line 795...
773
 
795
 
774
getInodeLocation:
796
getInodeLocation:
775
; in: eax = inode number
797
; in: eax = inode number
776
; out: ebx = inode sector, edx = offset in sector
798
; out: eax = inode sector, edx = offset in sector
777
        dec     eax
799
        dec     eax
778
        xor     edx, edx
800
        xor     edx, edx
779
        div     [ebp+EXTFS.superblock.inodesPerGroup]
-
 
780
        mov     ecx, edx
-
 
781
        shl     eax, 5
-
 
782
        xor     edx, edx
-
 
783
        div     [ebp+EXTFS.bytesPerBlock]
-
 
784
        add     eax, [ebp+EXTFS.superblock.firstGroupBlock]
-
 
785
        inc     eax
-
 
786
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
801
        div     [ebp+EXTFS.superblock.inodesPerGroup]
787
        call    extfsReadBlock
802
        call    extfsReadDescriptor
788
        jc      @f
-
 
789
        add     ebx, edx
803
        jc      @f
790
        mov     ebx, [ebx+BGDESCR.inodeTable]
-
 
791
        mov     eax, ecx
804
        mov     ebx, [ebx+BGDESCR.inodeTable]
792
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
805
        mov     ecx, [ebp+EXTFS.sectorsPerBlockLog]
-
 
806
        shl     ebx, cl
793
        shl     ebx, cl
807
        mov     eax, edx
794
        mul     [ebp+EXTFS.superblock.inodeSize]
808
        mul     [ebp+EXTFS.superblock.inodeSize]
795
        mov     edx, eax
809
        mov     edx, eax
796
        shr     eax, 9
810
        shr     eax, 9
797
        and     edx, 511
811
        and     edx, 511
798
        add     ebx, eax
-
 
799
        xor     eax, eax
812
        add     eax, ebx
800
@@:
813
@@:
Line 801... Line 814...
801
        ret
814
        ret
802
 
815
 
Line 808... Line 821...
808
        add     eax, 978307200
821
        add     eax, 978307200
809
        mov     [edi+INODE.inodeModified], eax
822
        mov     [edi+INODE.inodeModified], eax
810
        pop     eax
823
        pop     eax
811
        call    getInodeLocation
824
        call    getInodeLocation
812
        jc      .ret
825
        jc      .ret
813
        mov     eax, ebx
-
 
814
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
826
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
815
        mov     ecx, eax
827
        mov     ecx, eax
816
        call    fs_read32_sys
828
        call    fs_read32_sys
817
        test    eax, eax
829
        test    eax, eax
818
        jnz     @f
830
        jnz     @f
Line 836... Line 848...
836
; in: eax = inode number, ebx -> inode buffer
848
; in: eax = inode number, ebx -> inode buffer
837
        push    edx edi esi ecx ebx
849
        push    edx edi esi ecx ebx
838
        mov     edi, ebx
850
        mov     edi, ebx
839
        call    getInodeLocation
851
        call    getInodeLocation
840
        jc      @f
852
        jc      @f
841
        mov     eax, ebx
-
 
842
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
853
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
843
        call    fs_read32_sys
854
        call    fs_read32_sys
844
        test    eax, eax
855
        test    eax, eax
845
        jnz     @b
856
        jnz     @b
846
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
857
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
Line 1000... Line 1011...
1000
        jecxz   .end
1011
        jecxz   .end
1001
        mov     eax, [esp+16]
1012
        mov     eax, [esp+16]
1002
        call    extfsExtentAlloc
1013
        call    extfsExtentAlloc
1003
        jc      .end
1014
        jc      .end
1004
        sub     [esp+12], ecx
1015
        sub     [esp+12], ecx
1005
        mov     eax, ecx
-
 
1006
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1007
        add     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
-
 
1008
        jmp     @b
1016
        jmp     @b
Line 1009... Line 1017...
1009
 
1017
 
1010
extfsExtendFile:
1018
extfsExtendFile:
1011
;   in:
1019
;   in:
Line 1038... Line 1046...
1038
        test    ecx, ecx
1046
        test    ecx, ecx
1039
        jz      .done
1047
        jz      .done
1040
        call    extfsExtentAlloc
1048
        call    extfsExtentAlloc
1041
        jc      .errDone
1049
        jc      .errDone
1042
        sub     [esp], ecx
1050
        sub     [esp], ecx
1043
        mov     eax, ecx
-
 
1044
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1045
        add     [esi+INODE.sectorsUsed], eax
-
 
1046
        cmp     edx, 12
1051
        cmp     edx, 12
1047
        jc      .directBlocks
1052
        jc      .directBlocks
1048
        sub     edx, 12
1053
        sub     edx, 12
1049
        cmp     edx, [ebp+EXTFS.dwordsPerBlock]
1054
        cmp     edx, [ebp+EXTFS.dwordsPerBlock]
1050
        jc      .indirectBlocks
1055
        jc      .indirectBlocks
Line 1166... Line 1171...
1166
        mov     eax, [esp+4]
1171
        mov     eax, [esp+4]
1167
        jecxz   @f
1172
        jecxz   @f
1168
        call    extfsExtentAlloc
1173
        call    extfsExtentAlloc
1169
        jc      .errSave
1174
        jc      .errSave
1170
        sub     [esp], ecx
1175
        sub     [esp], ecx
1171
        mov     eax, ecx
-
 
1172
        imul    eax, [ebp+EXTFS.sectorsPerBlock]
-
 
1173
        add     [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
-
 
1174
        jmp     @b
1176
        jmp     @b
Line 1175... Line 1177...
1175
 
1177
 
1176
@@:
1178
@@:
1177
        mov     eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
1179
        mov     eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
Line 1204... Line 1206...
1204
        call    extfsReadBlock
1206
        call    extfsReadBlock
1205
        jc      .ret
1207
        jc      .ret
1206
        lea     edi, [ebx+edx*4]
1208
        lea     edi, [ebx+edx*4]
1207
        neg     edx
1209
        neg     edx
1208
        add     edx, [ebp+EXTFS.dwordsPerBlock]
1210
        add     edx, [ebp+EXTFS.dwordsPerBlock]
-
 
1211
.freeExtent:
-
 
1212
        mov     ebx, [edi]
-
 
1213
        test    ebx, ebx
-
 
1214
        jz      .end
-
 
1215
        xor     eax, eax
1209
        xor     ecx, ecx
1216
        xor     ecx, ecx
1210
@@:
1217
@@:
1211
        mov     eax, [edi]
-
 
1212
        test    eax, eax
-
 
1213
        jz      .end
-
 
1214
        call    extfsResourceFree
-
 
1215
        stosd
1218
        stosd
-
 
1219
        inc     ecx
1216
        dec     edx
1220
        dec     edx
-
 
1221
        jz      @f
-
 
1222
        mov     eax, [edi]
-
 
1223
        sub     eax, ebx
-
 
1224
        sub     eax, ecx
1217
        jnz     @b
1225
        jz      @b
-
 
1226
@@:
-
 
1227
        mov     eax, ebx
-
 
1228
        call    extfsExtentFree
-
 
1229
        test    edx, edx
-
 
1230
        jnz     .freeExtent
1218
        dec     dword[esp+8]
1231
        dec     dword[esp+8]
1219
.end:
1232
.end:
1220
        pop     edx edi
1233
        pop     edx edi
1221
        mov     eax, [edi]
1234
        mov     eax, [edi]
1222
        test    edx, edx
1235
        test    edx, edx
1223
        jnz     @f
1236
        jnz     @f
-
 
1237
        xor     ecx, ecx
-
 
1238
        inc     ecx
1224
        call    extfsResourceFree
1239
        call    extfsExtentFree
1225
        stosd
1240
        stosd
1226
        jmp     .done
1241
        jmp     .done
Line 1227... Line 1242...
1227
 
1242
 
-
 
1243
@@:
1228
@@:
1244
        mov     ebx, [ebp+EXTFS.mainBlockBuffer]
1229
        call    extfsWriteBlock
1245
        call    extfsWriteBlock
1230
        add     edi, 4
1246
        add     edi, 4
1231
.done:
1247
.done:
1232
        pop     eax ecx
1248
        pop     eax ecx
Line 1268... Line 1284...
1268
        pop     edi edx
1284
        pop     edi edx
1269
        mov     eax, [edi]
1285
        mov     eax, [edi]
1270
        test    edx, edx
1286
        test    edx, edx
1271
        jnz     @f
1287
        jnz     @f
1272
        xor     ecx, ecx
1288
        xor     ecx, ecx
-
 
1289
        inc     ecx
1273
        call    extfsResourceFree
1290
        call    extfsExtentFree
1274
        stosd
1291
        stosd
1275
        jmp     .done
1292
        jmp     .done
Line 1276... Line 1293...
1276
 
1293
 
1277
@@:
1294
@@:
Line 1289... Line 1306...
1289
.ret:
1306
.ret:
1290
        xor     edx, edx
1307
        xor     edx, edx
1291
        ret
1308
        ret
Line 1292... Line 1309...
1292
 
1309
 
1293
extfsTruncateFile:
-
 
1294
;   in:
1310
extfsTruncateFile:
1295
; [ebp+EXTFS.inodeBuffer] = inode
-
 
1296
; ecx = new size
1311
; in: ecx = new size, [ebp+EXTFS.inodeBuffer] = inode
1297
        push    ebx ecx edx esi edi
1312
        push    ebx ecx edx esi edi
1298
        lea     esi, [ebp+EXTFS.inodeBuffer]
1313
        lea     esi, [ebp+EXTFS.inodeBuffer]
1299
        cmp     ecx, [esi+INODE.fileSize]
1314
        cmp     ecx, [esi+INODE.fileSize]
1300
        jnc     .ret
1315
        jnc     .ret
Line 1320... Line 1335...
1320
.directBlocks:
1335
.directBlocks:
1321
        lea     edi, [esi+INODE.blockNumbers+edx*4]
1336
        lea     edi, [esi+INODE.blockNumbers+edx*4]
1322
        neg     edx
1337
        neg     edx
1323
        add     edx, 12
1338
        add     edx, 12
1324
        xor     ecx, ecx
1339
        xor     ecx, ecx
-
 
1340
        inc     ecx
1325
@@:
1341
@@:
1326
        mov     eax, [edi]
1342
        mov     eax, [edi]
1327
        test    eax, eax
1343
        test    eax, eax
1328
        jz      .ret
1344
        jz      .ret
1329
        call    extfsResourceFree
1345
        call    extfsExtentFree
1330
        stosd
1346
        stosd
1331
        dec     edx
1347
        dec     edx
1332
        jnz     @b
1348
        jnz     @b
1333
.indirectBlocks:
1349
.indirectBlocks:
1334
        lea     edi, [esi+INODE.addressBlock]
1350
        lea     edi, [esi+INODE.addressBlock]
Line 1366... Line 1382...
1366
.end:
1382
.end:
1367
        pop     edx eax
1383
        pop     edx eax
1368
        test    edx, edx
1384
        test    edx, edx
1369
        jnz     @f
1385
        jnz     @f
1370
        xor     ecx, ecx
1386
        xor     ecx, ecx
-
 
1387
        inc     ecx
1371
        call    extfsResourceFree
1388
        call    extfsExtentFree
1372
        mov     [esi+INODE.tripleAddress], eax
1389
        mov     [esi+INODE.tripleAddress], eax
1373
        jmp     .done
1390
        jmp     .done
Line 1374... Line 1391...
1374
 
1391
 
1375
@@:
1392
@@:
Line 1460... Line 1477...
1460
        mov     [edi+DIRENTRY.entryLength], ax
1477
        mov     [edi+DIRENTRY.entryLength], ax
1461
; this block wasn't linking to the next one, so write it, and use the next block
1478
; this block wasn't linking to the next one, so write it, and use the next block
1462
        pop     eax
1479
        pop     eax
1463
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1480
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1464
        call    extfsWriteBlock
1481
        call    extfsWriteBlock
1465
        jc      .error_get_inode_block
-
 
1466
        pop     ecx
1482
        pop     ecx
1467
        inc     ecx
1483
        inc     ecx
1468
        cmp     ecx, [esp]
1484
        cmp     ecx, [esp]
1469
        push    ecx
1485
        push    ecx
1470
        jnz     @f
1486
        jnz     @f
Line 1500... Line 1516...
1500
        add     edi, 8
1516
        add     edi, 8
1501
        rep movsb
1517
        rep movsb
1502
        mov     eax, edx
1518
        mov     eax, edx
1503
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1519
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1504
        call    extfsWriteBlock
1520
        call    extfsWriteBlock
1505
        jc      .error_block_write
-
 
1506
        mov     eax, [esp]
1521
        mov     eax, [esp]
1507
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1522
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1508
        call    readInode
1523
        call    readInode
1509
        jc      .error_block_write
1524
        jc      .error_block_write
1510
        pop     eax
1525
        pop     eax
Line 1525... Line 1540...
1525
.error_block_write:
1540
.error_block_write:
1526
        pop     ebx
1541
        pop     ebx
1527
        jmp     @b
1542
        jmp     @b
Line 1528... Line 1543...
1528
 
1543
 
1529
unlinkInode:
-
 
1530
;   in:
1544
unlinkInode:
1531
; eax = inode from which to unlink
-
 
1532
; ebx = inode to unlink
-
 
1533
;   out:
1545
; in: eax = inode from which to unlink, ebx = inode to unlink
1534
; eax = current number of links to inode, -1 = error
1546
; out: eax = current number of links to inode, -1 = error
1535
        push    edx ebx
1547
        push    edx ebx
1536
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1548
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1537
        call    readInode
1549
        call    readInode
1538
        jc      .fail
1550
        jc      .fail
Line 1591... Line 1603...
1591
.write_block:
1603
.write_block:
1592
        pop     eax
1604
        pop     eax
1593
        mov     eax, edi
1605
        mov     eax, edi
1594
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1606
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
1595
        call    extfsWriteBlock
1607
        call    extfsWriteBlock
1596
        jc      .fail
-
 
1597
        mov     eax, [esp]
1608
        mov     eax, [esp]
1598
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1609
        lea     ebx, [ebp+EXTFS.inodeBuffer]
1599
        call    readInode
1610
        call    readInode
1600
        jc      .fail
1611
        jc      .fail
1601
        dec     word [ebx+INODE.linksCount]
1612
        dec     word [ebx+INODE.linksCount]
Line 1622... Line 1633...
1622
        mov     edx, esi
1633
        mov     edx, esi
1623
        rep movsb
1634
        rep movsb
1624
        pop     esi
1635
        pop     esi
1625
        pushd   0 ROOT_INODE
1636
        pushd   0 ROOT_INODE
1626
        mov     edi, esi
1637
        mov     edi, esi
1627
        cmp     [edx+INODE.sectorsUsed], 0
1638
        cmp     [edx+INODE.fileSize], 0
1628
        jz      .not_found
1639
        jz      .not_found
1629
        cmp     byte [esi], 0
1640
        cmp     byte [esi], 0
1630
        jnz     .next_path_part
1641
        jnz     .next_path_part
1631
        xor     eax, eax
1642
        xor     eax, eax
1632
        pop     esi ecx
1643
        pop     esi ecx
Line 1639... Line 1650...
1639
        xor     edi, edi
1650
        xor     edi, edi
1640
        stc
1651
        stc
1641
        ret
1652
        ret
Line 1642... Line 1653...
1642
 
1653
 
1643
.next_path_part:
1654
.next_path_part:
1644
        push    [edx+INODE.sectorsUsed]
1655
        push    [edx+INODE.fileSize]
1645
        xor     ecx, ecx
1656
        xor     ecx, ecx
1646
.folder_block_cycle:
1657
.folder_block_cycle:
1647
        push    ecx
1658
        push    ecx
1648
        call    extfsGetExtent
1659
        call    extfsGetExtent
Line 1680... Line 1691...
1680
@@:
1691
@@:
1681
        pop     edx edx edi ecx eax
1692
        pop     edx edx edi ecx eax
1682
; ebx -> matched directory entry, esi -> name without parent, or not changed
1693
; ebx -> matched directory entry, esi -> name without parent, or not changed
1683
        cmp     edi, esi
1694
        cmp     edi, esi
1684
        jnz     @f
1695
        jnz     @f
1685
        sub     eax, [ebp+EXTFS.sectorsPerBlock]
1696
        sub     eax, [ebp+EXTFS.bytesPerBlock]
1686
        jle     .not_found
1697
        jle     .not_found
1687
        push    eax
1698
        push    eax
1688
        inc     ecx
1699
        inc     ecx
1689
        jmp     .folder_block_cycle
1700
        jmp     .folder_block_cycle
Line 2191... Line 2202...
2191
        jb      .dir_entry
2202
        jb      .dir_entry
2192
        pop     ecx
2203
        pop     ecx
2193
        inc     ecx
2204
        inc     ecx
2194
        jmp     .checkDirectory
2205
        jmp     .checkDirectory
Line -... Line 2206...
-
 
2206
 
-
 
2207
.not_empty:
-
 
2208
        pop     eax eax
-
 
2209
.error_stack8:
-
 
2210
        pop     eax eax
-
 
2211
        push    ERROR_ACCESS_DENIED
-
 
2212
        jmp     .ret
2195
 
2213
 
2196
.empty:
2214
.empty:
2197
        cmp     eax, ERROR_END_OF_FILE
2215
        cmp     eax, ERROR_END_OF_FILE
2198
        jnz     .not_empty_eax
2216
        jnz     .not_empty_eax
2199
        pop     edx edx ecx ebx
2217
        pop     edx edx ecx ebx
Line 2229... Line 2247...
2229
        mov     [edi+INODE.deletedTime], eax
2247
        mov     [edi+INODE.deletedTime], eax
2230
        mov     eax, [esp]
2248
        mov     eax, [esp]
2231
        mov     ebx, edi
2249
        mov     ebx, edi
2232
        call    writeInode
2250
        call    writeInode
2233
        jc      .error_stack4_eax
2251
        jc      .error_stack4_eax
2234
        cmp     edx, DIRECTORY
-
 
2235
        jne     @f
2252
        pop     eax
2236
        mov     eax, [esp]
-
 
2237
        dec     eax
2253
        dec     eax
-
 
2254
        mov     ecx, edx
2238
        xor     edx, edx
2255
        xor     edx, edx
2239
        div     [ebp+EXTFS.superblock.inodesPerGroup]
2256
        div     [ebp+EXTFS.superblock.inodesPerGroup]
2240
        push    eax
2257
        push    edx eax
2241
        call    extfsReadDescriptor
2258
        call    extfsReadDescriptor
2242
        jc      .error_stack8
2259
        jc      .error_stack8_eax
-
 
2260
        cmp     ecx, DIRECTORY
-
 
2261
        jnz     @f
2243
        dec     [eax+BGDESCR.directoriesCount]
2262
        dec     [ebx+BGDESCR.directoriesCount]
-
 
2263
@@:
-
 
2264
        inc     [ebx+BGDESCR.inodesFree]
-
 
2265
        mov     ecx, [ebx+BGDESCR.inodeBitmap]
2244
        pop     eax
2266
        pop     eax
2245
        call    extfsWriteDescriptor
2267
        call    extfsWriteDescriptor
2246
@@: ; free inode
2268
        mov     eax, ecx
-
 
2269
        mov     ebx, [ebp+EXTFS.tempBlockBuffer]
-
 
2270
        call    extfsReadBlock
-
 
2271
        jc      .error_stack4_eax
2247
        pop     eax
2272
        pop     eax
-
 
2273
        mov     edx, eax
-
 
2274
        and     edx, 31
-
 
2275
        shr     eax, 5
2248
        dec     eax
2276
        shl     eax, 2
2249
        xor     ecx, ecx
2277
        add     eax, ebx
-
 
2278
        btr     [eax], edx
2250
        inc     ecx
2279
        mov     eax, ecx
2251
        call    extfsResourceFree
2280
        call    extfsWriteBlock
-
 
2281
        inc     [ebp+EXTFS.superblock.inodesFree]
2252
        push    eax
2282
        push    eax
2253
.disk_sync:
2283
.disk_sync:
2254
        call    writeSuperblock
2284
        call    writeSuperblock
2255
        mov     esi, [ebp+PARTITION.Disk]
2285
        mov     esi, [ebp+PARTITION.Disk]
2256
        call    disk_sync
2286
        call    disk_sync
Line 2258... Line 2288...
2258
        call    ext_unlock
2288
        call    ext_unlock
2259
        xor     ebx, ebx
2289
        xor     ebx, ebx
2260
        pop     eax
2290
        pop     eax
2261
        ret
2291
        ret
Line 2262... Line -...
2262
 
-
 
2263
.not_empty:
-
 
2264
        pop     eax eax
-
 
2265
.error_stack8:
-
 
2266
        pop     eax eax
-
 
2267
        push    ERROR_ACCESS_DENIED
-
 
2268
        jmp     .disk_sync
-
 
2269
 
2292
 
2270
.not_empty_eax:
2293
.not_empty_eax:
-
 
2294
        pop     ebx ebx
-
 
2295
.error_stack8_eax:
2271
        add     esp, 12
2296
        pop     ebx
2272
.error_stack4_eax:
2297
.error_stack4_eax:
2273
        pop     ebx
2298
        pop     ebx
2274
        push    eax
2299
        push    eax
Line 2282... Line 2307...
2282
        test    edi, edi
2307
        test    edi, edi
2283
        jz      .error
2308
        jz      .error
2284
        mov     eax, esi
2309
        mov     eax, esi
2285
        call    extfsInodeAlloc
2310
        call    extfsInodeAlloc
2286
        jc      .error
2311
        jc      .error
2287
        inc     ebx
-
 
2288
        push    ebx esi edi
2312
        push    ebx esi edi
2289
        xor     al, al
2313
        xor     al, al
2290
        lea     edi, [ebp+EXTFS.inodeBuffer]
2314
        lea     edi, [ebp+EXTFS.inodeBuffer]
2291
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2315
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2292
        rep stosb
2316
        rep stosb
Line 2331... Line 2355...
2331
        dec     eax
2355
        dec     eax
2332
        xor     edx, edx
2356
        xor     edx, edx
2333
        div     [ebp+EXTFS.superblock.inodesPerGroup]
2357
        div     [ebp+EXTFS.superblock.inodesPerGroup]
2334
        mov     edx, eax
2358
        mov     edx, eax
2335
        call    extfsReadDescriptor
2359
        call    extfsReadDescriptor
2336
        jc      @f
2360
        jc      .error
2337
        inc     [eax+BGDESCR.directoriesCount]
2361
        inc     [ebx+BGDESCR.directoriesCount]
2338
        mov     eax, edx
2362
        mov     eax, edx
2339
        call    extfsWriteDescriptor
2363
        call    extfsWriteDescriptor
2340
.success:
2364
.success:
2341
.error:
2365
.error:
2342
        push    eax
2366
        push    eax
Line 2345... Line 2369...
2345
        call    disk_sync
2369
        call    disk_sync
2346
        call    ext_unlock
2370
        call    ext_unlock
2347
        pop     eax
2371
        pop     eax
2348
        ret
2372
        ret
Line 2349... Line -...
2349
 
-
 
2350
@@:
-
 
2351
        movi    eax, ERROR_DEVICE
-
 
2352
        jmp     .error
-
 
2353
 
2373
 
2354
self_link   db ".", 0
2374
self_link   db ".", 0
Line 2355... Line 2375...
2355
parent_link db "..", 0
2375
parent_link db "..", 0
2356
 
2376
 
Line 2363... Line 2383...
2363
        test    edi, edi
2383
        test    edi, edi
2364
        jz      .error
2384
        jz      .error
2365
        mov     eax, esi
2385
        mov     eax, esi
2366
        call    extfsInodeAlloc
2386
        call    extfsInodeAlloc
2367
        jc      .error
2387
        jc      .error
2368
        inc     ebx
-
 
2369
        push    ebx ebx esi edi
2388
        push    ebx ebx esi edi
2370
        xor     al, al
2389
        xor     al, al
2371
        lea     edi, [ebp+EXTFS.inodeBuffer]
2390
        lea     edi, [ebp+EXTFS.inodeBuffer]
2372
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2391
        movzx   ecx, [ebp+EXTFS.superblock.inodeSize]
2373
        rep stosb
2392
        rep stosb