Subversion Repositories Kolibri OS

Rev

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

Rev 5994 Rev 6019
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. 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: 5994 $
8
$Revision: 6019 $
Line 9... Line 9...
9
 
9
 
10
; NTFS driver
10
; NTFS driver
Line 44... Line 44...
44
attributeType = 0
44
attributeType = 0
45
sizeWithHeader = 4
45
sizeWithHeader = 4
46
nonResidentFlag = 8
46
nonResidentFlag = 8
47
nameLength = 9
47
nameLength = 9
48
nameOffset = 10
48
nameOffset = 10
-
 
49
attributeFlags = 12
49
attributeID = 14
50
attributeID = 14
50
sizeWithoutHeader = 16
51
sizeWithoutHeader = 16
51
attributeFlags = 16h
52
indexedFlag = 16h
52
    ; non resident attribute header
53
    ; non resident attribute header
53
lastVCN = 18h
54
lastVCN = 18h
54
dataRunsOffset = 20h
55
dataRunsOffset = 20h
55
attributeAllocatedSize = 28h
56
attributeAllocatedSize = 28h
56
attributeRealSize = 30h
57
attributeRealSize = 30h
Line 270... Line 271...
270
        jz      .exit
271
        jz      .exit
271
        mov     ecx, dword [ebp+PARTITION.FirstSector]
272
        mov     ecx, dword [ebp+PARTITION.FirstSector]
272
        mov     dword [eax+NTFS.FirstSector], ecx
273
        mov     dword [eax+NTFS.FirstSector], ecx
273
        mov     ecx, dword [ebp+PARTITION.FirstSector+4]
274
        mov     ecx, dword [ebp+PARTITION.FirstSector+4]
274
        mov     dword [eax+NTFS.FirstSector+4], ecx
275
        mov     dword [eax+NTFS.FirstSector+4], ecx
275
        mov     ecx, dword [ebp+PARTITION.Length]
-
 
276
        mov     dword [eax+NTFS.Length], ecx
-
 
277
        mov     ecx, dword [ebp+PARTITION.Length+4]
-
 
278
        mov     dword [eax+NTFS.Length+4], ecx
-
 
279
        mov     ecx, [ebp+PARTITION.Disk]
276
        mov     ecx, [ebp+PARTITION.Disk]
280
        mov     [eax+NTFS.Disk], ecx
277
        mov     [eax+NTFS.Disk], ecx
281
        mov     [eax+NTFS.FSUserFunctions], ntfs_user_functions
278
        mov     [eax+NTFS.FSUserFunctions], ntfs_user_functions
282
        mov     [eax+NTFS.ntfsWriteAttr], 0
279
        mov     [eax+NTFS.ntfsWriteAttr], 0
Line 1163... Line 1160...
1163
        popad
1160
        popad
1164
        stc
1161
        stc
1165
        ret
1162
        ret
Line 1166... Line 1163...
1166
 
1163
 
-
 
1164
ntfs_decode_mcb_entry:
-
 
1165
;   in:
-
 
1166
; esi -> mcb entry
-
 
1167
; esp -> buffer (16 bytes)
-
 
1168
;   out:
-
 
1169
; esi -> next mcb entry
-
 
1170
; esp -> data run size
-
 
1171
; esp+8 -> cluster (delta)
1167
ntfs_decode_mcb_entry:
1172
; CF=0 -> mcb end
1168
        push    eax ecx edi
1173
        push    eax ecx edi
1169
        lea     edi, [esp+16]
1174
        lea     edi, [esp+16]
1170
        xor     eax, eax
1175
        xor     eax, eax
1171
        lodsb
1176
        lodsb
Line 1987... Line 1992...
1987
        mov     [ebp+NTFS.ntfsFolder], 0
1992
        mov     [ebp+NTFS.ntfsFolder], 0
1988
@@:
1993
@@:
1989
        cmp     byte [esi], 0
1994
        cmp     byte [esi], 0
1990
        jnz     @f
1995
        jnz     @f
1991
        xor     ebx, ebx
1996
        xor     ebx, ebx
1992
        movi    eax, ERROR_ACCESS_DENIED    ; root directory itself
1997
        movi    eax, ERROR_ACCESS_DENIED
1993
        ret
1998
        ret
1994
@@: ; 1. Search file
1999
@@: ; 1. Search file
1995
        call    ntfs_lock
2000
        call    ntfs_lock
1996
        stdcall ntfs_find_lfn, [esp+4]
2001
        stdcall ntfs_find_lfn, [esp+4]
1997
        jnc     .found
2002
        jnc     .found
1998
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
2003
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
1999
        jnz     @f      ; record fragmented
2004
        jnz     ntfsUnsupported     ; record fragmented
2000
        test    eax, eax
2005
        test    eax, eax
2001
        jnz     .notFound
-
 
2002
        push    ERROR_FS_FAIL
-
 
2003
        jmp     ntfsError
2006
        jz      ntfsFail
2004
@@:
-
 
2005
        push    ERROR_UNSUPPORTED_FS
-
 
2006
        jmp     ntfsError
2007
        jmp     .notFound
Line 2007... Line 2008...
2007
 
2008
 
-
 
2009
.found:     ; rewrite
-
 
2010
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 16
-
 
2011
        jc      ntfsDenied
-
 
2012
        cmp     [ebp+NTFS.ntfsFolder], 1
2008
.found:     ; rewrite
2013
        jz      ntfsDenied
2009
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
2014
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
2010
        mov     [ebp+NTFS.ntfs_cur_offs], 0
2015
        mov     [ebp+NTFS.ntfs_cur_offs], 0
2011
        mov     [ebp+NTFS.ntfs_cur_size], 0
2016
        mov     [ebp+NTFS.ntfs_cur_size], 0
2012
        call    ntfs_read_attr
-
 
2013
        jnc     @f
-
 
2014
        push    ERROR_ACCESS_DENIED
2017
        call    ntfs_read_attr
2015
        jmp     ntfsError
-
 
2016
@@:
-
 
2017
        push    ERROR_UNSUPPORTED_FS
2018
        jc      ntfsDenied
2018
        mov     eax, [ebp+NTFS.frs_buffer]
2019
        mov     eax, [ebp+NTFS.frs_buffer]
2019
        cmp     word [eax+baseRecordReuse], 0
2020
        cmp     word [eax+baseRecordReuse], 0
2020
        jnz     ntfsError       ; auxiliary record
2021
        jnz     ntfsUnsupported     ; auxiliary record
2021
        cmp     byte [eax+hardLinkCounter], 1
2022
        cmp     byte [eax+hardLinkCounter], 1
2022
        jnz     ntfsError       ; file copying required
2023
        jnz     ntfsUnsupported     ; file copying required
2023
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2024
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2024
        cmp     byte [ecx+nonResidentFlag], 1
2025
        cmp     byte [ecx+nonResidentFlag], 1
2025
        jnz     ntfsError       ; resident $DATA
2026
        jnz     ntfsUnsupported     ; resident $DATA
2026
        mov     eax, [ebx+4]
2027
        mov     eax, [ebx+4]
2027
        mov     edx, [ebx+8]
2028
        mov     edx, [ebx+8]
2028
        add     eax, [ebx+12]
2029
        add     eax, [ebx+12]
2029
        adc     edx, 0
2030
        adc     edx, 0
2030
        cmp     edx, [ecx+attributeRealSize+4]
2031
        cmp     edx, [ecx+attributeRealSize+4]
2031
        jnz     ntfsError
2032
        jnz     ntfsUnsupported
2032
        cmp     [ecx+attributeRealSize], eax
2033
        cmp     [ecx+attributeRealSize], eax
2033
        jnz     ntfsError
2034
        jnz     ntfsUnsupported
Line 2034... Line 2035...
2034
        jmp     ntfs_WriteFile.write
