Subversion Repositories Kolibri OS

Rev

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

Rev 5954 Rev 5994
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: 5954 $
8
$Revision: 5994 $
Line 9... Line 9...
9
 
9
 
10
; NTFS driver
10
; NTFS driver
Line 35... Line 35...
35
hardLinkCounter = 12h
35
hardLinkCounter = 12h
36
attributeOffset = 14h
36
attributeOffset = 14h
37
recordFlags = 16h
37
recordFlags = 16h
38
recordRealSize = 18h
38
recordRealSize = 18h
39
recordAllocatedSize = 1ch
39
recordAllocatedSize = 1ch
-
 
40
baseRecordReference = 20h       ; for auxiliary records
-
 
41
baseRecordReuse = 26h
40
newAttributeID = 28h
42
newAttributeID = 28h
41
    ; attribute header
43
    ; attribute header
42
attributeType = 0
44
attributeType = 0
43
sizeWithHeader = 4
45
sizeWithHeader = 4
44
nonResidentFlag = 8
46
nonResidentFlag = 8
Line 109... Line 111...
109
fileDataSize            dd  ?   ; in clusters
111
fileDataSize            dd  ?   ; in clusters
110
fileRealSize            dd  ?   ; in bytes
112
fileRealSize            dd  ?   ; in bytes
111
indexOffset             dd  ?
113
indexOffset             dd  ?
112
nodeLastRead            dd  ?
114
nodeLastRead            dd  ?
113
ntfs_bCanContinue       db  ?
115
ntfs_bCanContinue       db  ?
114
ntfsNotFound            db  ?
-
 
115
ntfsFolder              db  ?
116
ntfsFolder              db  ?
-
 
117
ntfsWriteAttr           db  ?   ; Warning: Don't forget to turn off!!!
116
ntfsFragmentCount       db  ?
118
ntfsFragmentCount       db  ?
Line 117... Line 119...
117
 
119
 
118
cur_subnode_size        dd  ?
120
cur_subnode_size        dd  ?
119
ntfs_attr_iRecord       dd  ?
121
ntfs_attr_iRecord       dd  ?
Line 141... Line 143...
141
        dd      ntfs_free
143
        dd      ntfs_free
142
        dd      (ntfs_user_functions_end - ntfs_user_functions - 4) / 4
144
        dd      (ntfs_user_functions_end - ntfs_user_functions - 4) / 4
143
        dd      ntfs_ReadFile
145
        dd      ntfs_ReadFile
144
        dd      ntfs_ReadFolder
146
        dd      ntfs_ReadFolder
145
        dd      ntfs_CreateFile
147
        dd      ntfs_CreateFile
146
        dd      ntfs_Write
148
        dd      ntfs_WriteFile
147
        dd      ntfs_SetFileEnd
149
        dd      ntfs_SetFileEnd
148
        dd      ntfs_GetFileInfo
150
        dd      ntfs_GetFileInfo
149
        dd      ntfs_SetFileInfo
151
        dd      ntfs_SetFileInfo
150
        dd      0
152
        dd      0
151
        dd      ntfs_Delete
153
        dd      ntfs_Delete
Line 275... Line 277...
275
        mov     ecx, dword [ebp+PARTITION.Length+4]
277
        mov     ecx, dword [ebp+PARTITION.Length+4]
276
        mov     dword [eax+NTFS.Length+4], ecx
278
        mov     dword [eax+NTFS.Length+4], ecx
277
        mov     ecx, [ebp+PARTITION.Disk]
279
        mov     ecx, [ebp+PARTITION.Disk]
278
        mov     [eax+NTFS.Disk], ecx
280
        mov     [eax+NTFS.Disk], ecx
279
        mov     [eax+NTFS.FSUserFunctions], ntfs_user_functions
281
        mov     [eax+NTFS.FSUserFunctions], ntfs_user_functions
-
 
282
        mov     [eax+NTFS.ntfsWriteAttr], 0
Line 280... Line 283...
280
 
283
 
281
        push    ebx ebp esi
284
        push    ebx ebp esi
282
        mov     ebp, eax
285
        mov     ebp, eax
283
        lea     ecx, [ebp+NTFS.Lock]
286
        lea     ecx, [ebp+NTFS.Lock]
Line 542... Line 545...
542
        pop     ebx
545
        pop     ebx
543
        pop     ecx
546
        pop     ecx
544
        ret
547
        ret
Line 545... Line 548...
545
 
548
 
-
 
