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

@ -22,12 +22,17 @@ $Revision$
mov [hdpos],1
mov [known_part],1
search_partitions_ide0_1:
call set_PARTITION_variables
cmp [problem_partition],0
jne search_partitions_ide1
call set_PARTITION_variables
test [problem_partition],2
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]
call partition_data_transfer
add [transfer_adress],100
add [transfer_adress],100
@@:
inc [known_part]
jmp search_partitions_ide0_1
@ -39,12 +44,17 @@ $Revision$
mov [hdpos],2
mov [known_part],1
search_partitions_ide1_1:
call set_PARTITION_variables
cmp [problem_partition],0
jne search_partitions_ide2
call set_PARTITION_variables
test [problem_partition],2
jnz search_partitions_ide2
test [problem_partition],1
jnz @F
;cmp [problem_partition],0
;jne search_partitions_ide2
inc byte [DRIVE_DATA+3]
call partition_data_transfer
add [transfer_adress],100
add [transfer_adress],100
@@:
inc [known_part]
jmp search_partitions_ide1_1
@ -56,12 +66,17 @@ $Revision$
mov [hdpos],3
mov [known_part],1
search_partitions_ide2_1:
call set_PARTITION_variables
cmp [problem_partition],0
jne search_partitions_ide3
call set_PARTITION_variables
test [problem_partition],2
jnz search_partitions_ide3
test [problem_partition],1
jnz @F
;cmp [problem_partition],0
;jne search_partitions_ide3
inc byte [DRIVE_DATA+4]
call partition_data_transfer
add [transfer_adress],100
add [transfer_adress],100
@@:
inc [known_part]
jmp search_partitions_ide2_1
@ -73,12 +88,17 @@ $Revision$
mov [hdpos],4
mov [known_part],1
search_partitions_ide3_1:
call set_PARTITION_variables
cmp [problem_partition],0
jne end_search_partitions_ide
call set_PARTITION_variables
test [problem_partition],2
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]
call partition_data_transfer
add [transfer_adress],100
add [transfer_adress],100
@@:
inc [known_part]
jmp search_partitions_ide3_1
@ -93,13 +113,18 @@ start_search_partitions_bd:
and [BiosDiskPartitions+(eax-80h)*4], 0
mov [known_part], 1
search_partitions_bd:
call set_PARTITION_variables
cmp [problem_partition], 0
jne end_search_partitions_bd
call set_PARTITION_variables
test [problem_partition],2
jnz end_search_partitions_bd
test [problem_partition],1
jnz @F
;cmp [problem_partition], 0
;jne end_search_partitions_bd
mov eax, [hdpos]
inc [BiosDiskPartitions+(eax-80h)*4]
call partition_data_transfer
add [transfer_adress], 100
add [transfer_adress], 100
@@:
inc [known_part]
jmp search_partitions_bd
end_search_partitions_bd:
@ -128,26 +153,5 @@ partition_data_transfer_1:
; sti
ret
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
end_search_partitions:

View File

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

View File

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