2035
        jmp     ntfs_WriteFile.write
2035
 
2036
 
2036
.notFound:  ; create; check name
2037
.notFound:  ; create; check path folders
2037
        cmp     dword [esp+4], 0
2038
        cmp     dword [esp+4], 0
2038
        jnz     .bad
-
 
2039
        cmp     byte [esi], 0
-
 
2040
        jnz     @f
-
 
2041
.bad:       ; path folder not found
2039
        jnz     ntfsNotFound
2042
        push    ERROR_FILE_NOT_FOUND
2040
        cmp     byte [esi], 0
2043
        jmp     ntfsError
2041
        jz      ntfsNotFound
2044
@@: ; 2. Prepair directory record
2042
; 2. Prepare directory record
2045
        mov     ecx, esi
2043
        mov     ecx, esi
2046
@@:         ; count characters
2044
@@:         ; count characters
2047
        inc     ecx
2045
        inc     ecx
2048
        cmp     byte [ecx], '/'
2046
        cmp     byte [ecx], '/'
2049
        jz      .bad
2047
        jz      ntfsNotFound
2050
        cmp     byte [ecx], 0
2048
        cmp     byte [ecx], 0
2051
        jnz     @b
2049
        jnz     @b
2052
        sub     ecx, esi
2050
        sub     ecx, esi
2053
        push    ecx
2051
        push    ecx
2054
        lea     ecx, [ecx*2+52h]    ; precalculate index length
2052
        lea     ecx, [ecx*2+52h]    ; precalculate index length
2055
        add     ecx, 7              ; align 8
2053
        add     ecx, 7              ; align 8
2056
        and     ecx, not 7
2054
        and     ecx, not 7
2057
        mov     edi, [ebp+NTFS.cur_index_buf]
2055
        mov     edi, [ebp+NTFS.cur_index_buf]
2058
        push    esi
2056
        push    esi
2059
        push    ecx
2057
        push    ecx
2060
        cmp     dword [edi], 'INDX'         ; where are we?
2058
        cmp     dword [edi], 'INDX'
2061
        jz      .indexRecord
2059
        jz      .indexRecord
2062
        mov     esi, [ebp+NTFS.frs_buffer]  ; mftRecord
2060
        mov     esi, [ebp+NTFS.frs_buffer]  ; indexRoot
2063
        mov     edx, [esi+recordRealSize]
2061
        mov     edx, [esi+recordRealSize]
2064
        add     edx, ecx
2062
        add     edx, ecx
2065
        cmp     [esi+recordAllocatedSize], edx
2063
        cmp     [esi+recordAllocatedSize], edx
2066
        jnc     @f
2064
        jnc     @f
2067
        add     esp, 12
-
 
2068
        push    ERROR_UNSUPPORTED_FS    ; indexAllocation required
2065
        add     esp, 12
2069
        jmp     ntfsError
2066
        jmp     ntfsUnsupported     ; indexAllocation required
2070
@@:         ; index fits in the indexRoot
2067
@@:         ; index fits in the indexRoot
2071
        mov     [esi+recordRealSize], edx
2068
        mov     [esi+recordRealSize], edx
2072
        mov     ecx, edx
2069
        mov     ecx, edx
Line 2076... Line 2073...
2076
        sub     edi, [ebp+NTFS.frs_buffer]
2073
        sub     edi, [ebp+NTFS.frs_buffer]
2077
        add     edi, [ebp+NTFS.cur_index_buf]
2074
        add     edi, [ebp+NTFS.cur_index_buf]
2078
        mov     esi, [esp]
2075
        mov     esi, [esp]
2079
        add     [edi+sizeWithHeader], esi
2076
        add     [edi+sizeWithHeader], esi
2080
        add     [edi+sizeWithoutHeader], esi
2077
        add     [edi+sizeWithoutHeader], esi
2081
        mov     cx, [edi+attributeOffset]
2078
        mov     cl, [edi+attributeOffset]
2082
        add     edi, ecx
2079
        add     edi, ecx
2083
        add     [edi+16+nodeRealSize], esi
2080
        add     [edi+16+nodeRealSize], esi
2084
        add     [edi+16+nodeAllocatedSize], esi
2081
        add     [edi+16+nodeAllocatedSize], esi
2085
        sub     eax, [ebp+NTFS.cur_index_buf]
2082
        sub     eax, [ebp+NTFS.cur_index_buf]
2086
        add     eax, edi
2083
        add     eax, edi
Line 2088... Line 2085...
2088
        add     edi, edx
2085
        add     edi, edx
2089
        sub     edi, 4
2086
        sub     edi, 4
2090
        jmp     .common
2087
        jmp     .common
Line 2091... Line 2088...
2091
 
2088
 
2092
.indexRecord:
2089
.indexRecord:
2093
        mov     edx, [edi+1ch]
2090
        mov     edx, [edi+28]
2094
        add     edx, ecx
2091
        add     edx, ecx
2095
        cmp     [edi+20h], edx
2092
        cmp     [edi+32], edx
2096
        jnc     @f
2093
        jnc     @f
2097
        add     esp, 12
2094
        add     esp, 12
2098
        push    ERROR_UNSUPPORTED_FS    ; new node required
-
 
2099
        jmp     ntfsError
2095
        jmp     ntfsUnsupported     ; new node required
2100
@@:         ; index fits in the node
2096
@@:         ; index fits in the node
2101
        mov     [edi+1ch], edx
2097
        mov     [edi+28], edx
2102
        lea     edi, [edi+edx+14h]
2098
        lea     edi, [edi+edx+24-4]
2103
.common:
2099
.common:
2104
        mov     esi, edi
2100
        mov     esi, edi
2105
        sub     esi, [esp]
2101
        sub     esi, [esp]
2106
        mov     ecx, esi
2102
        mov     ecx, esi
Line 2165... Line 2161...
2165
        mov     eax, [ebp+NTFS.fileDataSize]
2161
        mov     eax, [ebp+NTFS.fileDataSize]
2166
        shr     eax, 5
2162
        shr     eax, 5
2167
        jz      .small
2163
        jz      .small
2168
        push    eax         ; bitmap dwords
2164
        push    eax         ; bitmap dwords
2169
        add     edi, 4
2165
        add     edi, 4
2170
        xor     edx, edx
-
 
2171
.start:
2166
.start:
2172
        mov     ecx, [ebp+NTFS.BitmapSize]
2167
        mov     ecx, [ebp+NTFS.BitmapSize]
2173
        mov     eax, edi
-
 
2174
        sub     eax, [ebp+NTFS.BitmapBuffer]
2168
        add     ecx, [ebp+NTFS.BitmapBuffer]
2175
        sub     ecx, eax
2169
        sub     ecx, edi
2176
        shr     ecx, 2
2170
        shr     ecx, 2
2177
@@:
2171
@@:
2178
        xor     eax, eax
2172
        xor     eax, eax
2179
        repnz scasd         ; search for empty dword
2173
        repnz scasd         ; search for empty dword
2180
        jz      @f
2174
        jz      @f
Line 2192... Line 2186...
2192
        xor     eax, eax
2186
        xor     eax, eax
2193
        repz scasd          ; check following dwords
2187
        repz scasd          ; check following dwords
2194
        jnz     .start
2188
        jnz     .start
2195
        sub     esi, 4
2189
        sub     esi, 4
2196
        mov     eax, [esi]
2190
        mov     eax, [esi]
-
 
2191
        xor     edx, edx
2197
        bsr     edx, eax
2192
        bsr     edx, eax
2198
        inc     edx
2193
        inc     edx
2199
        push    edx         ; starting bit
2194
        push    edx         ; starting bit
2200
        push    esi         ; starting dword
2195
        push    esi         ; starting dword
