summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_edit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgpt/cgpt_edit.c')
-rw-r--r--cgpt/cgpt_edit.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/cgpt/cgpt_edit.c b/cgpt/cgpt_edit.c
new file mode 100644
index 00000000..098187f6
--- /dev/null
+++ b/cgpt/cgpt_edit.c
@@ -0,0 +1,47 @@
+// Copyright 2018 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cgpt.h"
+#include "cgpt_params.h"
+#include "cgptlib_internal.h"
+#include "vboot_host.h"
+
+int CgptEdit(CgptEditParams *params) {
+ struct drive drive;
+ GptHeader *h;
+ int gpt_retval;
+
+ if (params == NULL)
+ return CGPT_FAILED;
+
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR, 0))
+ return CGPT_FAILED;
+
+ if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
+ Error("GptSanityCheck() returned %d: %s\n",
+ gpt_retval, GptError(gpt_retval));
+ goto bad;
+ }
+
+ if (CGPT_OK != CheckValid(&drive)) {
+ Error("Please run 'cgpt repair' before changing settings.\n");
+ goto bad;
+ }
+
+ h = (GptHeader *)drive.gpt.primary_header;
+ memcpy(&h->disk_uuid, &params->unique_guid, sizeof(h->disk_uuid));
+ // Copy to secondary
+ RepairHeader(&drive.gpt, MASK_PRIMARY);
+ drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_HEADER2);
+
+ UpdateCrc(&drive.gpt);
+
+ // Write it all out.
+ return DriveClose(&drive, 1);
+
+bad:
+
+ DriveClose(&drive, 0);
+ return CGPT_FAILED;
+}