549
ntfs_read_attr:
546
ntfs_read_attr:
550
; [ebp+NTFS.ntfsWriteAttr]=1 -> write attribute
547
;   in:
551
;   in:
548
; [ebp+NTFS.ntfs_cur_iRecord] = number of fileRecord
552
; [ebp+NTFS.ntfs_cur_iRecord] = number of fileRecord
549
; [ebp+NTFS.ntfs_cur_attr] = attribute type
553
; [ebp+NTFS.ntfs_cur_attr] = attribute type
550
; [ebp+NTFS.ntfs_cur_offs] = attribute VCN in sectors
554
; [ebp+NTFS.ntfs_cur_offs] = attribute VCN in sectors
Line 990... Line 994...
990
        xor     edx, edx
994
        xor     edx, edx
991
        div     [ebp+NTFS.sectors_per_cluster]
995
        div     [ebp+NTFS.sectors_per_cluster]
992
        sub     eax, [ecx+10h]  ; first_vbo
996
        sub     eax, [ecx+10h]  ; first_vbo
993
        jb      .okret
997
        jb      .okret
994
; eax = cluster, edx = starting sector
998
; eax = cluster, edx = starting sector
-
 
999
        cmp     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
1000
        jnz     .sys
-
 
1001
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 0
-
 
1002
        jz      .sys
-
 
1003
        push    fs_read64_app
-
 
1004
        cmp     [ebp+NTFS.ntfsWriteAttr], 1
-
 
1005
        jnz     @f
-
 
1006
        mov     dword[esp], fs_write64_app
-
 
1007
        jmp     @f
-
 
1008
.sys:
-
 
1009
        push    fs_read64_sys
-
 
1010
@@:
995
        sub     esp, 10h
1011
        sub     esp, 10h
996
        movzx   esi, word [ecx+20h]     ; mcb_info_ofs
1012
        movzx   esi, word [ecx+20h]     ; mcb_info_ofs
997
        add     esi, ecx
1013
        add     esi, ecx
998
        xor     edi, edi
1014
        xor     edi, edi
999
        mov     [ebp+NTFS.ntfsFragmentCount], 0
1015
        mov     [ebp+NTFS.ntfsFragmentCount], 0
Line 1019... Line 1035...
1019
@@:
1035
@@:
1020
        mov     ebx, [ebp+NTFS.ntfs_cur_buf]
1036
        mov     ebx, [ebp+NTFS.ntfs_cur_buf]
1021
        mov     [ebp+NTFS.ntfsLastRead], eax
1037
        mov     [ebp+NTFS.ntfsLastRead], eax
1022
        push    ecx
1038
        push    ecx
1023
        xor     edx, edx
1039
        xor     edx, edx
1024
        cmp     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
1025
        jnz     .sys
-
 
1026
        cmp     [ebp+NTFS.ntfs_cur_iRecord], 0
-
 
1027
        jz      .sys
-
 
1028
        call    fs_read64_app
1040
        call    dword[esp+18h]
1029
        jmp     .appsys
-
 
1030
.sys:
-
 
1031
        call    fs_read64_sys
-
 
1032
.appsys:
-
 
1033
        pop     ecx
1041
        pop     ecx
1034
        test    eax, eax
1042
        test    eax, eax
1035
        jnz     .errread2
1043
        jnz     .errread2
1036
        sub     [ebp+NTFS.ntfs_cur_size], ecx
1044
        sub     [ebp+NTFS.ntfs_cur_size], ecx
1037
        add     [ebp+NTFS.ntfs_cur_offs], ecx
1045
        add     [ebp+NTFS.ntfs_cur_offs], ecx
Line 1042... Line 1050...
1042
        pop     ecx
1050
        pop     ecx
1043
        xor     eax, eax
1051
        xor     eax, eax
1044
        xor     edx, edx
1052
        xor     edx, edx
1045
        cmp     [ebp+NTFS.ntfs_cur_size], 0
1053
        cmp     [ebp+NTFS.ntfs_cur_size], 0
1046
        jnz     .readloop
1054
        jnz     .readloop
1047
        add     esp, 10h
1055
        add     esp, 14h
1048
        mov     eax, [ebp+NTFS.ntfs_cur_tail]
1056
        mov     eax, [ebp+NTFS.ntfs_cur_tail]
1049
        test    eax, eax
1057
        test    eax, eax
1050
        jz      @f
1058
        jz      @f
1051
        sub     eax, 0x200
1059
        sub     eax, 0x200
1052
        add     [ebp+NTFS.ntfs_cur_read], eax