2201
        add     esi, 4
2196
        add     esi, 4
Line 2272... Line 2267...
2272
        xor     ecx, ecx
2267
        xor     ecx, ecx
2273
        add     dword [esp], 4
2268
        add     dword [esp], 4
2274
        mov     [esp+4], ecx
2269
        mov     [esp+4], ecx
2275
@@:
2270
@@:
2276
        mov     edi, [esp]
2271
        mov     edi, [esp]
2277
        mov     esi, [ebp+NTFS.fileDataSize]
2272
        xor     eax, eax
-
 
2273
        dec     eax
2278
        mov     edx, [edi]
2274
        shr     eax, cl
2279
        ror     edx, cl
2275
        shl     eax, cl
2280
        neg     ecx
2276
        neg     ecx
2281
        add     ecx, 32
2277
        add     ecx, 32
2282
        mov     eax, -1
-
 
2283
        sub     esi, ecx
2278
        sub     ecx, [ebp+NTFS.fileDataSize]
2284
        jnc     @f
2279
        jc      @f
2285
        mov     esi, ecx    ; fits inside
2280
        shl     eax, cl     ; fits inside dword
2286
        mov     ecx, [ebp+NTFS.fileDataSize]
-
 
2287
        shrd    edx, eax, cl
-
 
2288
        sub     esi, ecx
-
 
2289
        mov     ecx, esi
-
 
2290
        ror     edx, cl
2281
        shr     eax, cl
2291
        mov     [edi], edx
2282
        or      [edi], eax
2292
        jmp     .writeData
2283
        jmp     .writeData
Line 2293... Line 2284...
2293
 
2284
 
2294
@@:
2285
@@:
2295
        shrd    edx, eax, cl
2286
        or      [edi], eax
2296
        mov     [edi], edx
2287
        neg     ecx
2297
        mov     ecx, esi
2288
        push    ecx
2298
        shr     ecx, 5
2289
        shr     ecx, 5
-
 
2290
        add     edi, 4
-
 
2291
        xor     eax, eax
2299
        add     edi, 4
2292
        dec     eax
2300
        rep stosd
2293
        rep stosd
2301
        mov     ecx, esi
2294
        pop     ecx
2302
        and     ecx, 31
2295
        and     ecx, 31
2303
        mov     edx, [edi]
2296
        shr     eax, cl
2304
        shr     edx, cl
2297
        shl     eax, cl
2305
        shld    edx, eax, cl
2298
        not     eax
2306
        mov     [edi], edx
2299
        or      [edi], eax
2307
.writeData:
2300
.writeData:
2308
        pop     edx
2301
        pop     edx
2309
        sub     edx, [ebp+NTFS.BitmapBuffer]
2302
        sub     edx, [ebp+NTFS.BitmapBuffer]
2310
        shl     edx, 3
2303
        shl     edx, 3
Line 2317... Line 2310...
2317
        add     ecx, 511
2310
        add     ecx, 511
2318
        shr     ecx, 9
2311
        shr     ecx, 9
2319
        mov     ebx, [ebx+16]
2312
        mov     ebx, [ebx+16]
2320
        call    fs_write64_app
2313
        call    fs_write64_app
2321
        test    eax, eax
2314
        test    eax, eax
2322
        jz      .mftBitmap
-
 
2323
        push    ERROR_DEVICE
-
 
2324
        jmp     ntfsError
2315
        jnz     ntfsDevice
2325
 
-
 
2326
    ; 4. MFT record
2316
    ; 4. MFT record
2327
.mftBitmap: ; search for free record
2317
.mftBitmap: ; search for free record
2328
        mov     edi, [ebp+NTFS.mftBitmapBuffer]
2318
        mov     edi, [ebp+NTFS.mftBitmapBuffer]
2329
        mov     ecx, [ebp+NTFS.mftBitmapSize]
2319
        mov     ecx, [ebp+NTFS.mftBitmapSize]
2330
        mov     al, -1
2320
        mov     al, -1
Line 2333... Line 2323...
2333
        repz scasb
2323
        repz scasb
2334
        dec     edi
2324
        dec     edi
2335
        movzx   eax, byte [edi]
2325
        movzx   eax, byte [edi]
2336
        not     al
2326
        not     al
2337
        bsf     ecx, eax
2327
        bsf     ecx, eax
2338
        jnz     @f
-
 
2339
        push    ERROR_UNSUPPORTED_FS    ; no free records
2328
        jz      ntfsUnsupported     ; no free records
2340
        jmp     ntfsError
-
 
2341
@@:         ; mark record
-
 
2342
        mov     al, [edi]
-
 
2343
        bts     eax, ecx
2329
        bts     [edi], ecx
2344
        mov     [edi], al
-
 
2345
    ; get record location
2330
; get record location
2346
        sub     edi, [ebp+NTFS.mftBitmapBuffer]
2331
        sub     edi, [ebp+NTFS.mftBitmapBuffer]
2347
        shl     edi, 3
2332
        shl     edi, 3
2348
        add     edi, ecx
2333
        add     edi, ecx
2349
        mov     [ebp+NTFS.newMftRecord], edi
2334
        mov     [ebp+NTFS.newMftRecord], edi
Line 2360... Line 2345...
2360
        cmp     [ebp+NTFS.ntfs_cur_read], 0
2345
        cmp     [ebp+NTFS.ntfs_cur_read], 0
2361
        jnz     .mftRecord
2346
        jnz     .mftRecord
2362
    ; extend MFT $DATA
2347
; extend MFT $DATA
2363
        mov     eax, [ebp+NTFS.mft_cluster]
2348
        mov     eax, [ebp+NTFS.mft_cluster]
2364
        mul     [ebp+NTFS.sectors_per_cluster]
2349
        mul     [ebp+NTFS.sectors_per_cluster]
2365
        push    ERROR_UNSUPPORTED_FS
-
 
2366
        cmp     eax, [ebp+NTFS.ntfsLastRead]
2350
        cmp     eax, [ebp+NTFS.ntfsLastRead]
2367
        jnz     ntfsError       ; auxiliary record
2351
        jnz     ntfsUnsupported     ; auxiliary record
2368
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
2352
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
2369
        mov     ebx, [ebp+NTFS.sectors_per_cluster]
2353
        mov     ebx, [ebp+NTFS.sectors_per_cluster]
2370
        shl     ebx, 9+3
2354
        shl     ebx, 9+3
2371
        add     dword [edi+lastVCN], 8
2355
        add     dword [edi+lastVCN], 8
2372
        add     [edi+attributeAllocatedSize], ebx
2356
        add     [edi+attributeAllocatedSize], ebx
2373
        adc     byte [edi+attributeAllocatedSize+4], 0
2357
        adc     byte [edi+attributeAllocatedSize+4], 0
2374
        add     [edi+attributeRealSize], ebx
2358
        add     [edi+attributeRealSize], ebx
2375
        adc     byte [edi+attributeRealSize+4], 0
2359
        adc     byte [edi+attributeRealSize+4], 0
2376
        add     [edi+initialDataSize], ebx
2360
        add     [edi+initialDataSize], ebx
2377
        adc     byte [edi+initialDataSize+4], 0
2361
        adc     byte [edi+initialDataSize+4], 0
2378
        add     edi, [edi+dataRunsOffset]
2362
        movzx   eax, byte [edi+dataRunsOffset]
-
 
2363
        add     edi, eax
2379
        movzx   eax, byte [edi]
2364
        mov     al, [edi]
2380
        inc     edi
2365
        inc     edi
2381
        shl     eax, 4
2366
        shl     eax, 4
2382
        shr     al, 4
2367
        shr     al, 4
2383
        mov     cl, 4
2368
        mov     cl, 4
2384
        sub     cl, al
2369
        sub     cl, al
2385
        shl     cl, 3
