summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_common.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_common.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_common.c')
-rw-r--r--cgpt/cgpt_common.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index a5a509b1..d69eb670 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -153,10 +153,11 @@ static int Save(const int fd, const uint8_t *buf,
// Opens a block device or file, loads raw GPT data from it.
+// mode should be O_RDONLY or O_RDWR
//
// Returns CGPT_FAILED if any error happens.
// Returns CGPT_OK if success and information are stored in 'drive'. */
-int DriveOpen(const char *drive_path, struct drive *drive) {
+int DriveOpen(const char *drive_path, struct drive *drive, int mode) {
struct stat stat;
require(drive_path);
@@ -165,7 +166,7 @@ int DriveOpen(const char *drive_path, struct drive *drive) {
// Clear struct for proper error handling.
memset(drive, 0, sizeof(struct drive));
- drive->fd = open(drive_path, O_RDWR | O_LARGEFILE | O_NOFOLLOW);
+ drive->fd = open(drive_path, mode | O_LARGEFILE | O_NOFOLLOW);
if (drive->fd == -1) {
Error("Can't open %s: %s\n", drive_path, strerror(errno));
return CGPT_FAILED;