1060
        add     [ebp+NTFS.ntfs_cur_read], eax
1053
@@:
1061
@@:
1054
        clc
1062
        clc
1055
        ret
1063
        ret
1056
.errread2:
1064
.errread2:
1057
        pop     ecx
1065
        pop     ecx
1058
        add     esp, 10h
1066
        add     esp, 14h
1059
        stc
1067
        stc
1060
        ret
1068
        ret
1061
.break:
1069
.break:
1062
        add     esp, 10h        ; CF=0
1070
        add     esp, 14h        ; CF=0
1063
        mov     [ebp+NTFS.ntfs_bCanContinue], 1
1071
        mov     [ebp+NTFS.ntfs_bCanContinue], 1
1064
        ret
1072
        ret
Line 1065... Line 1073...
1065
 
1073
 
1066
ntfs_read_file_record:
1074
ntfs_read_file_record:
Line 1209... Line 1217...
1209
 
1217
 
1210
ntfs_find_lfn:
1218
ntfs_find_lfn:
1211
; in: [esi]+[esp+4] = name
1219
; in: [esi]+[esp+4] = name
1212
;   out:
1220
;   out:
1213
; [ebp+NTFS.ntfs_cur_iRecord] = number of MFT fileRecord
1221
; [ebp+NTFS.ntfs_cur_iRecord] = number of MFT fileRecord
1214
; eax = pointer in parent index node
1222
; eax -> index in the parent index node
1215
; CF=1 -> file not found (or just error)
1223
; CF=1 -> file not found, eax=0 -> error
1216
        mov     [ebp+NTFS.ntfs_cur_iRecord], 5   ; start parse from root cluster
1224
        mov     [ebp+NTFS.ntfs_cur_iRecord], 5   ; start parse from root cluster
1217
.doit2:
1225
.doit2:
1218
        mov     [ebp+NTFS.ntfs_cur_attr], 0x90   ; $INDEX_ROOT
1226
        mov     [ebp+NTFS.ntfs_cur_attr], 0x90   ; $INDEX_ROOT
1219
        and     [ebp+NTFS.ntfs_cur_offs], 0
1227
        and     [ebp+NTFS.ntfs_cur_offs], 0
1220
        mov     eax, [ebp+NTFS.cur_index_size]
1228
        mov     eax, [ebp+NTFS.cur_index_size]
1221
        mov     [ebp+NTFS.ntfs_cur_size], eax
1229
        mov     [ebp+NTFS.ntfs_cur_size], eax
1222
        mov     eax, [ebp+NTFS.cur_index_buf]
1230
        mov     eax, [ebp+NTFS.cur_index_buf]
1223
        mov     [ebp+NTFS.ntfs_cur_buf], eax
1231
        mov     [ebp+NTFS.ntfs_cur_buf], eax
-
 
1232
        call    ntfs_read_attr
1224
        call    ntfs_read_attr
1233
        mov     eax, 0
1225
        jnc     @f
1234
        jnc     @f
1226
.ret:
1235
.ret:
1227
        ret     4
1236
        ret     4
1228
@@:
-
 
1229
        xor     eax, eax
1237
@@:
1230
        cmp     [ebp+NTFS.ntfs_cur_read], 0x20
1238
        cmp     [ebp+NTFS.ntfs_cur_read], 0x20
1231
        jc      .ret
1239
        jc      .ret
1232
        pushad
1240
        pushad
1233
        mov     esi, [ebp+NTFS.cur_index_buf]
1241
        mov     esi, [ebp+NTFS.cur_index_buf]
Line 1343... Line 1351...
1343
        call    ntfs_restore_usa
1351
        call    ntfs_restore_usa
1344
        jc      .err
1352
        jc      .err
1345
        add     esi, 0x18
1353
        add     esi, 0x18
1346
        jmp     .scanloop
1354
        jmp     .scanloop
1347
.notfound:
1355
.notfound:
1348
        mov     [ebp+NTFS.ntfsNotFound], 1
-
 
1349
        mov     [esp+1Ch], esi
1356
        mov     [esp+1Ch], esi
1350
.err:
1357
.err:
1351
        popad
1358
        popad
1352
        stc
1359
        stc
1353
        ret     4
1360
        ret     4
Line 1468... Line 1475...
1468
        mov     edx, [ebx+8]
1475
        mov     edx, [ebx+8]
1469
        add     eax, 511
1476
        add     eax, 511
1470
        adc     edx, 0
1477
        adc     edx, 0
1471
        shrd    eax, edx, 9
1478
        shrd    eax, edx, 9
