reworked search partition on HDD

git-svn-id: svn://kolibrios.org@1410 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbanoff 2010-02-13 13:34:41 +00:00
parent acfa104846
commit 7f6ce667e1
3 changed files with 165 additions and 134 deletions

View File

@ -23,11 +23,16 @@ $Revision$
mov [known_part],1 mov [known_part],1
search_partitions_ide0_1: search_partitions_ide0_1:
call set_PARTITION_variables call set_PARTITION_variables
cmp [problem_partition],0 test [problem_partition],2
jne search_partitions_ide1 jnz search_partitions_ide1 ; not found part
test [problem_partition],1
jnz @F ; not found known_part
;cmp [problem_partition],0
;jne search_partitions_ide1
inc byte [DRIVE_DATA+2] inc byte [DRIVE_DATA+2]
call partition_data_transfer call partition_data_transfer
add [transfer_adress],100 add [transfer_adress],100
@@:
inc [known_part] inc [known_part]
jmp search_partitions_ide0_1 jmp search_partitions_ide0_1
@ -40,11 +45,16 @@ $Revision$
mov [known_part],1 mov [known_part],1
search_partitions_ide1_1: search_partitions_ide1_1:
call set_PARTITION_variables call set_PARTITION_variables
cmp [problem_partition],0 test [problem_partition],2
jne search_partitions_ide2 jnz search_partitions_ide2
test [problem_partition],1
jnz @F
;cmp [problem_partition],0
;jne search_partitions_ide2
inc byte [DRIVE_DATA+3] inc byte [DRIVE_DATA+3]
call partition_data_transfer call partition_data_transfer
add [transfer_adress],100 add [transfer_adress],100
@@:
inc [known_part] inc [known_part]
jmp search_partitions_ide1_1 jmp search_partitions_ide1_1
@ -57,11 +67,16 @@ $Revision$
mov [known_part],1 mov [known_part],1
search_partitions_ide2_1: search_partitions_ide2_1:
call set_PARTITION_variables call set_PARTITION_variables
cmp [problem_partition],0 test [problem_partition],2
jne search_partitions_ide3 jnz search_partitions_ide3
test [problem_partition],1
jnz @F
;cmp [problem_partition],0
;jne search_partitions_ide3
inc byte [DRIVE_DATA+4] inc byte [DRIVE_DATA+4]
call partition_data_transfer call partition_data_transfer
add [transfer_adress],100 add [transfer_adress],100
@@:
inc [known_part] inc [known_part]
jmp search_partitions_ide2_1 jmp search_partitions_ide2_1
@ -74,11 +89,16 @@ $Revision$
mov [known_part],1 mov [known_part],1
search_partitions_ide3_1: search_partitions_ide3_1:
call set_PARTITION_variables call set_PARTITION_variables
cmp [problem_partition],0 test [problem_partition],2
jne end_search_partitions_ide jnz end_search_partitions_ide
test [problem_partition],1
jnz @F
;cmp [problem_partition],0
;jne end_search_partitions_ide
inc byte [DRIVE_DATA+5] inc byte [DRIVE_DATA+5]
call partition_data_transfer call partition_data_transfer
add [transfer_adress],100 add [transfer_adress],100
@@:
inc [known_part] inc [known_part]
jmp search_partitions_ide3_1 jmp search_partitions_ide3_1
@ -94,12 +114,17 @@ start_search_partitions_bd:
mov [known_part], 1 mov [known_part], 1
search_partitions_bd: search_partitions_bd:
call set_PARTITION_variables call set_PARTITION_variables
cmp [problem_partition], 0 test [problem_partition],2
jne end_search_partitions_bd jnz end_search_partitions_bd
test [problem_partition],1
jnz @F
;cmp [problem_partition], 0
;jne end_search_partitions_bd
mov eax, [hdpos] mov eax, [hdpos]
inc [BiosDiskPartitions+(eax-80h)*4] inc [BiosDiskPartitions+(eax-80h)*4]
call partition_data_transfer call partition_data_transfer
add [transfer_adress], 100 add [transfer_adress], 100
@@:
inc [known_part] inc [known_part]
jmp search_partitions_bd jmp search_partitions_bd
end_search_partitions_bd: end_search_partitions_bd:
@ -130,24 +155,3 @@ partition_data_transfer_1:
end_search_partitions: end_search_partitions:
;PARTITION_START dd 0x3f
;PARTITION_END dd 0
;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
;
;fat_type db 0 ; 0=none, 16=fat16, 32=fat32

