diff options
Diffstat (limited to 'cgpt/cgpt_boot.c')
-rw-r--r-- | cgpt/cgpt_boot.c | 13 |
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: |