1472
        pop     edx
1479
        pop     edx
1473
.zero1:
-
 
1474
        mov     [ebp+NTFS.ntfs_cur_offs], eax
1480
        mov     [ebp+NTFS.ntfs_cur_offs], eax
1475
        mov     [ebp+NTFS.ntfs_cur_buf], edx
1481
        mov     [ebp+NTFS.ntfs_cur_buf], edx
1476
        mov     eax, ecx
1482
        mov     eax, ecx
1477
        shr     eax, 9
1483
        shr     eax, 9
1478
        mov     [ebp+NTFS.ntfs_cur_size], eax
1484
        mov     [ebp+NTFS.ntfs_cur_size], eax
Line 1548... Line 1554...
1548
        call    ntfs_read_attr
1554
        call    ntfs_read_attr
1549
        jnc     .ok
1555
        jnc     .ok
1550
        test    eax, eax
1556
        test    eax, eax
1551
        jz      .notfound
1557
        jz      .notfound
1552
        or      ebx, -1
1558
        or      ebx, -1
1553
        push    11
1559
        push    ERROR_DEVICE
1554
        jmp     .pop_ret
1560
        jmp     .pop_ret
1555
.ok:
1561
.ok:
1556
        cmp     [ebp+NTFS.ntfs_cur_read], 0x20
1562
        cmp     [ebp+NTFS.ntfs_cur_read], 0x20
1557
        jae     @f
1563
        jae     @f
1558
        or      ebx, -1
1564
        or      ebx, -1
Line 1585... Line 1591...
1585
        and     [ebp+NTFS.cur_index_buf], 0
1591
        and     [ebp+NTFS.cur_index_buf], 0
1586
.nomem:
1592
.nomem:
1587
        call    ntfs_unlock
1593
        call    ntfs_unlock
1588
        popad
1594
        popad
1589
        or      ebx, -1
1595
        or      ebx, -1
1590
        movi    eax, 12
1596
        movi    eax, ERROR_OUT_OF_MEMORY
1591
        ret
1597
        ret
1592
@@:
1598
@@:
1593
        mov     [ebp+NTFS.cur_index_buf], eax
1599
        mov     [ebp+NTFS.cur_index_buf], eax
1594
        popad
1600
        popad
1595
        jmp     .doit2
1601
        jmp     .doit2
Line 1974... Line 1980...
1974
 
1980
 
1975
;----------------------------------------------------------------
1981
;----------------------------------------------------------------
1976
ntfs_CreateFolder:
1982
ntfs_CreateFolder:
1977
        mov     [ebp+NTFS.ntfsFolder], 1
1983
        mov     [ebp+NTFS.ntfsFolder], 1
-
 
1984
        jmp     @f
1978
        jmp     @f
1985
 
1979
ntfs_CreateFile:
1986
ntfs_CreateFile:
1980
        mov     [ebp+NTFS.ntfsFolder], 0
1987
        mov     [ebp+NTFS.ntfsFolder], 0
1981
@@:
1988
@@:
1982
        cmp     byte [esi], 0
1989
        cmp     byte [esi], 0
1983
        jnz     @f
1990
        jnz     @f
1984
        xor     ebx, ebx
1991
        xor     ebx, ebx
1985
        movi    eax, ERROR_ACCESS_DENIED    ; root directory itself
1992
        movi    eax, ERROR_ACCESS_DENIED    ; root directory itself
1986
        ret
1993
        ret
1987
@@: ; 1. Search file
1994
@@: ; 1. Search file
1988
        call    ntfs_lock
-
 
1989
        mov     [ebp+NTFS.ntfsNotFound], 0
1995
        call    ntfs_lock
1990
        stdcall ntfs_find_lfn, [esp+4]
1996
        stdcall ntfs_find_lfn, [esp+4]
1991
        jnc     @f      ; found; rewrite
1997
        jnc     .found
1992
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
1998
        cmp     [ebp+NTFS.ntfsFragmentCount], 1
1993
        jnz     @f      ; record fragmented
1999
        jnz     @f      ; record fragmented
1994
        cmp     [ebp+NTFS.ntfsNotFound], 1
2000
        test    eax, eax
1995
        jz      .notFound
2001
        jnz     .notFound
1996
        push    ERROR_FS_FAIL
2002
        push    ERROR_FS_FAIL
1997
        jmp     ntfsError
2003
        jmp     ntfsError
1998
@@:
2004
@@:
1999
        push    ERROR_UNSUPPORTED_FS