2370
        shl     cl, 3
2386
        add     ah, al
2371
        add     ah, al
2387
        shr     eax, 8
2372
        shr     eax, 8
2388
        cmp     byte [edi+eax], 0
2373
        cmp     byte [edi+eax], 0
2389
        jnz     ntfsError       ; $MFT fragmented
2374
        jnz     ntfsUnsupported     ; $MFT fragmented
2390
        mov     al, 8
2375
        mov     al, 8
2391
        mov     edx, [edi]
2376
        mov     edx, [edi]
2392
        rol     eax, cl
2377
        rol     eax, cl
2393
        rol     edx, cl
2378
        rol     edx, cl
2394
        add     eax, edx
2379
        add     eax, edx
2395
        jc      ntfsError
2380
        jc      ntfsUnsupported
2396
        ror     eax, cl
2381
        ror     eax, cl
2397
        shr     edx, cl
2382
        shr     edx, cl
2398
        mov     [edi], eax
2383
        mov     [edi], eax
2399
        add     edx, [ebp+NTFS.mft_cluster]
2384
        add     edx, [ebp+NTFS.mft_cluster]
2400
        mov     esi, edx
2385
        mov     esi, edx
Line 2403... Line 2388...
2403
        shr     edx, 3
2388
        shr     edx, 3
2404
        add     edx, [ebp+NTFS.BitmapBuffer]
2389
        add     edx, [ebp+NTFS.BitmapBuffer]
2405
        mov     ax, [edx]
2390
        mov     ax, [edx]
2406
        shr     ax, cl
2391
        shr     ax, cl
2407
        test    al, al
2392
        test    al, al
2408
        jnz     ntfsError
2393
        jnz     ntfsUnsupported
2409
        dec     al
2394
        dec     al
2410
        xchg    [edx], al
2395
        xchg    [edx], al
2411
        mov     [edx+1], al
2396
        mov     [edx+1], al
2412
        pop     eax
-
 
2413
        push    ERROR_OUT_OF_MEMORY
-
 
2414
        stdcall kernel_alloc, ebx
2397
        stdcall kernel_alloc, ebx
2415
        test    eax, eax
2398
        test    eax, eax
2416
        jz      ntfsError
2399
        jz      ntfsNoMemory
2417
        mov     ecx, ebx
2400
        mov     ecx, ebx
2418
        shr     ecx, 2
2401
        shr     ecx, 2
2419
        mov     edi, eax
2402
        mov     edi, eax
2420
        push    ebx
2403
        push    ebx
2421
        mov     ebx, eax
2404
        mov     ebx, eax
Line 2425... Line 2408...
2425
        mul     [ebp+NTFS.sectors_per_cluster]
2408
        mul     [ebp+NTFS.sectors_per_cluster]
2426
        pop     ecx
2409
        pop     ecx
2427
        shr     ecx, 9
2410
        shr     ecx, 9
2428
        call    fs_write64_sys  ; clear new records
2411
        call    fs_write64_sys  ; clear new records
2429
        stdcall kernel_free, ebx
2412
        stdcall kernel_free, ebx
2430
        pop     eax
-
 
2431
        push    ERROR_DEVICE
-
 
2432
        mov     eax, esi
2413
        mov     eax, esi
2433
        shr     eax, 3+9
2414
        shr     eax, 3+9
2434
        mov     ebx, eax
2415
        mov     ebx, eax
2435
        shl     ebx, 9
2416
        shl     ebx, 9
2436
        add     ebx, [ebp+NTFS.BitmapBuffer]
2417
        add     ebx, [ebp+NTFS.BitmapBuffer]
2437
        add     eax, [ebp+NTFS.BitmapLocation]
2418
        add     eax, [ebp+NTFS.BitmapLocation]
2438
        mov     ecx, 1
2419
        mov     ecx, 1
2439
        xor     edx, edx
2420
        xor     edx, edx
2440
        call    fs_write64_app  ; partition bitmap
2421
        call    fs_write64_app  ; partition bitmap
2441
        test    eax, eax
2422
        test    eax, eax
2442
        jnz     ntfsError
2423
        jnz     ntfsDevice
2443
        mov     eax, [ebp+NTFS.frs_buffer]
2424
        mov     eax, [ebp+NTFS.frs_buffer]
2444
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2425
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2445
        call    writeRecord     ; $MFT
2426
        call    writeRecord     ; $MFT
2446
        test    eax, eax
2427
        test    eax, eax
2447
        jnz     ntfsError
2428
        jnz     ntfsDevice
2448
        mov     eax, [ebp+NTFS.mftmirr_cluster]
2429
        mov     eax, [ebp+NTFS.mftmirr_cluster]
2449
        mul     [ebp+NTFS.sectors_per_cluster]
2430
        mul     [ebp+NTFS.sectors_per_cluster]
2450
        mov     ebx, [ebp+NTFS.frs_buffer]
2431
        mov     ebx, [ebp+NTFS.frs_buffer]
2451
        movzx   ecx, word [ebx+updateSequenceSize]
2432
        movzx   ecx, word [ebx+updateSequenceSize]
2452
        dec     ecx
2433
        dec     ecx
2453
        call    fs_write64_sys  ; $MFTMirr
2434
        call    fs_write64_sys  ; $MFTMirr
2454
        test    eax, eax
2435
        test    eax, eax
2455
        jnz     ntfsError
2436
        jnz     ntfsDevice
2456
        pop     eax
-
 
2457
        mov     eax, [ebp+NTFS.ntfs_cur_offs]
2437
        mov     eax, [ebp+NTFS.ntfs_cur_offs]
2458
        add     [ebp+NTFS.ntfsLastRead], eax
2438
        add     [ebp+NTFS.ntfsLastRead], eax
2459
.mftRecord:
2439
.mftRecord:
2460
        mov     esi, [ebp+NTFS.indexOffset]
2440
        mov     esi, [ebp+NTFS.indexOffset]
2461
        mov     edi, [ebp+NTFS.frs_buffer]
2441
        mov     edi, [ebp+NTFS.frs_buffer]
Line 2491... Line 2471...
2491
        mov     [edi+sizeWithoutHeader], ecx
2471
        mov     [edi+sizeWithoutHeader], ecx
2492
        mov     cx, [esi+indexAllocatedSize]
2472
        mov     cx, [esi+indexAllocatedSize]
2493
        add     ecx, 8
2473
        add     ecx, 8
2494
        mov     [edi+sizeWithHeader], ecx
2474
        mov     [edi+sizeWithHeader], ecx
2495
        mov     byte [edi+attributeOffset], 18h
2475
        mov     byte [edi+attributeOffset], 18h
2496
        mov     byte [edi+attributeFlags], 1
2476
        mov     byte [edi+indexedFlag], 1
2497
        add     edi, 18h
2477
        add     edi, 18h
2498
        add     esi, 16
2478
        add     esi, 16
2499
        sub     ecx, 18h
2479
        sub     ecx, 18h
2500
        shr     ecx, 2
2480
        shr     ecx, 2
2501
        rep movsd
2481
        rep movsd
Line 2534... Line 2514...
2534
        mov     byte [edi+nameOffset], 18h
2514
        mov     byte [edi+nameOffset], 18h
2535
        mov     byte [edi+sizeWithoutHeader], 30h
2515
        mov     byte [edi+sizeWithoutHeader], 30h
2536
        mov     byte [edi+attributeOffset], 20h
2516
        mov     byte [edi+attributeOffset], 20h
2537
        mov     dword[edi+18h], 490024h     ; unicode $I30
2517
        mov     dword[edi+18h], 490024h     ; unicode $I30
2538
        mov     dword[edi+18h+4], 300033h
2518
        mov     dword[edi+18h+4], 300033h
2539
        add     edi, 20h
-
 
