diff options
author | Dan Ehrenberg <dehrenberg@chromium.org> | 2014-12-09 13:42:15 -0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-12-11 03:12:14 +0000 |
commit | b3d38f5c620da89662deb1a08971c5025d6c1132 (patch) | |
tree | 1a401569a1d4faf8c45c32708a1b3856b707e190 /cgpt | |
parent | cfe83a827d40b310003fc6996b9978d8cf301444 (diff) | |
download | vboot-b3d38f5c620da89662deb1a08971c5025d6c1132.tar.gz |
vboot: GPT interface cleanup
- Rename drive_sectors to streaming_drive_sectors, to contrast with
gpt_drive_sectors
- Replace stored_on_device field with flags field for future
extensibility
BUG=chromium:433433
TEST=make runtests
BRANCH=none
Change-Id: I785a3b735b8eb96f647a334659329db3ee43eb80
Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/234283
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r-- | cgpt/cgpt_boot.c | 4 | ||||
-rw-r--r-- | cgpt/cgpt_common.c | 19 | ||||
-rw-r--r-- | cgpt/cgpt_create.c | 9 |
3 files changed, 16 insertions, 16 deletions
diff --git a/cgpt/cgpt_boot.c b/cgpt/cgpt_boot.c index f4323962..d8976c42 100644 --- a/cgpt/cgpt_boot.c +++ b/cgpt/cgpt_boot.c @@ -99,8 +99,8 @@ int CgptBoot(CgptBootParams *params) { drive.pmbr.part[0].l_cyl = 0xff; drive.pmbr.part[0].f_lba = htole32(1); uint32_t max = 0xffffffff; - if (drive.gpt.drive_sectors < 0xffffffff) - max = drive.gpt.drive_sectors - 1; + if (drive.gpt.streaming_drive_sectors < 0xffffffff) + max = drive.gpt.streaming_drive_sectors - 1; drive.pmbr.part[0].num_sect = htole32(max); } diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c index 1438dfb3..b580e33a 100644 --- a/cgpt/cgpt_common.c +++ b/cgpt/cgpt_common.c @@ -150,11 +150,11 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) { (long long unsigned int)drive->size, drive->gpt.sector_bytes); return -1; } - drive->gpt.drive_sectors = drive->size / drive->gpt.sector_bytes; + drive->gpt.streaming_drive_sectors = drive->size / drive->gpt.sector_bytes; /* TODO(namnguyen): Remove this and totally trust gpt_drive_sectors. */ - if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) { - drive->gpt.gpt_drive_sectors = drive->gpt.drive_sectors; + if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) { + drive->gpt.gpt_drive_sectors = drive->gpt.streaming_drive_sectors; } /* Else, we trust gpt.gpt_drive_sectors. */ // Read the data. @@ -171,9 +171,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) { return -1; } GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header; - if (CheckHeader(primary_header, 0, drive->gpt.drive_sectors, + if (CheckHeader(primary_header, 0, drive->gpt.streaming_drive_sectors, drive->gpt.gpt_drive_sectors, - drive->gpt.stored_on_device) == 0) { + drive->gpt.flags) == 0) { if (CGPT_OK != Load(drive, &drive->gpt.primary_entries, primary_header->entries_lba, drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) { @@ -184,9 +184,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) { Warning("Primary GPT header is invalid\n"); } GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header; - if (CheckHeader(secondary_header, 1, drive->gpt.drive_sectors, + if (CheckHeader(secondary_header, 1, drive->gpt.streaming_drive_sectors, drive->gpt.gpt_drive_sectors, - drive->gpt.stored_on_device) == 0) { + drive->gpt.flags) == 0) { if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries, secondary_header->entries_lba, drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) { @@ -284,7 +284,6 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode, // Clear struct for proper error handling. memset(drive, 0, sizeof(struct drive)); - drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE; drive->fd = open(drive_path, mode | O_LARGEFILE | O_NOFOLLOW); if (drive->fd == -1) { @@ -303,10 +302,10 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode, drive->gpt.gpt_drive_sectors = gpt_drive_size / sector_bytes; if (drive_size == 0) { drive->size = gpt_drive_size; - drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE; + drive->gpt.flags = 0; } else { drive->size = drive_size; - drive->gpt.stored_on_device = GPT_STORED_OFF_DEVICE; + drive->gpt.flags = GPT_FLAG_EXTERNAL; } diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c index 298e2ae5..2265c8f9 100644 --- a/cgpt/cgpt_create.c +++ b/cgpt/cgpt_create.c @@ -46,14 +46,15 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) { h->my_lba = GPT_PMBR_SECTORS; /* The second sector on drive. */ h->alternate_lba = drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS; h->entries_lba = h->my_lba + GPT_HEADER_SECTORS; - if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) { + if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) { h->entries_lba += params->padding; h->first_usable_lba = h->entries_lba + GPT_ENTRIES_SECTORS; - h->last_usable_lba = (drive->gpt.drive_sectors - GPT_HEADER_SECTORS - + h->last_usable_lba = (drive->gpt.streaming_drive_sectors - + GPT_HEADER_SECTORS - GPT_ENTRIES_SECTORS - 1); } else { h->first_usable_lba = params->padding; - h->last_usable_lba = (drive->gpt.drive_sectors - 1); + h->last_usable_lba = (drive->gpt.streaming_drive_sectors - 1); } if (CGPT_OK != GenerateGuid(&h->disk_uuid)) { Error("Unable to generate new GUID.\n"); @@ -61,7 +62,7 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) { } h->size_of_entry = sizeof(GptEntry); h->number_of_entries = TOTAL_ENTRIES_SIZE / h->size_of_entry; - if (drive->gpt.stored_on_device != GPT_STORED_ON_DEVICE) { + if (drive->gpt.flags & GPT_FLAG_EXTERNAL) { // We might have smaller space for the GPT table. Scale accordingly. size_t half_size_sectors = drive->gpt.gpt_drive_sectors / 2; if (half_size_sectors < GPT_HEADER_SECTORS) { |