2005
        push    ERROR_UNSUPPORTED_FS
-
 
2006
        jmp     ntfsError
-
 
2007
 
-
 
2008
.found:     ; rewrite
-
 
2009
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
2010
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
2011
        mov     [ebp+NTFS.ntfs_cur_size], 0
-
 
2012
        call    ntfs_read_attr
-
 
2013
        jnc     @f
-
 
2014
        push    ERROR_ACCESS_DENIED
-
 
2015
        jmp     ntfsError
-
 
2016
@@:
-
 
2017
        push    ERROR_UNSUPPORTED_FS
-
 
2018
        mov     eax, [ebp+NTFS.frs_buffer]
-
 
2019
        cmp     word [eax+baseRecordReuse], 0
-
 
2020
        jnz     ntfsError       ; auxiliary record
-
 
2021
        cmp     byte [eax+hardLinkCounter], 1
-
 
2022
        jnz     ntfsError       ; file copying required
-
 
2023
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
-
 
2024
        cmp     byte [ecx+nonResidentFlag], 1
-
 
2025
        jnz     ntfsError       ; resident $DATA
-
 
2026
        mov     eax, [ebx+4]
-
 
2027
        mov     edx, [ebx+8]
-
 
2028
        add     eax, [ebx+12]
-
 
2029
        adc     edx, 0
-
 
2030
        cmp     edx, [ecx+attributeRealSize+4]
-
 
2031
        jnz     ntfsError
-
 
2032
        cmp     [ecx+attributeRealSize], eax
-
 
2033
        jnz     ntfsError
-
 
2034
        jmp     ntfs_WriteFile.write
2000
        jmp     ntfsError
2035
 
2001
.notFound:  ; create; check name
2036
.notFound:  ; create; check name
2002
        cmp     dword [esp+4], 0
2037
        cmp     dword [esp+4], 0
2003
        jnz     .bad
2038
        jnz     .bad
2004
        cmp     byte [esi], 0
2039
        cmp     byte [esi], 0
Line 2283... Line 2318...
2283
        shr     ecx, 9
2318
        shr     ecx, 9
2284
        mov     ebx, [ebx+16]
2319
        mov     ebx, [ebx+16]
2285
        call    fs_write64_app
2320
        call    fs_write64_app
2286
        test    eax, eax
2321
        test    eax, eax
2287
        jz      .mftBitmap
2322
        jz      .mftBitmap
2288
        push    11
2323
        push    ERROR_DEVICE
2289
        jmp     ntfsError
2324
        jmp     ntfsError
Line 2290... Line 2325...
2290
 
2325
 
2291
    ; 4. MFT record
2326
    ; 4. MFT record
2292
.mftBitmap: ; search for free record
2327
.mftBitmap: ; search for free record
Line 2333... Line 2368...
2333
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
2368
        mov     edi, [ebp+NTFS.ntfs_attr_offs]
2334
        mov     ebx, [ebp+NTFS.sectors_per_cluster]
2369
        mov     ebx, [ebp+NTFS.sectors_per_cluster]
2335
        shl     ebx, 9+3
2370
        shl     ebx, 9+3
2336
        add     dword [edi+lastVCN], 8
2371
        add     dword [edi+lastVCN], 8
2337
        add     [edi+attributeAllocatedSize], ebx
2372
        add     [edi+attributeAllocatedSize], ebx
-
 
2373
        adc     byte [edi+attributeAllocatedSize+4], 0
2338
        add     [edi+attributeRealSize], ebx
2374
        add     [edi+attributeRealSize], ebx
-
 
2375
        adc     byte [edi+attributeRealSize+4], 0
2339
        add     [edi+initialDataSize], ebx
2376
        add     [edi+initialDataSize], ebx
-
 
2377
        adc     byte [edi+initialDataSize+4], 0
2340
        add     edi, [edi+dataRunsOffset]
2378
        add     edi, [edi+dataRunsOffset]
2341
        movzx   eax, byte [edi]
2379
        movzx   eax, byte [edi]
2342
        inc     edi
2380
        inc     edi
2343
        shl     eax, 4
2381
        shl     eax, 4
2344
        shr     al, 4
2382
        shr     al, 4
Line 2362... Line 2400...
2362
        mov     esi, edx
2400
        mov     esi, edx
2363
        mov     ecx, edx
2401
        mov     ecx, edx
2364
        and     ecx, 7
2402
        and     ecx, 7
2365
        shr     edx, 3
2403
        shr     edx, 3
2366
        add     edx, [ebp+NTFS.BitmapBuffer]
