2007-03-26 14:18:08 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
2007-07-27 15:52:03 +02:00
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
;*************************************************************
|
|
|
|
|
;* 13.02.2010 Find all partition and check supported FS
|
2007-07-13 09:26:44 +02:00
|
|
|
|
;* 12.07.2007 Check all 4 entry of MBR and EMBR
|
|
|
|
|
;* 29.04.2006 Elimination of hangup after the
|
|
|
|
|
;* expiration hd_wait_timeout - Mario79
|
|
|
|
|
;* 28.01.2006 find all Fat16/32 partition in all input point
|
|
|
|
|
;* to MBR - Mario79
|
2006-03-28 21:32:58 +02:00
|
|
|
|
;*************************************************************
|
|
|
|
|
|
2007-01-17 15:43:18 +01:00
|
|
|
|
uglobal
|
2006-03-28 21:32:58 +02:00
|
|
|
|
align 4
|
2006-12-29 16:42:36 +01:00
|
|
|
|
|
2006-03-28 21:32:58 +02:00
|
|
|
|
;******************************************************
|
2007-03-26 14:18:08 +02:00
|
|
|
|
; Please do not change this place - variables in text
|
2006-03-28 21:32:58 +02:00
|
|
|
|
; Mario79
|
|
|
|
|
; START place
|
|
|
|
|
;******************************************************
|
|
|
|
|
PARTITION_START dd 0x3f
|
|
|
|
|
PARTITION_END dd 0
|
2010-02-13 14:34:41 +01:00
|
|
|
|
fs_type db 0 ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
|
2007-01-17 15:43:18 +01:00
|
|
|
|
align 4
|
2006-12-29 16:42:36 +01:00
|
|
|
|
|
|
|
|
|
fs_dependent_data_start:
|
|
|
|
|
; FATxx data
|
|
|
|
|
|
2006-03-28 21:32:58 +02:00
|
|
|
|
SECTORS_PER_FAT dd 0x1f3a
|
|
|
|
|
NUMBER_OF_FATS dd 0x2
|
|
|
|
|
SECTORS_PER_CLUSTER dd 0x8
|
|
|
|
|
BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes
|
|
|
|
|
ROOT_CLUSTER dd 2 ; first rootdir cluster
|
|
|
|
|
FAT_START dd 0 ; start of fat table
|
|
|
|
|
ROOT_START dd 0 ; start of rootdir (only fat16)
|
|
|
|
|
ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16)
|
|
|
|
|
DATA_START dd 0 ; start of data area (=first cluster 2)
|
|
|
|
|
LAST_CLUSTER dd 0 ; last availabe cluster
|
|
|
|
|
ADR_FSINFO dd 0 ; used only by fat32
|
|
|
|
|
|
|
|
|
|
fatRESERVED dd 0x0FFFFFF6
|
|
|
|
|
fatBAD dd 0x0FFFFFF7
|
|
|
|
|
fatEND dd 0x0FFFFFF8
|
|
|
|
|
fatMASK dd 0x0FFFFFFF
|
|
|
|
|
|
2007-10-15 16:05:52 +02:00
|
|
|
|
fatStartScan dd 2
|
|
|
|
|
|
2006-12-29 16:42:36 +01:00
|
|
|
|
fs_dependent_data_end:
|
2007-02-05 15:20:36 +01:00
|
|
|
|
file_system_data_size = $ - PARTITION_START
|
|
|
|
|
if file_system_data_size > 96
|
|
|
|
|
ERROR: sizeof(file system data) too big!
|
2010-01-23 17:01:24 +01:00
|
|
|
|
end if
|
2006-12-29 16:42:36 +01:00
|
|
|
|
|
|
|
|
|
virtual at fs_dependent_data_start
|
|
|
|
|
; NTFS data
|
|
|
|
|
ntfs_data:
|
|
|
|
|
.sectors_per_cluster dd ?
|
|
|
|
|
.mft_cluster dd ?
|
|
|
|
|
.mftmirr_cluster dd ?
|
|
|
|
|
.frs_size dd ? ; FRS size in bytes
|
|
|
|
|
.iab_size dd ? ; IndexAllocationBuffer size in bytes
|
|
|
|
|
.frs_buffer dd ?
|
|
|
|
|
.iab_buffer dd ?
|
|
|
|
|
.mft_retrieval dd ?
|
|
|
|
|
.mft_retrieval_size dd ?
|
|
|
|
|
.mft_retrieval_alloc dd ?
|
|
|
|
|
.mft_retrieval_end dd ?
|
|
|
|
|
.cur_index_size dd ?
|
|
|
|
|
.cur_index_buf dd ?
|
|
|
|
|
if $ > fs_dependent_data_end
|
|
|
|
|
ERROR: increase sizeof(fs_dependent_data)!
|
|
|
|
|
end if
|
2010-01-23 17:01:24 +01:00
|
|
|
|
end virtual
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
virtual at fs_dependent_data_start
|
|
|
|
|
; EXT2 data
|
|
|
|
|
ext2_data:
|
2010-01-23 17:01:24 +01:00
|
|
|
|
.log_block_size dd ?
|
|
|
|
|
.block_size dd ?
|
|
|
|
|
.count_block_in_block dd ?
|
|
|
|
|
.blocks_per_group dd ?
|
|
|
|
|
.inodes_per_group dd ?
|
|
|
|
|
.global_desc_table dd ?
|
|
|
|
|
.root_inode dd ? ; pointer to root inode in memory
|
|
|
|
|
.inode_size dd ?
|
|
|
|
|
.count_pointer_in_block dd ? ; block_size / 4
|
|
|
|
|
.count_pointer_in_block_square dd ? ; (block_size / 4)**2
|
|
|
|
|
.ext2_save_block dd ? ; <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD><EFBFBD>楤<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
.ext2_temp_block dd ? ; <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>楤<EFBFBD><EFBFBD>
|
|
|
|
|
.ext2_save_inode dd ? ; inode <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>楤<EFBFBD><EFBFBD><EFBFBD>
|
2010-02-17 18:26:25 +01:00
|
|
|
|
.ext2_temp_inode dd ? ; inode <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>楤<EFBFBD><EFBFBD>
|
|
|
|
|
.sb dd ? ; superblock
|
|
|
|
|
.groups_count dd ?
|
2010-01-23 16:24:03 +01:00
|
|
|
|
if $ > fs_dependent_data_end
|
|
|
|
|
ERROR: increase sizeof(fs_dependent_data)!
|
|
|
|
|
end if
|
2006-12-29 16:42:36 +01:00
|
|
|
|
end virtual
|
2010-01-23 17:01:24 +01:00
|
|
|
|
|
2006-03-28 21:32:58 +02:00
|
|
|
|
;***************************************************************************
|
|
|
|
|
; End place
|
|
|
|
|
; Mario79
|
|
|
|
|
;***************************************************************************
|
2007-01-17 15:43:18 +01:00
|
|
|
|
endg
|
|
|
|
|
iglobal
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
partition_types: ; list of fat16/32 partitions
|
|
|
|
|
db 0x04 ; DOS: fat16 <32M
|
|
|
|
|
db 0x06 ; DOS: fat16 >32M
|
|
|
|
|
db 0x0b ; WIN95: fat32
|
|
|
|
|
db 0x0c ; WIN95: fat32, LBA-mapped
|
|
|
|
|
db 0x0e ; WIN95: fat16, LBA-mapped
|
|
|
|
|
db 0x14 ; Hidden DOS: fat16 <32M
|
|
|
|
|
db 0x16 ; Hidden DOS: fat16 >32M
|
|
|
|
|
db 0x1b ; Hidden WIN95: fat32
|
|
|
|
|
db 0x1c ; Hidden WIN95: fat32, LBA-mapped
|
|
|
|
|
db 0x1e ; Hidden WIN95: fat16, LBA-mapped
|
|
|
|
|
db 0xc4 ; DRDOS/secured: fat16 <32M
|
|
|
|
|
db 0xc6 ; DRDOS/secured: fat16 >32M
|
|
|
|
|
db 0xcb ; DRDOS/secured: fat32
|
|
|
|
|
db 0xcc ; DRDOS/secured: fat32, LBA-mapped
|
|
|
|
|
db 0xce ; DRDOS/secured: fat16, LBA-mapped
|
|
|
|
|
db 0xd4 ; Old Multiuser DOS secured: fat16 <32M
|
|
|
|
|
db 0xd6 ; Old Multiuser DOS secured: fat16 >32M
|
2006-12-29 16:42:36 +01:00
|
|
|
|
db 0x07 ; NTFS
|
2010-01-23 17:01:24 +01:00
|
|
|
|
db 0x27 ; NTFS, hidden
|
2010-01-23 16:24:03 +01:00
|
|
|
|
db 0x83 ; Linux native file system (ext2fs)
|
2006-03-28 21:32:58 +02:00
|
|
|
|
partition_types_end:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extended_types: ; list of extended partitions
|
|
|
|
|
db 0x05 ; DOS: extended partition
|
|
|
|
|
db 0x0f ; WIN95: extended partition, LBA-mapped
|
|
|
|
|
db 0xc5 ; DRDOS/secured: extended partition
|
|
|
|
|
db 0xd5 ; Old Multiuser DOS secured: extended partition
|
|
|
|
|
extended_types_end:
|
|
|
|
|
|
|
|
|
|
endg
|
|
|
|
|
|
|
|
|
|
; Partition chain used:
|
2010-01-23 17:01:24 +01:00
|
|
|
|
; MBR <---------------------
|
|
|
|
|
; | |
|
|
|
|
|
; |-> PARTITION1 |
|
|
|
|
|
; |-> EXTENDED PARTITION - ;not need be second partition
|
|
|
|
|
; |-> PARTITION3
|
|
|
|
|
; |-> PARTITION4
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
set_PARTITION_variables:
|
|
|
|
|
set_FAT32_variables: ;deprecated
|
2010-02-13 14:34:41 +01:00
|
|
|
|
and [problem_partition], 0
|
2006-03-28 21:32:58 +02:00
|
|
|
|
call reserve_hd1
|
2007-02-05 15:20:36 +01:00
|
|
|
|
call reserve_hd_channel
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2008-02-04 16:31:59 +01:00
|
|
|
|
pushad
|
|
|
|
|
|
2006-03-28 21:32:58 +02:00
|
|
|
|
cmp dword [hdpos],0
|
|
|
|
|
je problem_hd
|
|
|
|
|
|
|
|
|
|
xor ecx,ecx ; partition count
|
2010-02-13 14:34:41 +01:00
|
|
|
|
;or edx,-1 ; flag for partition
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor eax,eax ; address MBR
|
2006-03-28 21:32:58 +02:00
|
|
|
|
xor ebp,ebp ; extended partition start
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
new_mbr:
|
|
|
|
|
test ebp,ebp ; is there extended partition? (MBR or EMBR)
|
2006-03-28 21:32:58 +02:00
|
|
|
|
jnz extended_already_set ; yes
|
|
|
|
|
xchg ebp,eax ; no. set it now
|
|
|
|
|
|
|
|
|
|
extended_already_set:
|
|
|
|
|
add eax,ebp ; mbr=mbr+0, ext_part=ext_start+relat_start
|
|
|
|
|
mov ebx,buffer
|
|
|
|
|
call hd_read
|
2006-04-29 15:10:34 +02:00
|
|
|
|
cmp [hd_error],0
|
|
|
|
|
jne problem_hd
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jnz end_partition_chain
|
|
|
|
|
push eax ; push only one time
|
2006-03-28 21:32:58 +02:00
|
|
|
|
cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_0
|
2007-07-13 09:26:44 +02:00
|
|
|
|
cmp dword [ebx+0x1be+0xc+16],0
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_1
|
2007-07-13 09:26:44 +02:00
|
|
|
|
cmp dword [ebx+0x1be+0xc+16+16],0
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_2
|
2007-07-13 09:26:44 +02:00
|
|
|
|
cmp dword [ebx+0x1be+0xc+16+16+16],0
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jnz test_primary_partition_3
|
|
|
|
|
pop eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jmp end_partition_chain
|
|
|
|
|
|
|
|
|
|
test_primary_partition_0:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4] ; get primary partition type
|
|
|
|
|
call scan_partition_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_1 ; no. skip over
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
inc ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp ecx,[known_part] ; is it wanted partition?
|
|
|
|
|
jnz test_primary_partition_1 ; no
|
2010-02-13 14:34:41 +01:00
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
;mov edx, eax ; start sector
|
|
|
|
|
add eax, [ebx+0x1be+8] ; add relative start
|
|
|
|
|
;mov [PARTITON_START],edx
|
|
|
|
|
;push edx
|
|
|
|
|
mov edx, [ebx+0x1be+12] ; length
|
|
|
|
|
;add edx, eax ; add length
|
|
|
|
|
;dec edx ; PARTITION_END is inclusive
|
|
|
|
|
;mov [PARTITION_END], edx ; note that this can be changed
|
2006-12-29 16:42:36 +01:00
|
|
|
|
; when file system data will be available
|
2010-02-13 14:34:41 +01:00
|
|
|
|
mov cl, [ebx+0x1be+4] ; fs_type
|
|
|
|
|
;mov [fs_type], dl ; save for FS recognizer (separate FAT vs NTFS)
|
|
|
|
|
;pop edx
|
|
|
|
|
jmp hd_and_partition_ok
|
2006-12-29 16:42:36 +01:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
test_primary_partition_1:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16] ; get primary partition type
|
|
|
|
|
call scan_partition_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_2 ; no. skip over
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
inc ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp ecx,[known_part] ; is it wanted partition?
|
|
|
|
|
jnz test_primary_partition_2 ; no
|
2010-02-13 14:34:41 +01:00
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
add eax, [ebx+0x1be+8+16]
|
|
|
|
|
mov edx, [ebx+0x1be+12+16]
|
|
|
|
|
mov cl, [ebx+0x1be+4+16]
|
|
|
|
|
jmp hd_and_partition_ok
|
|
|
|
|
|
|
|
|
|
;mov edx, eax
|
|
|
|
|
;add edx, [ebx+0x1be+8+16]
|
|
|
|
|
;push edx
|
|
|
|
|
;add edx, [ebx+0x1be+12+16]
|
|
|
|
|
;dec edx
|
|
|
|
|
;mov [PARTITION_END], edx
|
|
|
|
|
;mov al, [ebx+0x1be+4+16]
|
|
|
|
|
;mov [fs_type], dl
|
|
|
|
|
;pop edx
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
test_primary_partition_2:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16+16] ; get primary partition type
|
|
|
|
|
call scan_partition_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_primary_partition_3 ; no. skip over
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
inc ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp ecx,[known_part] ; is it wanted partition?
|
|
|
|
|
jnz test_primary_partition_3 ; no
|
2010-02-13 14:34:41 +01:00
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
add eax, [ebx+0x1be+8+16+16]
|
|
|
|
|
mov edx, [ebx+0x1be+12+16+16]
|
|
|
|
|
mov cl, [ebx+0x1be+4+16+16]
|
|
|
|
|
jmp hd_and_partition_ok
|
|
|
|
|
;mov edx, eax
|
|
|
|
|
;add edx, [ebx+0x1be+8+16+16]
|
|
|
|
|
;push edx
|
|
|
|
|
;add edx, [ebx+0x1be+12+16+16]
|
|
|
|
|
;dec edx
|
|
|
|
|
;mov [PARTITION_END], edx
|
|
|
|
|
;mov al, [ebx+0x1be+4+16+16]
|
|
|
|
|
;mov [fs_type], dl
|
|
|
|
|
;pop edx
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
test_primary_partition_3:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type
|
|
|
|
|
call scan_partition_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_ext_partition_0 ; no. skip over
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
inc ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp ecx,[known_part] ; is it wanted partition?
|
|
|
|
|
jnz test_ext_partition_0 ; no
|
2010-02-13 14:34:41 +01:00
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
add eax, [ebx+0x1be+8+16+16+16]
|
|
|
|
|
mov edx, [ebx+0x1be+12+16+16+16]
|
|
|
|
|
mov cl, [ebx+0x1be+4+16+16+16]
|
|
|
|
|
jmp hd_and_partition_ok
|
|
|
|
|
|
|
|
|
|
;mov edx, eax
|
|
|
|
|
;add edx, [ebx+0x1be+8+16+16+16]
|
|
|
|
|
;push edx
|
|
|
|
|
;add edx, [ebx+0x1be+12+16+16+16]
|
|
|
|
|
;dec edx
|
|
|
|
|
;mov [PARTITION_END], edx
|
|
|
|
|
;mov al, [ebx+0x1be+4+16+16+16]
|
|
|
|
|
;mov [fs_type], dl
|
|
|
|
|
;pop edx
|
|
|
|
|
|
|
|
|
|
test_ext_partition_0:
|
|
|
|
|
pop eax ; <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>모<EFBFBD>뢠<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD>⥪<EFBFBD>
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4] ; get extended partition type
|
|
|
|
|
call scan_extended_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_ext_partition_1
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
mov eax,[ebx+0x1be+8] ; add relative start
|
|
|
|
|
test eax,eax ; is there extended partition?
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz new_mbr ; yes. read it
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
test_ext_partition_1:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16] ; get extended partition type
|
|
|
|
|
call scan_extended_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_ext_partition_2
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax,[ebx+0x1be+8+16] ; add relative start
|
2006-03-28 21:32:58 +02:00
|
|
|
|
test eax,eax ; is there extended partition?
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz new_mbr ; yes. read it
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
test_ext_partition_2:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16+16] ; get extended partition type
|
|
|
|
|
call scan_extended_types
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz test_ext_partition_3
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
mov eax,[ebx+0x1be+8+16+16] ; add relative start
|
|
|
|
|
test eax,eax ; is there extended partition?
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz new_mbr ; yes. read it
|
|
|
|
|
|
|
|
|
|
test_ext_partition_3:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type
|
|
|
|
|
call scan_extended_types
|
|
|
|
|
jnz end_partition_chain ; no. end chain
|
|
|
|
|
|
|
|
|
|
mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition
|
|
|
|
|
test eax,eax ; is there extended partition?
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz new_mbr ; yes. read it
|
|
|
|
|
|
2006-03-28 21:32:58 +02:00
|
|
|
|
end_partition_chain:
|
2010-02-13 14:34:41 +01:00
|
|
|
|
;mov [partition_count],ecx
|
|
|
|
|
|
|
|
|
|
;cmp edx,-1 ; found wanted partition?
|
|
|
|
|
;jnz hd_and_partition_ok ; yes. install it
|
|
|
|
|
;jmp problem_partition_or_fat
|
|
|
|
|
problem_hd:
|
|
|
|
|
or [problem_partition], 2
|
|
|
|
|
jmp return_from_part_set
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scan_partition_types:
|
|
|
|
|
push ecx
|
|
|
|
|
mov edi,partition_types
|
|
|
|
|
mov ecx,partition_types_end-partition_types
|
|
|
|
|
cld
|
|
|
|
|
repne scasb ; is partition type ok?
|
|
|
|
|
pop ecx
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
scan_extended_types:
|
|
|
|
|
push ecx
|
|
|
|
|
mov edi,extended_types
|
|
|
|
|
mov ecx,extended_types_end-extended_types
|
|
|
|
|
cld
|
|
|
|
|
repne scasb ; is it extended partition?
|
|
|
|
|
pop ecx
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
problem_fat_dec_count: ; bootsector is missing or another problem
|
2010-02-13 14:34:41 +01:00
|
|
|
|
; dec [partition_count] ; remove it from partition_count
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
problem_partition_or_fat:
|
2010-02-13 14:34:41 +01:00
|
|
|
|
or [problem_partition],1
|
|
|
|
|
|
|
|
|
|
return_from_part_set:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
popad
|
2010-02-13 14:34:41 +01:00
|
|
|
|
;mov [fs_type],0
|
2007-02-05 15:20:36 +01:00
|
|
|
|
call free_hd_channel
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov [hd1_status],0 ; free
|
|
|
|
|
ret
|
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
hd_and_partition_ok:
|
|
|
|
|
|
|
|
|
|
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
|
|
|
|
|
mov [fs_type], cl
|
|
|
|
|
;mov eax,edx
|
|
|
|
|
mov [PARTITION_START],eax
|
|
|
|
|
add edx, eax
|
|
|
|
|
dec edx
|
|
|
|
|
mov [PARTITION_END], edx
|
|
|
|
|
|
|
|
|
|
; mov edx, [PARTITION_END]
|
|
|
|
|
; sub edx, eax
|
|
|
|
|
; inc edx ; edx = length of partition <EFBFBD><EFBFBD>祬 <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>??
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
2006-12-29 16:42:36 +01:00
|
|
|
|
; mov [hd_setup],1
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov ebx,buffer
|
|
|
|
|
call hd_read ; read boot sector of partition
|
2006-12-29 16:42:36 +01:00
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jz boot_read_ok
|
|
|
|
|
cmp [fs_type], 7
|
|
|
|
|
jnz problem_fat_dec_count
|
|
|
|
|
; NTFS duplicates bootsector:
|
|
|
|
|
; NT4/2k/XP+ saves bootsector copy in the end of disk
|
|
|
|
|
; NT 3.51 saves bootsector copy in the middle of disk
|
|
|
|
|
and [hd_error], 0
|
|
|
|
|
mov eax, [PARTITION_END]
|
|
|
|
|
call hd_read
|
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jnz @f
|
|
|
|
|
call ntfs_test_bootsec
|
|
|
|
|
jnc boot_read_ok
|
|
|
|
|
@@:
|
|
|
|
|
and [hd_error], 0
|
|
|
|
|
mov eax, edx
|
|
|
|
|
shr eax, 1
|
|
|
|
|
add eax, [PARTITION_START]
|
|
|
|
|
call hd_read
|
|
|
|
|
cmp [hd_error], 0
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jnz problem_fat_dec_count ; no chance...
|
2006-12-29 16:42:36 +01:00
|
|
|
|
boot_read_ok:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2006-12-29 16:42:36 +01:00
|
|
|
|
; if we are running on NTFS, check bootsector
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
call ntfs_test_bootsec ; test ntfs
|
2010-01-23 17:01:24 +01:00
|
|
|
|
jnc ntfs_setup
|
|
|
|
|
|
|
|
|
|
call ext2_test_superblock ; test ext2fs
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jnc ext2_setup
|
2010-01-23 17:01:24 +01:00
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
mov eax, [PARTITION_START] ;ext2 test changes [buffer]
|
|
|
|
|
call hd_read
|
2010-01-23 17:01:24 +01:00
|
|
|
|
cmp [hd_error], 0
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jnz problem_fat_dec_count
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
|
|
|
|
|
jnz problem_fat_dec_count
|
|
|
|
|
|
|
|
|
|
movzx eax,word [ebx+0xe] ; sectors reserved
|
|
|
|
|
add eax,[PARTITION_START]
|
|
|
|
|
mov [FAT_START],eax ; fat_start = partition_start + reserved
|
|
|
|
|
|
|
|
|
|
movzx eax,byte [ebx+0xd] ; sectors per cluster
|
2009-10-02 18:43:58 +02:00
|
|
|
|
test eax,eax
|
|
|
|
|
jz problem_fat_dec_count
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov [SECTORS_PER_CLUSTER],eax
|
|
|
|
|
|
|
|
|
|
movzx ecx,word [ebx+0xb] ; bytes per sector
|
2009-10-02 18:45:18 +02:00
|
|
|
|
cmp ecx,0x200
|
2009-10-02 18:43:58 +02:00
|
|
|
|
jnz problem_fat_dec_count
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov [BYTES_PER_SECTOR],ecx
|
|
|
|
|
|
|
|
|
|
movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32)
|
|
|
|
|
mov edx,32
|
|
|
|
|
mul edx
|
|
|
|
|
dec ecx
|
|
|
|
|
add eax,ecx ; round up if not equal count
|
|
|
|
|
inc ecx ; bytes per sector
|
|
|
|
|
div ecx
|
|
|
|
|
mov [ROOT_SECTORS],eax ; count of rootdir sectors
|
|
|
|
|
|
|
|
|
|
movzx eax,word [ebx+0x16] ; sectors per fat <65536
|
|
|
|
|
test eax,eax
|
|
|
|
|
jnz fat16_fatsize
|
|
|
|
|
mov eax,[ebx+0x24] ; sectors per fat
|
|
|
|
|
fat16_fatsize:
|
|
|
|
|
mov [SECTORS_PER_FAT],eax
|
|
|
|
|
|
|
|
|
|
movzx eax,byte [ebx+0x10] ; number of fats
|
|
|
|
|
test eax,eax ; if 0 it's not fat partition
|
|
|
|
|
jz problem_fat_dec_count
|
|
|
|
|
mov [NUMBER_OF_FATS],eax
|
|
|
|
|
imul eax,[SECTORS_PER_FAT]
|
|
|
|
|
add eax,[FAT_START]
|
|
|
|
|
mov [ROOT_START],eax ; rootdir = fat_start + fat_size * fat_count
|
|
|
|
|
add eax,[ROOT_SECTORS] ; rootdir sectors should be 0 on fat32
|
|
|
|
|
mov [DATA_START],eax ; data area = rootdir + rootdir_size
|
|
|
|
|
|
|
|
|
|
movzx eax,word [ebx+0x13] ; total sector count <65536
|
|
|
|
|
test eax,eax
|
|
|
|
|
jnz fat16_total
|
|
|
|
|
mov eax,[ebx+0x20] ; total sector count
|
|
|
|
|
fat16_total:
|
|
|
|
|
add eax,[PARTITION_START]
|
|
|
|
|
dec eax
|
|
|
|
|
mov [PARTITION_END],eax
|
|
|
|
|
inc eax
|
|
|
|
|
sub eax,[DATA_START] ; eax = count of data sectors
|
|
|
|
|
xor edx,edx
|
|
|
|
|
div dword [SECTORS_PER_CLUSTER]
|
|
|
|
|
inc eax
|
|
|
|
|
mov [LAST_CLUSTER],eax
|
|
|
|
|
dec eax ; cluster count
|
2007-10-15 16:05:52 +02:00
|
|
|
|
mov [fatStartScan],2
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
; limits by Microsoft Hardware White Paper v1.03
|
|
|
|
|
cmp eax,4085 ; 0xff5
|
|
|
|
|
jb problem_fat_dec_count ; fat12 not supported
|
|
|
|
|
cmp eax,65525 ; 0xfff5
|
|
|
|
|
jb fat16_partition
|
|
|
|
|
|
|
|
|
|
fat32_partition:
|
|
|
|
|
mov eax,[ebx+0x2c] ; rootdir cluster
|
|
|
|
|
mov [ROOT_CLUSTER],eax
|
|
|
|
|
movzx eax,word [ebx+0x30] ; fs info sector
|
|
|
|
|
add eax,[PARTITION_START]
|
|
|
|
|
mov [ADR_FSINFO],eax
|
2007-10-15 16:05:52 +02:00
|
|
|
|
call hd_read
|
|
|
|
|
mov eax,[ebx+0x1ec]
|
|
|
|
|
cmp eax,-1
|
|
|
|
|
jz @f
|
|
|
|
|
mov [fatStartScan],eax
|
|
|
|
|
@@:
|
2006-03-28 21:32:58 +02:00
|
|
|
|
|
|
|
|
|
popad
|
|
|
|
|
|
|
|
|
|
mov [fatRESERVED],0x0FFFFFF6
|
|
|
|
|
mov [fatBAD],0x0FFFFFF7
|
|
|
|
|
mov [fatEND],0x0FFFFFF8
|
|
|
|
|
mov [fatMASK],0x0FFFFFFF
|
2006-12-29 16:42:36 +01:00
|
|
|
|
mov [fs_type],32 ; Fat32
|
2007-02-05 15:20:36 +01:00
|
|
|
|
call free_hd_channel
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov [hd1_status],0 ; free
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
fat16_partition:
|
|
|
|
|
xor eax,eax
|
|
|
|
|
mov [ROOT_CLUSTER],eax
|
|
|
|
|
|
|
|
|
|
popad
|
|
|
|
|
|
|
|
|
|
mov [fatRESERVED],0x0000FFF6
|
|
|
|
|
mov [fatBAD],0x0000FFF7
|
|
|
|
|
mov [fatEND],0x0000FFF8
|
|
|
|
|
mov [fatMASK],0x0000FFFF
|
2006-12-29 16:42:36 +01:00
|
|
|
|
mov [fs_type],16 ; Fat16
|
2007-02-05 15:20:36 +01:00
|
|
|
|
call free_hd_channel
|
2006-03-28 21:32:58 +02:00
|
|
|
|
mov [hd1_status],0 ; free
|
2010-02-13 14:34:41 +01:00
|
|
|
|
ret
|
|
|
|
|
|