Subversion Repositories Kolibri OS

Rev

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

Rev 6080 Rev 6107
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-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: 6080 $
8
$Revision: 6107 $
Line 9... Line 9...
9
 
9
 
10
; NTFS driver
10
; NTFS driver
Line 440... Line 440...
440
        mov     [ebp+NTFS.ntfs_cur_offs], 0
440
        mov     [ebp+NTFS.ntfs_cur_offs], 0
441
        call    ntfs_read_attr
441
        call    ntfs_read_attr
442
        mov     eax, [ebp+NTFS.ntfs_cur_read]
442
        mov     eax, [ebp+NTFS.ntfs_cur_read]
443
        cmp     eax, 4
443
        cmp     eax, 4
444
        jc      .failFreeBitmapMFT
444
        jc      .failFreeBitmapMFT
-
 
445
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
-
 
446
        cmp     byte [ecx+nonResidentFlag], 1
-
 
447
        jnz     .failFreeBitmapMFT
445
        mov     [ebp+NTFS.mftBitmapSize], eax
448
        mov     [ebp+NTFS.mftBitmapSize], eax
446
        mov     eax, [ebp+NTFS.ntfsLastRead]
449
        mov     eax, [ebp+NTFS.ntfsLastRead]
447
        mov     [ebp+NTFS.mftBitmapLocation], eax
450
        mov     [ebp+NTFS.mftBitmapLocation], eax
Line 448... Line 451...
448
 
451
 
Line 658... Line 661...
658
        or      [ebp+NTFS.ntfs_attr_iBaseRecord], -1
661
        or      [ebp+NTFS.ntfs_attr_iBaseRecord], -1
659
        call    ntfs_read_file_record
662
        call    ntfs_read_file_record
660
        jc      .errret
663
        jc      .errret
661
; 2. Find required attribute.
664
; 2. Find required attribute.
662
        mov     eax, [ebp+NTFS.frs_buffer]
665
        mov     eax, [ebp+NTFS.frs_buffer]
663
; a) For auxiliary records, read base record
666
; a) For auxiliary records, read base record.
664
; N.B. If base record is present,
667
; If base record is present, base iRecord may be 0 (for $Mft),
665
;      base iRecord may be 0 (for $Mft), but SequenceNumber is nonzero
668
; but SequenceNumber is nonzero.
666
        cmp     dword [eax+24h], 0
669
        cmp     dword [eax+24h], 0
667
        jz      @f
670
        jz      @f
668
        mov     eax, [eax+20h]
671
        mov     eax, [eax+20h]
669
;        test    eax, eax
-
 
670
;        jz      @f
-
 
671
.beginfindattr:
672
.beginfindattr:
672
        mov     [ebp+NTFS.ntfs_attr_iRecord], eax
673
        mov     [ebp+NTFS.ntfs_attr_iRecord], eax
673
        call    ntfs_read_file_record
674
        call    ntfs_read_file_record
674
        jc      .errret
675
        jc      .errret
-
 
676
        jmp     @f
-
 
677
.newAttribute:
-
 
678
        pushad
675
@@:
679
@@:
676
; b) Scan for required attribute and for $ATTR_LIST
680
; b) Scan for required attribute and for $ATTR_LIST
677
        mov     eax, [ebp+NTFS.frs_buffer]
681
        mov     eax, [ebp+NTFS.frs_buffer]
678
        movzx   ecx, word [eax+14h]
682
        movzx   ecx, word [eax+14h]
679
        add     eax, ecx
683
        add     eax, ecx
Line 2048... Line 2052...
2048
        mov     ecx, [ebp+NTFS.frs_buffer]
2052
        mov     ecx, [ebp+NTFS.frs_buffer]
2049
        mov     eax, edx
2053
        mov     eax, edx
2050
        xor     edx, edx
2054
        xor     edx, edx
2051
        cmp     word [ecx+baseRecordReuse], 0
2055
        cmp     word [ecx+baseRecordReuse], 0
2052
        jnz     ntfsUnsupported     ; auxiliary record
2056
        jnz     ntfsUnsupported     ; auxiliary record
2053
        cmp     byte [ecx+hardLinkCounter], 1
-
 
2054
        jnz     ntfsUnsupported     ; file copying required
-
 
2055
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2057
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2056
        cmp     byte [ecx+nonResidentFlag], 1
2058
        cmp     byte [ecx+nonResidentFlag], 1
2057
        jnz     ntfsUnsupported     ; resident $DATA