2404
        add     edx, [ebp+NTFS.BitmapBuffer]
2367
        movzx   eax, word [edx]
2405
        mov     ax, [edx]
2368
        shr     eax, cl
2406
        shr     ax, cl
-
 
2407
        test    al, al
2369
        jnz     ntfsError
2408
        jnz     ntfsError
2370
        mov     al, -1
2409
        dec     al
2371
        xchg    [edx], al
2410
        xchg    [edx], al
2372
        mov     [edx+1], al
2411
        mov     [edx+1], al
2373
        pop     eax
2412
        pop     eax
2374
        push    12
2413
        push    ERROR_OUT_OF_MEMORY
2375
        stdcall kernel_alloc, ebx
2414
        stdcall kernel_alloc, ebx
2376
        test    eax, eax
2415
        test    eax, eax
2377
        jz      ntfsError
2416
        jz      ntfsError
2378
        mov     ecx, ebx
2417
        mov     ecx, ebx
2379
        shr     ecx, 2
2418
        shr     ecx, 2
Line 2387... Line 2426...
2387
        pop     ecx
2426
        pop     ecx
2388
        shr     ecx, 9
2427
        shr     ecx, 9
2389
        call    fs_write64_sys  ; clear new records
2428
        call    fs_write64_sys  ; clear new records
2390
        stdcall kernel_free, ebx
2429
        stdcall kernel_free, ebx
2391
        pop     eax
2430
        pop     eax
2392
        push    11
2431
        push    ERROR_DEVICE
2393
        mov     eax, esi
2432
        mov     eax, esi
2394
        shr     eax, 3+9
2433
        shr     eax, 3+9
2395
        mov     ebx, eax
2434
        mov     ebx, eax
2396
        shl     ebx, 9
2435
        shl     ebx, 9
2397
        add     ebx, [ebp+NTFS.BitmapBuffer]
2436
        add     ebx, [ebp+NTFS.BitmapBuffer]
Line 2519... Line 2558...
2519
        mov     [edi+recordFlags], al
2558
        mov     [edi+recordFlags], al
2520
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2559
        mov     [ebp+NTFS.ntfs_cur_buf], edi
2521
        call    writeRecord
2560
        call    writeRecord
2522
        test    eax, eax
2561
        test    eax, eax
2523
        jz      @f
2562
        jz      @f
2524
        push    11
2563
        push    ERROR_DEVICE
2525
        jmp     ntfsError
2564
        jmp     ntfsError
2526
@@:
2565
@@:
2527
        mov     esi, [ebp+PARTITION.Disk]
2566
        mov     esi, [ebp+PARTITION.Disk]
2528
        call    disk_sync
2567
        call    disk_sync
2529
    ; write MFT bitmap
2568
    ; write MFT bitmap
Line 2536... Line 2575...
2536
        mov     ecx, 1
2575
        mov     ecx, 1
2537
        xor     edx, edx
2576
        xor     edx, edx
2538
        call    fs_write64_sys
2577
        call    fs_write64_sys
2539
        test    eax, eax
2578
        test    eax, eax
2540
        jz      @f
2579
        jz      @f
2541
        push    11
2580
        push    ERROR_DEVICE
2542
        jmp     ntfsError
2581
        jmp     ntfsError
2543
@@: ; 5. Write partition bitmap
2582
@@: ; 5. Write partition bitmap
2544
        cmp     [ebp+NTFS.ntfsFolder], 0
2583
        cmp     [ebp+NTFS.ntfsFolder], 0
2545
        jnz     @f
2584
        jnz     @f
2546
        cmp     [ebp+NTFS.fileRealSize], 0
2585
        cmp     [ebp+NTFS.fileRealSize], 0
Line 2558... Line 2597...
2558
        add     ebx, [ebp+NTFS.BitmapBuffer]
2597
        add     ebx, [ebp+NTFS.BitmapBuffer]
2559
        xor     edx, edx
2598
        xor     edx, edx
2560
        call    fs_write64_app
2599
        call    fs_write64_app
2561
        test    eax, eax
2600
        test    eax, eax
2562
        jz      @f
2601
        jz      @f
2563
        push    11
2602
        push    ERROR_DEVICE
2564
        jmp     ntfsError
2603
        jmp     ntfsError
2565
@@:
2604
@@:
2566
        mov     esi, [ebp+PARTITION.Disk]
2605
        mov     esi, [ebp+PARTITION.Disk]
2567
        call    disk_sync
2606
        call    disk_sync