2540
        mov     byte [edi+attributeType], 30h
2519
        mov     byte [edi+20h+attributeType], 30h
2541
        mov     byte [edi+collationRule], 1
2520
        mov     byte [edi+20h+collationRule], 1
2542
        mov     eax, [ebp+NTFS.sectors_per_cluster]
2521
        mov     eax, [ebp+NTFS.sectors_per_cluster]
2543
        shl     eax, 9
2522
        shl     eax, 9
2544
        mov     [edi+indexRecordSize], eax
2523
        mov     [edi+20h+indexRecordSize], eax
2545
        mov     byte [edi+indexRecordSizeClus], 1
2524
        mov     byte [edi+20h+indexRecordSizeClus], 1
2546
        mov     byte [edi+16+indexOffset], 16
2525
        mov     byte [edi+30h+indexOffset], 16
2547
        mov     byte [edi+16+nodeRealSize], 32
2526
        mov     byte [edi+30h+nodeRealSize], 32
2548
        mov     byte [edi+16+nodeAllocatedSize], 32
2527
        mov     byte [edi+30h+nodeAllocatedSize], 32
2549
        mov     byte [edi+32+indexAllocatedSize], 16
2528
        mov     byte [edi+40h+indexAllocatedSize], 16
2550
        mov     byte [edi+32+indexFlags], 2
2529
        mov     byte [edi+40h+indexFlags], 2
2551
        sub     edi, 20h
-
 
2552
        mov     al, 3
2530
        mov     al, 3
2553
.writeMftRecord:
2531
.writeMftRecord:
2554
        mov     byte [edi+sizeWithHeader], 50h
2532
        mov     byte [edi+sizeWithHeader], 50h
2555
        mov     byte [edi+attributeID], 2
2533
        mov     byte [edi+attributeID], 2
2556
        mov     dword[edi+50h], -1      ; $End
2534
        mov     dword[edi+50h], -1      ; $End
2557
        mov     edi, [ebp+NTFS.frs_buffer]
2535
        mov     edi, [ebp+NTFS.frs_buffer]
2558
        mov     [edi+recordFlags], al
2536
        mov     [edi+recordFlags], al
2559
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2537
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2560
        call    writeRecord
2538
        call    writeRecord
2561
        test    eax, eax
2539
        test    eax, eax
2562
        jz      @f
-
 
2563
        push    ERROR_DEVICE
-
 
2564
        jmp     ntfsError
2540
        jnz     ntfsDevice
2565
@@:
-
 
2566
        mov     esi, [ebp+PARTITION.Disk]
2541
        mov     esi, [ebp+PARTITION.Disk]
2567
        call    disk_sync
2542
        call    disk_sync
2568
    ; write MFT bitmap
2543
; write MFT bitmap
2569
        mov     eax, [ebp+NTFS.newMftRecord]
2544
        mov     eax, [ebp+NTFS.newMftRecord]
2570
        shr     eax, 3+9
2545
        shr     eax, 3+9
Line 2574... Line 2549...
2574
        add     ebx, [ebp+NTFS.mftBitmapBuffer]
2549
        add     ebx, [ebp+NTFS.mftBitmapBuffer]
2575
        mov     ecx, 1
2550
        mov     ecx, 1
2576
        xor     edx, edx
2551
        xor     edx, edx
2577
        call    fs_write64_sys
2552
        call    fs_write64_sys
2578
        test    eax, eax
2553
        test    eax, eax
2579
        jz      @f
-
 
2580
        push    ERROR_DEVICE
-
 
2581
        jmp     ntfsError
2554
        jnz     ntfsDevice
2582
@@: ; 5. Write partition bitmap
2555
; 5. Write partition bitmap
2583
        cmp     [ebp+NTFS.ntfsFolder], 0
2556
        cmp     [ebp+NTFS.ntfsFolder], 0
2584
        jnz     @f
2557
        jnz     @f
2585
        cmp     [ebp+NTFS.fileRealSize], 0
2558
        cmp     [ebp+NTFS.fileRealSize], 0
2586
        jz      @f
2559
        jz      @f
2587
        mov     ecx, [ebp+NTFS.fileDataStart]
2560
        mov     ecx, [ebp+NTFS.fileDataStart]
Line 2596... Line 2569...
2596
        add     eax, [ebp+NTFS.BitmapLocation]
2569
        add     eax, [ebp+NTFS.BitmapLocation]
2597
        add     ebx, [ebp+NTFS.BitmapBuffer]
2570
        add     ebx, [ebp+NTFS.BitmapBuffer]
2598
        xor     edx, edx
2571
        xor     edx, edx
2599
        call    fs_write64_app
2572
        call    fs_write64_app
2600
        test    eax, eax
2573
        test    eax, eax
2601
        jz      @f
-
 
2602
        push    ERROR_DEVICE
-
 
2603
        jmp     ntfsError
2574
        jnz     ntfsDevice
2604
@@:
2575
@@:
2605
        mov     esi, [ebp+PARTITION.Disk]
2576
        mov     esi, [ebp+PARTITION.Disk]
2606
        call    disk_sync
2577
        call    disk_sync
2607
        mov     edi, [ebp+NTFS.indexOffset]
2578
        mov     edi, [ebp+NTFS.indexOffset]
2608
        mov     eax, [ebp+NTFS.newMftRecord]
2579
        mov     eax, [ebp+NTFS.newMftRecord]
Line 2611... Line 2582...
2611
        mov     eax, [ebp+NTFS.nodeLastRead]
2582
        mov     eax, [ebp+NTFS.nodeLastRead]
2612
        mov     [ebp+NTFS.ntfsLastRead], eax
2583
        mov     [ebp+NTFS.ntfsLastRead], eax
2613
        mov     eax, [ebp+NTFS.cur_index_buf]
2584
        mov     eax, [ebp+NTFS.cur_index_buf]
2614
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2585
        mov     [ebp+NTFS.ntfs_cur_buf], eax
2615
        call    writeRecord
2586
        call    writeRecord
2616
        push    eax
2587
        test    eax, eax
-
 
2588
        jnz     ntfsDevice
-
 
2589
        mov     ebx, [ebp+NTFS.fileRealSize]
-
 
2590
ntfsDone:
2617
        mov     esi, [ebp+PARTITION.Disk]
2591
        mov     esi, [ebp+PARTITION.Disk]
2618
        call    disk_sync
2592
        call    disk_sync
2619
        call    ntfs_unlock
2593
        call    ntfs_unlock
2620
        pop     eax
2594
        xor     eax, eax
2621
        mov     ebx, [ebp+NTFS.fileRealSize]
-
 
2622
        ret
2595
        ret
Line 2623... Line 2596...
2623
 
2596
 
2624
writeRecord:
2597
writeRecord:
2625
;   in:
2598
;   in:
Line 2649... Line 2622...
2649
        jmp     fs_write64_sys
2622
        jmp     fs_write64_sys
Line 2650... Line 2623...
2650
 
2623
 
2651
bitmapBuffering:
2624
bitmapBuffering:
2652
; Extend BitmapBuffer and read next 32kb of bitmap
2625
; Extend BitmapBuffer and read next 32kb of bitmap
-
 
2626
; Warning: $Bitmap fragmentation is not foreseen
-
 
2627
; if edi -> position in bitmap buffer,
2653
; Warning: $Bitmap fragmentation is not foreseen
2628
; then ecx = number of buffered dwords left
2654
        push    ebx
2629
        push    ebx
2655
        mov     eax, [ebp+NTFS.BitmapTotalSize]
2630
        mov     eax, [ebp+NTFS.BitmapTotalSize]
2656
        cmp     eax, [ebp+NTFS.BitmapSize]
2631
        cmp     eax, [ebp+NTFS.BitmapSize]
2657
        jz      .end