2059
        jnz     ntfsUnsupported     ; resident $DATA
2058
        test    eax, eax
2060
        test    eax, eax
2059
        jz      ntfsUnsupported
2061
        jz      ntfsUnsupported
Line 2213... Line 2215...
2213
        repz scasb
2215
        repz scasb
2214
        dec     edi
2216
        dec     edi
2215
        movzx   eax, byte [edi]
2217
        movzx   eax, byte [edi]
2216
        not     al
2218
        not     al
2217
        bsf     ecx, eax
2219
        bsf     ecx, eax
2218
        jz      ntfsUnsupported     ; no free records
2220
        jz      .extendBitmapMFT    ; no free records
2219
        bts     [edi], ecx
2221
        bts     [edi], ecx
2220
; get record location
2222
; get record location
2221
        sub     edi, [ebp+NTFS.mftBitmapBuffer]
2223
        sub     edi, [ebp+NTFS.mftBitmapBuffer]
2222
        shl     edi, 3
2224
        shl     edi, 3
2223
        add     edi, ecx
2225
        add     edi, ecx
Line 2231... Line 2233...
2231
        mov     [ebp+NTFS.ntfs_cur_size], 1
2233
        mov     [ebp+NTFS.ntfs_cur_size], 1
2232
        mov     eax, [ebp+NTFS.frs_buffer]
2234
        mov     eax, [ebp+NTFS.frs_buffer]
2233
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2235
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2234
        call    ntfs_read_attr
2236
        call    ntfs_read_attr
2235
        cmp     [ebp+NTFS.ntfs_cur_read], 0
2237
        cmp     [ebp+NTFS.ntfs_cur_read], 0
-
 
2238
        jz      .extendMFT
2236
        jnz     .mftRecord
2239
        jmp     .mftRecord
-
 
2240
 
2237
; extend MFT $DATA
2241
.extendBitmapMFT:
-
 
2242
        mov     eax, [ebp+NTFS.sectors_per_cluster]
-
 
2243
        shl     eax, 9
-
 
2244
        cmp     [ebp+NTFS.mftBitmapSize], eax
-
 
2245
        jnc     ntfsUnsupported
-
 
2246
        mov     [ebp+NTFS.ntfs_cur_iRecord], 0
-
 
2247
        mov     [ebp+NTFS.ntfs_cur_attr], 0xB0
-
 
2248
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
2249
        mov     [ebp+NTFS.ntfs_cur_size], 0
-
 
2250
        call    ntfs_read_attr
-
 
2251
        jc      ntfsFail
2238
        mov     eax, [ebp+NTFS.mft_cluster]
2252
        mov     eax, [ebp+NTFS.mft_cluster]
2239
        mul     [ebp+NTFS.sectors_per_cluster]
2253
        mul     [ebp+NTFS.sectors_per_cluster]
2240
        cmp     eax, [ebp+NTFS.ntfsLastRead]
2254
        cmp     eax, [ebp+NTFS.ntfsLastRead]
2241
        jnz     ntfsUnsupported     ; auxiliary record
2255
        jnz     ntfsUnsupported     ; auxiliary record
2242
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
2256
        mov     edi, [ebp+NTFS.mftBitmapBuffer]
2243
        mov     ebx, [ebp+NTFS.sectors_per_cluster]
2257
        mov     ecx, [ebp+NTFS.mftBitmapSize]
2244
        shl     ebx, 9+3
-
 
2245
        add     dword [edi+lastVCN], 8
-
 
2246
        add     [edi+attributeAllocatedSize], ebx
-
 
2247
        adc     byte [edi+attributeAllocatedSize+4], 0
-
 
2248
        add     [edi+attributeRealSize], ebx
-
 
2249
        adc     byte [edi+attributeRealSize+4], 0
-
 
2250
        add     [edi+initialDataSize], ebx
-
 
2251
        adc     byte [edi+initialDataSize+4], 0
-
 
2252
        movzx   eax, byte [edi+dataRunsOffset]
-
 
2253
        add     edi, eax
2258
        add     edi, ecx
2254
        mov     al, [edi]
-
 
2255
        inc     edi
-
 
2256
        shl     eax, 4
-
 
2257
        shr     al, 4
-
 
2258
        mov     cl, 4
-
 
2259
        sub     cl, al
-
 
2260
        shl     cl, 3
-
 
2261
        add     ah, al
-
 
2262
        shr     eax, 8
-
 
2263
        cmp     byte [edi+eax], 0
