Rev 6297 | Rev 6401 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6297 | Rev 6340 | ||
---|---|---|---|
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: 6297 $ |
8 | $Revision: 6340 $ |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | ; NTFS driver |
10 | ; NTFS driver |
Line 63... | Line 63... | ||
63 | initialDataSize = 38h |
63 | initialDataSize = 38h |
64 | ; $IndexRoot |
64 | ; $IndexRoot |
65 | indexedAttributesType = 0 |
65 | indexedAttributesType = 0 |
66 | collationRule = 4 |
66 | collationRule = 4 |
67 | indexRecordSize = 8 |
67 | indexRecordSize = 8 |
68 | indexRecordSizeClus = 12 |
68 | indexRecordSizeClus = 12 ; in sectors if less than one cluster |
69 | rootNode = 16 |
69 | rootNode = 16 |
70 | ; IndexRecord header |
70 | ; IndexRecord header |
71 | recordVCN = 16 |
71 | recordVCN = 16 |
72 | recordNode = 18h |
72 | recordNode = 18h |
73 | ; node header |
73 | ; node header |
Line 106... | Line 106... | ||
106 | mft_retrieval_size dd ? |
106 | mft_retrieval_size dd ? |
107 | mft_retrieval_alloc dd ? |
107 | mft_retrieval_alloc dd ? |
108 | mft_retrieval_end dd ? |
108 | mft_retrieval_end dd ? |
109 | cur_index_size dd ? ; in sectors |
109 | cur_index_size dd ? ; in sectors |
110 | cur_index_buf dd ? ; index node buffer |
110 | cur_index_buf dd ? ; index node buffer |
- | 111 | secondIndexBuffer dd ? |
|
111 | BitmapBuffer dd ? |
112 | BitmapBuffer dd ? |
112 | BitmapTotalSize dd ? ; bytes reserved |
113 | BitmapTotalSize dd ? ; bytes reserved |
113 | BitmapSize dd ? ; bytes readen |
114 | BitmapSize dd ? ; bytes readen |
114 | BitmapLocation dd ? ; starting sector |
115 | BitmapLocation dd ? ; starting sector |
115 | BitmapStart dd ? ; first byte after area, reserved for MFT |
116 | BitmapStart dd ? ; first byte after area, reserved for MFT |
Line 122... | Line 123... | ||
122 | cur_offs dd ? ; attribute VCN in sectors |
123 | cur_offs dd ? ; attribute VCN in sectors |
123 | cur_size dd ? ; max sectors to read |
124 | cur_size dd ? ; max sectors to read |
124 | cur_buf dd ? |
125 | cur_buf dd ? |
125 | cur_read dd ? ; bytes readen |
126 | cur_read dd ? ; bytes readen |
126 | LastRead dd ? ; last readen block of sectors |
127 | LastRead dd ? ; last readen block of sectors |
- | 128 | rootLastRead dd ? |
|
- | 129 | nodeLastRead dd ? |
|
- | 130 | indexRoot dd ? |
|
- | 131 | pointingIndex dd ? |
|
127 | newMftRecord dd ? ; number of fileRecord in MFT |
132 | newRecord dd ? |
128 | fileDataStart dd ? ; starting cluster |
133 | fileDataStart dd ? ; starting cluster |
129 | fileDataSize dd ? ; in clusters |
134 | fileDataSize dd ? ; in clusters |
130 | fileDataBuffer dd ? |
135 | fileDataBuffer dd ? |
131 | fileRealSize dd ? ; in bytes |
136 | fileRealSize dd ? ; in bytes |
132 | indexOffset dd ? |
137 | indexOffset dd ? |
133 | nodeLastRead dd ? |
- | |
134 | fragmentCount db ? |
138 | fragmentCount db ? |
135 | bCanContinue db ? |
139 | bCanContinue db ? |
136 | bFolder db ? |
140 | bFolder db ? |
137 | bWriteAttr db ? ; Warning: Don't forget to turn off!!! |
141 | bWriteAttr db ? ; Warning: Don't forget to turn off!!! |
Line 396... | Line 400... | ||
396 | 400 | ||
397 | .scanmcbend: |
401 | .scanmcbend: |
398 | add esp, 10h |
402 | add esp, 10h |
399 | ; there may be other portions of $DATA attribute in auxiliary records; |
403 | ; there may be other portions of $DATA attribute in auxiliary records; |
400 | ; if they will be needed, they will be loaded later |
- | |
401 | mov [ebp+NTFS.cur_index_size], 0x1000/0x200 |
404 | ; if they will be needed, they will be loaded later |
402 | stdcall kernel_alloc, 0x1000 |
405 | stdcall kernel_alloc, 2000h |
403 | test eax, eax |
406 | test eax, eax |
404 | jz .fail_free_mft |
407 | jz .fail_free_mft |
- | 408 | mov [ebp+NTFS.cur_index_buf], eax |
|
- | 409 | add eax, 1000h |
|
- | 410 | mov [ebp+NTFS.secondIndexBuffer], eax |
|
405 | mov [ebp+NTFS.cur_index_buf], eax |
411 | mov [ebp+NTFS.cur_index_size], 8 |
406 | ; reserve adress space for bitmap buffer and load some part of bitmap |
412 | ; reserve adress space for bitmap buffer and load some part of bitmap |
407 | mov eax, dword [ebp+NTFS.Length] |
413 | mov eax, dword [ebp+NTFS.Length] |
408 | xor edx, edx |
414 | xor edx, edx |
409 | div [ebp+NTFS.sectors_per_cluster] |
415 | div [ebp+NTFS.sectors_per_cluster] |
Line 482... | Line 488... | ||
482 | stdcall kernel_free, [ebx+NTFS.mftBitmapBuffer] |
488 | stdcall kernel_free, [ebx+NTFS.mftBitmapBuffer] |
483 | .failFreeBitmap: |
489 | .failFreeBitmap: |
484 | stdcall kernel_free, [ebx+NTFS.BitmapBuffer] |
490 | stdcall kernel_free, [ebx+NTFS.BitmapBuffer] |
485 | .failFreeIndex: |
491 | .failFreeIndex: |
486 | stdcall kernel_free, [ebp+NTFS.cur_index_buf] |
492 | stdcall kernel_free, [ebp+NTFS.cur_index_buf] |
- | 493 | stdcall kernel_free, [ebp+NTFS.secondIndexBuffer] |
|
487 | .fail_free_mft: |
494 | .fail_free_mft: |
488 | stdcall kernel_free, [ebp+NTFS.mft_retrieval] |
495 | stdcall kernel_free, [ebp+NTFS.mft_retrieval] |
489 | .fail_free_frs: |
496 | .fail_free_frs: |
490 | stdcall kernel_free, [ebp+NTFS.frs_buffer] |
497 | stdcall kernel_free, [ebp+NTFS.frs_buffer] |
491 | .fail_free: |
498 | .fail_free: |
Line 530... | Line 537... | ||
530 | push ebx |
537 | push ebx |
531 | mov ebx, eax |
538 | mov ebx, eax |
532 | stdcall kernel_free, [ebx+NTFS.frs_buffer] |
539 | stdcall kernel_free, [ebx+NTFS.frs_buffer] |
533 | stdcall kernel_free, [ebx+NTFS.mft_retrieval] |
540 | stdcall kernel_free, [ebx+NTFS.mft_retrieval] |
534 | stdcall kernel_free, [ebx+NTFS.cur_index_buf] |
541 | stdcall kernel_free, [ebx+NTFS.cur_index_buf] |
- | 542 | stdcall kernel_free, [ebp+NTFS.secondIndexBuffer] |
|
535 | stdcall kernel_free, [ebx+NTFS.mftBitmapBuffer] |
543 | stdcall kernel_free, [ebx+NTFS.mftBitmapBuffer] |
536 | stdcall kernel_free, [ebx+NTFS.BitmapBuffer] |
544 | stdcall kernel_free, [ebx+NTFS.BitmapBuffer] |
537 | mov eax, ebx |
545 | mov eax, ebx |
538 | pop ebx |
546 | pop ebx |
539 | jmp free |
547 | jmp free |
Line 1278... | Line 1286... | ||
1278 | jc .ret |
1286 | jc .ret |
1279 | cmp [ebp+NTFS.cur_read], 0x20 |
1287 | cmp [ebp+NTFS.cur_read], 0x20 |
1280 | jc .ret |
1288 | jc .ret |
1281 | pushad |
1289 | pushad |
1282 | mov esi, [ebp+NTFS.cur_index_buf] |
1290 | mov esi, [ebp+NTFS.cur_index_buf] |
1283 | mov edx, [esi+indexRecordSize] |
1291 | mov eax, [esi+indexRecordSize] |
1284 | shr edx, 9 |
1292 | shr eax, 9 |
1285 | cmp [ebp+NTFS.cur_index_size], edx |
1293 | cmp [ebp+NTFS.cur_index_size], eax |
1286 | jc .realloc |
1294 | jc .realloc |
- | 1295 | mov [ebp+NTFS.cur_size], eax |
|
- | 1296 | mov al, [esi+indexRecordSizeClus] |
|
- | 1297 | mov [ebp+NTFS.cur_subnode_size], eax |
|
1287 | add esi, rootNode |
1298 | add esi, rootNode |
1288 | mov eax, [esi+nodeRealSize] |
1299 | mov eax, [esi+nodeRealSize] |
1289 | add eax, rootNode |
1300 | add eax, rootNode |
1290 | cmp [ebp+NTFS.cur_read], eax |
1301 | cmp [ebp+NTFS.cur_read], eax |
1291 | jc .err |
1302 | jc .err |
1292 | mov edi, [esp+4] |
1303 | mov edi, [esp+4] |
- | 1304 | mov eax, [ebp+NTFS.LastRead] |
|
- | 1305 | mov [ebp+NTFS.rootLastRead], eax |
|
- | 1306 | mov eax, [ebp+NTFS.attr_offs] |
|
- | 1307 | mov [ebp+NTFS.indexRoot], eax |
|
1293 | ; edi -> name, esi -> current index node, edx = subnode size |
1308 | ; edi -> name, esi -> current index node |
1294 | .scanloop: |
1309 | .scanloop: |
1295 | add esi, [esi+indexOffset] |
1310 | add esi, [esi+indexOffset] |
1296 | .scanloopint: |
1311 | .scanloopint: |
1297 | test byte [esi+indexFlags], 2 |
1312 | test byte [esi+indexFlags], 2 |
1298 | jnz .subnode |
1313 | jnz .subnode |
Line 1321... | Line 1336... | ||
1321 | movzx eax, word [esi+indexAllocatedSize] |
1336 | movzx eax, word [esi+indexAllocatedSize] |
1322 | add esi, eax |
1337 | add esi, eax |
1323 | jmp .scanloopint |
1338 | jmp .scanloopint |
Line 1324... | Line 1339... | ||
1324 | 1339 | ||
1325 | .realloc: |
1340 | .realloc: |
1326 | mov edi, edx |
1341 | mov edi, eax |
- | 1342 | mov eax, [esi+indexRecordSize] |
|
- | 1343 | shl eax, 1 |
|
1327 | stdcall kernel_alloc, [esi+indexRecordSize] |
1344 | stdcall kernel_alloc, eax |
1328 | test eax, eax |
1345 | test eax, eax |
- | 1346 | jz .err |
|
1329 | jz .err |
1347 | push [ebp+NTFS.secondIndexBuffer] |
1330 | push [ebp+NTFS.cur_index_buf] |
1348 | push [ebp+NTFS.cur_index_buf] |
1331 | mov [ebp+NTFS.cur_index_buf], eax |
1349 | mov [ebp+NTFS.cur_index_buf], eax |
- | 1350 | add eax, [esi+indexRecordSize] |
|
1332 | call kernel_free |
1351 | mov [ebp+NTFS.secondIndexBuffer], eax |
- | 1352 | mov [ebp+NTFS.cur_index_size], edi |
|
- | 1353 | call kernel_free |
|
1333 | mov [ebp+NTFS.cur_index_size], edi |
1354 | call kernel_free |
1334 | popad |
1355 | popad |
Line 1335... | Line 1356... | ||
1335 | jmp .doit2 |
1356 | jmp .doit2 |
1336 | 1357 | ||
Line 1349... | Line 1370... | ||
1349 | .subnode: |
1370 | .subnode: |
1350 | test byte [esi+indexFlags], 1 |
1371 | test byte [esi+indexFlags], 1 |
1351 | jz .notfound |
1372 | jz .notfound |
1352 | movzx eax, word [esi+indexAllocatedSize] |
1373 | movzx eax, word [esi+indexAllocatedSize] |
1353 | mov eax, [esi+eax-8] |
1374 | mov eax, [esi+eax-8] |
- | 1375 | mov edx, [ebp+NTFS.cur_size] |
|
- | 1376 | push edx |
|
- | 1377 | cmp edx, [ebp+NTFS.cur_subnode_size] |
|
- | 1378 | jz @f |
|
1354 | imul eax, [ebp+NTFS.sectors_per_cluster] |
1379 | mul [ebp+NTFS.sectors_per_cluster] |
- | 1380 | @@: |
|
- | 1381 | mov [ebp+NTFS.pointingIndex], esi |
|
- | 1382 | mov esi, [ebp+NTFS.cur_index_buf] |
|
- | 1383 | xchg [ebp+NTFS.secondIndexBuffer], esi |
|
- | 1384 | mov [ebp+NTFS.cur_index_buf], esi |
|
1355 | mov [ebp+NTFS.cur_offs], eax |
1385 | mov [ebp+NTFS.cur_buf], esi |
1356 | mov [ebp+NTFS.cur_attr], 0xA0 ; $INDEX_ALLOCATION |
1386 | mov [ebp+NTFS.cur_attr], 0xA0 ; $INDEX_ALLOCATION |
1357 | mov [ebp+NTFS.cur_size], edx |
- | |
1358 | mov eax, [ebp+NTFS.cur_index_buf] |
- | |
1359 | mov esi, eax |
- | |
1360 | mov [ebp+NTFS.cur_buf], eax |
1387 | mov [ebp+NTFS.cur_offs], eax |
1361 | call ntfs_read_attr.newAttribute |
1388 | call ntfs_read_attr.newAttribute |
1362 | mov eax, edx |
1389 | pop eax |
- | 1390 | mov [ebp+NTFS.cur_size], eax |
|
1363 | shl eax, 9 |
1391 | shl eax, 9 |
1364 | cmp [ebp+NTFS.cur_read], eax |
1392 | cmp [ebp+NTFS.cur_read], eax |
1365 | jnz .err |
1393 | jnz .err |
1366 | cmp dword [esi], 'INDX' |
1394 | cmp dword [esi], 'INDX' |
1367 | jnz .err |
1395 | jnz .err |
1368 | mov [ebp+NTFS.cur_buf], esi |
- | |
1369 | mov ebx, esi |
1396 | mov ebx, esi |
1370 | call ntfs_restore_usa |
1397 | call ntfs_restore_usa |
1371 | jc .err |
1398 | jc .err |
1372 | add esi, recordNode |
1399 | add esi, recordNode |
1373 | jmp .scanloop |
1400 | jmp .scanloop |
Line 1564... | Line 1591... | ||
1564 | jc ntfsFail |
1591 | jc ntfsFail |
1565 | cmp [ebp+NTFS.cur_read], 0x20 |
1592 | cmp [ebp+NTFS.cur_read], 0x20 |
1566 | jc ntfsFail |
1593 | jc ntfsFail |
1567 | pushad |
1594 | pushad |
1568 | mov esi, [ebp+NTFS.cur_index_buf] |
1595 | mov esi, [ebp+NTFS.cur_index_buf] |
1569 | mov edx, [esi+indexRecordSize] |
1596 | mov eax, [esi+indexRecordSize] |
1570 | shr edx, 9 |
1597 | shr eax, 9 |
1571 | cmp [ebp+NTFS.cur_index_size], edx |
1598 | cmp [ebp+NTFS.cur_index_size], eax |
1572 | jc .realloc |
1599 | jc .realloc |
1573 | mov [ebp+NTFS.cur_subnode_size], edx |
1600 | mov [ebp+NTFS.cur_subnode_size], eax |
1574 | add esi, rootNode |
1601 | add esi, rootNode |
1575 | mov eax, [esi+nodeRealSize] |
1602 | mov eax, [esi+nodeRealSize] |
1576 | add eax, rootNode |
1603 | add eax, rootNode |
1577 | cmp [ebp+NTFS.cur_read], eax |
1604 | cmp [ebp+NTFS.cur_read], eax |
1578 | jc .err |
1605 | jc .err |
Line 1610... | Line 1637... | ||
1610 | movzx eax, word [esi+indexAllocatedSize] |
1637 | movzx eax, word [esi+indexAllocatedSize] |
1611 | add esi, eax |
1638 | add esi, eax |
1612 | jmp .dump_root |
1639 | jmp .dump_root |
Line 1613... | Line 1640... | ||
1613 | 1640 | ||
1614 | .realloc: |
1641 | .realloc: |
1615 | mov edi, edx |
1642 | mov edi, eax |
- | 1643 | mov eax, [esi+indexRecordSize] |
|
- | 1644 | shl eax, 1 |
|
1616 | stdcall kernel_alloc, [esi+indexRecordSize] |
1645 | stdcall kernel_alloc, eax |
1617 | test eax, eax |
1646 | test eax, eax |
- | 1647 | jz .err |
|
1618 | jz .err |
1648 | push [ebp+NTFS.secondIndexBuffer] |
1619 | push [ebp+NTFS.cur_index_buf] |
1649 | push [ebp+NTFS.cur_index_buf] |
1620 | mov [ebp+NTFS.cur_index_buf], eax |
1650 | mov [ebp+NTFS.cur_index_buf], eax |
- | 1651 | add eax, [esi+indexRecordSize] |
|
1621 | call kernel_free |
1652 | mov [ebp+NTFS.secondIndexBuffer], eax |
- | 1653 | mov [ebp+NTFS.cur_index_size], edi |
|
- | 1654 | call kernel_free |
|
1622 | mov [ebp+NTFS.cur_index_size], edi |
1655 | call kernel_free |
1623 | popad |
1656 | popad |
Line 1624... | Line 1657... | ||
1624 | jmp .doit |
1657 | jmp .doit |
1625 | 1658 | ||
Line 2046... | Line 2079... | ||
2046 | sub eax, [ebp+NTFS.cur_index_buf] |
2079 | sub eax, [ebp+NTFS.cur_index_buf] |
2047 | add eax, edi |
2080 | add eax, edi |
2048 | mov edi, [ebp+NTFS.cur_index_buf] |
2081 | mov edi, [ebp+NTFS.cur_index_buf] |
2049 | jmp .common |
2082 | jmp .common |
Line 2050... | Line -... | ||
2050 | - | ||
2051 | @@: |
- | |
2052 | add esp, 16 |
- | |
2053 | jmp ntfsUnsupported |
- | |
2054 | 2083 | ||
- | 2084 | .growTree: |
|
2055 | .growTree: |
2085 | sub eax, edi |
2056 | sub eax, rootNode |
2086 | sub eax, rootNode |
2057 | sub eax, [edi+rootNode+indexOffset] |
2087 | sub eax, [edi+rootNode+indexOffset] |
- | 2088 | push eax |
|
- | 2089 | xchg [ebp+NTFS.secondIndexBuffer], edi |
|
2058 | push eax |
2090 | mov [ebp+NTFS.cur_index_buf], edi |
2059 | ; create indexRecord |
2091 | ; create indexRecord |
2060 | mov ecx, 10 |
2092 | mov ecx, 10 |
2061 | xor eax, eax |
2093 | xor eax, eax |
2062 | rep stosd |
- | |
2063 | rdtsc |
- | |
2064 | stosw |
2094 | rep stosd |
2065 | mov esi, [ebp+NTFS.attr_offs] |
2095 | mov esi, [ebp+NTFS.attr_offs] |
2066 | mov cl, [esi+attributeOffset] |
2096 | mov al, [esi+attributeOffset] |
2067 | add esi, ecx |
2097 | add esi, eax |
2068 | mov eax, [esi+indexRecordSizeClus] |
- | |
2069 | cmp eax, 129 |
- | |
2070 | jnc @b |
2098 | mov al, [esi+indexRecordSizeClus] |
- | 2099 | mov [ebp+NTFS.fileDataSize], eax |
|
- | 2100 | rdtsc |
|
2071 | mov [ebp+NTFS.fileDataSize], eax |
2101 | stosw |
2072 | mov eax, [esi+indexRecordSize] |
2102 | mov eax, [esi+indexRecordSize] |
2073 | cmp eax, [ebp+NTFS.frs_size] |
2103 | cmp eax, [ebp+NTFS.frs_size] |
2074 | jc @b |
2104 | jc .errorPop4 |
2075 | shr eax, 9 |
2105 | shr eax, 9 |
2076 | inc eax |
2106 | inc eax |
2077 | mov edi, [ebp+NTFS.cur_index_buf] |
2107 | mov edi, [ebp+NTFS.cur_index_buf] |
2078 | mov dword[edi], 'INDX' |
2108 | mov dword[edi], 'INDX' |
Line 2113... | Line 2143... | ||
2113 | mov eax, edi |
2143 | mov eax, edi |
2114 | sub eax, esi |
2144 | sub eax, esi |
2115 | mov word [esi+sizeWithoutHeader], 38h |
2145 | mov word [esi+sizeWithoutHeader], 38h |
2116 | xchg [esi+sizeWithHeader], eax |
2146 | xchg [esi+sizeWithHeader], eax |
2117 | cmp byte [esi+eax], -1 |
2147 | cmp byte [esi+eax], -1 |
2118 | jnz @b |
2148 | jnz .errorPop4 |
2119 | mov cl, 32 |
2149 | mov cl, 32 |
2120 | xor eax, eax |
2150 | xor eax, eax |
2121 | push edi |
2151 | push edi |
2122 | rep stosd |
2152 | rep stosd |
2123 | mov edi, [ebp+NTFS.BitmapStart] |
2153 | mov edi, [ebp+NTFS.BitmapStart] |
Line 2126... | Line 2156... | ||
2126 | add esp, 20 |
2156 | add esp, 20 |
2127 | jmp ntfsDiskFull |
2157 | jmp ntfsDiskFull |
Line 2128... | Line 2158... | ||
2128 | 2158 | ||
2129 | @@: ; create $IndexAllocation |
2159 | @@: ; create $IndexAllocation |
- | 2160 | pop edi |
|
2130 | pop edi |
2161 | mov [ebp+NTFS.attr_offs], edi |
2131 | mov byte [edi+attributeType], 0xA0 |
2162 | mov byte [edi+attributeType], 0xA0 |
2132 | mov byte [edi+nonResidentFlag], 1 |
2163 | mov byte [edi+nonResidentFlag], 1 |
2133 | mov byte [edi+nameLength], 4 |
2164 | mov byte [edi+nameLength], 4 |
2134 | mov byte [edi+nameOffset], 40h |
2165 | mov byte [edi+nameOffset], 40h |
Line 2179... | Line 2210... | ||
2179 | mov [ebp+NTFS.LastRead], eax |
2210 | mov [ebp+NTFS.LastRead], eax |
2180 | mov eax, [ebp+NTFS.cur_index_buf] |
2211 | mov eax, [ebp+NTFS.cur_index_buf] |
2181 | mov [ebp+NTFS.cur_buf], eax |
2212 | mov [ebp+NTFS.cur_buf], eax |
2182 | call writeRecord ; indexRecord |
2213 | call writeRecord ; indexRecord |
2183 | mov ebx, [ebp+NTFS.cur_index_buf] |
2214 | mov ebx, [ebp+NTFS.cur_index_buf] |
2184 | mov ax, [ebx+6] |
2215 | mov ax, [ebx+updateSequenceSize] |
2185 | dec eax |
2216 | dec eax |
2186 | shl eax, 9 |
2217 | shl eax, 9 |
2187 | call ntfs_restore_usa |
2218 | call ntfs_restore_usa |
2188 | mov edi, [ebp+NTFS.cur_index_buf] |
2219 | mov edi, [ebp+NTFS.cur_index_buf] |
2189 | pop eax |
2220 | pop eax |
2190 | add eax, recordNode |
2221 | add eax, recordNode |
- | 2222 | add eax, edi |
|
2191 | add eax, [edi+recordNode+indexOffset] |
2223 | add eax, [edi+recordNode+indexOffset] |
2192 | mov edx, [esp] |
2224 | mov edx, [esp] |
2193 | .indexRecord: |
2225 | .indexRecord: |
2194 | add edi, recordNode |
2226 | add edi, recordNode |
2195 | add edx, [edi+nodeRealSize] |
2227 | add edx, [edi+nodeRealSize] |
2196 | cmp [edi+nodeAllocatedSize], edx |
2228 | cmp [edi+nodeAllocatedSize], edx |
- | 2229 | jc .arborizeTree |
|
- | 2230 | mov [edi+nodeRealSize], edx |
|
- | 2231 | jmp .common |
|
- | 2232 | ||
- | 2233 | .errorPop4: |
|
2197 | jnc @f |
2234 | pop eax |
- | 2235 | .errorPop3: |
|
2198 | add esp, 12 |
2236 | add esp, 12 |
- | 2237 | jmp ntfsUnsupported |
|
- | 2238 | ||
- | 2239 | .arborizeTree: |
|
- | 2240 | ; directory bitmap |
|
- | 2241 | mov esi, [ebp+NTFS.attr_offs] |
|
- | 2242 | add esi, [esi+sizeWithHeader] |
|
- | 2243 | cmp byte [esi], 0xB0 |
|
- | 2244 | jnz .errorPop3 |
|
- | 2245 | movzx eax, byte [esi+attributeOffset] |
|
- | 2246 | add esi, eax |
|
- | 2247 | mov eax, [esi] |
|
- | 2248 | not eax |
|
- | 2249 | bsf eax, eax |
|
- | 2250 | jz .errorPop3 |
|
- | 2251 | bts [esi], eax |
|
- | 2252 | mul [ebp+NTFS.cur_subnode_size] |
|
- | 2253 | mov [ebp+NTFS.newRecord], eax |
|
- | 2254 | ; find median index |
|
- | 2255 | mov ecx, [edi+nodeRealSize] |
|
- | 2256 | sub ecx, [edi+indexOffset] |
|
- | 2257 | shr ecx, 1 |
|
- | 2258 | add edi, [edi+indexOffset] |
|
- | 2259 | xor eax, eax |
|
- | 2260 | @@: |
|
- | 2261 | add edi, eax |
|
- | 2262 | mov ax, [edi+indexAllocatedSize] |
|
- | 2263 | sub ecx, eax |
|
- | 2264 | jnc @b |
|
- | 2265 | mov esi, [ebp+NTFS.secondIndexBuffer] |
|
- | 2266 | cmp dword [esi], 'INDX' |
|
- | 2267 | jz .errorPop3 ; move index to the branch node |
|
- | 2268 | ; move index to the root node |
|
- | 2269 | mov esi, [ebp+NTFS.frs_buffer] |
|
- | 2270 | mov ecx, [esi+recordRealSize] |
|
- | 2271 | add eax, 8 |
|
- | 2272 | add ecx, eax |
|
- | 2273 | cmp [esi+recordAllocatedSize], ecx |
|
2199 | jmp ntfsUnsupported ; new node required |
2274 | jc .errorPop3 ; tree grow required |
- | 2275 | mov [esi+recordRealSize], ecx |
|
- | 2276 | add esi, ecx |
|
- | 2277 | push edi |
|
- | 2278 | mov edi, [ebp+NTFS.indexRoot] |
|
- | 2279 | add [ebp+NTFS.attr_offs], eax |
|
- | 2280 | add [edi+sizeWithHeader], eax |
|
- | 2281 | add [edi+sizeWithoutHeader], eax |
|
- | 2282 | movzx ecx, byte [edi+attributeOffset] |
|
- | 2283 | add ecx, edi |
|
- | 2284 | add [ecx+rootNode+nodeRealSize], eax |
|
- | 2285 | add [ecx+rootNode+nodeAllocatedSize], eax |
|
- | 2286 | add ecx, [ebp+NTFS.pointingIndex] |
|
- | 2287 | sub ecx, [ebp+NTFS.secondIndexBuffer] |
|
- | 2288 | mov edi, esi |
|
- | 2289 | sub esi, eax |
|
- | 2290 | neg ecx |
|
- | 2291 | add ecx, esi |
|
- | 2292 | shr ecx, 2 |
|
- | 2293 | sub esi, 4 |
|
- | 2294 | sub edi, 4 |
|
- | 2295 | std |
|
- | 2296 | rep movsd ; make space |
|
- | 2297 | mov [edi], ecx |
|
- | 2298 | mov edi, esi |
|
- | 2299 | add edi, 4 |
|
- | 2300 | mov esi, [esp] |
|
- | 2301 | add word [esi+indexAllocatedSize], 8 |
|
- | 2302 | mov byte [esi+indexFlags], 1 |
|
- | 2303 | mov ecx, eax |
|
- | 2304 | sub ecx, 8 |
|
- | 2305 | shr ecx, 2 |
|
- | 2306 | cld |
|
- | 2307 | rep movsd ; insert index |
|
- | 2308 | mov eax, [ebp+NTFS.newRecord] |
|
- | 2309 | stosd |
|
- | 2310 | ; split node |
|
- | 2311 | mov edi, [ebp+NTFS.cur_index_buf] |
|
- | 2312 | mov eax, edi |
|
- | 2313 | add eax, recordNode |
|
- | 2314 | add eax, [edi+recordNode+nodeRealSize] |
|
- | 2315 | sub eax, esi |
|
- | 2316 | push eax |
|
- | 2317 | mov ecx, [edi+recordNode+indexOffset] |
|
- | 2318 | add eax, ecx |
|
- | 2319 | add ecx, recordNode |
|
- | 2320 | shr ecx, 2 |
|
- | 2321 | push esi |
|
- | 2322 | mov esi, edi |
|
- | 2323 | mov edi, [ebp+NTFS.secondIndexBuffer] |
|
- | 2324 | rep movsd |
|
- | 2325 | pop esi |
|
- | 2326 | pop ecx |
|
- | 2327 | shr ecx, 2 |
|
- | 2328 | rep movsd |
|
- | 2329 | mov edi, [ebp+NTFS.secondIndexBuffer] |
|
- | 2330 | mov [edi+recordNode+nodeRealSize], eax |
|
- | 2331 | pop edi |
|
- | 2332 | mov cl, 4 |
|
- | 2333 | xor eax, eax |
|
- | 2334 | mov esi, edi |
|
- | 2335 | rep stosd |
|
- | 2336 | mov byte [esi+indexAllocatedSize], 16 |
|
- | 2337 | mov byte [esi+indexFlags], 2 |
|
- | 2338 | mov esi, [ebp+NTFS.cur_index_buf] |
|
- | 2339 | mov eax, [ebp+NTFS.newRecord] |
|
- | 2340 | movzx edx, word [esi+updateSequenceSize] |
|
- | 2341 | dec edx |
|
- | 2342 | mov [esi+recordVCN], eax |
|
- | 2343 | add esi, recordNode |
|
- | 2344 | sub edi, esi |
|
- | 2345 | mov [esi+nodeRealSize], edi |
|
- | 2346 | ; allocate new node |
|
- | 2347 | add eax, [ebp+NTFS.cur_subnode_size] |
|
- | 2348 | cmp edx, [ebp+NTFS.cur_subnode_size] |
|
- | 2349 | jz @f |
|
- | 2350 | mul [ebp+NTFS.sectors_per_cluster] |
|
- | 2351 | @@: |
|
- | 2352 | shl eax, 9 |
|
- | 2353 | mov esi, [ebp+NTFS.attr_offs] |
|
- | 2354 | cmp [esi+attributeAllocatedSize], eax |
|
- | 2355 | jnc .errorPop3 |
|
- | 2356 | call resizeAttribute |
|
- | 2357 | jc ntfsErrorPop3 |
|
- | 2358 | mov eax, [ebp+NTFS.secondIndexBuffer] |
|
- | 2359 | mov [ebp+NTFS.cur_buf], eax |
|
- | 2360 | call writeRecord |
|
- | 2361 | mov eax, [ebp+NTFS.fileDataStart] |
|
- | 2362 | mul [ebp+NTFS.sectors_per_cluster] |
|
- | 2363 | mov [ebp+NTFS.LastRead], eax |
|
- | 2364 | mov eax, [ebp+NTFS.cur_index_buf] |
|
- | 2365 | mov [ebp+NTFS.cur_buf], eax |
|
- | 2366 | call writeRecord |
|
- | 2367 | mov eax, [ebp+NTFS.rootLastRead] |
|
- | 2368 | mov [ebp+NTFS.LastRead], eax |
|
- | 2369 | mov eax, [ebp+NTFS.frs_buffer] |
|
- | 2370 | mov [ebp+NTFS.cur_buf], eax |
|
- | 2371 | call writeRecord |
|
- | 2372 | mov esi, [esp+4] |
|
- | 2373 | stdcall ntfs_find_lfn.doit2, 0 |
|
- | 2374 | test eax, eax |
|
- | 2375 | jz .errorPop3 |
|
- | 2376 | mov edi, [ebp+NTFS.cur_index_buf] |
|
- | 2377 | mov edx, [esp] |
|
- | 2378 | jmp .indexRecord |
|
Line 2200... | Line -... | ||
2200 | - | ||
2201 | @@: ; index fits in the node |
- | |
2202 | mov [edi+nodeRealSize], edx |
2379 | |
2203 | .common: |
2380 | .common: |
2204 | add edi, edx |
2381 | add edi, edx |
2205 | sub edi, 4 |
2382 | sub edi, 4 |
2206 | mov esi, edi |
2383 | mov esi, edi |
Line 2298... | Line 2475... | ||
2298 | bts [edi], ecx |
2475 | bts [edi], ecx |
2299 | ; get record location |
2476 | ; get record location |
2300 | sub edi, [ebp+NTFS.mftBitmapBuffer] |
2477 | sub edi, [ebp+NTFS.mftBitmapBuffer] |
2301 | shl edi, 3 |
2478 | shl edi, 3 |
2302 | add edi, ecx |
2479 | add edi, ecx |
2303 | mov [ebp+NTFS.newMftRecord], edi |
2480 | mov [ebp+NTFS.newRecord], edi |
2304 | mov eax, [ebp+NTFS.frs_size] |
2481 | mov eax, [ebp+NTFS.frs_size] |
2305 | shr eax, 9 |
2482 | shr eax, 9 |
2306 | mul edi |
2483 | mul edi |
2307 | mov [ebp+NTFS.cur_iRecord], 0 |
2484 | mov [ebp+NTFS.cur_iRecord], 0 |
2308 | mov [ebp+NTFS.cur_attr], 0x80 |
2485 | mov [ebp+NTFS.cur_attr], 0x80 |
Line 2337... | Line 2514... | ||
2337 | mov edx, [ebp+NTFS.attr_offs] |
2514 | mov edx, [ebp+NTFS.attr_offs] |
2338 | add ecx, 8 |
2515 | add ecx, 8 |
2339 | mov [edx+attributeRealSize], ecx |
2516 | mov [edx+attributeRealSize], ecx |
2340 | mov [edx+initialDataSize], ecx |
2517 | mov [edx+initialDataSize], ecx |
2341 | shl eax, 3 |
2518 | shl eax, 3 |
2342 | mov [ebp+NTFS.newMftRecord], eax |
2519 | mov [ebp+NTFS.newRecord], eax |
2343 | mov dword [edi], 1 |
2520 | mov dword [edi], 1 |
2344 | mov dword [edi+4], 0 |
2521 | mov dword [edi+4], 0 |
2345 | mov [ebp+NTFS.cur_attr], 0x80 |
2522 | mov [ebp+NTFS.cur_attr], 0x80 |
2346 | call ntfs_read_attr.newAttribute |
2523 | call ntfs_read_attr.newAttribute |
2347 | jc ntfsFail |
2524 | jc ntfsFail |
Line 2501... | Line 2678... | ||
2501 | mov [ebp+NTFS.cur_buf], esi |
2678 | mov [ebp+NTFS.cur_buf], esi |
2502 | mov [esi+recordFlags], al |
2679 | mov [esi+recordFlags], al |
2503 | mov [esi+recordRealSize], edi |
2680 | mov [esi+recordRealSize], edi |
2504 | call writeRecord |
2681 | call writeRecord |
2505 | ; write MFT bitmap |
2682 | ; write MFT bitmap |
2506 | mov eax, [ebp+NTFS.newMftRecord] |
2683 | mov eax, [ebp+NTFS.newRecord] |
2507 | shr eax, 3+9 |
2684 | shr eax, 3+9 |
2508 | mov ebx, eax |
2685 | mov ebx, eax |
2509 | shl ebx, 9 |
2686 | shl ebx, 9 |
2510 | add eax, [ebp+NTFS.mftBitmapLocation] |
2687 | add eax, [ebp+NTFS.mftBitmapLocation] |
2511 | add ebx, [ebp+NTFS.mftBitmapBuffer] |
2688 | add ebx, [ebp+NTFS.mftBitmapBuffer] |
2512 | mov ecx, 1 |
2689 | mov ecx, 1 |
2513 | xor edx, edx |
2690 | xor edx, edx |
2514 | call fs_write64_sys |
2691 | call fs_write64_sys |
2515 | mov edi, [ebp+NTFS.indexOffset] |
2692 | mov edi, [ebp+NTFS.indexOffset] |
2516 | mov eax, [ebp+NTFS.newMftRecord] |
2693 | mov eax, [ebp+NTFS.newRecord] |
2517 | mov [edi+fileRecordReference], eax |
2694 | mov [edi+fileRecordReference], eax |
2518 | ; 5. Write directory node |
2695 | ; 5. Write directory node |
2519 | mov eax, [ebp+NTFS.nodeLastRead] |
2696 | mov eax, [ebp+NTFS.nodeLastRead] |
2520 | mov [ebp+NTFS.LastRead], eax |
2697 | mov [ebp+NTFS.LastRead], eax |
2521 | mov eax, [ebp+NTFS.cur_index_buf] |
2698 | mov eax, [ebp+NTFS.cur_index_buf] |
Line 3685... | Line 3862... | ||
3685 | push ERROR_FS_FAIL |
3862 | push ERROR_FS_FAIL |
3686 | jmp ntfsOut |
3863 | jmp ntfsOut |
3687 | ntfsDiskFull: |
3864 | ntfsDiskFull: |
3688 | push ERROR_DISK_FULL |
3865 | push ERROR_DISK_FULL |
3689 | jmp ntfsOut |
3866 | jmp ntfsOut |
- | 3867 | ntfsErrorPop3: |
|
- | 3868 | pop ebx |
|
3690 | ntfsErrorPop2: |
3869 | ntfsErrorPop2: |
3691 | pop ebx |
3870 | pop ebx |
3692 | ntfsErrorPop: |
3871 | ntfsErrorPop: |
3693 | pop ebx |
3872 | pop ebx |
3694 | ntfsError: |
3873 | ntfsError: |