2632
        jz      .end
Line 2678... Line 2653...
2678
        cmp     eax, [ebp+NTFS.BitmapSize]
2653
        cmp     eax, [ebp+NTFS.BitmapSize]
2679
        jnc     @f
2654
        jnc     @f
2680
        mov     [ebp+NTFS.BitmapSize], eax
2655
        mov     [ebp+NTFS.BitmapSize], eax
2681
@@:
2656
@@:
2682
        mov     ecx, [ebp+NTFS.BitmapSize]
2657
        mov     ecx, [ebp+NTFS.BitmapSize]
2683
        mov     eax, edi
-
 
2684
        sub     eax, [ebp+NTFS.BitmapBuffer]
2658
        add     ecx, [ebp+NTFS.BitmapBuffer]
2685
        sub     ecx, eax
2659
        sub     ecx, edi
2686
        shr     ecx, 2
2660
        shr     ecx, 2
2687
        pop     ebx
2661
        pop     ebx
2688
        ret
2662
        ret
Line 2689... Line 2663...
2689
 
2663
 
Line 2693... Line 2667...
2693
        mov     ecx, 8
2667
        mov     ecx, 8
2694
        call    release_pages
2668
        call    release_pages
2695
.end:
2669
.end:
2696
        add     esp, 12     ; double ret
2670
        add     esp, 12     ; double ret
2697
        push    ERROR_DISK_FULL
2671
        push    ERROR_DISK_FULL
2698
        jmp     ntfsError
2672
        jmp     ntfsOut
Line 2699... Line 2673...
2699
 
2673
 
2700
;----------------------------------------------------------------
2674
;----------------------------------------------------------------
2701
ntfs_WriteFile:
2675
ntfs_WriteFile:
2702
        cmp     byte [esi], 0
2676
        cmp     byte [esi], 0
Line 2705... Line 2679...
2705
        movi    eax, ERROR_ACCESS_DENIED
2679
        movi    eax, ERROR_ACCESS_DENIED
2706
        ret
2680
        ret
2707
@@:
2681
@@:
2708
        call    ntfs_lock
2682
        call    ntfs_lock
2709
        stdcall ntfs_find_lfn, [esp+4]
2683
        stdcall ntfs_find_lfn, [esp+4]
2710
        jnc     .found
2684
        jc      ntfsNotFound
2711
        push    ERROR_FILE_NOT_FOUND
2685
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 16
2712
        jmp     ntfsError
2686
        jc      ntfsDenied
2713
.found:
-
 
2714
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
2687
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
2715
        mov     [ebp+NTFS.ntfs_cur_offs], 0
2688
        mov     [ebp+NTFS.ntfs_cur_offs], 0
2716
        mov     [ebp+NTFS.ntfs_cur_size], 0
2689
        mov     [ebp+NTFS.ntfs_cur_size], 0
2717
        call    ntfs_read_attr
2690
        call    ntfs_read_attr
2718
        jnc     @f
-
 
2719
        push    ERROR_ACCESS_DENIED
-
 
2720
        jmp     ntfsError
2691
        jc      ntfsDenied
2721
@@:
-
 
2722
        push    ERROR_UNSUPPORTED_FS
-
 
2723
        mov     eax, [ebp+NTFS.frs_buffer]
2692
        mov     eax, [ebp+NTFS.frs_buffer]
2724
        cmp     word [eax+baseRecordReuse], 0
2693
        cmp     word [eax+baseRecordReuse], 0
2725
        jnz     ntfsError       ; auxiliary record
2694
        jnz     ntfsUnsupported     ; auxiliary record
2726
        cmp     byte [eax+hardLinkCounter], 1
2695
        cmp     byte [eax+hardLinkCounter], 1
2727
        jnz     ntfsError       ; file copying required
2696
        jnz     ntfsUnsupported     ; file copying required
2728
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2697
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
2729
        cmp     byte [ecx+nonResidentFlag], 1
2698
        cmp     byte [ecx+nonResidentFlag], 1
2730
        jnz     ntfsError       ; resident $DATA
2699
        jnz     ntfsUnsupported     ; resident $DATA
-
 
2700
        cmp     word [ecx+attributeFlags], 0
-
 
2701
        jnz     ntfsUnsupported
2731
        mov     eax, [ebx+4]
2702
        mov     eax, [ebx+4]
2732
        mov     edx, [ebx+8]
2703
        mov     edx, [ebx+8]
2733
        add     eax, [ebx+12]
2704
        add     eax, [ebx+12]
2734
        adc     edx, 0
2705
        adc     edx, 0
2735
        cmp     edx, [ecx+attributeRealSize+4]
2706
        cmp     edx, [ecx+attributeRealSize+4]
2736
        jc      .write
2707
        jc      .write
2737
        jnz     ntfsError       ; end of file
2708
        jnz     ntfsUnsupported     ; end of file
2738
        cmp     [ecx+attributeRealSize], eax
2709
        cmp     [ecx+attributeRealSize], eax
2739
        jc      ntfsError
2710
        jc      ntfsUnsupported
2740
.write:
2711
.write:
2741
        pop     eax
-
 
2742
        push    ERROR_DEVICE
-
 
2743
        mov     eax, [ebx+4]
2712
        mov     eax, [ebx+4]
2744
        mov     edx, [ebx+8]
2713
        mov     edx, [ebx+8]
2745
        mov     ecx, [ebx+12]
2714
        mov     ecx, [ebx+12]
2746
        mov     esi, [ebx+16]
2715
        mov     esi, [ebx+16]
2747
        shrd    eax, edx, 9
2716
        shrd    eax, edx, 9
Line 2750... Line 2719...
2750
        mov     [ebp+NTFS.ntfs_cur_offs], eax
2719
        mov     [ebp+NTFS.ntfs_cur_offs], eax
2751
        mov     [ebp+NTFS.ntfs_cur_size], 1
2720
        mov     [ebp+NTFS.ntfs_cur_size], 1
2752
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
2721
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
2753
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2722
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2754
        call    ntfs_read_attr.continue
2723
        call    ntfs_read_attr.continue
2755
        jc      ntfsError
2724
        jc      ntfsDevice
2756
        mov     eax, [ebx+4]
2725
        mov     eax, [ebx+4]
2757
        and     eax, 1FFh
2726
        and     eax, 1FFh
2758
        add     edi, eax
2727
        add     edi, eax
2759
        sub     eax, [ebp+NTFS.ntfs_cur_read]
2728
        sub     eax, [ebp+NTFS.ntfs_cur_read]
2760
        neg     eax
2729
        neg     eax
Line 2772... Line 2741...
2772
        xor     edx, edx
2741
        xor     edx, edx
2773
        call    fs_write64_app
2742
        call    fs_write64_app
2774
        pop     ebx
2743
        pop     ebx
2775
        pop     ecx
2744
        pop     ecx
2776
        test    eax, eax
2745
        test    eax, eax
2777
        jnz     ntfsError
2746
        jnz     ntfsDevice
2778
        test    ecx, ecx
2747
        test    ecx, ecx
2779
        jz      @f
2748
        jz      @f
2780
        mov     eax, [ebx+4]
2749
        mov     eax, [ebx+4]
2781
        mov     edx, [ebx+8]
2750
        mov     edx, [ebx+8]
2782
        shrd    eax, edx, 9
2751
        shrd    eax, edx, 9
Line 2792... Line 2761...
2792
        mov     [ebp+NTFS.ntfsWriteAttr], 1
2761
        mov     [ebp+NTFS.ntfsWriteAttr], 1
2793
        call    ntfs_read_attr.continue
2762
        call    ntfs_read_attr.continue
2794
        mov     [ebp+NTFS.ntfsWriteAttr], 0
2763
        mov     [ebp+NTFS.ntfsWriteAttr], 0