-
 
2264
        jnz     ntfsUnsupported     ; $MFT fragmented
-
 
2265
        mov     al, 8
2259
        mov     eax, ecx
2266
        mov     edx, [edi]
2260
        mov     edx, [ebp+NTFS.ntfs_attr_offs]
2267
        rol     eax, cl
-
 
2268
        rol     edx, cl
-
 
2269
        add     eax, edx
2261
        add     ecx, 8
2270
        jc      ntfsUnsupported
-
 
2271
        ror     eax, cl
-
 
2272
        shr     edx, cl
-
 
2273
        mov     [edi], eax
2262
        mov     [edx+attributeRealSize], ecx
2274
        add     edx, [ebp+NTFS.mft_cluster]
-
 
2275
        mov     esi, edx
-
 
2276
        mov     ecx, edx
2263
        mov     [edx+initialDataSize], ecx
2277
        and     ecx, 7
-
 
2278
        shr     edx, 3
2264
        shl     eax, 3
2279
        add     edx, [ebp+NTFS.BitmapBuffer]
2265
        mov     [ebp+NTFS.newMftRecord], eax
2280
        mov     ax, [edx]
2266
        mov     dword [edi], 1
2281
        shr     ax, cl
-
 
2282
        test    al, al
-
 
2283
        jnz     ntfsUnsupported
-
 
2284
        dec     al
-
 
2285
        xchg    [edx], al
2267
        mov     dword [edi+4], 0
2286
        mov     [edx+1], al
2268
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
2287
        stdcall kernel_alloc, ebx
2269
        call    ntfs_read_attr.newAttribute
2288
        test    eax, eax
-
 
2289
        jz      ntfsNoMemory
2270
        jc      ntfsFail
2290
        mov     ecx, ebx
-
 
2291
        shr     ecx, 2
-
 
2292
        mov     edi, eax
2271
        mov     [ebp+NTFS.mftBitmapSize], ecx
2293
        push    ebx
-
 
2294
        mov     ebx, eax
-
 
2295
        xor     eax, eax
-
 
2296
        rep stosd
2272
.extendMFT:
2297
        mov     eax, esi
2273
        mov     eax, [ebp+NTFS.mft_cluster]
2298
        mul     [ebp+NTFS.sectors_per_cluster]
2274
        mul     [ebp+NTFS.sectors_per_cluster]
2299
        pop     ecx
2275
        cmp     eax, [ebp+NTFS.ntfsLastRead]
2300
        shr     ecx, 9
2276
        jnz     ntfsUnsupported     ; auxiliary record
2301
        call    fs_write64_sys  ; clear new records
2277
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2302
        stdcall kernel_free, ebx
2278
        mov     eax, [ecx+attributeRealSize]
2303
        mov     eax, esi
2279
        mov     edx, [ecx+attributeRealSize+4]
2304
        shr     eax, 3+9
2280
        xor     ax, ax
2305
        mov     ebx, eax
2281
        add     eax, 10000h
2306
        shl     ebx, 9
2282
        adc     edx, 0
2307
        add     ebx, [ebp+NTFS.BitmapBuffer]
2283
        push    [ebp+NTFS.fileDataStart]
2308
        add     eax, [ebp+NTFS.BitmapLocation]
2284
        push    [ebp+NTFS.fileDataSize]
2309
        mov     ecx, 1
-
 
2310
        xor     edx, edx
-
 
2311
        call    fs_write64_app  ; partition bitmap
-
 
2312
        test    eax, eax
2285
        call    resizeAttribute
2313
        jnz     ntfsDevice
2286
        jc      ntfsErrorPop2
2314
        mov     eax, [ebp+NTFS.frs_buffer]
2287
        mov     eax, [ebp+NTFS.frs_buffer]
2315
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2288
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2316
        call    writeRecord     ; $MFT
2289
        call    writeRecord     ; $MFT
2317
        test    eax, eax
-
 
2318
        jnz     ntfsDevice
-
 
2319
        mov     eax, [ebp+NTFS.mftmirr_cluster]
2290
        mov     eax, [ebp+NTFS.mftmirr_cluster]
2320
        mul     [ebp+NTFS.sectors_per_cluster]
2291
        mul     [ebp+NTFS.sectors_per_cluster]
2321
        mov     ebx, [ebp+NTFS.frs_buffer]
2292
        mov     ebx, [ebp+NTFS.frs_buffer]
2322
        movzx   ecx, word [ebx+updateSequenceSize]
