Rev 65 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 65 | Rev 74 | ||
---|---|---|---|
1 | ;************************************************************* |
1 | ;************************************************************* |
- | 2 | ;* 29.04.2006 Elimination of hangup after the * |
|
- | 3 | ;* expiration hd_wait_timeout - Mario79 * |
|
2 | ;* 28.01.2006 find all Fat16/32 partition in all input point * |
4 | ;* 28.01.2006 find all Fat16/32 partition in all input point * |
3 | ;* to MBR - Mario79 * |
5 | ;* to MBR - Mario79 * |
4 | ;************************************************************* |
6 | ;************************************************************* |
5 | 7 | ||
6 | align 4 |
8 | align 4 |
7 | ;****************************************************** |
9 | ;****************************************************** |
8 | ; Please do not change this place - variables in text |
10 | ; Please do not change this place - variables in text |
9 | ; Mario79 |
11 | ; Mario79 |
10 | ; START place |
12 | ; START place |
11 | ;****************************************************** |
13 | ;****************************************************** |
12 | PARTITION_START dd 0x3f |
14 | PARTITION_START dd 0x3f |
13 | PARTITION_END dd 0 |
15 | PARTITION_END dd 0 |
14 | SECTORS_PER_FAT dd 0x1f3a |
16 | SECTORS_PER_FAT dd 0x1f3a |
15 | NUMBER_OF_FATS dd 0x2 |
17 | NUMBER_OF_FATS dd 0x2 |
16 | SECTORS_PER_CLUSTER dd 0x8 |
18 | SECTORS_PER_CLUSTER dd 0x8 |
17 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
19 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
18 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
20 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
19 | FAT_START dd 0 ; start of fat table |
21 | FAT_START dd 0 ; start of fat table |
20 | ROOT_START dd 0 ; start of rootdir (only fat16) |
22 | ROOT_START dd 0 ; start of rootdir (only fat16) |
21 | ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16) |
23 | ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16) |
22 | DATA_START dd 0 ; start of data area (=first cluster 2) |
24 | DATA_START dd 0 ; start of data area (=first cluster 2) |
23 | LAST_CLUSTER dd 0 ; last availabe cluster |
25 | LAST_CLUSTER dd 0 ; last availabe cluster |
24 | ADR_FSINFO dd 0 ; used only by fat32 |
26 | ADR_FSINFO dd 0 ; used only by fat32 |
25 | 27 | ||
26 | fatRESERVED dd 0x0FFFFFF6 |
28 | fatRESERVED dd 0x0FFFFFF6 |
27 | fatBAD dd 0x0FFFFFF7 |
29 | fatBAD dd 0x0FFFFFF7 |
28 | fatEND dd 0x0FFFFFF8 |
30 | fatEND dd 0x0FFFFFF8 |
29 | fatMASK dd 0x0FFFFFFF |
31 | fatMASK dd 0x0FFFFFFF |
30 | 32 | ||
31 | fat_type db 0 ; 0=none, 16=fat16, 32=fat32 |
33 | fat_type db 0 ; 0=none, 16=fat16, 32=fat32 |
32 | ;*************************************************************************** |
34 | ;*************************************************************************** |
33 | ; End place |
35 | ; End place |
34 | ; Mario79 |
36 | ; Mario79 |
35 | ;*************************************************************************** |
37 | ;*************************************************************************** |
36 | 38 | ||
37 | iglobal |
39 | iglobal |
38 | partition_types: ; list of fat16/32 partitions |
40 | partition_types: ; list of fat16/32 partitions |
39 | db 0x04 ; DOS: fat16 <32M |
41 | db 0x04 ; DOS: fat16 <32M |
40 | db 0x06 ; DOS: fat16 >32M |
42 | db 0x06 ; DOS: fat16 >32M |
41 | db 0x0b ; WIN95: fat32 |
43 | db 0x0b ; WIN95: fat32 |
42 | db 0x0c ; WIN95: fat32, LBA-mapped |
44 | db 0x0c ; WIN95: fat32, LBA-mapped |
43 | db 0x0e ; WIN95: fat16, LBA-mapped |
45 | db 0x0e ; WIN95: fat16, LBA-mapped |
44 | db 0x14 ; Hidden DOS: fat16 <32M |
46 | db 0x14 ; Hidden DOS: fat16 <32M |
45 | db 0x16 ; Hidden DOS: fat16 >32M |
47 | db 0x16 ; Hidden DOS: fat16 >32M |
46 | db 0x1b ; Hidden WIN95: fat32 |
48 | db 0x1b ; Hidden WIN95: fat32 |
47 | db 0x1c ; Hidden WIN95: fat32, LBA-mapped |
49 | db 0x1c ; Hidden WIN95: fat32, LBA-mapped |
48 | db 0x1e ; Hidden WIN95: fat16, LBA-mapped |
50 | db 0x1e ; Hidden WIN95: fat16, LBA-mapped |
49 | db 0xc4 ; DRDOS/secured: fat16 <32M |
51 | db 0xc4 ; DRDOS/secured: fat16 <32M |
50 | db 0xc6 ; DRDOS/secured: fat16 >32M |
52 | db 0xc6 ; DRDOS/secured: fat16 >32M |
51 | db 0xcb ; DRDOS/secured: fat32 |
53 | db 0xcb ; DRDOS/secured: fat32 |
52 | db 0xcc ; DRDOS/secured: fat32, LBA-mapped |
54 | db 0xcc ; DRDOS/secured: fat32, LBA-mapped |
53 | db 0xce ; DRDOS/secured: fat16, LBA-mapped |
55 | db 0xce ; DRDOS/secured: fat16, LBA-mapped |
54 | db 0xd4 ; Old Multiuser DOS secured: fat16 <32M |
56 | db 0xd4 ; Old Multiuser DOS secured: fat16 <32M |
55 | db 0xd6 ; Old Multiuser DOS secured: fat16 >32M |
57 | db 0xd6 ; Old Multiuser DOS secured: fat16 >32M |
56 | partition_types_end: |
58 | partition_types_end: |
57 | 59 | ||
58 | 60 | ||
59 | extended_types: ; list of extended partitions |
61 | extended_types: ; list of extended partitions |
60 | db 0x05 ; DOS: extended partition |
62 | db 0x05 ; DOS: extended partition |
61 | db 0x0f ; WIN95: extended partition, LBA-mapped |
63 | db 0x0f ; WIN95: extended partition, LBA-mapped |
62 | db 0xc5 ; DRDOS/secured: extended partition |
64 | db 0xc5 ; DRDOS/secured: extended partition |
63 | db 0xd5 ; Old Multiuser DOS secured: extended partition |
65 | db 0xd5 ; Old Multiuser DOS secured: extended partition |
64 | extended_types_end: |
66 | extended_types_end: |
65 | 67 | ||
66 | endg |
68 | endg |
67 | 69 | ||
68 | ; Partition chain used: |
70 | ; Partition chain used: |
69 | ; MBR ; PARTITION2 ; PARTITION3 ; PARTITION4 |
71 | ; MBR ; PARTITION2 ; PARTITION3 ; PARTITION4 |
70 | ;========================================================== |
72 | ;========================================================== |
71 | ; fat16/32 +-- fat16/32 +-- fat16/32 +-- fat16/32 +-- |
73 | ; fat16/32 +-- fat16/32 +-- fat16/32 +-- fat16/32 +-- |
72 | ; extended --+ extended --+ extended --+ extended --+ |
74 | ; extended --+ extended --+ extended --+ extended --+ |
73 | ; 0 0 0 0 |
75 | ; 0 0 0 0 |
74 | ; 0 0 0 0 |
76 | ; 0 0 0 0 |
75 | ; Notes: |
77 | ; Notes: |
76 | ; - extended partition need to be in second entry on table |
78 | ; - extended partition need to be in second entry on table |
77 | ; - it will skip over removed partitions |
79 | ; - it will skip over removed partitions |
78 | 80 | ||
79 | set_FAT32_variables: |
81 | set_FAT32_variables: |
80 | mov [0xfe10],dword 0 ; entries in hd cache |
82 | mov [0xfe10],dword 0 ; entries in hd cache |
81 | mov [problem_partition],0 |
83 | mov [problem_partition],0 |
82 | call reserve_hd1 |
84 | call reserve_hd1 |
83 | call clear_hd_cache |
85 | call clear_hd_cache |
84 | 86 | ||
85 | cmp dword [hdpos],0 |
87 | cmp dword [hdpos],0 |
86 | je problem_hd |
88 | je problem_hd |
87 | 89 | ||
88 | pushad |
90 | pushad |
89 | xor ecx,ecx ; partition count |
91 | xor ecx,ecx ; partition count |
90 | mov edx,-1 ; flag for partition |
92 | mov edx,-1 ; flag for partition |
91 | xor eax,eax ; read MBR |
93 | xor eax,eax ; read MBR |
92 | xor ebp,ebp ; extended partition start |
94 | xor ebp,ebp ; extended partition start |
93 | 95 | ||
94 | new_partition: |
96 | new_partition: |
95 | test ebp,ebp ; is there extended partition? |
97 | test ebp,ebp ; is there extended partition? |
96 | jnz extended_already_set ; yes |
98 | jnz extended_already_set ; yes |
97 | xchg ebp,eax ; no. set it now |
99 | xchg ebp,eax ; no. set it now |
98 | 100 | ||
99 | extended_already_set: |
101 | extended_already_set: |
100 | add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start |
102 | add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start |
101 | mov ebx,buffer |
103 | mov ebx,buffer |
102 | call hd_read |
104 | call hd_read |
- | 105 | cmp [hd_error],0 |
|
- | 106 | jne problem_hd |
|
103 | 107 | ||
104 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
108 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
105 | jnz end_partition_chain |
109 | jnz end_partition_chain |
106 | cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition |
110 | cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition |
107 | jz next_partition |
111 | jz next_partition |
108 | 112 | ||
109 | push eax |
113 | push eax |
110 | mov al,[ebx+0x1be+4] ; get primary partition type |
114 | mov al,[ebx+0x1be+4] ; get primary partition type |
111 | call scan_partition_types |
115 | call scan_partition_types |
112 | pop eax |
116 | pop eax |
113 | jnz next_primary_partition ; no. skip over |
117 | jnz next_primary_partition ; no. skip over |
114 | 118 | ||
115 | inc ecx |
119 | inc ecx |
116 | cmp ecx,[fat32part] ; is it wanted partition? |
120 | cmp ecx,[fat32part] ; is it wanted partition? |
117 | jnz next_primary_partition ; no |
121 | jnz next_primary_partition ; no |
118 | 122 | ||
119 | mov edx,eax ; start sector |
123 | mov edx,eax ; start sector |
120 | add edx,[ebx+0x1be+8] ; add relative start |
124 | add edx,[ebx+0x1be+8] ; add relative start |
121 | 125 | ||
122 | next_primary_partition: |
126 | next_primary_partition: |
123 | push eax |
127 | push eax |
124 | mov al,[ebx+0x1be+4+16] ; get primary partition type |
128 | mov al,[ebx+0x1be+4+16] ; get primary partition type |
125 | call scan_partition_types |
129 | call scan_partition_types |
126 | pop eax |
130 | pop eax |
127 | jnz next_primary_partition_1 ; no. skip over |
131 | jnz next_primary_partition_1 ; no. skip over |
128 | 132 | ||
129 | inc ecx |
133 | inc ecx |
130 | cmp ecx,[fat32part] ; is it wanted partition? |
134 | cmp ecx,[fat32part] ; is it wanted partition? |
131 | jnz next_primary_partition_1 ; no |
135 | jnz next_primary_partition_1 ; no |
132 | 136 | ||
133 | mov edx,eax ; start sector |
137 | mov edx,eax ; start sector |
134 | add edx,[ebx+0x1be+8+16] ; add relative start |
138 | add edx,[ebx+0x1be+8+16] ; add relative start |
135 | 139 | ||
136 | next_primary_partition_1: |
140 | next_primary_partition_1: |
137 | push eax |
141 | push eax |
138 | mov al,[ebx+0x1be+4+16+16] ; get primary partition type |
142 | mov al,[ebx+0x1be+4+16+16] ; get primary partition type |
139 | call scan_partition_types |
143 | call scan_partition_types |
140 | pop eax |
144 | pop eax |
141 | jnz next_primary_partition_2 ; no. skip over |
145 | jnz next_primary_partition_2 ; no. skip over |
142 | 146 | ||
143 | inc ecx |
147 | inc ecx |
144 | cmp ecx,[fat32part] ; is it wanted partition? |
148 | cmp ecx,[fat32part] ; is it wanted partition? |
145 | jnz next_primary_partition_2 ; no |
149 | jnz next_primary_partition_2 ; no |
146 | 150 | ||
147 | mov edx,eax ; start sector |
151 | mov edx,eax ; start sector |
148 | add edx,[ebx+0x1be+8+16+16] ; add relative start |
152 | add edx,[ebx+0x1be+8+16+16] ; add relative start |
149 | 153 | ||
150 | next_primary_partition_2: |
154 | next_primary_partition_2: |
151 | push eax |
155 | push eax |
152 | mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type |
156 | mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type |
153 | call scan_partition_types |
157 | call scan_partition_types |
154 | pop eax |
158 | pop eax |
155 | jnz next_partition ; no. skip over |
159 | jnz next_partition ; no. skip over |
156 | 160 | ||
157 | inc ecx |
161 | inc ecx |
158 | cmp ecx,[fat32part] ; is it wanted partition? |
162 | cmp ecx,[fat32part] ; is it wanted partition? |
159 | jnz next_partition ; no |
163 | jnz next_partition ; no |
160 | 164 | ||
161 | mov edx,eax ; start sector |
165 | mov edx,eax ; start sector |
162 | add edx,[ebx+0x1be+8+16+16+16] ; add relative start |
166 | add edx,[ebx+0x1be+8+16+16+16] ; add relative start |
163 | 167 | ||
164 | next_partition: |
168 | next_partition: |
165 | push eax |
169 | push eax |
166 | mov al,[ebx+0x1be+4] ; get extended partition type |
170 | mov al,[ebx+0x1be+4] ; get extended partition type |
167 | call scan_extended_types |
171 | call scan_extended_types |
168 | pop eax |
172 | pop eax |
169 | jnz next_partition_1 |
173 | jnz next_partition_1 |
170 | 174 | ||
171 | mov eax,[ebx+0x1be+8] ; add relative start |
175 | mov eax,[ebx+0x1be+8] ; add relative start |
172 | test eax,eax ; is there extended partition? |
176 | test eax,eax ; is there extended partition? |
173 | jnz new_partition ; yes. read it |
177 | jnz new_partition ; yes. read it |
174 | 178 | ||
175 | next_partition_1: |
179 | next_partition_1: |
176 | push eax |
180 | push eax |
177 | mov al,[ebx+0x1be+4+16] ; get extended partition type |
181 | mov al,[ebx+0x1be+4+16] ; get extended partition type |
178 | call scan_extended_types |
182 | call scan_extended_types |
179 | pop eax |
183 | pop eax |
180 | jnz next_partition_2 |
184 | jnz next_partition_2 |
181 | 185 | ||
182 | mov eax,[ebx+0x1be+8+16] ; add relative start |
186 | mov eax,[ebx+0x1be+8+16] ; add relative start |
183 | test eax,eax ; is there extended partition? |
187 | test eax,eax ; is there extended partition? |
184 | jnz new_partition ; yes. read it |
188 | jnz new_partition ; yes. read it |
185 | 189 | ||
186 | next_partition_2: |
190 | next_partition_2: |
187 | push eax |
191 | push eax |
188 | mov al,[ebx+0x1be+4+16+16] ; get extended partition type |
192 | mov al,[ebx+0x1be+4+16+16] ; get extended partition type |
189 | call scan_extended_types |
193 | call scan_extended_types |
190 | pop eax |
194 | pop eax |
191 | jnz next_partition_3 |
195 | jnz next_partition_3 |
192 | 196 | ||
193 | mov eax,[ebx+0x1be+8+16+16] ; add relative start |
197 | mov eax,[ebx+0x1be+8+16+16] ; add relative start |
194 | test eax,eax ; is there extended partition? |
198 | test eax,eax ; is there extended partition? |
195 | jnz new_partition ; yes. read it |
199 | jnz new_partition ; yes. read it |
196 | 200 | ||
197 | next_partition_3: |
201 | next_partition_3: |
198 | push eax |
202 | push eax |
199 | mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type |
203 | mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type |
200 | call scan_extended_types |
204 | call scan_extended_types |
201 | pop eax |
205 | pop eax |
202 | jnz end_partition_chain ; no. end chain |
206 | jnz end_partition_chain ; no. end chain |
203 | 207 | ||
204 | mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition |
208 | mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition |
205 | test eax,eax ; is there extended partition? |
209 | test eax,eax ; is there extended partition? |
206 | jnz new_partition ; yes. read it |
210 | jnz new_partition ; yes. read it |
207 | 211 | ||
208 | end_partition_chain: |
212 | end_partition_chain: |
209 | mov [partition_count],ecx |
213 | mov [partition_count],ecx |
210 | 214 | ||
211 | cmp edx,-1 ; found wanted partition? |
215 | cmp edx,-1 ; found wanted partition? |
212 | jnz hd_and_partition_ok ; yes. install it |
216 | jnz hd_and_partition_ok ; yes. install it |
213 | jmp problem_partition_or_fat |
217 | jmp problem_partition_or_fat |
214 | 218 | ||
215 | scan_partition_types: |
219 | scan_partition_types: |
216 | push ecx |
220 | push ecx |
217 | mov edi,partition_types |
221 | mov edi,partition_types |
218 | mov ecx,partition_types_end-partition_types |
222 | mov ecx,partition_types_end-partition_types |
219 | cld |
223 | cld |
220 | repne scasb ; is partition type ok? |
224 | repne scasb ; is partition type ok? |
221 | pop ecx |
225 | pop ecx |
222 | ret |
226 | ret |
223 | 227 | ||
224 | scan_extended_types: |
228 | scan_extended_types: |
225 | push ecx |
229 | push ecx |
226 | mov edi,extended_types |
230 | mov edi,extended_types |
227 | mov ecx,extended_types_end-extended_types |
231 | mov ecx,extended_types_end-extended_types |
228 | cld |
232 | cld |
229 | repne scasb ; is it extended partition? |
233 | repne scasb ; is it extended partition? |
230 | pop ecx |
234 | pop ecx |
231 | ret |
235 | ret |
232 | 236 | ||
233 | problem_fat_dec_count: ; bootsector is missing or another problem |
237 | problem_fat_dec_count: ; bootsector is missing or another problem |
234 | dec [partition_count] ; remove it from partition_count |
238 | dec [partition_count] ; remove it from partition_count |
235 | 239 | ||
236 | problem_partition_or_fat: |
240 | problem_partition_or_fat: |
237 | popad |
241 | popad |
238 | 242 | ||
239 | problem_hd: |
243 | problem_hd: |
240 | mov [fat_type],0 |
244 | mov [fat_type],0 |
241 | mov [hd1_status],0 ; free |
245 | mov [hd1_status],0 ; free |
242 | mov [problem_partition],1 |
246 | mov [problem_partition],1 |
243 | ret |
247 | ret |
244 | 248 | ||
245 | hd_and_partition_ok: |
249 | hd_and_partition_ok: |
246 | mov eax,edx |
250 | mov eax,edx |
247 | mov [PARTITION_START],eax |
251 | mov [PARTITION_START],eax |
248 | 252 | ||
249 | mov [hd_setup],1 |
253 | mov [hd_setup],1 |
250 | mov ebx,buffer |
254 | mov ebx,buffer |
251 | call hd_read ; read boot sector of partition |
255 | call hd_read ; read boot sector of partition |
- | 256 | cmp [hd_error],0 |
|
- | 257 | jne problem_fat_dec_count |
|
- | 258 | ||
252 | mov [hd_setup],0 |
259 | mov [hd_setup],0 |
253 | 260 | ||
254 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
261 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
255 | jnz problem_fat_dec_count |
262 | jnz problem_fat_dec_count |
256 | 263 | ||
257 | movzx eax,word [ebx+0xe] ; sectors reserved |
264 | movzx eax,word [ebx+0xe] ; sectors reserved |
258 | add eax,[PARTITION_START] |
265 | add eax,[PARTITION_START] |
259 | mov [FAT_START],eax ; fat_start = partition_start + reserved |
266 | mov [FAT_START],eax ; fat_start = partition_start + reserved |
260 | 267 | ||
261 | movzx eax,byte [ebx+0xd] ; sectors per cluster |
268 | movzx eax,byte [ebx+0xd] ; sectors per cluster |
262 | mov [SECTORS_PER_CLUSTER],eax |
269 | mov [SECTORS_PER_CLUSTER],eax |
263 | 270 | ||
264 | movzx ecx,word [ebx+0xb] ; bytes per sector |
271 | movzx ecx,word [ebx+0xb] ; bytes per sector |
265 | mov [BYTES_PER_SECTOR],ecx |
272 | mov [BYTES_PER_SECTOR],ecx |
266 | 273 | ||
267 | movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32) |
274 | movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32) |
268 | mov edx,32 |
275 | mov edx,32 |
269 | mul edx |
276 | mul edx |
270 | dec ecx |
277 | dec ecx |
271 | add eax,ecx ; round up if not equal count |
278 | add eax,ecx ; round up if not equal count |
272 | inc ecx ; bytes per sector |
279 | inc ecx ; bytes per sector |
273 | div ecx |
280 | div ecx |
274 | mov [ROOT_SECTORS],eax ; count of rootdir sectors |
281 | mov [ROOT_SECTORS],eax ; count of rootdir sectors |
275 | 282 | ||
276 | movzx eax,word [ebx+0x16] ; sectors per fat <65536 |
283 | movzx eax,word [ebx+0x16] ; sectors per fat <65536 |
277 | test eax,eax |
284 | test eax,eax |
278 | jnz fat16_fatsize |
285 | jnz fat16_fatsize |
279 | mov eax,[ebx+0x24] ; sectors per fat |
286 | mov eax,[ebx+0x24] ; sectors per fat |
280 | fat16_fatsize: |
287 | fat16_fatsize: |
281 | mov [SECTORS_PER_FAT],eax |
288 | mov [SECTORS_PER_FAT],eax |
282 | 289 | ||
283 | movzx eax,byte [ebx+0x10] ; number of fats |
290 | movzx eax,byte [ebx+0x10] ; number of fats |
284 | test eax,eax ; if 0 it's not fat partition |
291 | test eax,eax ; if 0 it's not fat partition |
285 | jz problem_fat_dec_count |
292 | jz problem_fat_dec_count |
286 | mov [NUMBER_OF_FATS],eax |
293 | mov [NUMBER_OF_FATS],eax |
287 | imul eax,[SECTORS_PER_FAT] |
294 | imul eax,[SECTORS_PER_FAT] |
288 | add eax,[FAT_START] |
295 | add eax,[FAT_START] |
289 | mov [ROOT_START],eax ; rootdir = fat_start + fat_size * fat_count |
296 | mov [ROOT_START],eax ; rootdir = fat_start + fat_size * fat_count |
290 | add eax,[ROOT_SECTORS] ; rootdir sectors should be 0 on fat32 |
297 | add eax,[ROOT_SECTORS] ; rootdir sectors should be 0 on fat32 |
291 | mov [DATA_START],eax ; data area = rootdir + rootdir_size |
298 | mov [DATA_START],eax ; data area = rootdir + rootdir_size |
292 | 299 | ||
293 | movzx eax,word [ebx+0x13] ; total sector count <65536 |
300 | movzx eax,word [ebx+0x13] ; total sector count <65536 |
294 | test eax,eax |
301 | test eax,eax |
295 | jnz fat16_total |
302 | jnz fat16_total |
296 | mov eax,[ebx+0x20] ; total sector count |
303 | mov eax,[ebx+0x20] ; total sector count |
297 | fat16_total: |
304 | fat16_total: |
298 | add eax,[PARTITION_START] |
305 | add eax,[PARTITION_START] |
299 | dec eax |
306 | dec eax |
300 | mov [PARTITION_END],eax |
307 | mov [PARTITION_END],eax |
301 | inc eax |
308 | inc eax |
302 | sub eax,[DATA_START] ; eax = count of data sectors |
309 | sub eax,[DATA_START] ; eax = count of data sectors |
303 | xor edx,edx |
310 | xor edx,edx |
304 | div dword [SECTORS_PER_CLUSTER] |
311 | div dword [SECTORS_PER_CLUSTER] |
305 | inc eax |
312 | inc eax |
306 | mov [LAST_CLUSTER],eax |
313 | mov [LAST_CLUSTER],eax |
307 | dec eax ; cluster count |
314 | dec eax ; cluster count |
308 | 315 | ||
309 | ; limits by Microsoft Hardware White Paper v1.03 |
316 | ; limits by Microsoft Hardware White Paper v1.03 |
310 | cmp eax,4085 ; 0xff5 |
317 | cmp eax,4085 ; 0xff5 |
311 | jb problem_fat_dec_count ; fat12 not supported |
318 | jb problem_fat_dec_count ; fat12 not supported |
312 | cmp eax,65525 ; 0xfff5 |
319 | cmp eax,65525 ; 0xfff5 |
313 | jb fat16_partition |
320 | jb fat16_partition |
314 | 321 | ||
315 | fat32_partition: |
322 | fat32_partition: |
316 | mov eax,[ebx+0x2c] ; rootdir cluster |
323 | mov eax,[ebx+0x2c] ; rootdir cluster |
317 | mov [ROOT_CLUSTER],eax |
324 | mov [ROOT_CLUSTER],eax |
318 | movzx eax,word [ebx+0x30] ; fs info sector |
325 | movzx eax,word [ebx+0x30] ; fs info sector |
319 | add eax,[PARTITION_START] |
326 | add eax,[PARTITION_START] |
320 | mov [ADR_FSINFO],eax |
327 | mov [ADR_FSINFO],eax |
321 | 328 | ||
322 | popad |
329 | popad |
323 | 330 | ||
324 | mov [fatRESERVED],0x0FFFFFF6 |
331 | mov [fatRESERVED],0x0FFFFFF6 |
325 | mov [fatBAD],0x0FFFFFF7 |
332 | mov [fatBAD],0x0FFFFFF7 |
326 | mov [fatEND],0x0FFFFFF8 |
333 | mov [fatEND],0x0FFFFFF8 |
327 | mov [fatMASK],0x0FFFFFFF |
334 | mov [fatMASK],0x0FFFFFFF |
328 | mov [fat_type],32 ; Fat32 |
335 | mov [fat_type],32 ; Fat32 |
329 | mov [hd1_status],0 ; free |
336 | mov [hd1_status],0 ; free |
330 | ret |
337 | ret |
331 | 338 | ||
332 | fat16_partition: |
339 | fat16_partition: |
333 | xor eax,eax |
340 | xor eax,eax |
334 | mov [ROOT_CLUSTER],eax |
341 | mov [ROOT_CLUSTER],eax |
335 | 342 | ||
336 | popad |
343 | popad |
337 | 344 | ||
338 | mov [fatRESERVED],0x0000FFF6 |
345 | mov [fatRESERVED],0x0000FFF6 |
339 | mov [fatBAD],0x0000FFF7 |
346 | mov [fatBAD],0x0000FFF7 |
340 | mov [fatEND],0x0000FFF8 |
347 | mov [fatEND],0x0000FFF8 |
341 | mov [fatMASK],0x0000FFFF |
348 | mov [fatMASK],0x0000FFFF |
342 | mov [fat_type],16 ; Fat16 |
349 | mov [fat_type],16 ; Fat16 |
343 | mov [hd1_status],0 ; free |
350 | mov [hd1_status],0 ; free |
344 | ret65536 |
351 | ret65536 |
345 | >65536 |
352 | >65536 |
346 | >32M |
353 | >32M |
347 | >32M |
354 | >32M |
348 | >32M |
355 | >32M |
349 | >32M |
356 | >32M |
350 | >> |
357 | >> |