summaryrefslogtreecommitdiff
path: root/cgpt/cmd_create.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgpt/cmd_create.c')
-rw-r--r--cgpt/cmd_create.c54
1 files changed, 8 insertions, 46 deletions
diff --git a/cgpt/cmd_create.c b/cgpt/cmd_create.c
index 6dabde3a..1e081f8c 100644
--- a/cgpt/cmd_create.c
+++ b/cgpt/cmd_create.c
@@ -1,16 +1,13 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 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 <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-#include <uuid/uuid.h>
-#include "cgptlib_internal.h"
+#include "cgpt_params.h"
static void Usage(void)
{
@@ -23,7 +20,9 @@ static void Usage(void)
int cmd_create(int argc, char *argv[]) {
struct drive drive;
- int zap = 0;
+
+ CgptCreateParams params;
+ memset(&params, 0, sizeof(params));
int c;
int errorcnt = 0;
@@ -34,7 +33,7 @@ int cmd_create(int argc, char *argv[]) {
switch (c)
{
case 'z':
- zap = 1;
+ params.zap = 1;
break;
case 'h':
@@ -64,44 +63,7 @@ int cmd_create(int argc, char *argv[]) {
return CGPT_FAILED;
}
- if (CGPT_OK != DriveOpen(argv[optind], &drive))
- return CGPT_FAILED;
-
- // Erase the data
- memset(drive.gpt.primary_header, 0,
- drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
- memset(drive.gpt.secondary_header, 0,
- drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
- memset(drive.gpt.primary_entries, 0,
- drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
- memset(drive.gpt.secondary_entries, 0,
- drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
-
- drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
- GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2);
-
- // Initialize a blank set
- if (!zap)
- {
- GptHeader *h = (GptHeader *)drive.gpt.primary_header;
- memcpy(h->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
- h->revision = GPT_HEADER_REVISION;
- h->size = sizeof(GptHeader);
- h->my_lba = 1;
- h->alternate_lba = drive.gpt.drive_sectors - 1;
- h->first_usable_lba = 1 + 1 + GPT_ENTRIES_SECTORS;
- h->last_usable_lba = drive.gpt.drive_sectors - 1 - GPT_ENTRIES_SECTORS - 1;
- uuid_generate((uint8_t *)&h->disk_uuid);
- h->entries_lba = 2;
- h->number_of_entries = 128;
- h->size_of_entry = sizeof(GptEntry);
-
- // Copy to secondary
- RepairHeader(&drive.gpt, MASK_PRIMARY);
-
- UpdateCrc(&drive.gpt);
- }
+ params.driveName = argv[optind];
- // Write it all out
- return DriveClose(&drive, 1);
+ return cgpt_create(&params);
}