2293
        movzx   ecx, word [ebx+updateSequenceSize]
2323
        dec     ecx
2294
        dec     ecx
2324
        call    fs_write64_sys  ; $MFTMirr
2295
        call    fs_write64_sys  ; $MFTMirr
2325
        test    eax, eax
-
 
2326
        jnz     ntfsDevice
2296
        call    ntfsSpaceClean
2327
        mov     eax, [ebp+NTFS.ntfs_cur_offs]
2297
        pop     [ebp+NTFS.fileDataSize]
2328
        add     [ebp+NTFS.ntfsLastRead], eax
2298
        pop     [ebp+NTFS.fileDataStart]
2329
.mftRecord:
2299
.mftRecord:
2330
        mov     esi, [ebp+NTFS.indexOffset]
2300
        mov     esi, [ebp+NTFS.indexOffset]
2331
        mov     edi, [ebp+NTFS.frs_buffer]
2301
        mov     edi, [ebp+NTFS.frs_buffer]
2332
        xor     eax, eax
2302
        xor     eax, eax
2333
        movzx   ecx, word [esi+indexAllocatedSize]
2303
        movzx   ecx, word [esi+indexAllocatedSize]
Line 2568... Line 2538...
2568
;   in:
2538
;   in:
2569
; [ebp+NTFS.frs_buffer] -> file record
2539
; [ebp+NTFS.frs_buffer] -> file record
2570
; [ebp+NTFS.ntfs_attr_offs] -> attribute
2540
; [ebp+NTFS.ntfs_attr_offs] -> attribute
2571
; edx:eax = new size
2541
; edx:eax = new size
2572
;   out:
2542
;   out:
-
 
2543
; [ebp+NTFS.fileDataSize] = clusters added (positive)
-
 
2544
; [ebp+NTFS.fileDataStart] = added block
2573
; CF=1 -> eax = error code
2545
; CF=1 -> eax = error code
2574
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
2546
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
2575
        mov     ecx, [ebp+NTFS.sectors_per_cluster]
2547
        mov     ecx, [ebp+NTFS.sectors_per_cluster]
2576
        shl     ecx, 9
2548
        shl     ecx, 9
2577
        mov     dword [ebp+NTFS.ntfs_attr_size], eax
2549
        mov     dword [ebp+NTFS.ntfs_attr_size], eax
Line 2590... Line 2562...
2590
        mov     [esi+attributeAllocatedSize+4], edx
2562
        mov     [esi+attributeAllocatedSize+4], edx
2591
        mov     ecx, [esi+lastVCN]
2563
        mov     ecx, [esi+lastVCN]
2592
        mov     [esi+lastVCN], edi
2564
        mov     [esi+lastVCN], edi
2593
        movzx   eax, byte [esi+dataRunsOffset]
2565
        movzx   eax, byte [esi+dataRunsOffset]
2594
        sub     edi, ecx
2566
        sub     edi, ecx
-
 
2567
        mov     [ebp+NTFS.fileDataSize], edi
2595
        jz      .done
2568
        jz      .done
2596
        jc      .shrinkAttribute
2569
        jc      .shrinkAttribute
2597
; extend attribute
2570
; extend attribute
2598
        mov     [ebp+NTFS.fileDataSize], edi
-
 
2599
        xor     edi, edi
2571
        xor     edi, edi
2600
        add     esi, eax
2572
        add     esi, eax
2601
        push    edi edi edi edi
2573
        push    edi edi edi edi
2602
@@:
2574
@@:
2603
        mov     edx, eax
2575
        mov     edx, eax
Line 2610... Line 2582...
2610
        add     edi, [esp]
2582
        add     edi, [esp]
2611
        push    edi
2583
        push    edi
2612
        shr     edi, 5
2584
        shr     edi, 5
2613
        shl     edi, 2
2585
        shl     edi, 2
2614
        push    eax
2586
        push    eax
-
 
2587
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 0
-
 
2588
        jz      @f
2615
        cmp     edi, [ebp+NTFS.BitmapStart]
2589
        cmp     edi, [ebp+NTFS.BitmapStart]
2616
        jc      .err1
2590
        jc      .err1
-
 
2591
@@:
2617
        call    ntfsSpaceAlloc
2592
        call    ntfsSpaceAlloc
2618
        jc      .err1
2593
        jc      .err1
2619
        pop     edi
2594
        pop     edi
2620
        pop     edx
2595
        pop     edx
