Rev 6273 | Rev 6297 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6273 | Rev 6292 | ||
---|---|---|---|
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: 6273 $ |
8 | $Revision: 6292 $ |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | ; NTFS driver |
10 | ; NTFS driver |
Line 119... | Line 119... | ||
119 | cur_read dd ? ; bytes readen |
119 | cur_read dd ? ; bytes readen |
120 | LastRead dd ? ; last readen block of sectors |
120 | LastRead dd ? ; last readen block of sectors |
121 | newMftRecord dd ? ; number of fileRecord in MFT |
121 | newMftRecord dd ? ; number of fileRecord in MFT |
122 | fileDataStart dd ? ; starting cluster |
122 | fileDataStart dd ? ; starting cluster |
123 | fileDataSize dd ? ; in clusters |
123 | fileDataSize dd ? ; in clusters |
- | 124 | fileDataBuffer dd ? |
|
124 | fileRealSize dd ? ; in bytes |
125 | fileRealSize dd ? ; in bytes |
125 | indexOffset dd ? |
126 | indexOffset dd ? |
126 | nodeLastRead dd ? |
127 | nodeLastRead dd ? |
127 | fragmentCount db ? |
128 | fragmentCount db ? |
128 | bCanContinue db ? |
129 | bCanContinue db ? |
Line 2091... | Line 2092... | ||
2091 | lea ecx, [ecx*2+52h+7] ; precalculate index length |
2092 | lea ecx, [ecx*2+52h+7] ; precalculate index length |
2092 | and ecx, not 7 ; align 8 |
2093 | and ecx, not 7 ; align 8 |
2093 | mov edi, [ebp+NTFS.cur_index_buf] |
2094 | mov edi, [ebp+NTFS.cur_index_buf] |
2094 | push esi |
2095 | push esi |
2095 | push ecx |
2096 | push ecx |
- | 2097 | mov edx, [ebx+12] |
|
- | 2098 | mov [ebp+NTFS.fileRealSize], edx |
|
- | 2099 | mov edx, [ebx+16] |
|
- | 2100 | mov [ebp+NTFS.fileDataBuffer], edx |
|
- | 2101 | mov edx, ecx |
|
2096 | cmp dword [edi], 'INDX' |
2102 | cmp dword [edi], 'INDX' |
2097 | jz .indexRecord |
2103 | jz .indexRecord |
2098 | mov esi, [ebp+NTFS.frs_buffer] ; indexRoot |
2104 | mov esi, [ebp+NTFS.frs_buffer] ; indexRoot |
2099 | mov edx, [esi+recordRealSize] |
2105 | mov ecx, [esi+recordRealSize] |
2100 | add edx, ecx |
2106 | add edx, ecx |
2101 | cmp [esi+recordAllocatedSize], edx |
2107 | cmp [esi+recordAllocatedSize], edx |
2102 | jnc @f |
- | |
2103 | add esp, 12 |
2108 | jc .growTree |
2104 | jmp ntfsUnsupported ; indexAllocation required |
- | |
2105 | @@: ; index fits in the indexRoot |
- | |
2106 | mov [esi+recordRealSize], edx |
2109 | mov [esi+recordRealSize], edx |
2107 | mov ecx, edx |
- | |
2108 | shr ecx, 2 |
2110 | shr ecx, 2 |
2109 | rep movsd |
2111 | rep movsd |
2110 | mov edi, [ebp+NTFS.attr_offs] |
2112 | mov edi, [ebp+NTFS.attr_offs] |
2111 | sub edi, [ebp+NTFS.frs_buffer] |
2113 | sub edi, [ebp+NTFS.frs_buffer] |
2112 | add edi, [ebp+NTFS.cur_index_buf] |
2114 | add edi, [ebp+NTFS.cur_index_buf] |
Line 2118... | Line 2120... | ||
2118 | add [edi+rootNode+nodeRealSize], esi |
2120 | add [edi+rootNode+nodeRealSize], esi |
2119 | add [edi+rootNode+nodeAllocatedSize], esi |
2121 | add [edi+rootNode+nodeAllocatedSize], esi |
2120 | sub eax, [ebp+NTFS.cur_index_buf] |
2122 | sub eax, [ebp+NTFS.cur_index_buf] |
2121 | add eax, edi |
2123 | add eax, edi |
2122 | mov edi, [ebp+NTFS.cur_index_buf] |
2124 | mov edi, [ebp+NTFS.cur_index_buf] |
2123 | add edi, edx |
- | |
2124 | sub edi, 4 |
- | |
2125 | jmp .common |
2125 | jmp .common |
Line -... | Line 2126... | ||
- | 2126 | ||
- | 2127 | @@: |
|
- | 2128 | add esp, 16 |
|
- | 2129 | jmp ntfsUnsupported |
|
- | 2130 | ||
- | 2131 | .growTree: |
|
- | 2132 | sub eax, rootNode |
|
- | 2133 | sub eax, [edi+rootNode+indexOffset] |
|
- | 2134 | push eax |
|
- | 2135 | ; create indexRecord |
|
- | 2136 | mov ecx, 10 |
|
- | 2137 | xor eax, eax |
|
- | 2138 | rep stosd |
|
- | 2139 | rdtsc |
|
- | 2140 | stosw |
|
- | 2141 | mov esi, [ebp+NTFS.attr_offs] |
|
- | 2142 | mov cl, [esi+attributeOffset] |
|
- | 2143 | add esi, ecx |
|
- | 2144 | mov eax, [esi+indexRecordSizeClus] |
|
- | 2145 | cmp eax, 128 |
|
- | 2146 | jnc @b |
|
- | 2147 | mov [ebp+NTFS.fileDataSize], eax |
|
- | 2148 | mov eax, [esi+indexRecordSize] |
|
- | 2149 | cmp eax, [ebp+NTFS.frs_size] |
|
- | 2150 | jc @b |
|
- | 2151 | shr eax, 9 |
|
- | 2152 | inc eax |
|
- | 2153 | mov edi, [ebp+NTFS.cur_index_buf] |
|
- | 2154 | mov dword[edi], 'INDX' |
|
- | 2155 | mov byte [edi+updateSequenceOffset], 28h |
|
- | 2156 | mov [edi+updateSequenceSize], al |
|
- | 2157 | add edi, recordNode |
|
- | 2158 | shl eax, 1 |
|
- | 2159 | add eax, 28h-recordNode+7 |
|
- | 2160 | and eax, not 7 |
|
- | 2161 | mov [edi+indexOffset], eax |
|
- | 2162 | mov ecx, [esi+indexRecordSize] |
|
- | 2163 | sub ecx, recordNode |
|
- | 2164 | mov [edi+nodeAllocatedSize], ecx |
|
- | 2165 | add esi, rootNode |
|
- | 2166 | push esi |
|
- | 2167 | mov ecx, [esi+nodeRealSize] |
|
- | 2168 | sub ecx, [esi+indexOffset] |
|
- | 2169 | add eax, ecx |
|
- | 2170 | mov [edi+nodeRealSize], eax |
|
- | 2171 | shr ecx, 2 |
|
- | 2172 | add esi, [esi+indexOffset] |
|
- | 2173 | add edi, [edi+indexOffset] |
|
- | 2174 | rep movsd ; copy root indexes |
|
- | 2175 | ; clear root node |
|
- | 2176 | mov cl, 10 |
|
- | 2177 | mov edi, [esp] |
|
- | 2178 | xor eax, eax |
|
- | 2179 | rep stosd |
|
- | 2180 | pop edi |
|
- | 2181 | mov byte [edi+indexOffset], 16 |
|
- | 2182 | mov byte [edi+nodeRealSize], 28h |
|
- | 2183 | mov byte [edi+nodeAllocatedSize], 28h |
|
- | 2184 | mov byte [edi+nonLeafFlag], 1 |
|
- | 2185 | mov byte [edi+16+indexAllocatedSize], 18h |
|
- | 2186 | mov byte [edi+16+indexFlags], 3 |
|
- | 2187 | mov esi, [ebp+NTFS.attr_offs] |
|
- | 2188 | add edi, 28h |
|
- | 2189 | mov eax, edi |
|
- | 2190 | sub eax, esi |
|
- | 2191 | mov word [esi+sizeWithoutHeader], 38h |
|
- | 2192 | xchg [esi+sizeWithHeader], eax |
|
- | 2193 | cmp byte [esi+eax], -1 |
|
- | 2194 | jnz @b |
|
- | 2195 | mov cl, 32 |
|
- | 2196 | xor eax, eax |
|
- | 2197 | push edi |
|
- | 2198 | rep stosd |
|
- | 2199 | mov edi, [ebp+NTFS.BitmapStart] |
|
- | 2200 | call ntfsSpaceAlloc |
|
- | 2201 | jnc @f |
|
- | 2202 | add esp, 20 |
|
- | 2203 | jmp ntfsDiskFull |
|
- | 2204 | ||
- | 2205 | @@: ; create $IndexAllocation |
|
- | 2206 | pop edi |
|
- | 2207 | mov byte [edi+attributeType], 0xA0 |
|
- | 2208 | mov byte [edi+nonResidentFlag], 1 |
|
- | 2209 | mov byte [edi+nameLength], 4 |
|
- | 2210 | mov byte [edi+nameOffset], 40h |
|
- | 2211 | mov byte [edi+dataRunsOffset], 48h |
|
- | 2212 | mov byte [edi+sizeWithHeader], 50h |
|
- | 2213 | mov eax, [ebp+NTFS.fileDataSize] |
|
- | 2214 | dec eax |
|
- | 2215 | mov [edi+lastVCN], eax |
|
- | 2216 | inc eax |
|
- | 2217 | mul [ebp+NTFS.sectors_per_cluster] |
|
- | 2218 | shl eax, 9 |
|
- | 2219 | mov [edi+attributeAllocatedSize], eax |
|
- | 2220 | mov [edi+attributeRealSize], eax |
|
- | 2221 | mov [edi+initialDataSize], eax |
|
- | 2222 | mov dword[edi+40h], 490024h ; unicode $I30 |
|
- | 2223 | mov dword[edi+40h+4], 300033h |
|
- | 2224 | push edi |
|
- | 2225 | mov esi, edi |
|
- | 2226 | add edi, 48h |
|
- | 2227 | call createMcbEntry |
|
- | 2228 | mov esi, [ebp+NTFS.frs_buffer] |
|
- | 2229 | pop edi |
|
- | 2230 | mov al, [esi+newAttributeID] |
|
- | 2231 | mov [edi+attributeID], al |
|
- | 2232 | add edi, 50h |
|
- | 2233 | inc eax |
|
- | 2234 | ; create $Bitmap |
|
- | 2235 | mov [edi+attributeID], al |
|
- | 2236 | inc eax |
|
- | 2237 | mov [esi+newAttributeID], al |
|
- | 2238 | mov byte [edi+attributeType], 0xB0 |
|
- | 2239 | mov byte [edi+nameLength], 4 |
|
- | 2240 | mov byte [edi+nameOffset], 18h |
|
- | 2241 | mov byte [edi+attributeOffset], 20h |
|
- | 2242 | mov byte [edi+sizeWithoutHeader], 8 |
|
- | 2243 | mov byte [edi+sizeWithHeader], 28h |
|
- | 2244 | mov dword[edi+18h], 490024h ; unicode $I30 |
|
- | 2245 | mov dword[edi+18h+4], 300033h |
|
- | 2246 | mov byte [edi+20h], 1 |
|
- | 2247 | mov dword[edi+28h], -1 |
|
- | 2248 | add edi, 30h |
|
- | 2249 | sub edi, esi |
|
- | 2250 | mov [esi+recordRealSize], edi |
|
- | 2251 | mov [ebp+NTFS.cur_buf], esi |
|
- | 2252 | call writeRecord ; fileRecord |
|
- | 2253 | mov eax, [ebp+NTFS.fileDataStart] |
|
- | 2254 | mul [ebp+NTFS.sectors_per_cluster] |
|
- | 2255 | mov [ebp+NTFS.LastRead], eax |
|
- | 2256 | mov eax, [ebp+NTFS.cur_index_buf] |
|
- | 2257 | mov [ebp+NTFS.cur_buf], eax |
|
- | 2258 | call writeRecord ; indexRecord |
|
- | 2259 | mov ebx, [ebp+NTFS.cur_index_buf] |
|
- | 2260 | mov ax, [ebx+6] |
|
- | 2261 | dec eax |
|
- | 2262 | shl eax, 9 |
|
- | 2263 | call ntfs_restore_usa |
|
- | 2264 | mov edi, [ebp+NTFS.cur_index_buf] |
|
- | 2265 | pop eax |
|
- | 2266 | add eax, recordNode |
|
- | 2267 | add eax, [edi+recordNode+indexOffset] |
|
2126 | 2268 | mov edx, [esp] |
|
2127 | .indexRecord: |
2269 | .indexRecord: |
2128 | add edi, recordNode |
2270 | add edi, recordNode |
2129 | mov edx, [edi+nodeRealSize] |
- | |
2130 | add edx, ecx |
2271 | add edx, [edi+nodeRealSize] |
2131 | cmp [edi+nodeAllocatedSize], edx |
2272 | cmp [edi+nodeAllocatedSize], edx |
2132 | jnc @f |
2273 | jnc @f |
2133 | add esp, 12 |
2274 | add esp, 12 |
- | 2275 | jmp ntfsUnsupported ; new node required |
|
2134 | jmp ntfsUnsupported ; new node required |
2276 | |
2135 | @@: ; index fits in the node |
2277 | @@: ; index fits in the node |
- | 2278 | mov [edi+nodeRealSize], edx |
|
2136 | mov [edi+nodeRealSize], edx |
2279 | .common: |
2137 | add edi, edx |
2280 | add edi, edx |
2138 | sub edi, 4 |
- | |
2139 | .common: |
2281 | sub edi, 4 |
2140 | mov esi, edi |
2282 | mov esi, edi |
2141 | sub esi, [esp] |
2283 | sub esi, [esp] |
2142 | mov ecx, esi |
2284 | mov ecx, esi |
2143 | sub ecx, eax ; eax = pointer in the node |
2285 | sub ecx, eax ; eax = pointer in the record |
2144 | shr ecx, 2 |
2286 | shr ecx, 2 |
2145 | inc ecx |
2287 | inc ecx |
2146 | std |
2288 | std |
2147 | rep movsd ; move forward, make space |
2289 | rep movsd ; move forward, make space |
Line 2161... | Line 2303... | ||
2161 | mov eax, [ebp+NTFS.attr_iRecord] |
2303 | mov eax, [ebp+NTFS.attr_iRecord] |
2162 | mov [edi+directoryRecordReference], eax |
2304 | mov [edi+directoryRecordReference], eax |
2163 | mov eax, [ebp+NTFS.frs_buffer] |
2305 | mov eax, [ebp+NTFS.frs_buffer] |
2164 | mov eax, [eax+reuseCounter] |
2306 | mov eax, [eax+reuseCounter] |
2165 | mov [edi+directoryReferenceReuse], ax |
2307 | mov [edi+directoryReferenceReuse], ax |
2166 | mov eax, [ebx+12] |
2308 | mov eax, [ebp+NTFS.frs_size] |
- | 2309 | shr eax, 8 |
|
2167 | add ecx, 30h+48h+8+18h+8 |
2310 | add ecx, 30h+48h+8+18h+8 |
2168 | add ecx, eax |
2311 | add ecx, eax |
2169 | mov [ebp+NTFS.fileRealSize], eax |
2312 | mov eax, [ebp+NTFS.fileRealSize] |
- | 2313 | add ecx, eax |
|
2170 | mov [edi+fileRealSize], eax |
2314 | mov [edi+fileRealSize], eax |
2171 | cmp [ebp+NTFS.frs_size], ecx |
2315 | cmp [ebp+NTFS.frs_size], ecx |
2172 | jc @f |
2316 | jc @f |
2173 | mov eax, [ebx+16] |
- | |
2174 | mov [ebp+NTFS.fileDataStart], eax |
- | |
2175 | xor eax, eax |
2317 | xor eax, eax |
2176 | @@: |
2318 | @@: |
2177 | mov ecx, [ebp+NTFS.sectors_per_cluster] |
2319 | mov ecx, [ebp+NTFS.sectors_per_cluster] |
2178 | shl ecx, 9 |
2320 | shl ecx, 9 |
2179 | add eax, ecx |
2321 | add eax, ecx |
Line 2205... | Line 2347... | ||
2205 | cmp [ebp+NTFS.fileDataSize], 0 |
2347 | cmp [ebp+NTFS.fileDataSize], 0 |
2206 | jz .mftBitmap |
2348 | jz .mftBitmap |
2207 | mov edi, [ebp+NTFS.BitmapStart] |
2349 | mov edi, [ebp+NTFS.BitmapStart] |
2208 | call ntfsSpaceAlloc |
2350 | call ntfsSpaceAlloc |
2209 | jc ntfsDiskFull |
2351 | jc ntfsDiskFull |
2210 | mov [ebp+NTFS.fileDataStart], eax |
2352 | mov eax, [ebp+NTFS.fileDataStart] |
2211 | mul [ebp+NTFS.sectors_per_cluster] |
2353 | mul [ebp+NTFS.sectors_per_cluster] |
2212 | mov ecx, [ebp+NTFS.fileRealSize] |
2354 | mov ecx, [ebp+NTFS.fileRealSize] |
2213 | add ecx, 511 |
2355 | add ecx, 511 |
2214 | shr ecx, 9 |
2356 | shr ecx, 9 |
2215 | mov ebx, [ebx+16] |
2357 | mov ebx, [ebp+NTFS.fileDataBuffer] |
2216 | call fs_write64_app |
2358 | call fs_write64_app |
2217 | test eax, eax |
2359 | test eax, eax |
2218 | jnz ntfsDevice |
2360 | jnz ntfsDevice |
2219 | ; 4. MFT record |
2361 | ; 4. MFT record |
2220 | .mftBitmap: ; search for free record |
2362 | .mftBitmap: ; search for free record |
Line 2313... | Line 2455... | ||
2313 | mov edi, [ebp+NTFS.frs_buffer] |
2455 | mov edi, [ebp+NTFS.frs_buffer] |
2314 | xor eax, eax |
2456 | xor eax, eax |
2315 | rep stosd |
2457 | rep stosd |
2316 | mov edi, [ebp+NTFS.frs_buffer] |
2458 | mov edi, [ebp+NTFS.frs_buffer] |
2317 | ; record header |
2459 | ; record header |
- | 2460 | rdtsc |
|
- | 2461 | mov [edi+2ah], ax |
|
2318 | mov eax, [ebp+NTFS.frs_size] |
2462 | mov eax, [ebp+NTFS.frs_size] |
2319 | mov [edi+recordAllocatedSize], eax |
2463 | mov [edi+recordAllocatedSize], eax |
2320 | shr eax, 9 |
2464 | shr eax, 9 |
2321 | inc eax |
2465 | inc eax |
2322 | mov [edi+updateSequenceSize], al |
2466 | mov [edi+updateSequenceSize], al |
- | 2467 | shl eax, 1 |
|
- | 2468 | add eax, 2ah+7 |
|
- | 2469 | and eax, not 7 |
|
2323 | mov dword[edi], 'FILE' |
2470 | mov dword[edi], 'FILE' |
2324 | mov byte [edi+updateSequenceOffset], 2ah |
2471 | mov byte [edi+updateSequenceOffset], 2ah |
2325 | mov byte [edi+hardLinkCounter], 1 |
2472 | mov byte [edi+hardLinkCounter], 1 |
2326 | mov byte [edi+attributeOffset], 30h |
- | |
2327 | mov byte [edi+newAttributeID], 3 |
2473 | mov byte [edi+newAttributeID], 3 |
2328 | rdtsc |
- | |
2329 | mov [edi+2ah], ax |
2474 | mov [edi+attributeOffset], al |
2330 | add edi, 30h |
2475 | add edi, eax |
2331 | ; $StandardInformation |
2476 | ; $StandardInformation |
2332 | mov byte [edi+attributeType], 10h |
2477 | mov byte [edi+attributeType], 10h |
2333 | mov byte [edi+sizeWithHeader], 48h |
2478 | mov byte [edi+sizeWithHeader], 48h |
2334 | mov byte [edi+sizeWithoutHeader], 30h |
2479 | mov byte [edi+sizeWithoutHeader], 30h |
2335 | mov byte [edi+attributeOffset], 18h |
2480 | mov byte [edi+attributeOffset], 18h |
Line 2379... | Line 2524... | ||
2379 | .resident: |
2524 | .resident: |
2380 | mov ecx, [ebp+NTFS.fileRealSize] |
2525 | mov ecx, [ebp+NTFS.fileRealSize] |
2381 | mov [edi+sizeWithoutHeader], ecx |
2526 | mov [edi+sizeWithoutHeader], ecx |
2382 | mov byte [edi+attributeOffset], 18h |
2527 | mov byte [edi+attributeOffset], 18h |
2383 | push edi |
2528 | push edi |
2384 | mov esi, [ebp+NTFS.fileDataStart] |
2529 | mov esi, [ebp+NTFS.fileDataBuffer] |
2385 | add edi, 18h |
2530 | add edi, 18h |
2386 | rep movsb |
2531 | rep movsb |
2387 | @@: |
2532 | @@: |
2388 | mov eax, edi |
2533 | mov eax, edi |
2389 | pop edi |
2534 | pop edi |
Line 2391... | Line 2536... | ||
2391 | add eax, 7 |
2536 | add eax, 7 |
2392 | and eax, not 7 |
2537 | and eax, not 7 |
2393 | mov [edi+sizeWithHeader], eax |
2538 | mov [edi+sizeWithHeader], eax |
2394 | add edi, eax |
2539 | add edi, eax |
2395 | mov al, 1 |
2540 | mov al, 1 |
2396 | jmp @f |
2541 | jmp .end |
Line 2397... | Line 2542... | ||
2397 | 2542 | ||
2398 | .indexRoot: |
2543 | .indexRoot: |
2399 | mov byte [edi+attributeType], 90h |
2544 | mov byte [edi+attributeType], 90h |
2400 | mov byte [edi+nameLength], 4 |
2545 | mov byte [edi+nameLength], 4 |
Line 2404... | Line 2549... | ||
2404 | mov dword[edi+18h], 490024h ; unicode $I30 |
2549 | mov dword[edi+18h], 490024h ; unicode $I30 |
2405 | mov dword[edi+18h+4], 300033h |
2550 | mov dword[edi+18h+4], 300033h |
2406 | mov byte [edi+20h+indexedAttributesType], 30h |
2551 | mov byte [edi+20h+indexedAttributesType], 30h |
2407 | mov byte [edi+20h+collationRule], 1 |
2552 | mov byte [edi+20h+collationRule], 1 |
2408 | mov eax, [ebp+NTFS.sectors_per_cluster] |
2553 | mov eax, [ebp+NTFS.sectors_per_cluster] |
- | 2554 | mov dl, 1 |
|
- | 2555 | shl eax, 8 |
|
- | 2556 | @@: |
|
2409 | shl eax, 9 |
2557 | shl eax, 1 |
- | 2558 | shl edx, 1 |
|
- | 2559 | cmp eax, [ebp+NTFS.frs_size] |
|
- | 2560 | jc @b |
|
- | 2561 | shr edx, 1 |
|
2410 | mov [edi+20h+indexRecordSize], eax |
2562 | mov [edi+20h+indexRecordSize], eax |
2411 | mov byte [edi+20h+indexRecordSizeClus], 1 |
2563 | mov [edi+20h+indexRecordSizeClus], dl |
2412 | mov byte [edi+30h+indexOffset], 16 |
2564 | mov byte [edi+30h+indexOffset], 16 |
2413 | mov byte [edi+30h+nodeRealSize], 32 |
2565 | mov byte [edi+30h+nodeRealSize], 32 |
2414 | mov byte [edi+30h+nodeAllocatedSize], 32 |
2566 | mov byte [edi+30h+nodeAllocatedSize], 32 |
2415 | mov byte [edi+40h+indexAllocatedSize], 16 |
2567 | mov byte [edi+40h+indexAllocatedSize], 16 |
2416 | mov byte [edi+40h+indexFlags], 2 |
2568 | mov byte [edi+40h+indexFlags], 2 |
2417 | add edi, 50h |
2569 | add edi, 50h |
2418 | mov al, 3 |
2570 | mov al, 3 |
2419 | @@: |
2571 | .end: |
2420 | mov esi, [ebp+NTFS.frs_buffer] |
2572 | mov esi, [ebp+NTFS.frs_buffer] |
2421 | mov dword [edi], -1 |
2573 | mov dword [edi], -1 |
2422 | mov dword [edi+4], 0 |
2574 | mov dword [edi+4], 0 |
2423 | add edi, 8 |
2575 | add edi, 8 |
2424 | sub edi, esi |
2576 | sub edi, esi |
2425 | mov [ebp+NTFS.cur_buf], esi |
2577 | mov [ebp+NTFS.cur_buf], esi |
2426 | mov [esi+recordFlags], al |
2578 | mov [esi+recordFlags], al |
2427 | mov [esi+recordRealSize], edi |
2579 | mov [esi+recordRealSize], edi |
2428 | call writeRecord |
2580 | call writeRecord |
2429 | test eax, eax |
- | |
2430 | jnz ntfsDevice |
- | |
2431 | ; write MFT bitmap |
2581 | ; write MFT bitmap |
2432 | mov eax, [ebp+NTFS.newMftRecord] |
2582 | mov eax, [ebp+NTFS.newMftRecord] |
2433 | shr eax, 3+9 |
2583 | shr eax, 3+9 |
2434 | mov ebx, eax |
2584 | mov ebx, eax |
2435 | shl ebx, 9 |
2585 | shl ebx, 9 |
2436 | add eax, [ebp+NTFS.mftBitmapLocation] |
2586 | add eax, [ebp+NTFS.mftBitmapLocation] |
2437 | add ebx, [ebp+NTFS.mftBitmapBuffer] |
2587 | add ebx, [ebp+NTFS.mftBitmapBuffer] |
2438 | mov ecx, 1 |
2588 | mov ecx, 1 |
2439 | xor edx, edx |
2589 | xor edx, edx |
2440 | call fs_write64_sys |
2590 | call fs_write64_sys |
2441 | test eax, eax |
- | |
2442 | jnz ntfsDevice |
- | |
2443 | ; 5. Write partition bitmap |
- | |
2444 | cmp [ebp+NTFS.bFolder], 1 |
- | |
2445 | jz @f |
- | |
2446 | mov eax, [ebp+NTFS.fileDataStart] |
- | |
2447 | mov ecx, [ebp+NTFS.fileDataSize] |
- | |
2448 | test ecx, ecx |
- | |
2449 | jz @f |
- | |
2450 | add ecx, eax |
- | |
2451 | add ecx, 4095 |
- | |
2452 | shr ecx, 3+9 |
- | |
2453 | shr eax, 3+9 |
- | |
2454 | sub ecx, eax |
- | |
2455 | mov ebx, eax |
- | |
2456 | shl ebx, 9 |
- | |
2457 | add eax, [ebp+NTFS.BitmapLocation] |
- | |
2458 | add ebx, [ebp+NTFS.BitmapBuffer] |
- | |
2459 | xor edx, edx |
- | |
2460 | call fs_write64_app |
- | |
2461 | test eax, eax |
- | |
2462 | jnz ntfsDevice |
- | |
2463 | @@: |
- | |
2464 | mov edi, [ebp+NTFS.indexOffset] |
2591 | mov edi, [ebp+NTFS.indexOffset] |
2465 | mov eax, [ebp+NTFS.newMftRecord] |
2592 | mov eax, [ebp+NTFS.newMftRecord] |
2466 | mov [edi+fileRecordReference], eax |
2593 | mov [edi+fileRecordReference], eax |
2467 | ; 6. Write directory node |
2594 | ; 5. Write directory node |
2468 | mov eax, [ebp+NTFS.nodeLastRead] |
2595 | mov eax, [ebp+NTFS.nodeLastRead] |
2469 | mov [ebp+NTFS.LastRead], eax |
2596 | mov [ebp+NTFS.LastRead], eax |
2470 | mov eax, [ebp+NTFS.cur_index_buf] |
2597 | mov eax, [ebp+NTFS.cur_index_buf] |
2471 | mov [ebp+NTFS.cur_buf], eax |
2598 | mov [ebp+NTFS.cur_buf], eax |
2472 | call writeRecord |
2599 | call writeRecord |
Line 2624... | Line 2751... | ||
2624 | cmp edi, [ebp+NTFS.BitmapStart] |
2751 | cmp edi, [ebp+NTFS.BitmapStart] |
2625 | jc .err1 |
2752 | jc .err1 |
2626 | @@: |
2753 | @@: |
2627 | call ntfsSpaceAlloc |
2754 | call ntfsSpaceAlloc |
2628 | jc .err1 |
2755 | jc .err1 |
- | 2756 | mov eax, [ebp+NTFS.fileDataStart] |
|
2629 | pop edi |
2757 | pop edi |
2630 | pop edx |
2758 | pop edx |
2631 | cmp edx, eax |
2759 | cmp edx, eax |
2632 | jnz .newEntry |
2760 | jnz .newEntry |
2633 | pop edx |
2761 | pop edx |
Line 2646... | Line 2774... | ||
2646 | sub eax, edx |
2774 | sub eax, edx |
2647 | mov [ebp+NTFS.fileDataStart], eax |
2775 | mov [ebp+NTFS.fileDataStart], eax |
2648 | @@: |
2776 | @@: |
2649 | mov esi, [ebp+NTFS.attr_offs] |
2777 | mov esi, [ebp+NTFS.attr_offs] |
2650 | call createMcbEntry |
2778 | call createMcbEntry |
2651 | pop ecx |
- | |
2652 | pop eax |
- | |
2653 | jc .err2 |
- | |
2654 | mov [ebp+NTFS.fileDataSize], ecx |
2779 | pop [ebp+NTFS.fileDataSize] |
2655 | mov [ebp+NTFS.fileDataStart], eax |
2780 | pop [ebp+NTFS.fileDataStart] |
2656 | .writeBitmap: |
- | |
2657 | add ecx, eax |
- | |
2658 | add ecx, 4095 |
- | |
2659 | shr ecx, 3+9 |
- | |
2660 | shr eax, 3+9 |
- | |
2661 | sub ecx, eax |
- | |
2662 | mov ebx, eax |
- | |
2663 | shl ebx, 9 |
- | |
2664 | add eax, [ebp+NTFS.BitmapLocation] |
- | |
2665 | add ebx, [ebp+NTFS.BitmapBuffer] |
2781 | movi eax, ERROR_UNSUPPORTED_FS |
2666 | xor edx, edx |
- | |
2667 | call fs_write64_app |
- | |
2668 | test eax, eax |
- | |
2669 | jnz @f |
- | |
2670 | .done: |
2782 | .done: |
2671 | ret |
2783 | ret |
Line 2672... | Line -... | ||
2672 | - | ||
2673 | .err4: |
- | |
2674 | pop eax |
- | |
2675 | @@: |
- | |
2676 | movi eax, ERROR_DEVICE |
- | |
2677 | stc |
- | |
2678 | ret |
- | |
2679 | 2784 | ||
2680 | .err1: |
2785 | .err1: |
2681 | add esp, 24 |
2786 | add esp, 24 |
2682 | stc |
2787 | stc |
2683 | .err10: |
2788 | .err2: |
2684 | movi eax, ERROR_DISK_FULL |
2789 | movi eax, ERROR_DISK_FULL |
Line 2685... | Line 2790... | ||
2685 | ret |
2790 | ret |
2686 | 2791 | ||
- | 2792 | .err3: |
|
- | 2793 | movi eax, ERROR_FS_FAIL |
|
2687 | .err2: |
2794 | add esp, 20 |
Line 2688... | Line 2795... | ||
2688 | movi eax, ERROR_UNSUPPORTED_FS |
2795 | stc |
2689 | ret |
2796 | ret |
2690 | 2797 | ||
Line 2730... | Line 2837... | ||
2730 | call createMcbEntry |
2837 | call createMcbEntry |
2731 | mov [ebp+NTFS.fileDataSize], 0 |
2838 | mov [ebp+NTFS.fileDataSize], 0 |
2732 | @@: |
2839 | @@: |
2733 | ret |
2840 | ret |
Line 2734... | Line -... | ||
2734 | - | ||
2735 | .err3: |
- | |
2736 | movi eax, ERROR_FS_FAIL |
- | |
2737 | add esp, 20 |
- | |
2738 | stc |
- | |
2739 | ret |
- | |
2740 | 2841 | ||
2741 | .resident: |
2842 | .resident: |
2742 | test edx, edx |
2843 | test edx, edx |
2743 | jnz .nonResident |
2844 | jnz .nonResident |
2744 | cmp eax, 8000h |
2845 | cmp eax, 8000h |
Line 2789... | Line 2890... | ||
2789 | mov [ebp+NTFS.fileDataSize], eax |
2890 | mov [ebp+NTFS.fileDataSize], eax |
2790 | mov edi, [ebp+NTFS.BitmapStart] |
2891 | mov edi, [ebp+NTFS.BitmapStart] |
2791 | push ecx |
2892 | push ecx |
2792 | call ntfsSpaceAlloc |
2893 | call ntfsSpaceAlloc |
2793 | pop ecx |
2894 | pop ecx |
2794 | jc .err10 |
2895 | jc .err2 |
2795 | mov [ebp+NTFS.fileDataStart], eax |
- | |
2796 | mov esi, [ebp+NTFS.attr_offs] |
2896 | mov esi, [ebp+NTFS.attr_offs] |
2797 | xor eax, eax |
2897 | xor eax, eax |
2798 | xor edx, edx |
2898 | xor edx, edx |
2799 | @@: |
2899 | @@: |
2800 | add eax, ecx |
2900 | add eax, ecx |
Line 2818... | Line 2918... | ||
2818 | mov eax, [ebp+NTFS.fileDataStart] |
2918 | mov eax, [ebp+NTFS.fileDataStart] |
2819 | mul [ebp+NTFS.sectors_per_cluster] |
2919 | mul [ebp+NTFS.sectors_per_cluster] |
2820 | pop ecx |
2920 | pop ecx |
2821 | shr ecx, 9 |
2921 | shr ecx, 9 |
2822 | call fs_write64_app |
2922 | call fs_write64_app |
2823 | push ebx |
- | |
2824 | mov ebx, eax |
- | |
2825 | call kernel_free |
2923 | stdcall kernel_free, ebx |
2826 | test ebx, ebx |
- | |
2827 | jnz .err4 |
- | |
2828 | mov esi, [ebp+NTFS.attr_offs] |
2924 | mov esi, [ebp+NTFS.attr_offs] |
2829 | add esi, [esi+sizeWithHeader] |
2925 | add esi, [esi+sizeWithHeader] |
2830 | mov ecx, [ebp+NTFS.frs_buffer] |
2926 | mov ecx, [ebp+NTFS.frs_buffer] |
2831 | add ecx, [ecx+recordRealSize] |
2927 | add ecx, [ecx+recordRealSize] |
2832 | sub ecx, esi |
2928 | sub ecx, esi |
Line 2873... | Line 2969... | ||
2873 | rep movsd |
2969 | rep movsd |
2874 | mov esi, [ebp+NTFS.frs_buffer] |
2970 | mov esi, [ebp+NTFS.frs_buffer] |
2875 | sub edi, esi |
2971 | sub edi, esi |
2876 | mov [esi+recordRealSize], edi |
2972 | mov [esi+recordRealSize], edi |
2877 | pop edx |
2973 | pop edx |
2878 | mov ecx, [ebp+NTFS.fileDataSize] |
- | |
2879 | sub [ebp+NTFS.fileDataSize], edx |
2974 | sub [ebp+NTFS.fileDataSize], edx |
2880 | mov eax, [ebp+NTFS.fileDataStart] |
- | |
2881 | add [ebp+NTFS.fileDataStart], edx |
2975 | add [ebp+NTFS.fileDataStart], edx |
2882 | jmp .writeBitmap |
2976 | ret |
Line 2883... | Line 2977... | ||
2883 | 2977 | ||
2884 | .makeResident: ; convert non-resident to empty resident |
2978 | .makeResident: ; convert non-resident to empty resident |
2885 | movzx eax, byte [esi+dataRunsOffset] |
2979 | movzx eax, byte [esi+dataRunsOffset] |
2886 | mov byte [esi+nonResidentFlag], 0 |
2980 | mov byte [esi+nonResidentFlag], 0 |
Line 2934... | Line 3028... | ||
2934 | stdcall kernel_free, ebx |
3028 | stdcall kernel_free, ebx |
2935 | @@: |
3029 | @@: |
2936 | ret |
3030 | ret |
Line 2937... | Line 3031... | ||
2937 | 3031 | ||
2938 | ntfsSpaceAlloc: |
3032 | ntfsSpaceAlloc: |
2939 | ; find and mark block of free space in bitmap buffer |
3033 | ; allocate disk space |
2940 | ; in: |
3034 | ; in: |
2941 | ; edi = offset in bitmap to start search from |
3035 | ; edi = offset in bitmap to start search from |
2942 | ; [ebp+NTFS.fileDataSize] = block size in clusters |
3036 | ; [ebp+NTFS.fileDataSize] = block size in clusters |
2943 | ; out: |
3037 | ; out: |
2944 | ; eax = allocated block starting cluster |
3038 | ; [ebp+NTFS.fileDataStart] = allocated block starting cluster |
- | 3039 | ; CF=1 -> disk full |
|
2945 | ; CF=1 -> disk full |
3040 | push eax |
2946 | mov ecx, [ebp+NTFS.BitmapBuffer] |
3041 | mov ecx, [ebp+NTFS.BitmapBuffer] |
2947 | add edi, ecx |
3042 | add edi, ecx |
2948 | add ecx, [ebp+NTFS.BitmapSize] |
3043 | add ecx, [ebp+NTFS.BitmapSize] |
2949 | sub ecx, edi |
3044 | sub ecx, edi |
Line 2953... | Line 3048... | ||
2953 | @@: |
3048 | @@: |
2954 | shr ecx, 2 |
3049 | shr ecx, 2 |
2955 | mov eax, [ebp+NTFS.fileDataSize] |
3050 | mov eax, [ebp+NTFS.fileDataSize] |
2956 | shr eax, 5 |
3051 | shr eax, 5 |
2957 | jz .small |
3052 | jz .small |
2958 | push eax ; bitmap dwords |
3053 | mov ebx, eax ; bitmap dwords |
2959 | .start: |
3054 | .start: |
2960 | mov ecx, [ebp+NTFS.BitmapBuffer] |
3055 | mov ecx, [ebp+NTFS.BitmapBuffer] |
2961 | add ecx, [ebp+NTFS.BitmapSize] |
3056 | add ecx, [ebp+NTFS.BitmapSize] |
2962 | sub ecx, edi |
3057 | sub ecx, edi |
2963 | shr ecx, 2 |
3058 | shr ecx, 2 |
Line 2966... | Line 3061... | ||
2966 | repnz scasd ; search for empty dword |
3061 | repnz scasd ; search for empty dword |
2967 | jz @f |
3062 | jz @f |
2968 | call bitmapBuffering |
3063 | call bitmapBuffering |
2969 | jmp @b |
3064 | jmp @b |
2970 | @@: |
3065 | @@: |
2971 | cmp ecx, [esp] |
3066 | cmp ecx, ebx |
2972 | jnc @f |
3067 | jnc @f |
2973 | call bitmapBuffering |
3068 | call bitmapBuffering |
2974 | jmp @b |
3069 | jmp @b |
2975 | @@: |
3070 | @@: |
2976 | sub edi, 4 |
3071 | sub edi, 4 |
2977 | mov ecx, [esp] |
3072 | mov ecx, ebx |
2978 | mov esi, edi |
3073 | mov esi, edi |
2979 | xor eax, eax |
3074 | xor eax, eax |
2980 | repz scasd ; check following dwords |
3075 | repz scasd ; check following dwords |
2981 | jnz .start |
3076 | jnz .start |
2982 | sub esi, 4 |
3077 | sub esi, 4 |
Line 3005... | Line 3100... | ||
3005 | jmp .start |
3100 | jmp .start |
Line 3006... | Line 3101... | ||
3006 | 3101 | ||
3007 | .small: ; less than 32 clusters |
3102 | .small: ; less than 32 clusters |
3008 | mov eax, -1 |
3103 | mov eax, -1 |
3009 | repz scasd ; search for zero bits |
- | |
3010 | push ecx |
3104 | repz scasd ; search for zero bits |
3011 | test ecx, ecx |
3105 | test ecx, ecx |
3012 | jnz @f |
3106 | jnz @f |
3013 | call bitmapBuffering |
- | |
3014 | pop eax |
3107 | call bitmapBuffering |
3015 | jmp .small |
3108 | jmp .small |
3016 | @@: |
3109 | @@: |
3017 | sub edi, 4 |
3110 | sub edi, 4 |
3018 | mov eax, [edi] |
3111 | mov eax, [edi] |
3019 | not eax |
3112 | not eax |
3020 | @@: |
3113 | @@: |
3021 | bsf ecx, eax ; first 0 |
3114 | bsf ebx, eax ; first 0 |
3022 | jz .again |
3115 | jz .again |
3023 | not eax |
3116 | not eax |
3024 | shr eax, cl |
3117 | shr eax, cl |
3025 | shl eax, cl |
3118 | shl eax, cl |
3026 | bsf edx, eax ; next 1 |
3119 | bsf edx, eax ; next 1 |
3027 | jz @f |
3120 | jz @f |
3028 | sub edx, ecx |
3121 | sub edx, ebx |
3029 | cmp edx, [ebp+NTFS.fileDataSize] |
3122 | cmp edx, [ebp+NTFS.fileDataSize] |
3030 | jnc .got ; fits inside |
3123 | jnc .got ; fits inside |
3031 | bsf ecx, eax |
3124 | bsf ebx, eax |
3032 | not eax |
3125 | not eax |
3033 | shr eax, cl |
3126 | shr eax, cl |
3034 | shl eax, cl |
3127 | shl eax, cl |
3035 | jmp @b |
3128 | jmp @b |
3036 | @@: ; next dword |
3129 | @@: ; next dword |
3037 | mov eax, [edi+4] |
3130 | mov eax, [edi+4] |
3038 | bsf edx, eax |
3131 | bsf edx, eax |
3039 | jz .got ; empty |
3132 | jz .got ; empty |
3040 | add edx, 32 |
3133 | add edx, 32 |
3041 | sub edx, ecx |
3134 | sub edx, ebx |
3042 | cmp edx, [ebp+NTFS.fileDataSize] |
3135 | cmp edx, [ebp+NTFS.fileDataSize] |
3043 | jnc .got ; share between dwords |
3136 | jnc .got ; share between dwords |
3044 | .again: |
3137 | .again: |
3045 | add edi, 4 |
- | |
3046 | pop ecx |
3138 | add edi, 4 |
Line 3047... | Line 3139... | ||
3047 | jmp .small |
3139 | jmp .small |
3048 | 3140 | ||
3049 | .got: |
3141 | .got: |
3050 | push ecx ; starting bit |
3142 | push ebx ; starting bit |
3051 | push edi ; starting dword |
3143 | push edi ; starting dword |
3052 | .done: ; mark space |
3144 | .done: ; mark space |
3053 | mov ecx, [esp+4] |
3145 | mov ecx, [esp+4] |
Line 3086... | Line 3178... | ||
3086 | shl eax, cl |
3178 | shl eax, cl |
3087 | not eax |
3179 | not eax |
3088 | or [edi], eax |
3180 | or [edi], eax |
3089 | .end: |
3181 | .end: |
3090 | pop eax |
3182 | pop eax |
- | 3183 | pop ecx |
|
3091 | sub eax, [ebp+NTFS.BitmapBuffer] |
3184 | sub eax, [ebp+NTFS.BitmapBuffer] |
3092 | shl eax, 3 |
3185 | shl eax, 3 |
- | 3186 | add eax, ecx |
|
3093 | pop edx |
3187 | pop ecx |
- | 3188 | mov ecx, [ebp+NTFS.fileDataSize] |
|
- | 3189 | mov [ebp+NTFS.fileDataStart], eax |
|
3094 | add eax, edx |
3190 | add ecx, eax |
- | 3191 | add ecx, 4095 |
|
- | 3192 | shr ecx, 3+9 |
|
- | 3193 | shr eax, 3+9 |
|
- | 3194 | sub ecx, eax |
|
- | 3195 | mov ebx, eax |
|
3095 | pop edx |
3196 | shl ebx, 9 |
- | 3197 | add eax, [ebp+NTFS.BitmapLocation] |
|
- | 3198 | add ebx, [ebp+NTFS.BitmapBuffer] |
|
3096 | ret |
3199 | xor edx, edx |
- | 3200 | jmp fs_write64_app |
|
Line 3097... | Line 3201... | ||
3097 | 3201 | ||
3098 | ntfsSpaceFree: |
3202 | ntfsSpaceFree: |
3099 | ; free disk space |
3203 | ; free disk space |
3100 | ; in: |
3204 | ; in: |
Line 3206... | Line 3310... | ||
3206 | mov eax, [ebp+NTFS.BitmapBuffer] |
3310 | mov eax, [ebp+NTFS.BitmapBuffer] |
3207 | add eax, [ebp+NTFS.BitmapSize] |
3311 | add eax, [ebp+NTFS.BitmapSize] |
3208 | mov ecx, 8 |
3312 | mov ecx, 8 |
3209 | call release_pages |
3313 | call release_pages |
3210 | .end: |
3314 | .end: |
3211 | pop ebx |
- | |
3212 | pop eax ; ret |
3315 | add esp, 12 ; ret |
3213 | pop eax |
- | |
3214 | stc |
3316 | stc |
3215 | ret |
3317 | ret |
Line 3216... | Line 3318... | ||
3216 | 3318 | ||
3217 | ;---------------------------------------------------------------- |
3319 | ;---------------------------------------------------------------- |