Rev 5363 | Rev 5994 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5363 | Rev 5954 | ||
---|---|---|---|
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 | ||
- | 8 | $Revision: 5954 $ |
|
- | 9 | ||
- | 10 | ; NTFS driver |
|
- | 11 | ||
- | 12 | ; Basic concepts: |
|
- | 13 | ; File is a FileRecord in the $MFT. |
|
- | 14 | ; $MFT is a file, that consists of FileRecords and starts with FileRecord of itself. |
|
- | 15 | ; FileRecord (FILE) consists of a header and attributes. |
|
- | 16 | ; Attribute consists of a header and a body. |
|
- | 17 | ; Attribute's body can be inside (resident) or outside of FileRecord. |
|
- | 18 | ; File's data is a body of $Data (80h) attribute. |
|
- | 19 | ; FileRecords is a data of the $MFT file. |
|
- | 20 | ; Directory is a file, that consists of index nodes. |
|
- | 21 | ; Resident index node is always located in a body of $IndexRoot (90h) attribute. |
|
- | 22 | ; Body of $IndexAllocation (A0h) attribute is always non resident |
|
- | 23 | ; and consists of IndexRecords. |
|
- | 24 | ; IndexRecord (INDX) consists of a header and an index node. |
|
- | 25 | ; Index node consists of a header and indexes. |
|
- | 26 | ; Index consists of a header and a copy of indexed attribute's body. |
|
- | 27 | ; Directories index $Filename (30h) attribute of all existing files. |
|
- | 28 | ; $IndexRoot and $IndexAllocation attributes of a directory has a name — $I30. |
|
- | 29 | ||
- | 30 | ; Offsets: |
|
- | 31 | ; record header |
|
- | 32 | updateSequenceOffset = 4 |
|
- | 33 | updateSequenceSize = 6 |
|
- | 34 | reuseCounter = 16 |
|
- | 35 | hardLinkCounter = 12h |
|
- | 36 | attributeOffset = 14h |
|
- | 37 | recordFlags = 16h |
|
- | 38 | recordRealSize = 18h |
|
- | 39 | recordAllocatedSize = 1ch |
|
- | 40 | newAttributeID = 28h |
|
- | 41 | ; attribute header |
|
- | 42 | attributeType = 0 |
|
- | 43 | sizeWithHeader = 4 |
|
- | 44 | nonResidentFlag = 8 |
|
- | 45 | nameLength = 9 |
|
- | 46 | nameOffset = 10 |
|
- | 47 | attributeID = 14 |
|
- | 48 | sizeWithoutHeader = 16 |
|
- | 49 | attributeFlags = 16h |
|
- | 50 | ; non resident attribute header |
|
- | 51 | lastVCN = 18h |
|
- | 52 | dataRunsOffset = 20h |
|
- | 53 | attributeAllocatedSize = 28h |
|
- | 54 | attributeRealSize = 30h |
|
- | 55 | initialDataSize = 38h |
|
- | 56 | ; $IndexRoot |
|
- | 57 | collationRule = 4 |
|
- | 58 | indexRecordSize = 8 |
|
- | 59 | indexRecordSizeClus = 12 |
|
- | 60 | ; node header |
|
- | 61 | indexOffset = 0 |
|
- | 62 | nodeRealSize = 4 |
|
- | 63 | nodeAllocatedSize = 8 |
|
- | 64 | ; $Filename index |
|
- | 65 | fileRecordReference = 0 |
|
- | 66 | fileReferenceReuse = 6 |
|
- | 67 | indexAllocatedSize = 8 |
|
- | 68 | indexRawSize = 10 |
|
- | 69 | indexFlags = 12 |
|
- | 70 | directoryRecordReference = 16 |
|
- | 71 | directoryReferenceReuse = 16h |
|
- | 72 | fileAllocatedSize = 38h |
|
- | 73 | fileRealSize = 40h |
|
- | 74 | fileFlags = 48h |
|
Line 8... | Line 75... | ||
8 | $Revision: 5363 $ |
75 | fileNameLength = 50h |
9 | 76 | ||
10 | struct NTFS PARTITION |
- | |
11 | Lock MUTEX ? ; currently operations with one partition |
77 | struct NTFS PARTITION |
12 | ; can not be executed in parallel since the |
- | |
13 | ; legacy code is not ready; this mutex guards |
78 | Lock MUTEX ? ; Currently operations with one partition |
14 | ; all operations |
79 | ; can not be executed in parallel since the legacy code is not ready. |
15 | sectors_per_cluster dd ? |
80 | sectors_per_cluster dd ? |
16 | mft_cluster dd ? |
81 | mft_cluster dd ? ; location |
17 | mftmirr_cluster dd ? |
- | |
18 | frs_size dd ? ; FRS size in bytes |
82 | mftmirr_cluster dd ? ; location |
19 | iab_size dd ? ; IndexAllocationBuffer size in bytes |
- | |
20 | frs_buffer dd ? |
83 | frs_size dd ? ; in bytes |
21 | iab_buffer dd ? |
84 | frs_buffer dd ? ; MFT fileRecord buffer |
22 | mft_retrieval dd ? |
85 | mft_retrieval dd ? |
23 | mft_retrieval_size dd ? |
86 | mft_retrieval_size dd ? |
24 | mft_retrieval_alloc dd ? |
87 | mft_retrieval_alloc dd ? |
25 | mft_retrieval_end dd ? |
88 | mft_retrieval_end dd ? |
- | 89 | cur_index_size dd ? ; in sectors |
|
- | 90 | cur_index_buf dd ? ; index node buffer |
|
- | 91 | BitmapBuffer dd ? |
|
- | 92 | BitmapTotalSize dd ? ; bytes reserved |
|
- | 93 | BitmapSize dd ? ; bytes readen |
|
- | 94 | BitmapLocation dd ? ; starting sector |
|
- | 95 | BitmapStart dd ? ; first byte after area, reserved for MFT |
|
- | 96 | mftBitmapBuffer dd ? ; one cluster |
|
26 | cur_index_size dd ? |
97 | mftBitmapSize dd ? ; bytes readen |
27 | cur_index_buf dd ? |
98 | mftBitmapLocation dd ? ; starting sector |
28 | 99 | ||
29 | ntfs_cur_attr dd ? |
100 | ntfs_cur_attr dd ? ; attribute type |
30 | ntfs_cur_iRecord dd ? |
101 | ntfs_cur_iRecord dd ? ; number of fileRecord in MFT |
31 | ntfs_cur_offs dd ? ; in sectors |
102 | ntfs_cur_offs dd ? ; attribute VCN in sectors |
32 | ntfs_cur_size dd ? ; in sectors |
103 | ntfs_cur_size dd ? ; max sectors to read |
- | 104 | ntfs_cur_buf dd ? |
|
- | 105 | ntfs_cur_read dd ? ; bytes readen |
|
- | 106 | ntfsLastRead dd ? ; last readen block of sectors |
|
- | 107 | newMftRecord dd ? ; number of fileRecord in MFT |
|
- | 108 | fileDataStart dd ? ; starting cluster |
|
- | 109 | fileDataSize dd ? ; in clusters |
|
- | 110 | fileRealSize dd ? ; in bytes |
|
33 | ntfs_cur_buf dd ? |
111 | indexOffset dd ? |
- | 112 | nodeLastRead dd ? |
|
34 | ntfs_cur_read dd ? ; [output] |
113 | ntfs_bCanContinue db ? |
- | 114 | ntfsNotFound db ? |
|
Line 35... | Line 115... | ||
35 | ntfs_bCanContinue db ? |
115 | ntfsFolder db ? |
36 | rb 3 |
116 | ntfsFragmentCount db ? |
37 | 117 | ||
38 | cur_subnode_size dd ? |
118 | cur_subnode_size dd ? |
Line 46... | Line 126... | ||
46 | ntfs_attrlist_buf rb 0x400 |
126 | ntfs_attrlist_buf rb 0x400 |
47 | ntfs_attrlist_mft_buf rb 0x400 |
127 | ntfs_attrlist_mft_buf rb 0x400 |
48 | ntfs_bitmap_buf rb 0x400 |
128 | ntfs_bitmap_buf rb 0x400 |
49 | ends |
129 | ends |
Line -... | Line 130... | ||
- | 130 | ||
- | 131 | ; NTFS external functions |
|
- | 132 | ; in: |
|
- | 133 | ; ebx -> parameter structure of sysfunc 70 |
|
- | 134 | ; ebp -> NTFS structure |
|
- | 135 | ; [esi]+[esp+4] = name |
|
- | 136 | ; out: |
|
50 | 137 | ; eax, ebx = return values for sysfunc 70 |
|
51 | iglobal |
138 | iglobal |
52 | align 4 |
139 | align 4 |
53 | ntfs_user_functions: |
140 | ntfs_user_functions: |
54 | dd ntfs_free |
141 | dd ntfs_free |
55 | dd (ntfs_user_functions_end - ntfs_user_functions - 4) / 4 |
142 | dd (ntfs_user_functions_end - ntfs_user_functions - 4) / 4 |
56 | dd ntfs_Read |
143 | dd ntfs_ReadFile |
57 | dd ntfs_ReadFolder |
144 | dd ntfs_ReadFolder |
58 | dd ntfs_Rewrite |
145 | dd ntfs_CreateFile |
59 | dd ntfs_Write |
146 | dd ntfs_Write |
60 | dd ntfs_SetFileEnd |
147 | dd ntfs_SetFileEnd |
61 | dd ntfs_GetFileInfo |
148 | dd ntfs_GetFileInfo |
62 | dd ntfs_SetFileInfo |
149 | dd ntfs_SetFileInfo |
Line 66... | Line 153... | ||
66 | ntfs_user_functions_end: |
153 | ntfs_user_functions_end: |
67 | endg |
154 | endg |
Line 68... | Line 155... | ||
68 | 155 | ||
69 | ntfs_test_bootsec: |
156 | ntfs_test_bootsec: |
70 | ; in: ebx->buffer, edx=size of partition |
157 | ; in: ebx -> buffer, edx = size of partition |
71 | ; out: CF set <=> invalid |
158 | ; out: CF=1 -> invalid |
72 | ; 1. Name=='NTFS ' |
159 | ; 1. Name=='NTFS ' |
73 | cmp dword [ebx+3], 'NTFS' |
160 | cmp dword [ebx+3], 'NTFS' |
74 | jnz .no |
161 | jnz .no |
75 | cmp dword [ebx+7], ' ' |
162 | cmp dword [ebx+7], ' ' |
Line 119... | Line 206... | ||
119 | test edx, edx |
206 | test edx, edx |
120 | pop edx |
207 | pop edx |
121 | jnz .no |
208 | jnz .no |
122 | cmp eax, edx |
209 | cmp eax, edx |
123 | ja .no |
210 | ja .no |
124 | ; 7. Clusters per FRS must be either negative and in [-31,-9] or positive and power of 2 |
211 | ; 7. Clusters per FRS must be either power of 2 or between -31 and -9 |
125 | movsx eax, byte [ebx+0x40] |
212 | movsx eax, byte [ebx+0x40] |
126 | cmp al, -31 |
213 | cmp al, -31 |
127 | jl .no |
214 | jl .no |
128 | cmp al, -9 |
215 | cmp al, -9 |
129 | jle @f |
216 | jle @f |
130 | dec eax |
217 | dec eax |
131 | js .no |
218 | js .no |
132 | test [ebx+0x40], al |
219 | test [ebx+0x40], al |
133 | jnz .no |
220 | jnz .no |
134 | @@: |
- | |
135 | ; 8. Same for clusters per IndexAllocationBuffer |
221 | @@: ; 8. Same for clusters per IndexAllocationBuffer |
136 | movsx eax, byte [ebx+0x44] |
222 | movsx eax, byte [ebx+0x44] |
137 | cmp al, -31 |
223 | cmp al, -31 |
138 | jl .no |
224 | jl .no |
139 | cmp al, -9 |
225 | cmp al, -9 |
140 | jle @f |
226 | jle @f |
141 | dec eax |
227 | dec eax |
142 | js .no |
228 | js .no |
143 | test [ebx+0x44], al |
229 | test [ebx+0x44], al |
144 | jnz .no |
230 | jnz .no |
145 | @@: |
- | |
146 | ; OK, this is correct NTFS bootsector |
231 | @@: ; OK, this is correct NTFS bootsector |
147 | clc |
232 | clc |
148 | ret |
233 | ret |
149 | .no: |
- | |
150 | ; No, this bootsector isn't NTFS |
234 | .no: ; No, this bootsector isn't NTFS |
151 | stc |
235 | stc |
152 | ret |
236 | ret |
Line 153... | Line 237... | ||
153 | 237 | ||
154 | proc ntfs_create_partition |
238 | ntfs_create_partition: |
155 | cmp dword [esi+DISK.MediaInfo.SectorSize], 512 |
239 | cmp dword [esi+DISK.MediaInfo.SectorSize], 512 |
156 | jnz .nope |
240 | jnz .nope |
157 | mov edx, dword [ebp+PARTITION.Length] |
241 | mov edx, dword [ebp+PARTITION.Length] |
158 | cmp dword [esp+4], 0 |
242 | cmp dword [esp+4], 0 |
Line 167... | Line 251... | ||
167 | @@: |
251 | @@: |
168 | mov eax, edx |
252 | mov eax, edx |
169 | shr eax, 1 |
253 | shr eax, 1 |
170 | call fs_read32_sys |
254 | call fs_read32_sys |
171 | test eax, eax |
255 | test eax, eax |
172 | jnz .nope ; no chance... |
256 | jnz .nope |
173 | .boot_read_ok: |
257 | .boot_read_ok: |
174 | call ntfs_test_bootsec |
258 | call ntfs_test_bootsec |
175 | jnc .ntfs_setup |
259 | jnc .ntfs_setup |
176 | .nope: |
260 | .nope: |
177 | xor eax, eax |
261 | xor eax, eax |
178 |