2621
        cmp     edx, eax
2596
        cmp     edx, eax
Line 2640... Line 2615...
2640
        call    createMcbEntry
2615
        call    createMcbEntry
2641
        pop     ecx
2616
        pop     ecx
2642
        pop     eax
2617
        pop     eax
2643
        jc      .err2
2618
        jc      .err2
2644
        mov     byte [edi], 0
2619
        mov     byte [edi], 0
-
 
2620
        mov     [ebp+NTFS.fileDataSize], ecx
-
 
2621
        mov     [ebp+NTFS.fileDataStart], eax
2645
        add     ecx, eax
2622
        add     ecx, eax
2646
        add     ecx, 4095
2623
        add     ecx, 4095
2647
        shr     ecx, 3+9
2624
        shr     ecx, 3+9
2648
        shr     eax, 3+9
2625
        shr     eax, 3+9
2649
        sub     ecx, eax
2626
        sub     ecx, eax
Line 2708... Line 2685...
2708
        pop     edi
2685
        pop     edi
2709
        cmp     [ebp+NTFS.fileDataSize], 0
2686
        cmp     [ebp+NTFS.fileDataSize], 0
2710
        jz      @f
2687
        jz      @f
2711
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
2688
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
2712
        call    createMcbEntry
2689
        call    createMcbEntry
-
 
2690
        mov     [ebp+NTFS.fileDataSize], 0
2713
@@:
2691
@@:
2714
        mov     byte [edi], 0
2692
        mov     byte [edi], 0
2715
        ret
2693
        ret
Line 2716... Line 2694...
2716
 
2694
 
2717
.err3:
2695
.err3:
2718
        movi    eax, ERROR_FS_FAIL
2696
        movi    eax, ERROR_FS_FAIL
2719
        add     esp, 20
2697
        add     esp, 20
2720
        stc
2698
        stc
Line -... Line 2699...
-
 
2699
        ret
-
 
2700
 
-
 
2701
ntfsSpaceClean:
-
 
2702
; clean up to 16 Mb of disk space
-
 
2703
;   in:
-
 
2704
; [ebp+NTFS.fileDataStart] = block to clean
-
 
2705
; [ebp+NTFS.fileDataSize] = block size
-
 
2706
        mov     eax, [ebp+NTFS.fileDataSize]
-
 
2707
        test    eax, eax
-
 
2708
        jz      @f
-
 
2709
        mul     [ebp+NTFS.sectors_per_cluster]
-
 
2710
        cmp     eax, 8001h
-
 
2711
        jnc     @f
-
 
2712
        push    eax
-
 
2713
        shl     eax, 9
-
 
2714
        stdcall kernel_alloc, eax
-
 
2715
        pop     ecx
-
 
2716
        test    eax, eax
-
 
2717
        jz      @f
-
 
2718
        push    ecx
-
 
2719
        shl     ecx, 7
-
 
2720
        mov     edi, eax
-
 
2721
        mov     ebx, eax
-
 
2722
        xor     eax, eax
-
 
2723
        rep stosd
-
 
2724
        mov     eax, [ebp+NTFS.fileDataStart]
-
 
2725
        mul     [ebp+NTFS.sectors_per_cluster]
-
 
2726
        mov     [ebp+NTFS.ntfsLastRead], eax
-
 
2727
        pop     ecx
-
 
2728
        call    fs_write64_app
-
 
2729
        stdcall kernel_free, ebx
-
 
2730
@@:
2721
        ret
2731
        ret
2722
 
2732
 
2723
ntfsSpaceAlloc:
2733
ntfsSpaceAlloc:
2724
; find and mark block of free space in bitmap buffer
2734
; find and mark block of free space in bitmap buffer
2725
;   in:
2735
;   in:
Line 3056... Line 3066...
3056
        pop     eax
3066
        pop     eax
3057
        jc      ntfsFail
3067
        jc      ntfsFail
3058
        mov     ecx, [ebp+NTFS.frs_buffer]
3068
        mov     ecx, [ebp+NTFS.frs_buffer]
3059
        cmp     word [ecx+baseRecordReuse], 0
3069
        cmp     word [ecx+baseRecordReuse], 0
3060
        jnz     ntfsUnsupported     ; auxiliary record
3070
        jnz     ntfsUnsupported     ; auxiliary record
3061
        cmp     byte [ecx+hardLinkCounter], 1
-
 
3062
        jnz     ntfsUnsupported     ; file copying required
-
 
