Revert "disk: Fix logic issue with UEFI volume detection"

This reverts commit 19bd781661.
This commit is contained in:
mintsuki 2022-01-14 02:04:22 +01:00
parent 0eba7b0a95
commit 6223f65bff
2 changed files with 15 additions and 27 deletions

View File

@ -217,7 +217,6 @@ int disk_read_sectors(struct volume *volume, void *buf, uint64_t block, size_t c
} }
} }
static uint64_t unique_sector_column;
static alignas(4096) uint8_t unique_sector_pool[8192]; static alignas(4096) uint8_t unique_sector_pool[8192];
struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) { struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) {
@ -231,16 +230,12 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) {
return NULL; return NULL;
} }
if (unique_sector_column == (uint64_t)-1) {
goto fallback;
}
for (size_t i = 0; i < volume_index_i; i++) { for (size_t i = 0; i < volume_index_i; i++) {
if (volume_index[i]->unique_sector_valid == false) { if (volume_index[i]->unique_sector_valid == false) {
continue; continue;
} }
size_t unique_sector = (unique_sector_column * volume_index[i]->sector_size) / block_io->Media->BlockSize; size_t unique_sector = (volume_index[i]->unique_sector * volume_index[i]->sector_size) / block_io->Media->BlockSize;
status = block_io->ReadBlocks(block_io, block_io->Media->MediaId, status = block_io->ReadBlocks(block_io, block_io->Media->MediaId,
unique_sector, unique_sector,
@ -258,7 +253,7 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) {
} }
// Fallback to read-back method // Fallback to read-back method
fallback:;
EFI_GUID disk_io_guid = DISK_IO_PROTOCOL; EFI_GUID disk_io_guid = DISK_IO_PROTOCOL;
EFI_DISK_IO *disk_io = NULL; EFI_DISK_IO *disk_io = NULL;
@ -325,13 +320,14 @@ fallback:;
return NULL; return NULL;
} }
static struct volume *volume_by_unique_sector(uint32_t crc32) { static struct volume *volume_by_unique_sector(size_t sect, uint32_t crc32) {
for (size_t i = 0; i < volume_index_i; i++) { for (size_t i = 0; i < volume_index_i; i++) {
if (volume_index[i]->unique_sector_valid == false) { if (volume_index[i]->unique_sector_valid == false) {
continue; continue;
} }
if (volume_index[i]->unique_sector_crc32 == crc32) { if (volume_index[i]->unique_sector == sect
&& volume_index[i]->unique_sector_crc32 == crc32) {
return volume_index[i]; return volume_index[i];
} }
} }
@ -344,13 +340,10 @@ static struct volume *volume_by_unique_sector(uint32_t crc32) {
static void find_unique_sectors(void) { static void find_unique_sectors(void) {
EFI_STATUS status; EFI_STATUS status;
for (size_t j = 0; j < UNIQUE_SECT_MAX_SEARCH_RANGE; j++) { for (size_t i = 0; i < volume_index_i; i++) {
unique_sector_column = j; for (size_t j = 0; j < UNIQUE_SECT_MAX_SEARCH_RANGE; j++) {
for (size_t i = 0; i < volume_index_i; i++) {
if (volume_index[i]->first_sect % (volume_index[i]->sector_size / 512)) { if (volume_index[i]->first_sect % (volume_index[i]->sector_size / 512)) {
volume_index[i]->unique_sector_valid = false; break;
continue;
} }
size_t first_sect = volume_index[i]->first_sect / (volume_index[i]->sector_size / 512); size_t first_sect = volume_index[i]->first_sect / (volume_index[i]->sector_size / 512);
@ -362,26 +355,19 @@ static void find_unique_sectors(void) {
volume_index[i]->sector_size, volume_index[i]->sector_size,
unique_sector_pool); unique_sector_pool);
if (status != 0) { if (status != 0) {
volume_index[i]->unique_sector_valid = false; break;
continue;
} }
uint32_t crc32 = get_crc32(unique_sector_pool, volume_index[i]->sector_size); uint32_t crc32 = get_crc32(unique_sector_pool, volume_index[i]->sector_size);
if (volume_by_unique_sector(crc32) == NULL) { if (volume_by_unique_sector(j, crc32) == NULL) {
volume_index[i]->unique_sector_valid = true; volume_index[i]->unique_sector_valid = true;
volume_index[i]->unique_sector = j;
volume_index[i]->unique_sector_crc32 = crc32; volume_index[i]->unique_sector_crc32 = crc32;
} else { break;
// next column
goto next_column;
} }
} }
return;
next_column:;
} }
unique_sector_column = (uint64_t)-1;
} }
static void find_part_handles(EFI_HANDLE *handles, size_t handle_count) { static void find_part_handles(EFI_HANDLE *handles, size_t handle_count) {

View File

@ -20,6 +20,7 @@ struct volume {
EFI_BLOCK_IO *block_io; EFI_BLOCK_IO *block_io;
bool unique_sector_valid; bool unique_sector_valid;
size_t unique_sector;
uint32_t unique_sector_crc32; uint32_t unique_sector_crc32;
#elif bios == 1 #elif bios == 1
int drive; int drive;
@ -85,9 +86,10 @@ bool volume_read(struct volume *part, void *buffer, uint64_t loc, uint64_t count
\ \
struct volume *_PART = volume_get_by_coord(_VOLUME->is_optical, \ struct volume *_PART = volume_get_by_coord(_VOLUME->is_optical, \
_VOLUME->index, _PARTNO); \ _VOLUME->index, _PARTNO); \
_PART_CNT++; \
if (_PART == NULL) \ if (_PART == NULL) \
continue; \ continue; \
\
_PART_CNT++; \
\ \
_BODY_ \ _BODY_ \
} \ } \