2568
        mov     edi, [ebp+NTFS.indexOffset]
2607
        mov     edi, [ebp+NTFS.indexOffset]
Line 2657... Line 2696...
2657
        add     esp, 12     ; double ret
2696
        add     esp, 12     ; double ret
2658
        push    ERROR_DISK_FULL
2697
        push    ERROR_DISK_FULL
2659
        jmp     ntfsError
2698
        jmp     ntfsError
Line 2660... Line 2699...
2660
 
2699
 
2661
;----------------------------------------------------------------
2700
;----------------------------------------------------------------
-
 
2701
ntfs_WriteFile:
-
 
2702
        cmp     byte [esi], 0
2662
ntfs_Write:
2703
        jnz     @f
-
 
2704
        xor     ebx, ebx
-
 
2705
        movi    eax, ERROR_ACCESS_DENIED
-
 
2706
        ret
-
 
2707
@@:
-
 
2708
        call    ntfs_lock
-
 
2709
        stdcall ntfs_find_lfn, [esp+4]
-
 
2710
        jnc     .found
-
 
2711
        push    ERROR_FILE_NOT_FOUND
-
 
2712
        jmp     ntfsError
-
 
2713
.found:
-
 
2714
        mov     [ebp+NTFS.ntfs_cur_attr], 0x80
-
 
2715
        mov     [ebp+NTFS.ntfs_cur_offs], 0
-
 
2716
        mov     [ebp+NTFS.ntfs_cur_size], 0
-
 
2717
        call    ntfs_read_attr
-
 
2718
        jnc     @f
-
 
2719
        push    ERROR_ACCESS_DENIED
-
 
2720
        jmp     ntfsError
2663
        xor     ebx, ebx
2721
@@:
-
 
2722
        push    ERROR_UNSUPPORTED_FS
-
 
2723
        mov     eax, [ebp+NTFS.frs_buffer]
-
 
2724
        cmp     word [eax+baseRecordReuse], 0
-
 
2725
        jnz     ntfsError       ; auxiliary record
-
 
2726
        cmp     byte [eax+hardLinkCounter], 1
-
 
2727
        jnz     ntfsError       ; file copying required
-
 
2728
        mov     ecx, [ebp+NTFS.ntfs_attr_offs]
-
 
2729
        cmp     byte [ecx+nonResidentFlag], 1
-
 
2730
        jnz     ntfsError       ; resident $DATA
-
 
2731
        mov     eax, [ebx+4]
-
 
2732
        mov     edx, [ebx+8]
-
 
2733
        add     eax, [ebx+12]
-
 
2734
        adc     edx, 0
-
 
2735
        cmp     edx, [ecx+attributeRealSize+4]
-
 
2736
        jc      .write
-
 
2737
        jnz     ntfsError       ; end of file
-
 
2738
        cmp     [ecx+attributeRealSize], eax
-
 
2739
        jc      ntfsError
-
 
2740
.write:
-
 
2741
        pop     eax
-
 
2742
        push    ERROR_DEVICE
-
 
2743
        mov     eax, [ebx+4]
-
 
2744
        mov     edx, [ebx+8]
-
 
2745
        mov     ecx, [ebx+12]
-
 
2746
        mov     esi, [ebx+16]
-
 
2747
        shrd    eax, edx, 9
-
 
2748
        test    dword[ebx+4], 1FFh
-
 
2749
        jz      .aligned
-
 
2750
        mov     [ebp+NTFS.ntfs_cur_offs], eax
-
 
2751
        mov     [ebp+NTFS.ntfs_cur_size], 1
-
 
2752
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
-
 
2753
        mov     [ebp+NTFS.ntfs_cur_buf], edi
-
 
2754
        call    ntfs_read_attr.continue
-
 
2755
        jc      ntfsError
-
 
2756
        mov     eax, [ebx+4]
-
 
2757
        and     eax, 1FFh
-
 
2758
        add     edi, eax
-
 
2759
        sub     eax, [ebp+NTFS.ntfs_cur_read]
-
 
2760
        neg     eax
-
 
2761
        push    ecx
-
 
2762
        cmp     ecx, eax
-
 
2763
        jb      @f
-
 
2764
        mov     ecx, eax
-
 
2765
@@:
-
 
2766
        sub     [esp], ecx
-
 
2767
        rep movsb
-
 
2768
        push    ebx
-
 
2769
        mov     eax, [ebp+NTFS.ntfsLastRead]
-
 
2770
        lea     ebx, [ebp+NTFS.ntfs_bitmap_buf]
-
 