3063
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
3071
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
3064
        cmp     byte [ecx+nonResidentFlag], 1
3072
        cmp     byte [ecx+nonResidentFlag], 1
3065
        jnz     ntfsUnsupported     ; resident $DATA
3073
        jnz     ntfsUnsupported     ; resident $DATA
3066
        cmp     edx, [ecx+attributeRealSize+4]
3074
        cmp     edx, [ecx+attributeRealSize+4]
3067
        jc      .writeNode
3075
        jc      .writeNode
Line 3069... Line 3077...
3069
        cmp     [ecx+attributeRealSize], eax
3077
        cmp     [ecx+attributeRealSize], eax
3070
        jnc     .writeNode
3078
        jnc     .writeNode
3071
.resizeAttribute:
3079
.resizeAttribute:
3072
        push    ebx
3080
        push    ebx
3073
        call    resizeAttribute
3081
        call    resizeAttribute
3074
        jc      ntfsError
3082
        jc      ntfsErrorPop
3075
        mov     eax, [ebp+NTFS.frs_buffer]
3083
        mov     eax, [ebp+NTFS.frs_buffer]
3076
        mov     [ebp+NTFS.ntfs_cur_buf], eax
3084
        mov     [ebp+NTFS.ntfs_cur_buf], eax
3077
        call    writeRecord     ; file
3085
        call    writeRecord     ; file
3078
        mov     ebx, [ebp+NTFS.frs_buffer]
3086
        mov     ebx, [ebp+NTFS.frs_buffer]
3079
        call    ntfs_restore_usa_frs
3087
        call    ntfs_restore_usa_frs
Line 3183... Line 3191...
3183
        shr     edx, 3
3191
        shr     edx, 3
3184
        cmp     edx, [ebp+NTFS.mftBitmapSize]
3192
        cmp     edx, [ebp+NTFS.mftBitmapSize]
3185
        jnc     ntfsUnsupported
3193
        jnc     ntfsUnsupported
3186
; delete index from the node
3194
; delete index from the node
3187
        movzx   edx, word [eax+indexAllocatedSize]
3195
        movzx   edx, word [eax+indexAllocatedSize]
-
 
3196
        mov     ecx, [eax+fileRecordReference]
-
 
3197
        cmp     [eax+edx+fileRecordReference], ecx
-
 
3198
        jnz     @f
-
 
3199
        add     dx, [eax+edx+indexAllocatedSize]
-
 
3200
@@:
3188
        mov     edi, [ebp+NTFS.cur_index_buf]
3201
        mov     edi, [ebp+NTFS.cur_index_buf]
3189
        cmp     dword [edi], 'INDX'
3202
        cmp     dword [edi], 'INDX'
3190
        jz      .indexRecord
3203
        jz      .indexRecord
3191
        mov     esi, [ebp+NTFS.frs_buffer]  ; indexRoot
3204
        mov     esi, [ebp+NTFS.frs_buffer]  ; indexRoot
3192
        mov     ecx, [esi+recordRealSize]
3205
        mov     ecx, [esi+recordRealSize]
Line 3229... Line 3242...
3229
        call    ntfs_read_attr
3242
        call    ntfs_read_attr
3230
        jc      .folder
3243
        jc      .folder
3231
        mov     esi, [ebp+NTFS.frs_buffer]
3244
        mov     esi, [ebp+NTFS.frs_buffer]
3232
        cmp     word [esi+baseRecordReuse], 0
3245
        cmp     word [esi+baseRecordReuse], 0
3233
        jnz     ntfsUnsupported     ; auxiliary record
3246
        jnz     ntfsUnsupported     ; auxiliary record
3234
        cmp     byte [esi+hardLinkCounter], 2
-
 
3235
        jnc     .writeFileRecord    ; delete hard link
-
 
3236
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
3247
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
3237
        cmp     byte [esi+nonResidentFlag], 0
3248
        cmp     byte [esi+nonResidentFlag], 0
3238
        jz      .writeBitmapMFT
3249
        jz      .writeBitmapMFT
3239
        movzx   eax, byte [esi+dataRunsOffset]
3250
        movzx   eax, byte [esi+dataRunsOffset]
3240
        add     esi, eax
3251
        add     esi, eax
Line 3278... Line 3289...
3278
        add     ebx, edi
3289
        add     ebx, edi
3279
        mov     ecx, 1
3290
        mov     ecx, 1
3280
        xor     edx, edx
3291
        xor     edx, edx
