mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 18:55:24 +00:00
In several places the existing code assumes LBA, but was improperly converted to use byte offsets, so multiply by the sector size to correct it and maintain the same interface between MTD & GPT. Also, since we will need to cgpt create on /dev/fts, which isn't a stat()able device, allow providing the disk size on the commandline. BRANCH=none BUG=chromium:221745 TEST=make runtests; cgpt create -s 12345 on MTD image Change-Id: Icc89a4505aba9a3dfc39b176a372f6e12d106aed Reviewed-on: https://gerrit.chromium.org/gerrit/62675 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org>
72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
// 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 <getopt.h>
|
|
#include <string.h>
|
|
|
|
#include "cgpt.h"
|
|
#include "vboot_host.h"
|
|
|
|
static void Usage(void)
|
|
{
|
|
printf("\nUsage: %s create [OPTIONS] DRIVE\n\n"
|
|
"Create or reset an empty GPT.\n\n"
|
|
"Options:\n"
|
|
" -z Zero the sectors of the GPT table and entries\n"
|
|
" -s Size (in byes) of the disk (MTD only)\n"
|
|
"\n", progname);
|
|
}
|
|
|
|
int cmd_create(int argc, char *argv[]) {
|
|
CgptCreateParams params;
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
int c;
|
|
int errorcnt = 0;
|
|
char *e = 0;
|
|
|
|
opterr = 0; // quiet, you
|
|
while ((c=getopt(argc, argv, ":hzs:")) != -1)
|
|
{
|
|
switch (c)
|
|
{
|
|
case 'z':
|
|
params.zap = 1;
|
|
break;
|
|
case 's':
|
|
params.size = strtoull(optarg, &e, 0);
|
|
break;
|
|
|
|
case 'h':
|
|
Usage();
|
|
return CGPT_OK;
|
|
case '?':
|
|
Error("unrecognized option: -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
case ':':
|
|
Error("missing argument to -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
default:
|
|
errorcnt++;
|
|
break;
|
|
}
|
|
}
|
|
if (errorcnt)
|
|
{
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
if (optind >= argc) {
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
params.drive_name = argv[optind];
|
|
|
|
return CgptCreate(¶ms);
|
|
}
|