2771
        mov     ecx, 1
-
 
2772
        xor     edx, edx
-
 
2773
        call    fs_write64_app
-
 
2774
        pop     ebx
-
 
2775
        pop     ecx
-
 
2776
        test    eax, eax
-
 
2777
        jnz     ntfsError
-
 
2778
        test    ecx, ecx
-
 
2779
        jz      @f
-
 
2780
        mov     eax, [ebx+4]
-
 
2781
        mov     edx, [ebx+8]
-
 
2782
        shrd    eax, edx, 9
-
 
2783
        inc     eax
-
 
2784
.aligned:
-
 
2785
        push    ecx
-
 
2786
        shr     ecx, 9
-
 
2787
        mov     [ebp+NTFS.ntfs_cur_offs], eax
-
 
2788
        mov     [ebp+NTFS.ntfs_cur_size], ecx
-
 
2789
        mov     [ebp+NTFS.ntfs_cur_buf], esi
-
 
2790
        add     eax, ecx
-
 
2791
        push    eax
-
 
2792
        mov     [ebp+NTFS.ntfsWriteAttr], 1
-
 
2793
        call    ntfs_read_attr.continue
-
 
2794
        mov     [ebp+NTFS.ntfsWriteAttr], 0
-
 
2795
        pop     [ebp+NTFS.ntfs_cur_offs]
-
 
2796
        pop     ecx
-
 
2797
        jc      ntfsError
-
 
2798
        and     ecx, 1FFh
-
 
2799
        jz      @f
-
 
2800
        add     esi, [ebp+NTFS.ntfs_cur_read]
-
 
2801
        mov     [ebp+NTFS.ntfs_cur_size], 1
-
 
2802
        lea     edi, [ebp+NTFS.ntfs_bitmap_buf]
-
 
2803
        mov     [ebp+NTFS.ntfs_cur_buf], edi
-
 
2804
        call    ntfs_read_attr.continue
-
 
2805
        jc      ntfsError
-
 
2806
        rep movsb
-
 
2807
        push    ebx
-
 
2808
        mov     eax, [ebp+NTFS.ntfsLastRead]
-
 
2809
        lea     ebx, [ebp+NTFS.ntfs_bitmap_buf]
-
 
2810
        mov     ecx, 1
-
 
2811
        xor     edx, edx
-
 
2812
        call    fs_write64_app
-
 
2813
        pop     ebx
-
 
2814
@@:
-
 
2815
        mov     esi, [ebp+PARTITION.Disk]
-
 
2816
        call    disk_sync
-
 
2817
        call    ntfs_unlock
-
 
2818
        pop     eax
-
 
2819
        xor     eax, eax
2664
        mov     eax, ERROR_UNSUPPORTED_FS
2820
        mov     ebx, [ebx+12]
Line 2665... Line 2821...
2665
        ret
2821
        ret
2666
 
2822
 
2667
;----------------------------------------------------------------
2823
;----------------------------------------------------------------
Line 2673... Line 2829...
2673
 
2829
 
2674
;----------------------------------------------------------------
2830
;----------------------------------------------------------------
2675
ntfs_GetFileInfo:
2831
ntfs_GetFileInfo:
2676
        cmp     byte [esi], 0
2832
        cmp     byte [esi], 0
2677
        jnz     @f
2833
        jnz     @f
2678
        movi    eax, 2
2834
        movi    eax, ERROR_UNSUPPORTED_FS
2679
        ret
2835
        ret
2680
@@:
2836
@@:
2681
        call    ntfs_lock
2837
        call    ntfs_lock
2682
        stdcall ntfs_find_lfn, [esp+4]
2838
        stdcall ntfs_find_lfn, [esp+4]
2683
        jnc     .doit
-
 
2684
        test    eax, eax
2839
        jnc     .found
-
 
2840
        push    ERROR_FILE_NOT_FOUND
2685
        push    ERROR_FILE_NOT_FOUND
2841
        test    eax, eax
2686
        jz      ntfsError
2842
        jnz     ntfsError
2687
        pop     eax
2843
        pop     eax
2688
        push    11
2844
        push    ERROR_FS_FAIL
2689
        jmp     ntfsError
2845
        jmp     ntfsError
2690
.doit:
2846
.found:
2691
        push    esi edi
2847
        push    esi edi
2692
        mov     esi, eax
2848
        mov     esi, eax
2693
        mov     edi, [ebx+16]
2849
        mov     edi, [ebx+16]
2694
        xor     eax, eax
2850
        xor     eax, eax