3281
        call    fs_write64_sys
3292
        call    fs_write64_sys
3282
        mov     esi, [ebp+NTFS.frs_buffer]
3293
        mov     esi, [ebp+NTFS.frs_buffer]
3283
        mov     byte [esi+recordFlags], 0
-
 
3284
.writeFileRecord:
-
 
3285
        dec     byte [esi+hardLinkCounter]
-
 
3286
        mov     [ebp+NTFS.ntfs_cur_buf], esi
3294
        mov     [ebp+NTFS.ntfs_cur_buf], esi
-
 
3295
        mov     byte [esi+recordFlags], 0
3287
        call    writeRecord
3296
        call    writeRecord
3288
; write directory node
3297
; write directory node
3289
        mov     eax, [ebp+NTFS.nodeLastRead]
3298
        mov     eax, [ebp+NTFS.nodeLastRead]
3290
        mov     [ebp+NTFS.ntfsLastRead], eax
3299
        mov     [ebp+NTFS.ntfsLastRead], eax
3291
        mov     eax, [ebp+NTFS.cur_index_buf]
3300
        mov     eax, [ebp+NTFS.cur_index_buf]
Line 3293... Line 3302...
3293
        call    writeRecord
3302
        call    writeRecord
3294
        jmp     ntfsDone
3303
        jmp     ntfsDone
Line 3295... Line 3304...
3295
 
3304
 
3296
;----------------------------------------------------------------
3305
;----------------------------------------------------------------
-
 
3306
ntfs_SetFileEnd:
-
 
3307
        cmp     byte [esi], 0
-
 
3308
        jnz     @f
-
 
3309
        xor     ebx, ebx
-
 
3310
        movi    eax, ERROR_ACCESS_DENIED
-
 
3311
        ret
-
 
3312
@@:
-
 
3313
        call    ntfs_lock
-
 
3314
        stdcall ntfs_find_lfn, [esp+4]
-
 
3315
        jc      ntfsNotFound
-
 
3316
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 16
-
 
3317
        jc      ntfsDenied
-
 
3318
        bt      dword [eax+fileFlags], 28
-
 
3319
        jc      ntfsDenied
-
 
3320
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
-
 
3321
        jnz     ntfsUnsupported     ; record fragmented
-
 
3322
; set file size in the directory
-
 
3323
        mov     edi, [ebp+NTFS.cur_index_buf]
-
 
3324
        cmp     dword [edi], 'INDX'
-
 
3325
        jz      @f
-
 
3326
        mov     esi, [ebp+NTFS.frs_buffer]
-
 
3327
        mov     ecx, [esi+recordRealSize]
-
 
3328
        shr     ecx, 2
-
 
3329
        rep movsd
-
 
3330
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
-
 
3331
        mov     cl, [esi+attributeOffset]
-
 
3332
        sub     esi, [ebp+NTFS.frs_buffer]
-
 
3333
        add     eax, ecx
-
 
3334
        add     eax, esi
-
 
3335
@@:
-
 
3336
        mov     ecx, [ebx+4]
-
 
3337
        mov     edx, [ebx+8]
-
 
3338
        mov     [eax+fileRealSize], ecx
-
 
3339
        mov     [eax+fileRealSize+4], edx
-
 
3340
        mov     eax, [ebp+NTFS.ntfsLastRead]
-
 
3341
        mov     [ebp+NTFS.nodeLastRead], eax
-
 
3342
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
3343
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
3344
        mov     [ebp+NTFS.ntfs_cur_size], 0
-
 
3345
        call    ntfs_read_attr
-
 
3346
        jc      ntfsFail
-
 
3347
        mov     eax, ecx
-
 
3348
        mov     ecx, [ebp+NTFS.frs_buffer]
-
 
3349
        cmp     word [ecx+baseRecordReuse], 0
-
 
3350
        jnz     ntfsUnsupported     ; auxiliary record
-
 
3351
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
-
 
3352
        cmp     byte [ecx+nonResidentFlag], 1
-
 
3353
        jnz     ntfsUnsupported     ; resident $DATA
-
 
3354
        cmp     [ecx+attributeRealSize+4], edx
-
 
3355
        jnz     .resizeAttribute
-
 
3356
        cmp     [ecx+attributeRealSize], eax
-
 
3357
        jnc     .resizeAttribute
-
 
3358
        mov     eax, [ecx+attributeRealSize]
-
 
3359
        mov     ecx, [ebp+NTFS.sectors_per_cluster]
