Rev 256 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
65 | mario79 | 1 | ;************************************************************* |
74 | mario79 | 2 | ;* 29.04.2006 Elimination of hangup after the * |
3 | ;* expiration hd_wait_timeout - Mario79 * |
||
65 | mario79 | 4 | ;* 28.01.2006 find all Fat16/32 partition in all input point * |
5 | ;* to MBR - Mario79 * |
||
6 | ;************************************************************* |
||
7 | |||
277 | diamond | 8 | uglobal |
65 | mario79 | 9 | align 4 |
256 | diamond | 10 | |
65 | mario79 | 11 | ;****************************************************** |
12 | ; Please do not change this place - variables in text |
||
13 | ; Mario79 |
||
14 | ; START place |
||
15 | ;****************************************************** |
||
16 | PARTITION_START dd 0x3f |
||
17 | PARTITION_END dd 0 |
||
256 | diamond | 18 | fs_type db 0 ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32 |
277 | diamond | 19 | align 4 |
256 | diamond | 20 | |
21 | fs_dependent_data_start: |
||
22 | ; FATxx data |
||
23 | |||
65 | mario79 | 24 | SECTORS_PER_FAT dd 0x1f3a |
25 | NUMBER_OF_FATS dd 0x2 |
||
26 | SECTORS_PER_CLUSTER dd 0x8 |
||
27 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
||
28 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
||
29 | FAT_START dd 0 ; start of fat table |
||
30 | ROOT_START dd 0 ; start of rootdir (only fat16) |
||
31 | ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16) |
||
32 | DATA_START dd 0 ; start of data area (=first cluster 2) |
||
33 | LAST_CLUSTER dd 0 ; last availabe cluster |
||
34 | ADR_FSINFO dd 0 ; used only by fat32 |
||
35 | |||
36 | fatRESERVED dd 0x0FFFFFF6 |
||
37 | fatBAD dd 0x0FFFFFF7 |
||
38 | fatEND dd 0x0FFFFFF8 |
||
39 | fatMASK dd 0x0FFFFFFF |
||
40 | |||
256 | diamond | 41 | fs_dependent_data_end: |
42 | |||
43 | virtual at fs_dependent_data_start |
||
44 | ; NTFS data |
||
45 | ntfs_data: |
||
46 | .sectors_per_cluster dd ? |
||
47 | .mft_cluster dd ? |
||
48 | .mftmirr_cluster dd ? |
||
49 | .frs_size dd ? ; FRS size in bytes |
||
50 | .iab_size dd ? ; IndexAllocationBuffer size in bytes |
||
51 | .frs_buffer dd ? |
||
52 | .iab_buffer dd ? |
||
53 | .mft_retrieval dd ? |
||
54 | .mft_retrieval_size dd ? |
||
55 | .mft_retrieval_alloc dd ? |
||
56 | .mft_retrieval_end dd ? |
||
57 | .cur_index_size dd ? |
||
58 | .cur_index_buf dd ? |
||
59 | if $ > fs_dependent_data_end |
||
60 | ERROR: increase sizeof(fs_dependent_data)! |
||
61 | end if |
||
62 | end virtual |
||
63 | |||
65 | mario79 | 64 | ;*************************************************************************** |
65 | ; End place |
||
66 | ; Mario79 |
||
67 | ;*************************************************************************** |
||
277 | diamond | 68 | endg |
69 | iglobal |
||
65 | mario79 | 70 | |
71 | partition_types: ; list of fat16/32 partitions |
||
72 | db 0x04 ; DOS: fat16 <32M |
||
73 | db 0x06 ; DOS: fat16 >32M |
||
74 | db 0x0b ; WIN95: fat32 |
||
75 | db 0x0c ; WIN95: fat32, LBA-mapped |
||
76 | db 0x0e ; WIN95: fat16, LBA-mapped |
||
77 | db 0x14 ; Hidden DOS: fat16 <32M |
||
78 | db 0x16 ; Hidden DOS: fat16 >32M |
||
79 | db 0x1b ; Hidden WIN95: fat32 |
||
80 | db 0x1c ; Hidden WIN95: fat32, LBA-mapped |
||
81 | db 0x1e ; Hidden WIN95: fat16, LBA-mapped |
||
82 | db 0xc4 ; DRDOS/secured: fat16 <32M |
||
83 | db 0xc6 ; DRDOS/secured: fat16 >32M |
||
84 | db 0xcb ; DRDOS/secured: fat32 |
||
85 | db 0xcc ; DRDOS/secured: fat32, LBA-mapped |
||
86 | db 0xce ; DRDOS/secured: fat16, LBA-mapped |
||
87 | db 0xd4 ; Old Multiuser DOS secured: fat16 <32M |
||
88 | db 0xd6 ; Old Multiuser DOS secured: fat16 >32M |
||
256 | diamond | 89 | db 0x07 ; NTFS |
65 | mario79 | 90 | partition_types_end: |
91 | |||
92 | |||
93 | extended_types: ; list of extended partitions |
||
94 | db 0x05 ; DOS: extended partition |
||
95 | db 0x0f ; WIN95: extended partition, LBA-mapped |
||
96 | db 0xc5 ; DRDOS/secured: extended partition |
||
97 | db 0xd5 ; Old Multiuser DOS secured: extended partition |
||
98 | extended_types_end: |
||
99 | |||
100 | endg |
||
101 | |||
102 | ; Partition chain used: |
||
103 | ; MBR ; PARTITION2 ; PARTITION3 ; PARTITION4 |
||
104 | ;========================================================== |
||
105 | ; fat16/32 +-- fat16/32 +-- fat16/32 +-- fat16/32 +-- |
||
106 | ; extended --+ extended --+ extended --+ extended --+ |
||
107 | ; 0 0 0 0 |
||
108 | ; 0 0 0 0 |
||
109 | ; Notes: |
||
110 | ; - extended partition need to be in second entry on table |
||
111 | ; - it will skip over removed partitions |
||
112 | |||
113 | set_FAT32_variables: |
||
114 | mov [0xfe10],dword 0 ; entries in hd cache |
||
115 | mov [problem_partition],0 |
||
116 | call reserve_hd1 |
||
117 | call clear_hd_cache |
||
118 | |||
119 | cmp dword [hdpos],0 |
||
120 | je problem_hd |
||
121 | |||
122 | pushad |
||
123 | xor ecx,ecx ; partition count |
||
124 | mov edx,-1 ; flag for partition |
||
125 | xor eax,eax ; read MBR |
||
126 | xor ebp,ebp ; extended partition start |
||
127 | |||
128 | new_partition: |
||
129 | test ebp,ebp ; is there extended partition? |
||
130 | jnz extended_already_set ; yes |
||
131 | xchg ebp,eax ; no. set it now |
||
132 | |||
133 | extended_already_set: |
||
134 | add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start |
||
135 | mov ebx,buffer |
||
136 | call hd_read |
||
74 | mario79 | 137 | cmp [hd_error],0 |
138 | jne problem_hd |
||
65 | mario79 | 139 | |
140 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
||
141 | jnz end_partition_chain |
||
142 | cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition |
||
143 | jz next_partition |
||
144 | |||
145 | push eax |
||
146 | mov al,[ebx+0x1be+4] ; get primary partition type |
||
147 | call scan_partition_types |
||
148 | pop eax |
||
149 | jnz next_primary_partition ; no. skip over |
||
150 | |||
151 | inc ecx |
||
152 | cmp ecx,[fat32part] ; is it wanted partition? |
||
153 | jnz next_primary_partition ; no |
||
154 | |||
256 | diamond | 155 | mov edx, eax ; start sector |
156 | add edx, [ebx+0x1be+8] ; add relative start |
||
157 | push edx |
||
158 | add edx, [ebx+0x1be+12] ; add length |
||
159 | dec edx ; PARTITION_END is inclusive |
||
160 | mov [PARTITION_END], edx ; note that this can be changed |
||
161 | ; when file system data will be available |
||
162 | mov dl, [ebx+0x1be+4] |
||
163 | mov [fs_type], dl ; save for FS recognizer (separate FAT vs NTFS) |
||
164 | pop edx |
||
165 | |||
65 | mario79 | 166 | next_primary_partition: |
167 | push eax |
||
168 | mov al,[ebx+0x1be+4+16] ; get primary partition type |
||
169 | call scan_partition_types |
||
170 | pop eax |
||
171 | jnz next_primary_partition_1 ; no. skip over |
||
172 | |||
173 | inc ecx |
||
174 | cmp ecx,[fat32part] ; is it wanted partition? |
||
175 | jnz next_primary_partition_1 ; no |
||
176 | |||
256 | diamond | 177 | mov edx, eax |
178 | add edx, [ebx+0x1be+8+16] |
||
179 | push edx |
||
180 | add edx, [ebx+0x1be+12+16] |
||
181 | dec edx |
||
182 | mov [PARTITION_END], edx |
||
183 | mov dl, [ebx+0x1be+4+16] |
||
184 | mov [fs_type], dl |
||
185 | pop edx |
||
65 | mario79 | 186 | |
187 | next_primary_partition_1: |
||
188 | push eax |
||
189 | mov al,[ebx+0x1be+4+16+16] ; get primary partition type |
||
190 | call scan_partition_types |
||
191 | pop eax |
||
192 | jnz next_primary_partition_2 ; no. skip over |
||
193 | |||
194 | inc ecx |
||
195 | cmp ecx,[fat32part] ; is it wanted partition? |
||
196 | jnz next_primary_partition_2 ; no |
||
197 | |||
256 | diamond | 198 | mov edx, eax |
199 | add edx, [ebx+0x1be+8+16+16] |
||
200 | push edx |
||
201 | add edx, [ebx+0x1be+12+16+16] |
||
202 | dec edx |
||
203 | mov [PARTITION_END], edx |
||
204 | mov dl, [ebx+0x1be+4+16+16] |
||
205 | mov [fs_type], dl |
||
206 | pop edx |
||
65 | mario79 | 207 | |
208 | next_primary_partition_2: |
||
209 | push eax |
||
210 | mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type |
||
211 | call scan_partition_types |
||
212 | pop eax |
||
213 | jnz next_partition ; no. skip over |
||
214 | |||
215 | inc ecx |
||
216 | cmp ecx,[fat32part] ; is it wanted partition? |
||
217 | jnz next_partition ; no |
||
218 | |||
256 | diamond | 219 | mov edx, eax |
220 | add edx, [ebx+0x1be+8+16+16+16] |
||
221 | push edx |
||
222 | add edx, [ebx+0x1be+12+16+16+16] |
||
223 | dec edx |
||
224 | mov [PARTITION_END], edx |
||
225 | mov dl, [ebx+0x1be+4+16+16+16] |
||
226 | mov [fs_type], dl |
||
227 | pop edx |
||
65 | mario79 | 228 | |
229 | next_partition: |
||
230 | push eax |
||
231 | mov al,[ebx+0x1be+4] ; get extended partition type |
||
232 | call scan_extended_types |
||
233 | pop eax |
||
234 | jnz next_partition_1 |
||
235 | |||
236 | mov eax,[ebx+0x1be+8] ; add relative start |
||
237 | test eax,eax ; is there extended partition? |
||
238 | jnz new_partition ; yes. read it |
||
239 | |||
240 | next_partition_1: |
||
241 | push eax |
||
242 | mov al,[ebx+0x1be+4+16] ; get extended partition type |
||
243 | call scan_extended_types |
||
244 | pop eax |
||
245 | jnz next_partition_2 |
||
246 | |||
247 | mov eax,[ebx+0x1be+8+16] ; add relative start |
||
248 | test eax,eax ; is there extended partition? |
||
249 | jnz new_partition ; yes. read it |
||
250 | |||
251 | next_partition_2: |
||
252 | push eax |
||
253 | mov al,[ebx+0x1be+4+16+16] ; get extended partition type |
||
254 | call scan_extended_types |
||
255 | pop eax |
||
256 | jnz next_partition_3 |
||
257 | |||
258 | mov eax,[ebx+0x1be+8+16+16] ; add relative start |
||
259 | test eax,eax ; is there extended partition? |
||
260 | jnz new_partition ; yes. read it |
||
261 | |||
262 | next_partition_3: |
||
263 | push eax |
||
264 | mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type |
||
265 | call scan_extended_types |
||
266 | pop eax |
||
267 | jnz end_partition_chain ; no. end chain |
||
268 | |||
269 | mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition |
||
270 | test eax,eax ; is there extended partition? |
||
271 | jnz new_partition ; yes. read it |
||
272 | |||
273 | end_partition_chain: |
||
274 | mov [partition_count],ecx |
||
275 | |||
276 | cmp edx,-1 ; found wanted partition? |
||
277 | jnz hd_and_partition_ok ; yes. install it |
||
278 | jmp problem_partition_or_fat |
||
279 | |||
280 | scan_partition_types: |
||
281 | push ecx |
||
282 | mov edi,partition_types |
||
283 | mov ecx,partition_types_end-partition_types |
||
284 | cld |
||
285 | repne scasb ; is partition type ok? |
||
286 | pop ecx |
||
287 | ret |
||
288 | |||
289 | scan_extended_types: |
||
290 | push ecx |
||
291 | mov edi,extended_types |
||
292 | mov ecx,extended_types_end-extended_types |
||
293 | cld |
||
294 | repne scasb ; is it extended partition? |
||
295 | pop ecx |
||
296 | ret |
||
297 | |||
298 | problem_fat_dec_count: ; bootsector is missing or another problem |
||
299 | dec [partition_count] ; remove it from partition_count |
||
300 | |||
301 | problem_partition_or_fat: |
||
302 | popad |
||
303 | |||
304 | problem_hd: |
||
256 | diamond | 305 | mov [fs_type],0 |
65 | mario79 | 306 | mov [hd1_status],0 ; free |
307 | mov [problem_partition],1 |
||
308 | ret |
||
309 | |||
310 | hd_and_partition_ok: |
||
311 | mov eax,edx |
||
312 | mov [PARTITION_START],eax |
||
256 | diamond | 313 | mov edx, [PARTITION_END] |
314 | sub edx, eax |
||
315 | inc edx ; edx = length of partition |
||
65 | mario79 | 316 | |
256 | diamond | 317 | ; mov [hd_setup],1 |
65 | mario79 | 318 | mov ebx,buffer |
319 | call hd_read ; read boot sector of partition |
||
256 | diamond | 320 | cmp [hd_error], 0 |
321 | jz boot_read_ok |
||
322 | cmp [fs_type], 7 |
||
323 | jnz problem_fat_dec_count |
||
324 | ; NTFS duplicates bootsector: |
||
325 | ; NT4/2k/XP+ saves bootsector copy in the end of disk |
||
326 | ; NT 3.51 saves bootsector copy in the middle of disk |
||
327 | and [hd_error], 0 |
||
328 | mov eax, [PARTITION_END] |
||
329 | call hd_read |
||
330 | cmp [hd_error], 0 |
||
331 | jnz @f |
||
332 | call ntfs_test_bootsec |
||
333 | jnc boot_read_ok |
||
334 | @@: |
||
335 | and [hd_error], 0 |
||
336 | mov eax, edx |
||
337 | shr eax, 1 |
||
338 | add eax, [PARTITION_START] |
||
339 | call hd_read |
||
340 | cmp [hd_error], 0 |
||
341 | jnz problem_fat_dec_count ; не судьба... |
||
342 | boot_read_ok: |
||
343 | ; mov [hd_setup], 0 |
||
344 | ; if we are running on NTFS, check bootsector |
||
345 | cmp [fs_type], 7 |
||
346 | jz ntfs_setup |
||
74 | mario79 | 347 | |
65 | mario79 | 348 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
349 | jnz problem_fat_dec_count |
||
350 | |||
351 | movzx eax,word [ebx+0xe] ; sectors reserved |
||
352 | add eax,[PARTITION_START] |
||
353 | mov [FAT_START],eax ; fat_start = partition_start + reserved |
||
354 | |||
355 | movzx eax,byte [ebx+0xd] ; sectors per cluster |
||
356 | mov [SECTORS_PER_CLUSTER],eax |
||
357 | |||
358 | movzx ecx,word [ebx+0xb] ; bytes per sector |
||
359 | mov [BYTES_PER_SECTOR],ecx |
||
360 | |||
361 | movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32) |
||
362 | mov edx,32 |
||
363 | mul edx |
||
364 | dec ecx |
||
365 | add eax,ecx ; round up if not equal count |
||
366 | inc ecx ; bytes per sector |
||
367 | div ecx |
||
368 | mov [ROOT_SECTORS],eax ; count of rootdir sectors |
||
369 | |||
370 | movzx eax,word [ebx+0x16] ; sectors per fat <65536 |
||
371 | test eax,eax |
||
372 | jnz fat16_fatsize |
||
373 | mov eax,[ebx+0x24] ; sectors per fat |
||
374 | fat16_fatsize: |
||
375 | mov [SECTORS_PER_FAT],eax |
||
376 | |||
377 | movzx eax,byte [ebx+0x10] ; number of fats |
||
378 | test eax,eax ; if 0 it's not fat partition |
||
379 | jz problem_fat_dec_count |
||
380 | mov [NUMBER_OF_FATS],eax |
||
381 | imul eax,[SECTORS_PER_FAT] |
||
382 | add eax,[FAT_START] |
||
383 | mov [ROOT_START],eax ; rootdir = fat_start + fat_size * fat_count |
||
384 | add eax,[ROOT_SECTORS] ; rootdir sectors should be 0 on fat32 |
||
385 | mov [DATA_START],eax ; data area = rootdir + rootdir_size |
||
386 | |||
387 | movzx eax,word [ebx+0x13] ; total sector count <65536 |
||
388 | test eax,eax |
||
389 | jnz fat16_total |
||
390 | mov eax,[ebx+0x20] ; total sector count |
||
391 | fat16_total: |
||
392 | add eax,[PARTITION_START] |
||
393 | dec eax |
||
394 | mov [PARTITION_END],eax |
||
395 | inc eax |
||
396 | sub eax,[DATA_START] ; eax = count of data sectors |
||
397 | xor edx,edx |
||
398 | div dword [SECTORS_PER_CLUSTER] |
||
399 | inc eax |
||
400 | mov [LAST_CLUSTER],eax |
||
401 | dec eax ; cluster count |
||
402 | |||
403 | ; limits by Microsoft Hardware White Paper v1.03 |
||
404 | cmp eax,4085 ; 0xff5 |
||
405 | jb problem_fat_dec_count ; fat12 not supported |
||
406 | cmp eax,65525 ; 0xfff5 |
||
407 | jb fat16_partition |
||
408 | |||
409 | fat32_partition: |
||
410 | mov eax,[ebx+0x2c] ; rootdir cluster |
||
411 | mov [ROOT_CLUSTER],eax |
||
412 | movzx eax,word [ebx+0x30] ; fs info sector |
||
413 | add eax,[PARTITION_START] |
||
414 | mov [ADR_FSINFO],eax |
||
415 | |||
416 | popad |
||
417 | |||
418 | mov [fatRESERVED],0x0FFFFFF6 |
||
419 | mov [fatBAD],0x0FFFFFF7 |
||
420 | mov [fatEND],0x0FFFFFF8 |
||
421 | mov [fatMASK],0x0FFFFFFF |
||
256 | diamond | 422 | mov [fs_type],32 ; Fat32 |
65 | mario79 | 423 | mov [hd1_status],0 ; free |
424 | ret |
||
425 | |||
426 | fat16_partition: |
||
427 | xor eax,eax |
||
428 | mov [ROOT_CLUSTER],eax |
||
429 | |||
430 | popad |
||
431 | |||
432 | mov [fatRESERVED],0x0000FFF6 |
||
433 | mov [fatBAD],0x0000FFF7 |
||
434 | mov [fatEND],0x0000FFF8 |
||
435 | mov [fatMASK],0x0000FFFF |
||
256 | diamond | 436 | mov [fs_type],16 ; Fat16 |
65 | mario79 | 437 | mov [hd1_status],0 ; free |
438 | ret65536 |