2795
        pop     [ebp+NTFS.ntfs_cur_offs]
2764
        pop     [ebp+NTFS.ntfs_cur_offs]
2796
        pop     ecx
2765
        pop     ecx
2797
        jc      ntfsError
2766
        jc      ntfsDevice
2798
        and     ecx, 1FFh
2767
        and     ecx, 1FFh
2799
        jz      @f
2768
        jz      @f
2800
        add     esi, [ebp+NTFS.ntfs_cur_read]
2769
        add     esi, [ebp+NTFS.ntfs_cur_read]
2801
        mov     [ebp+NTFS.ntfs_cur_size], 1
2770
        mov     [ebp+NTFS.ntfs_cur_size], 1
2802
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
2771
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
2803
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2772
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2804
        call    ntfs_read_attr.continue
2773
        call    ntfs_read_attr.continue
2805
        jc      ntfsError
2774
        jc      ntfsDevice
2806
        rep movsb
2775
        rep movsb
2807
        push    ebx
2776
        push    ebx
2808
        mov     eax, [ebp+NTFS.ntfsLastRead]
2777
        mov     eax, [ebp+NTFS.ntfsLastRead]
2809
        lea     ebx, [ebp+NTFS.ntfs_bitmap_buf]
2778
        lea     ebx, [ebp+NTFS.ntfs_bitmap_buf]
2810
        mov     ecx, 1
2779
        mov     ecx, 1
2811
        xor     edx, edx
2780
        xor     edx, edx
2812
        call    fs_write64_app
2781
        call    fs_write64_app
2813
        pop     ebx
2782
        pop     ebx
-
 
2783
        test    eax, eax
-
 
2784
        jnz     ntfsDevice
2814
@@:
2785
@@:
2815
        mov     esi, [ebp+PARTITION.Disk]
-
 
2816
        call    disk_sync
-
 
2817
        call    ntfs_unlock
-
 
2818
        pop     eax
-
 
2819
        xor     eax, eax
-
 
2820
        mov     ebx, [ebx+12]
2786
        mov     ebx, [ebx+12]
-
 
2787
        jmp     ntfsDone
-
 
2788
 
-
 
2789
;----------------------------------------------------------------
-
 
2790
ntfs_Delete:
-
 
2791
        cmp     byte [esi], 0
-
 
2792
        jnz     @f
-
 
2793
        xor     ebx, ebx
-
 
2794
        movi    eax, ERROR_ACCESS_DENIED
2821
        ret
2795
        ret
-
 
2796
@@:
-
 
2797
        call    ntfs_lock
-
 
2798
        stdcall ntfs_find_lfn, [esp+4]
-
 
2799
        jc      ntfsNotFound
-
 
2800
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 16
-
 
2801
        jc      ntfsDenied
-
 
2802
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
-
 
2803
        jnz     ntfsUnsupported     ; record fragmented
-
 
2804
        test    byte [eax+indexFlags], 1
-
 
2805
        jnz     ntfsUnsupported     ; index has a subnode
-
 
2806
        mov     edx, [ebp+NTFS.ntfs_cur_iRecord]
-
 
2807
        shr     edx, 3
-
 
2808
        cmp     edx, [ebp+NTFS.mftBitmapSize]
-
 
2809
        jnc     ntfsUnsupported
-
 
2810
; delete index from the node
-
 
2811
        movzx   edx, word [eax+indexAllocatedSize]
-
 
2812
        mov     edi, [ebp+NTFS.cur_index_buf]
-
 
2813
        cmp     dword [edi], 'INDX'
-
 
2814
        jz      .indexRecord
-
 
2815
        mov     esi, [ebp+NTFS.frs_buffer]  ; indexRoot
-
 
2816
        mov     ecx, [esi+recordRealSize]
-
 
2817
        shr     ecx, 2
-
 
2818
        rep movsd
-
 
2819
        mov     esi, [ebp+NTFS.cur_index_buf]
-
 
2820
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
-
 
2821
        sub     edi, [ebp+NTFS.frs_buffer]
-
 
2822
        add     edi, esi
-
 
2823
        sub     [edi+sizeWithHeader], edx
-
 
2824
        sub     [edi+sizeWithoutHeader], edx
-
 
2825
        mov     cl, [edi+attributeOffset]
-
 
2826
        add     edi, ecx
-
 
2827
        sub     [edi+16+nodeRealSize], edx
-
 
2828
        sub     [edi+16+nodeAllocatedSize], edx
-
 
2829
        sub     eax, esi
-
 
2830
        add     eax, edi
-
 
2831
        sub     [esi+recordRealSize], edx
-
 
2832
        mov     ecx, [esi+recordRealSize]
-
 
2833
        jmp     @f
-
 
2834
 
-
 
2835
.indexRecord:
-
 
2836
        sub     [edi+28], edx
-
 
2837
        mov     ecx, [edi+28]
-
 
2838
        add     ecx, 24
-
 
2839
@@:
-
 
2840
        add     ecx, [ebp+NTFS.cur_index_buf]
-
 
2841
        sub     ecx, eax
-
 
2842
        shr     ecx, 2
-
 
2843
        mov     esi, eax
-
 
2844
        add     esi, edx
-
 
2845
        mov     edi, eax
-
 
2846
        rep movsd
-
 
2847
        mov     eax, [ebp+NTFS.ntfsLastRead]
-
 
2848
        mov     [ebp+NTFS.nodeLastRead], eax
-
 
2849
; examine file record
-
 
2850
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
2851
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
2852
        mov     [ebp+NTFS.ntfs_cur_size], 0
-
 
2853
        call    ntfs_read_attr
-
 
2854
        jc      .folder
-
 
2855
        mov     esi, [ebp+NTFS.frs_buffer]
-
 
2856
        cmp     word [esi+baseRecordReuse], 0
-
 
2857
        jnz     ntfsUnsupported     ; auxiliary record
-
 
2858
        cmp     byte [esi+hardLinkCounter], 2
-
 
2859
        jnc     .writeFileRecord    ; delete hard link
-
 
2860
        mov     esi, [ebp+NTFS.ntfs_attr_offs]
-
 
2861
        cmp     byte [esi+nonResidentFlag], 0
-
 
2862
        jz      .writeBitmapMFT
-
 
2863
        movzx   eax, byte [esi+dataRunsOffset]
-
 
2864
        add     esi, eax
-
 
2865
        xor     edi, edi
-
 
2866
        sub     esp, 16
-
 
2867
.clearBitmap:       ; "delete" file data
-
 
2868
        call    ntfs_decode_mcb_entry
-
 
2869
        jnc     .mcbEnd
-
 
2870
        cmp     dword[esp+8], 0
-
 
2871
        jz      .clearBitmap
-
 
2872
        add     edi, [esp+8]
-
 
2873
        mov     ebx, [esp]
-
 
2874
        mov     eax, edi
-
 
2875
        add     eax, ebx
-
 
2876
        shr     eax, 3
-
 
2877
        inc     eax
-
 
2878
        cmp     eax, [ebp+NTFS.BitmapSize]
-
 
2879
        jc      .buffered
-
 
2880
        add     eax, [ebp+NTFS.BitmapBuffer]
-
 
2881
        add     esp, 16
-
 
2882
        push    edi
-
 
2883
        mov     edi, eax
-
 
2884
@@:
-
 
2885
        call    bitmapBuffering
-
 
2886
        shl     ecx, 2
-
 
2887
        js      @b
-
 
2888
        pop     edi
-
 
2889
        sub     esp, 16
-
 
2890
.buffered:
-
 
2891
        push    edi
-
 
2892
        mov     ecx, edi
-
 
2893
        shr     edi, 5
-
 
2894
        shl     edi, 2
-
 
2895
        add     edi, [ebp+NTFS.BitmapBuffer]