-
 
3360
        mov     [ebp+NTFS.ntfs_cur_size], ecx
-
 
3361
        shl     ecx, 9
-
 
3362
        div     ecx
-
 
3363
        test    edx, edx
-
 
3364
        jz      .aligned
-
 
3365
        push    edx
-
 
3366
        push    ecx
-
 
3367
        mul     [ebp+NTFS.sectors_per_cluster]
-
 
3368
        mov     [ebp+NTFS.ntfs_cur_offs], eax
-
 
3369
        stdcall kernel_alloc, ecx
-
 
3370
        pop     ecx
-
 
3371
        pop     edi
-
 
3372
        sub     ecx, edi
-
 
3373
        add     edi, eax
-
 
3374
        mov     [ebp+NTFS.ntfs_cur_buf], eax
-
 
3375
        push    [ebp+NTFS.ntfsLastRead]
-
 
3376
        call    ntfs_read_attr.continue
-
 
3377
        jc      @f
-
 
3378
        xor     eax, eax
-
 
3379
        rep stosb
-
 
3380
        push    ebx
-
 
3381
        mov     eax, [ebp+NTFS.ntfsLastRead]
-
 
3382
        mov     ebx, [ebp+NTFS.ntfs_cur_buf]
-
 
3383
        mov     ecx, [ebp+NTFS.sectors_per_cluster]
-
 
3384
        xor     edx, edx
-
 
3385
        call    fs_write64_app
-
 
3386
        pop     ebx
-
 
3387
@@:
-
 
3388
        pop     [ebp+NTFS.ntfsLastRead]
-
 
3389
        stdcall kernel_free, [ebp+NTFS.ntfs_cur_buf]
-
 
3390
.aligned:
-
 
3391
        mov     eax, [ebx+4]
-
 
3392
        mov     edx, [ebx+8]
-
 
3393
.resizeAttribute:
-
 
3394
        call    resizeAttribute
-
 
3395
        jc      ntfsError
-
 
3396
        mov     eax, [ebp+NTFS.frs_buffer]
-
 
3397
        mov     [ebp+NTFS.ntfs_cur_buf], eax
-
 
3398
        call    writeRecord     ; file
-
 
3399
        mov     eax, [ebp+NTFS.nodeLastRead]
-
 
3400
        mov     [ebp+NTFS.ntfsLastRead], eax
-
 
3401
        mov     eax, [ebp+NTFS.cur_index_buf]
-
 
3402
        mov     [ebp+NTFS.ntfs_cur_buf], eax
-
 
3403
        call    writeRecord     ; directory
-
 
3404
        call    ntfsSpaceClean
-
 
3405
        jmp     ntfsDone
-
 
3406
 
3297
ntfs_SetFileEnd:
3407
;----------------------------------------------------------------
3298
ntfs_SetFileInfo:
3408
ntfs_SetFileInfo:
3299
        movi    eax, ERROR_UNSUPPORTED_FS
3409
        movi    eax, ERROR_UNSUPPORTED_FS
Line 3300... Line 3410...
3300
        ret
3410
        ret
Line 3336... Line 3446...
3336
        push    ERROR_ACCESS_DENIED
3446
        push    ERROR_ACCESS_DENIED
3337
        jmp     ntfsOut
3447
        jmp     ntfsOut
3338
ntfsFail:
3448
ntfsFail:
3339
        push    ERROR_FS_FAIL
3449
        push    ERROR_FS_FAIL
3340
        jmp     ntfsOut
3450
        jmp     ntfsOut
3341
ntfsNoMemory:
-
 
3342
        push    ERROR_OUT_OF_MEMORY
-
 
3343
        jmp     ntfsOut
-
 
3344
ntfsDiskFull:
3451
ntfsDiskFull:
3345
        push    ERROR_DISK_FULL
3452
        push    ERROR_DISK_FULL
3346
        jmp     ntfsOut
3453
        jmp     ntfsOut
-
 
3454
ntfsErrorPop2:
-
 
3455
        pop     ebx
3347
ntfsError:
3456
ntfsErrorPop:
3348
        pop     ebx
3457
        pop     ebx
-
 
3458
ntfsError:
3349
        push    eax
3459
        push    eax
3350
ntfsOut:
3460
ntfsOut:
3351
        call    ntfs_unlock
3461
        call    ntfs_unlock
3352
        xor     ebx, ebx
3462
        xor     ebx, ebx
3353
        pop     eax
3463
        pop     eax