View File

@ -41,6 +41,8 @@ FS_FT_DIR = 0x10 ;это папка
FS_FT_ASCII = 0 ;имя в ascii FS_FT_ASCII = 0 ;имя в ascii
FS_FT_UNICODE = 1 ;имя в unicode FS_FT_UNICODE = 1 ;имя в unicode
EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002
uglobal uglobal
EXT2_files_in_folder dd ? ;всего файлов в папке EXT2_files_in_folder dd ? ;всего файлов в папке
EXT2_read_in_folder dd ? ;сколько файлов "считали" EXT2_read_in_folder dd ? ;сколько файлов "считали"
@ -80,18 +82,24 @@ ends
ext2_test_superblock: ext2_test_superblock:
cmp [fs_type], 0x83
jne .no
mov eax, [PARTITION_START] mov eax, [PARTITION_START]
add eax, 2 ;superblock start at 1024b add eax, 2 ;superblock start at 1024b
call hd_read call hd_read
cmp [fs_type], 0x83
jne .no
cmp dword [ebx+24], 3 ;s_block_size 0,1,2,3 cmp dword [ebx+24], 3 ;s_block_size 0,1,2,3
ja .no ja .no
cmp word [ebx+56], 0xEF53 ;s_magic cmp word [ebx+56], 0xEF53 ;s_magic
jne .no jne .no
cmp word [ebx+58], 1 ;s_state (EXT_VALID_FS=1) cmp word [ebx+58], 1 ;s_state (EXT_VALID_FS=1)
jne .no jne .no
mov eax, [ebx+96]
test eax, EXT2_FEATURE_INCOMPAT_FILETYPE
jz .no
test eax, not EXT2_FEATURE_INCOMPAT_FILETYPE
jnz .no
; OK, this is correct EXT2 superblock ; OK, this is correct EXT2 superblock
clc clc
@ -155,11 +163,8 @@ ext2_setup:
mov ebx, eax mov ebx, eax
mov eax, EXT2_ROOT_INO mov eax, EXT2_ROOT_INO
call ext2_get_inode ; read root inode call ext2_get_inode ; read root inode
jmp return_from_part_set
popad
call free_hd_channel
and [hd1_status], 0
ret
;================================================================== ;==================================================================
;in: eax = i_block ;in: eax = i_block
; ebx = pointer to return memory ; ebx = pointer to return memory
@ -270,21 +275,22 @@ ext2_get_inode:
add eax, [PARTITION_START] ; а старт раздела - в терминах hdd (512) add eax, [PARTITION_START] ; а старт раздела - в терминах hdd (512)
;eax - указывает на таблицу inode-ов на hdd ;eax - указывает на таблицу inode-ов на hdd
mov ecx, eax ;сохраним его пока в ecx mov esi, eax ;сохраним его пока в esi
; прибавим локальный адрес inode-а ; прибавим локальный адрес inode-а
pop eax ; index pop eax ; index
mul [ext2_data.inode_size] ; (index * inode_size) mov ecx, [ext2_data.inode_size]
mul ecx ; (index * inode_size)
mov ebp, 512 mov ebp, 512
div ebp ;поделим на размер блока div ebp ;поделим на размер блока
add eax, ecx ;нашли адрес блока для чтения add eax, esi ;нашли адрес блока для чтения
mov ebx, [ext2_data.ext2_temp_block] mov ebx, [ext2_data.ext2_temp_block]
call hd_read call hd_read
mov esi, edx ;добавим "остаток" mov esi, edx ;добавим "остаток"
add esi, ebx ;к адресу add esi, ebx ;к адресу
mov ecx, [ext2_data.inode_size] ; mov ecx, [ext2_data.inode_size]
rep movsb ;копируем inode rep movsb ;копируем inode
popad popad
ret ret

View File

@ -9,6 +9,7 @@ $Revision$
;************************************************************* ;*************************************************************
;* 13.02.2010 Find all partition and check supported FS
;* 12.07.2007 Check all 4 entry of MBR and EMBR ;* 12.07.2007 Check all 4 entry of MBR and EMBR
;* 29.04.2006 Elimination of hangup after the ;* 29.04.2006 Elimination of hangup after the
;* expiration hd_wait_timeout - Mario79 ;* expiration hd_wait_timeout - Mario79
@ -26,7 +27,7 @@ align 4
;****************************************************** ;******************************************************
PARTITION_START dd 0x3f PARTITION_START dd 0x3f
PARTITION_END dd 0 PARTITION_END dd 0
fs_type db 0 ; 0=none, 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32 fs_type db 0 ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
align 4 align 4
fs_dependent_data_start: fs_dependent_data_start:
@ -150,7 +151,7 @@ endg
set_PARTITION_variables: set_PARTITION_variables:
set_FAT32_variables: ;deprecated set_FAT32_variables: ;deprecated
mov [problem_partition],0 and [problem_partition], 0
call reserve_hd1 call reserve_hd1
call reserve_hd_channel call reserve_hd_channel
@ -160,7 +161,7 @@ set_FAT32_variables: ;deprecated
je problem_hd je problem_hd
xor ecx,ecx ; partition count xor ecx,ecx ; partition count
or edx,-1 ; flag for partition ;or edx,-1 ; flag for partition
xor eax,eax ; address MBR xor eax,eax ; address MBR
xor ebp,ebp ; extended partition start xor ebp,ebp ; extended partition start
@ -178,6 +179,7 @@ extended_already_set:
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
jnz end_partition_chain jnz end_partition_chain
push eax ; push only one time
cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition cmp dword [ebx+0x1be+0xc],0 ; skip over empty partition
jnz test_primary_partition_0 jnz test_primary_partition_0
cmp dword [ebx+0x1be+0xc+16],0 cmp dword [ebx+0x1be+0xc+16],0
@ -186,98 +188,111 @@ extended_already_set:
jnz test_primary_partition_2 jnz test_primary_partition_2
cmp dword [ebx+0x1be+0xc+16+16+16],0 cmp dword [ebx+0x1be+0xc+16+16+16],0
jnz test_primary_partition_3 jnz test_primary_partition_3
pop eax
jmp end_partition_chain jmp end_partition_chain
test_primary_partition_0: test_primary_partition_0:
push eax
mov al,[ebx+0x1be+4] ; get primary partition type mov al,[ebx+0x1be+4] ; get primary partition type
call scan_partition_types call scan_partition_types
pop eax
jnz test_primary_partition_1 ; no. skip over jnz test_primary_partition_1 ; no. skip over
inc ecx inc ecx
cmp ecx,[known_part] ; is it wanted partition? cmp ecx,[known_part] ; is it wanted partition?
jnz test_primary_partition_1 ; no jnz test_primary_partition_1 ; no
mov edx, eax ; start sector pop eax
add edx, [ebx+0x1be+8] ; add relative start ;mov edx, eax ; start sector
push edx add eax, [ebx+0x1be+8] ; add relative start
add edx, [ebx+0x1be+12] ; add length ;mov [PARTITON_START],edx
dec edx ; PARTITION_END is inclusive ;push edx
mov [PARTITION_END], edx ; note that this can be changed 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
; when file system data will be available ; when file system data will be available
mov dl, [ebx+0x1be+4] mov cl, [ebx+0x1be+4] ; fs_type
mov [fs_type], dl ; save for FS recognizer (separate FAT vs NTFS) ;mov [fs_type], dl ; save for FS recognizer (separate FAT vs NTFS)
pop edx ;pop edx
jmp hd_and_partition_ok
test_primary_partition_1: test_primary_partition_1:
push eax
mov al,[ebx+0x1be+4+16] ; get primary partition type mov al,[ebx+0x1be+4+16] ; get primary partition type
call scan_partition_types call scan_partition_types
pop eax
jnz test_primary_partition_2 ; no. skip over jnz test_primary_partition_2 ; no. skip over
inc ecx inc ecx
cmp ecx,[known_part] ; is it wanted partition? cmp ecx,[known_part] ; is it wanted partition?
jnz test_primary_partition_2 ; no jnz test_primary_partition_2 ; no
mov edx, eax pop eax
add edx, [ebx+0x1be+8+16] add eax, [ebx+0x1be+8+16]
push edx mov edx, [ebx+0x1be+12+16]
add edx, [ebx+0x1be+12+16] mov cl, [ebx+0x1be+4+16]
dec edx jmp hd_and_partition_ok
mov [PARTITION_END], edx
mov dl, [ebx+0x1be+4+16] ;mov edx, eax
mov [fs_type], dl ;add edx, [ebx+0x1be+8+16]
pop edx ;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
test_primary_partition_2: test_primary_partition_2:
push eax
mov al,[ebx+0x1be+4+16+16] ; get primary partition type mov al,[ebx+0x1be+4+16+16] ; get primary partition type
call scan_partition_types call scan_partition_types
pop eax
jnz test_primary_partition_3 ; no. skip over jnz test_primary_partition_3 ; no. skip over
inc ecx inc ecx
cmp ecx,[known_part] ; is it wanted partition? cmp ecx,[known_part] ; is it wanted partition?
jnz test_primary_partition_3 ; no jnz test_primary_partition_3 ; no
mov edx, eax pop eax
add edx, [ebx+0x1be+8+16+16] add eax, [ebx+0x1be+8+16+16]
push edx mov edx, [ebx+0x1be+12+16+16]
add edx, [ebx+0x1be+12+16+16] mov cl, [ebx+0x1be+4+16+16]
dec edx jmp hd_and_partition_ok
mov [PARTITION_END], edx ;mov edx, eax
mov dl, [ebx+0x1be+4+16+16] ;add edx, [ebx+0x1be+8+16+16]
mov [fs_type], dl ;push edx
pop 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
test_primary_partition_3: test_primary_partition_3:
push eax
mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type mov al,[ebx+0x1be+4+16+16+16] ; get primary partition type
call scan_partition_types call scan_partition_types
pop eax
jnz test_ext_partition_0 ; no. skip over jnz test_ext_partition_0 ; no. skip over
inc ecx inc ecx
cmp ecx,[known_part] ; is it wanted partition? cmp ecx,[known_part] ; is it wanted partition?
jnz test_ext_partition_0 ; no jnz test_ext_partition_0 ; no
mov edx, eax pop eax
add edx, [ebx+0x1be+8+16+16+16] add eax, [ebx+0x1be+8+16+16+16]
push edx mov edx, [ebx+0x1be+12+16+16+16]
add edx, [ebx+0x1be+12+16+16+16] mov cl, [ebx+0x1be+4+16+16+16]
dec edx jmp hd_and_partition_ok
mov [PARTITION_END], edx
mov dl, [ebx+0x1be+4+16+16+16] ;mov edx, eax
mov [fs_type], dl ;add edx, [ebx+0x1be+8+16+16+16]
pop edx ;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: test_ext_partition_0:
push eax pop eax ; ¯à®áâ® ¢ëª¨¤ë¢ ¥¬ ¨§ á⥪ 
mov al,[ebx+0x1be+4] ; get extended partition type mov al,[ebx+0x1be+4] ; get extended partition type
call scan_extended_types call scan_extended_types
pop eax
jnz test_ext_partition_1 jnz test_ext_partition_1
mov eax,[ebx+0x1be+8] ; add relative start mov eax,[ebx+0x1be+8] ; add relative start
@ -285,10 +300,8 @@ test_ext_partition_0:
jnz new_mbr ; yes. read it jnz new_mbr ; yes. read it
test_ext_partition_1: test_ext_partition_1:
push eax
mov al,[ebx+0x1be+4+16] ; get extended partition type mov al,[ebx+0x1be+4+16] ; get extended partition type
call scan_extended_types call scan_extended_types
pop eax
jnz test_ext_partition_2 jnz test_ext_partition_2
mov eax,[ebx+0x1be+8+16] ; add relative start mov eax,[ebx+0x1be+8+16] ; add relative start
@ -296,10 +309,8 @@ test_ext_partition_1:
jnz new_mbr ; yes. read it jnz new_mbr ; yes. read it
test_ext_partition_2: test_ext_partition_2:
push eax
mov al,[ebx+0x1be+4+16+16] ; get extended partition type mov al,[ebx+0x1be+4+16+16] ; get extended partition type
call scan_extended_types call scan_extended_types
pop eax
jnz test_ext_partition_3 jnz test_ext_partition_3
mov eax,[ebx+0x1be+8+16+16] ; add relative start mov eax,[ebx+0x1be+8+16+16] ; add relative start
@ -307,10 +318,8 @@ test_ext_partition_2:
jnz new_mbr ; yes. read it jnz new_mbr ; yes. read it
test_ext_partition_3: test_ext_partition_3:
push eax
mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type mov al,[ebx+0x1be+4+16+16+16] ; get extended partition type
call scan_extended_types call scan_extended_types
pop eax
jnz end_partition_chain ; no. end chain jnz end_partition_chain ; no. end chain
mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition mov eax,[ebx+0x1be+8+16+16+16] ; get start of extended partition
@ -318,11 +327,15 @@ test_ext_partition_3:
jnz new_mbr ; yes. read it jnz new_mbr ; yes. read it
end_partition_chain: end_partition_chain:
mov [partition_count],ecx ;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
cmp edx,-1 ; found wanted partition?
jnz hd_and_partition_ok ; yes. install it
jmp problem_partition_or_fat
scan_partition_types: scan_partition_types:
push ecx push ecx
@ -343,24 +356,31 @@ scan_extended_types:
ret ret
problem_fat_dec_count: ; bootsector is missing or another problem problem_fat_dec_count: ; bootsector is missing or another problem
dec [partition_count] ; remove it from partition_count ; dec [partition_count] ; remove it from partition_count
problem_partition_or_fat: problem_partition_or_fat:
problem_hd: or [problem_partition],1
popad
mov [fs_type],0 return_from_part_set:
popad
;mov [fs_type],0
call free_hd_channel call free_hd_channel
mov [hd1_status],0 ; free mov [hd1_status],0 ; free
mov [problem_partition],1
ret ret
hd_and_partition_ok: hd_and_partition_ok:
mov eax,edx
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
mov [fs_type], cl
;mov eax,edx
mov [PARTITION_START],eax mov [PARTITION_START],eax
mov edx, [PARTITION_END] add edx, eax
sub edx, eax dec edx
inc edx ; edx = length of partition mov [PARTITION_END], edx
; mov edx, [PARTITION_END]
; sub edx, eax
; inc edx ; edx = length of partition § ç¥¬ ®­® ­ ¬??
; mov [hd_setup],1 ; mov [hd_setup],1
mov ebx,buffer mov ebx,buffer
@ -395,12 +415,12 @@ boot_read_ok:
jnc ntfs_setup jnc ntfs_setup
call ext2_test_superblock ; test ext2fs call ext2_test_superblock ; test ext2fs
jnc ext2_setup jnc ext2_setup
mov eax, [PARTITION_START] ;ext2 test changes [buffer] mov eax, [PARTITION_START] ;ext2 test changes [buffer]
call hd_read call hd_read
cmp [hd_error], 0 cmp [hd_error], 0
jnz problem_fat_dec_count jnz problem_fat_dec_count
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
jnz problem_fat_dec_count jnz problem_fat_dec_count
@ -506,3 +526,4 @@ fat16_partition:
call free_hd_channel call free_hd_channel
mov [hd1_status],0 ; free mov [hd1_status],0 ; free
ret ret