summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_boot.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-04-30 11:33:13 -0700
committerGerrit <chrome-bot@google.com>2012-05-02 22:34:32 -0700
commit23429d3d782f7506fb4747356974294cce08ac47 (patch)
tree2c98d253f97d92b3c48ea3d87d4375e64f8ea4cd /cgpt/cgpt_boot.c
parent81f704edad78f03deed5ef899a55e9d0c28dd16c (diff)
downloadvboot-23429d3d782f7506fb4747356974294cce08ac47.tar.gz
Let cgpt open devices in read-only mode when possible.
BUG=chromium-os:12430 TEST=manual Running "make; make runtests" in src/platform/vboot_refererence will test this change. Tests for use on a Chromebook are described in the bug report, but will require a USB or SD card that has a physical write-protect switch. Change-Id: I16a67bad3b59bec0981f4064f51fb1a29da65a90 Reviewed-on: https://gerrit.chromium.org/gerrit/21474 Tested-by: Bill Richardson <wfrichar@chromium.org> Commit-Ready: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Richard Barnette <jrbarnette@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'cgpt/cgpt_boot.c')
-rw-r--r--cgpt/cgpt_boot.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/cgpt/cgpt_boot.c b/cgpt/cgpt_boot.c
index 33c5471c..f8e712d6 100644
--- a/cgpt/cgpt_boot.c
+++ b/cgpt/cgpt_boot.c
@@ -21,7 +21,7 @@ int cgpt_get_boot_partition_number(CgptBootParams *params) {
if (params == NULL)
return CGPT_FAILED;
- if (CGPT_OK != DriveOpen(params->drive_name, &drive))
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDONLY))
return CGPT_FAILED;
if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
@@ -65,12 +65,17 @@ int cgpt_boot(CgptBootParams *params) {
struct drive drive;
int retval = 1;
int gpt_retval= 0;
+ int mode = O_RDONLY;
if (params == NULL)
return CGPT_FAILED;
- if (CGPT_OK != DriveOpen(params->drive_name, &drive))
+ if (params->create_pmbr || params->partition || params->bootfile)
+ mode = O_RDWR;
+
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive, mode)) {
return CGPT_FAILED;
+ }
if (CGPT_OK != ReadPMBR(&drive)) {
Error("Unable to read PMBR\n");
@@ -135,8 +140,8 @@ int cgpt_boot(CgptBootParams *params) {
GuidToStr(&drive.pmbr.boot_guid, buf, sizeof(buf));
printf("%s\n", buf);
- // Write it all out
- if (CGPT_OK == WritePMBR(&drive))
+ // Write it all out, if needed.
+ if (mode == O_RDONLY || CGPT_OK == WritePMBR(&drive))
retval = 0;
done: