mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 10:45:02 +00:00
cgpt: Handle read errors gracefully
When a read fails in getting the GPT, just zero the contents of the buffer and carry on. Some testing changes are required for this. When a read of the GPT fails, it is no longer fatal, so tests of that have been adjusted. Tests have been improved to show that the GPT is automatically repaired when a read error occurs. There was one test which checked that a zero-sized disk would fail to load a kernel, but it was surrounded by a number of mocked functions which normally do that error checking, and it amounted to the same test as read failure; that test was deleted. BUG=chrome-os-partner:35440 TEST=vboot tests pass BRANCH=none Change-Id: I0c05813e7492920433733947d3fb74a7e4aa66f2 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/266882 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
e2e14ae827
commit
d7da706484
@@ -43,8 +43,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
|
||||
return 1;
|
||||
|
||||
/* Read primary header from the drive, skipping the protective MBR */
|
||||
if (0 != VbExDiskRead(disk_handle, 1, 1, gptdata->primary_header))
|
||||
return 1;
|
||||
if (0 != VbExDiskRead(disk_handle, 1, 1, gptdata->primary_header)) {
|
||||
VBDEBUG(("Read error in primary GPT header\n"));
|
||||
Memset(gptdata->primary_header, 0, gptdata->sector_bytes);
|
||||
}
|
||||
|
||||
/* Only read primary GPT if the primary header is valid */
|
||||
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
|
||||
@@ -60,16 +62,20 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
|
||||
if (0 != VbExDiskRead(disk_handle,
|
||||
primary_header->entries_lba,
|
||||
entries_sectors,
|
||||
gptdata->primary_entries))
|
||||
return 1;
|
||||
gptdata->primary_entries)) {
|
||||
VBDEBUG(("Read error in primary GPT entries\n"));
|
||||
primary_valid = 0;
|
||||
}
|
||||
} else {
|
||||
VBDEBUG(("Primary GPT header invalid!\n"));
|
||||
}
|
||||
|
||||
/* Read secondary header from the end of the drive */
|
||||
if (0 != VbExDiskRead(disk_handle, gptdata->gpt_drive_sectors - 1, 1,
|
||||
gptdata->secondary_header))
|
||||
return 1;
|
||||
gptdata->secondary_header)) {
|
||||
VBDEBUG(("Read error in secondary GPT header\n"));
|
||||
Memset(gptdata->secondary_header, 0, gptdata->sector_bytes);
|
||||
}
|
||||
|
||||
/* Only read secondary GPT if the secondary header is valid */
|
||||
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
|
||||
@@ -85,8 +91,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
|
||||
if (0 != VbExDiskRead(disk_handle,
|
||||
secondary_header->entries_lba,
|
||||
entries_sectors,
|
||||
gptdata->secondary_entries))
|
||||
return 1;
|
||||
gptdata->secondary_entries)) {
|
||||
VBDEBUG(("Read error in secondary GPT entries\n"));
|
||||
secondary_valid = 0;
|
||||
}
|
||||
} else {
|
||||
VBDEBUG(("Secondary GPT header invalid!\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user