Rev 63 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 63 | Rev 65 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | ;; ;; |
6 | ;; ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; See file COPYING for details ;; |
9 | ;; See file COPYING for details ;; |
10 | ;; ;; |
10 | ;; ;; |
- | 11 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
|
- | 12 | ;; to MBR, see file part_set.inc - Mario79 ;; |
|
11 | ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; |
13 | ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; |
12 | ;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;; |
14 | ;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;; |
13 | ;; 29.11.2004 get_free_FAT changed, append dir bug fixed - ATV ;; |
15 | ;; 29.11.2004 get_free_FAT changed, append dir bug fixed - ATV ;; |
14 | ;; 23.11.2004 don't allow overwrite dir with file - ATV ;; |
16 | ;; 23.11.2004 don't allow overwrite dir with file - ATV ;; |
15 | ;; 18.11.2004 get_disk_info and more error codes - ATV ;; |
17 | ;; 18.11.2004 get_disk_info and more error codes - ATV ;; |
Line 49... | Line 51... | ||
49 | PUSHAD_EBX equ [esp+16] |
51 | PUSHAD_EBX equ [esp+16] |
50 | PUSHAD_EBP equ [esp+8] |
52 | PUSHAD_EBP equ [esp+8] |
51 | PUSHAD_ESI equ [esp+4] |
53 | PUSHAD_ESI equ [esp+4] |
52 | PUSHAD_EDI equ [esp+0] |
54 | PUSHAD_EDI equ [esp+0] |
Line 53... | Line -... | ||
53 | - | ||
54 | align 4 |
- | |
55 | ;****************************************************** |
- | |
56 | ; Please do not change this place - variables in text |
- | |
57 | ; Mario79 |
- | |
58 | ; START place |
- | |
59 | ;****************************************************** |
- | |
60 | PARTITION_START dd 0x3f |
- | |
61 | PARTITION_END dd 0 |
- | |
62 | SECTORS_PER_FAT dd 0x1f3a |
- | |
63 | NUMBER_OF_FATS dd 0x2 |
- | |
64 | SECTORS_PER_CLUSTER dd 0x8 |
- | |
65 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
- | |
66 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
- | |
67 | FAT_START dd 0 ; start of fat table |
- | |
68 | ROOT_START dd 0 ; start of rootdir (only fat16) |
- | |
69 | ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16) |
- | |
70 | DATA_START dd 0 ; start of data area (=first cluster 2) |
- | |
71 | LAST_CLUSTER dd 0 ; last availabe cluster |
- | |
72 | ADR_FSINFO dd 0 ; used only by fat32 |
- | |
73 | - | ||
74 | fatRESERVED dd 0x0FFFFFF6 |
- | |
75 | fatBAD dd 0x0FFFFFF7 |
- | |
76 | fatEND dd 0x0FFFFFF8 |
- | |
77 | fatMASK dd 0x0FFFFFFF |
- | |
78 | - | ||
79 | fat_type db 0 ; 0=none, 16=fat16, 32=fat32 |
- | |
80 | ;*************************************************************************** |
- | |
81 | ; End place |
- | |
82 | ; Mario79 |
- | |
83 | ;*************************************************************************** |
55 | |
84 | cluster dd 0 ; used by file_write,makedir,append |
56 | cluster dd 0 ; used by file_write,makedir,append |
85 | partition_count dd 0 ; partitions found by set_FAT32_variables |
57 | partition_count dd 0 ; partitions found by set_FAT32_variables |
86 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
58 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
Line 129... | Line 101... | ||
129 | f_del db 0 ; 1=overwrite fat entry |
101 | f_del db 0 ; 1=overwrite fat entry |
130 | fat_change db 0 ; 1=fat has changed |
102 | fat_change db 0 ; 1=fat has changed |
Line 131... | Line 103... | ||
131 | 103 | ||
Line 132... | Line -... | ||
132 | endg |
- | |
133 | - | ||
134 | iglobal |
- | |
135 | partition_types: ; list of fat16/32 partitions |
- | |
136 | db 0x04 ; DOS: fat16 <32M |
- | |
137 | db 0x06 ; DOS: fat16 >32M |
- | |
138 | db 0x0b ; WIN95: fat32 |
- | |
139 | db 0x0c ; WIN95: fat32, LBA-mapped |
- | |
140 | db 0x0e ; WIN95: fat16, LBA-mapped |
- | |
141 | db 0x14 ; Hidden DOS: fat16 <32M |
- | |
142 | db 0x16 ; Hidden DOS: fat16 >32M |
- | |
143 | db 0x1b ; Hidden WIN95: fat32 |
- | |
144 | db 0x1c ; Hidden WIN95: fat32, LBA-mapped |
- | |
145 | db 0x1e ; Hidden WIN95: fat16, LBA-mapped |
- | |
146 | db 0xc4 ; DRDOS/secured: fat16 <32M |
- | |
147 | db 0xc6 ; DRDOS/secured: fat16 >32M |
- | |
148 | db 0xcb ; DRDOS/secured: fat32 |
- | |
149 | db 0xcc ; DRDOS/secured: fat32, LBA-mapped |
- | |
150 | db 0xce ; DRDOS/secured: fat16, LBA-mapped |
- | |
151 | db 0xd4 ; Old Multiuser DOS secured: fat16 <32M |
- | |
152 | db 0xd6 ; Old Multiuser DOS secured: fat16 >32M |
- | |
153 | partition_types_end: |
- | |
154 | - | ||
155 | - | ||
156 | extended_types: ; list of extended partitions |
- | |
157 | db 0x05 ; DOS: extended partition |
- | |
158 | db 0x0f ; WIN95: extended partition, LBA-mapped |
- | |
159 | db 0xc5 ; DRDOS/secured: extended partition |
- | |
160 | db 0xd5 ; Old Multiuser DOS secured: extended partition |
- | |
161 | extended_types_end: |
- | |
162 | - | ||
163 | endg |
- | |
164 | 104 | endg |
|
Line 165... | Line 105... | ||
165 | 105 | ||
166 | reserve_hd1: |
106 | reserve_hd1: |
167 | 107 | ||
Line 199... | Line 139... | ||
199 | pop edi ecx eax |
139 | pop edi ecx eax |
200 | ret |
140 | ret |
Line 201... | Line 141... | ||
201 | 141 | ||
Line 202... | Line -... | ||
202 | problem_partition db 0 ; used for partitions search |
- | |
203 | - | ||
204 | ; Partition chain used: |
- | |
205 | ; MBR ; PARTITION2 ; PARTITION3 ; PARTITION4 |
- | |
206 | ;========================================================== |
- | |
207 | ; fat16/32 +-- fat16/32 +-- fat16/32 +-- fat16/32 +-- |
- | |
208 | ; extended --+ extended --+ extended --+ extended --+ |
- | |
209 | ; 0 0 0 0 |
- | |
210 | ; 0 0 0 0 |
- | |
211 | ; Notes: |
- | |
212 | ; - extended partition need to be in second entry on table |
- | |
213 | ; - it will skip over removed partitions |
- | |
214 | - | ||
215 | set_FAT32_variables: |
- | |
216 | mov [0xfe10],dword 0 ; entries in hd cache |
- | |
217 | mov [problem_partition],0 |
- | |
218 | call reserve_hd1 |
- | |
219 | call clear_hd_cache |
- | |
220 | - | ||
221 | cmp dword [hdpos],0 |
- | |
222 | je problem_hd |
- | |
223 | - | ||
224 | pushad |
- | |
225 | xor ecx,ecx ; partition count |
- | |
226 | mov edx,-1 ; flag for partition |
- | |
227 | xor eax,eax ; read MBR |
- | |
228 | xor ebp,ebp ; extended partition start |
- | |
229 | - | ||
230 | new_partition: |
- | |
231 | test ebp,ebp ; is there extended partition? |
- | |
232 | jnz extended_already_set ; yes |
- | |
233 | xchg ebp,eax ; no. set it now |
- | |
234 | - | ||
235 | extended_already_set: |
- | |
236 | add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start |
- | |
237 | mov ebx,buffer |
- | |
238 | call hd_read |
- | |
239 | - | ||
240 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
- | |
241 | jnz end_partition_chain |
- | |
242 | cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition |
- | |
243 | jz next_partition |
- | |
244 | - | ||
245 | push eax ecx |
- | |
246 | mov edi,partition_types |
- | |
247 | mov ecx,partition_types_end-partition_types |
- | |
248 | mov al,[ebx+0x1be+4] ; get partition type |
- | |
249 | cld |
- | |
250 | repne scasb ; is partition type ok? |
- | |
251 | pop ecx eax |
- | |
252 | jnz next_partition ; no. skip over |
- | |
253 | - | ||
254 | inc ecx |
- | |
255 | cmp ecx,[fat32part] ; is it wanted partition? |
- | |
256 | jnz next_partition ; no |
- | |
257 | - | ||
258 | mov edx,eax ; start sector |
- | |
259 | add edx,[ebx+0x1be+8] ; add relative start |
- | |
260 | - | ||
261 | next_partition: |
- | |
262 | push ecx |
- | |
263 | mov edi,extended_types |
- | |
264 | mov ecx,extended_types_end-extended_types |
- | |
265 | mov al,[ebx+0x1be+4+16] ; get second partition type |
- | |
266 | cld |
- | |
267 | repne scasb ; is it extended partition? |
- | |
268 | pop ecx |
- | |
269 | jnz end_partition_chain ; no. end chain |
- | |
270 | - | ||
271 | mov eax,[ebx+0x1be+8+16] ; get start of extended partition |
- | |
272 | test eax,eax ; is there extended partition? |
- | |
273 | jnz new_partition ; yes. read it |
- | |
274 | - | ||
275 | end_partition_chain: |
- | |
276 | mov [partition_count],ecx |
- | |
277 | - | ||
278 | cmp edx,-1 ; found wanted partition? |
- | |
279 | jnz hd_and_partition_ok ; yes. install it |
- | |
280 | jmp problem_partition_or_fat |
- | |
281 | - | ||
282 | problem_fat_dec_count: ; bootsector is missing or another problem |
- | |
283 | dec [partition_count] ; remove it from partition_count |
- | |
284 | - | ||
285 | problem_partition_or_fat: |
- | |
286 | popad |
- | |
287 | - | ||
288 | problem_hd: |
- | |
289 | mov [fat_type],0 |
- | |
290 | mov [hd1_status],0 ; free |
- | |
291 | mov [problem_partition],1 |
- | |
292 | ret |
- | |
293 | - | ||
294 | hd_and_partition_ok: |
- | |
295 | mov eax,edx |
- | |
296 | mov [PARTITION_START],eax |
- | |
297 | - | ||
298 | mov [hd_setup],1 |
- | |
299 | mov ebx,buffer |
142 | problem_partition db 0 ; used for partitions search |
300 | call hd_read ; read boot sector of partition |
- | |
301 | mov [hd_setup],0 |
- | |
302 | - | ||
303 | cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? |
- | |
304 | jnz problem_fat_dec_count |
- | |
305 | - | ||
306 | movzx eax,word [ebx+0xe] ; sectors reserved |
- | |
307 | add eax,[PARTITION_START] |
- | |
308 | mov [FAT_START],eax ; fat_start = partition_start + reserved |
- | |
309 | - | ||
310 | movzx eax,byte [ebx+0xd] ; sectors per cluster |
- | |
311 | mov [SECTORS_PER_CLUSTER],eax |
- | |
312 | - | ||
313 | movzx ecx,word [ebx+0xb] ; bytes per sector |
- | |
314 | mov [BYTES_PER_SECTOR],ecx |
- | |
315 | - | ||
316 | movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32) |
- | |
317 | mov edx,32 |
- | |
318 | mul edx |
- | |
319 | dec ecx |
- | |
320 | add eax,ecx ; round up if not equal count |
- | |
321 | inc ecx ; bytes per sector |
- | |
322 | div ecx |
- | |
323 | mov [ROOT_SECTORS],eax ; count of rootdir sectors |
- | |
324 | - | ||
325 | movzx eax,word [ebx+0x16] ; sectors per fat <65536 |
- | |
326 | test eax,eax |
- | |
327 | jnz fat16_fatsize |
- | |
328 | mov eax,[ebx+0x24] ; sectors per fat |
- | |
329 | fat16_fatsize: |
- | |
330 | mov [SECTORS_PER_FAT],eax |
- | |
331 | - | ||
332 | movzx eax,byte [ebx+0x10] ; number of fats |
- | |
333 | test eax,eax ; if 0 it's not fat partition |
- | |
334 | jz problem_fat_dec_count |
- | |
335 | mov [NUMBER_OF_FATS],eax |
- | |
336 | imul eax,[SECTORS_PER_FAT] |
- | |
337 | add eax,[FAT_START] |
- | |
338 | mov [ROOT_START],eax ; rootdir = fat_start + fat_size * fat_count |
- | |
339 | add eax,[ROOT_SECTORS] ; rootdir sectors should be 0 on fat32 |
- | |
340 | mov [DATA_START],eax ; data area = rootdir + rootdir_size |
- | |
341 | - | ||
342 | movzx eax,word [ebx+0x13] ; total sector count <65536 |
- | |
343 | test eax,eax |
- | |
344 | jnz fat16_total |
- | |
345 | mov eax,[ebx+0x20] ; total sector count |
- | |
346 | fat16_total: |
- | |
347 | add eax,[PARTITION_START] |
- | |
348 | dec eax |
- | |
349 | mov [PARTITION_END],eax |
- | |
350 | inc eax |
- | |
351 | sub eax,[DATA_START] ; eax = count of data sectors |
- | |
352 | xor edx,edx |
- | |
353 | div dword [SECTORS_PER_CLUSTER] |
- | |
354 | inc eax |
- | |
355 | mov [LAST_CLUSTER],eax |
- | |
356 | dec eax ; cluster count |
- | |
357 | - | ||
358 | ; limits by Microsoft Hardware White Paper v1.03 |
- | |
359 | cmp eax,4085 ; 0xff5 |
- | |
360 | jb problem_fat_dec_count ; fat12 not supported |
- | |
361 | cmp eax,65525 ; 0xfff5 |
- | |
362 | jb fat16_partition |
- | |
363 | - | ||
364 | fat32_partition: |
- | |
365 | mov eax,[ebx+0x2c] ; rootdir cluster |
- | |
366 | mov [ROOT_CLUSTER],eax |
- | |
367 | movzx eax,word [ebx+0x30] ; fs info sector |
- | |
368 | add eax,[PARTITION_START] |
- | |
369 | mov [ADR_FSINFO],eax |
- | |
370 | - | ||
371 | popad |
- | |
372 | - | ||
373 | mov [fatRESERVED],0x0FFFFFF6 |
- | |
374 | mov [fatBAD],0x0FFFFFF7 |
- | |
375 | mov [fatEND],0x0FFFFFF8 |
- | |
376 | mov [fatMASK],0x0FFFFFFF |
- | |
377 | mov [fat_type],32 ; Fat32 |
- | |
378 | mov [hd1_status],0 ; free |
- | |
379 | ret |
- | |
380 | - | ||
381 | fat16_partition: |
- | |
382 | xor eax,eax |
- | |
383 | mov [ROOT_CLUSTER],eax |
- | |
384 | - | ||
385 | popad |
- | |
386 | - | ||
387 | mov [fatRESERVED],0x0000FFF6 |
- | |
388 | mov [fatBAD],0x0000FFF7 |
- | |
389 | mov [fatEND],0x0000FFF8 |
- | |
390 | mov [fatMASK],0x0000FFFF |
- | |
391 | mov [fat_type],16 ; Fat16 |
- | |
392 | mov [hd1_status],0 ; free |
- | |
Line 393... | Line 143... | ||
393 | ret |
143 | |
394 | 144 | include 'part_set.inc' |
|
395 | 145 | ||
396 | set_FAT: |
146 | set_FAT: |