-
 
2896
        and     ecx, 31
-
 
2897
        xor     eax, eax
-
 
2898
        dec     eax
-
 
2899
        shr     eax, cl
-
 
2900
        shl     eax, cl
-
 
2901
        neg     ecx
-
 
2902
        add     ecx, 32
-
 
2903
        sub     ecx, ebx
-
 
2904
        jc      @f
-
 
2905
        shl     eax, cl     ; fits inside dword
-
 
2906
        shr     eax, cl
-
 
2907
        not     eax
-
 
2908
        and     [edi], eax
-
 
2909
        jmp     .writeBitmap
-
 
2910
 
-
 
2911
@@:
-
 
2912
        not     eax
-
 
2913
        and     [edi], eax
-
 
2914
        neg     ecx
-
 
2915
        push    ecx
-
 
2916
        shr     ecx, 5
-
 
2917
        add     edi, 4
-
 
2918
        xor     eax, eax
-
 
2919
        rep stosd
-
 
2920
        pop     ecx
-
 
2921
        and     ecx, 31
-
 
2922
        dec     eax
-
 
2923
        shr     eax, cl
-
 
2924
        shl     eax, cl
-
 
2925
        and     [edi], eax
-
 
2926
.writeBitmap:
-
 
2927
        pop     edi
-
 
2928
        mov     ecx, edi
-
 
2929
        add     ecx, ebx
-
 
2930
        add     ecx, 4095
-
 
2931
        shr     ecx, 3+9
-
 
2932
        mov     eax, edi
-
 
2933
        shr     eax, 3+9
-
 
2934
        sub     ecx, eax
-
 
2935
        mov     ebx, eax
-
 
2936
        shl     ebx, 9
-
 
2937
        add     eax, [ebp+NTFS.BitmapLocation]
-
 
2938
        add     ebx, [ebp+NTFS.BitmapBuffer]
-
 
2939
        xor     edx, edx
-
 
2940
        call    fs_write64_app
-
 
2941
        jmp     .clearBitmap
-
 
2942
 
-
 
2943
.mcbEnd:
-
 
2944
        add     esp, 16
-
 
2945
        jmp     .writeBitmapMFT
-
 
2946
 
-
 
2947
.folder:    ; empty?
-
 
2948
        lea     esi, [ebp+NTFS.ntfs_bitmap_buf]
-
 
2949
        mov     [ebp+NTFS.ntfs_cur_buf], esi
-
 
2950
        mov     [ebp+NTFS.ntfs_cur_attr], 0x90
-
 
2951
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
2952
        mov     [ebp+NTFS.ntfs_cur_size], 1
-
 
2953
        call    ntfs_read_attr
-
 
2954
        cmp     [ebp+NTFS.ntfs_cur_read], 48
-
 
2955
        jnz     ntfsDenied
-
 
2956
        test    byte [esi+32+indexFlags], 1
-
 
2957
        jnz     ntfsDenied
-
 
2958
.writeBitmapMFT:    ; "delete" file record
-
 
2959
        mov     eax, [ebp+NTFS.ntfs_cur_iRecord]
-
 
2960
        mov     ecx, eax
-
 
2961
        shr     eax, 3
-
 
2962
        and     ecx, 7
-
 
2963
        mov     edi, [ebp+NTFS.mftBitmapBuffer]
-
 
2964
        btr     [edi+eax], ecx
-
 
2965
        shr     eax, 9
-
 
2966
        mov     ebx, eax
-
 
2967
        shl     ebx, 9
-
 
2968
        add     eax, [ebp+NTFS.mftBitmapLocation]
-
 
2969
        add     ebx, edi
-
 
2970
        mov     ecx, 1
-
 
2971
        xor     edx, edx
-
 
2972
        call    fs_write64_sys
-
 
2973
        mov     esi, [ebp+NTFS.frs_buffer]
-
 
2974
        mov     byte [esi+recordFlags], 0
-
 
2975
.writeFileRecord:
-
 
2976
        dec     byte [esi+hardLinkCounter]
-
 
2977
        mov     [ebp+NTFS.ntfs_cur_buf], esi
-
 
2978
        call    writeRecord
-
 
2979
; write directory node
-
 
2980
        mov     eax, [ebp+NTFS.nodeLastRead]
-
 
2981
        mov     [ebp+NTFS.ntfsLastRead], eax
-
 
2982
        mov     eax, [ebp+NTFS.cur_index_buf]
-
 
2983
        mov     [ebp+NTFS.ntfs_cur_buf], eax
-
 
2984
        call    writeRecord
-
 
2985
        test    eax, eax
-
 
2986
        jz      ntfsDone
-
 
2987
        jmp     ntfsDevice
Line 2822... Line 2988...
2822
 
2988
 
2823
;----------------------------------------------------------------
2989
;----------------------------------------------------------------
2824
ntfs_SetFileEnd:
2990
ntfs_SetFileEnd:
2825
ntfs_SetFileInfo:
-
 
2826
ntfs_Delete:
2991
ntfs_SetFileInfo:
2827
        mov     eax, ERROR_UNSUPPORTED_FS
2992
        movi    eax, ERROR_UNSUPPORTED_FS
Line 2828... Line 2993...
2828
        ret
2993
        ret
2829
 
2994
 
2830
;----------------------------------------------------------------
2995
;----------------------------------------------------------------
Line 2835... Line 3000...
2835
        ret
3000
        ret
2836
@@:
3001
@@:
2837
        call    ntfs_lock
3002
        call    ntfs_lock
2838
        stdcall ntfs_find_lfn, [esp+4]
3003
        stdcall ntfs_find_lfn, [esp+4]
2839
        jnc     .found
3004
        jnc     .found
2840
        push    ERROR_FILE_NOT_FOUND
-
 
2841
        test    eax, eax
3005
        test    eax, eax
2842
        jnz     ntfsError
3006
        jz      ntfsFail
2843
        pop     eax
-
 
2844
        push    ERROR_FS_FAIL
-
 
2845
        jmp     ntfsError
3007
        jmp     ntfsNotFound
2846
.found:
3008
.found:
2847
        push    esi edi
3009
        push    esi edi
2848
        mov     esi, eax
3010
        mov     esi, eax
2849
        mov     edi, [ebx+16]
3011
        mov     edi, [ebx+16]
2850
        xor     eax, eax
3012
        xor     eax, eax
Line 2852... Line 3014...
2852
        pop     edi esi
3014
        pop     edi esi
2853
        call    ntfs_unlock
3015
        call    ntfs_unlock
2854
        xor     eax, eax
3016
        xor     eax, eax
2855
        ret
3017
        ret
Line -... Line 3018...
-
 
3018
 
-
 
3019
ntfsUnsupported:
2856
 
3020
        push    ERROR_UNSUPPORTED_FS
2857
ntfsError:
3021
ntfsOut:
2858
        call    ntfs_unlock
3022
        call    ntfs_unlock
2859
        xor     ebx, ebx
3023
        xor     ebx, ebx
2860
        pop     eax
3024
        pop     eax
-
 
3025
        ret
-
 
3026
ntfsDevice:
-
 
3027
        push    ERROR_DEVICE
-
 
3028
        jmp     ntfsOut
-
 
3029
ntfsNotFound:
-
 
3030
        push    ERROR_FILE_NOT_FOUND
-
 
3031
        jmp     ntfsOut
-
 
3032
ntfsDenied:
-
 
3033
        push    ERROR_ACCESS_DENIED
-
 
3034
        jmp     ntfsOut
-
 
3035
ntfsFail:
-
 
3036
        push    ERROR_FS_FAIL
-
 
3037
        jmp     ntfsOut
-
 
3038
ntfsNoMemory:
-
 
3039
        push    ERROR_OUT_OF_MEMORY