For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before) otherwise size is in bytes.
This commit is contained in:
parent
e767fbcf4a
commit
2098c8504e
|
@ -29,7 +29,7 @@
|
|||
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
|
||||
#endif
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: add.c,v 1.22 2013/12/06 02:31:31 jnemeth Exp $");
|
||||
__RCSID("$NetBSD: add.c,v 1.23 2013/12/08 09:32:51 jnemeth Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -46,12 +46,12 @@ __RCSID("$NetBSD: add.c,v 1.22 2013/12/06 02:31:31 jnemeth Exp $");
|
|||
#include "gpt.h"
|
||||
|
||||
static uuid_t type;
|
||||
static off_t alignment, block, size;
|
||||
static off_t alignment, block, sectors, size;
|
||||
static unsigned int entry;
|
||||
static uint8_t *name;
|
||||
|
||||
const char addmsg1[] = "add [-a alignment] [-b blocknr] [-i index] [-l label]";
|
||||
const char addmsg2[] = " [-s sectors] [-t type] device ...";
|
||||
const char addmsg2[] = " [-s size] [-t type] device ...";
|
||||
|
||||
__dead static void
|
||||
usage_add(void)
|
||||
|
@ -134,14 +134,14 @@ add(int fd)
|
|||
|
||||
if (alignment > 0) {
|
||||
alignsecs = alignment / secsz;
|
||||
map = map_alloc(block, size, alignsecs);
|
||||
map = map_alloc(block, sectors, alignsecs);
|
||||
if (map == NULL) {
|
||||
warnx("%s: error: not enough space available on "
|
||||
"device for an aligned partition", device_name);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
map = map_alloc(block, size, 0);
|
||||
map = map_alloc(block, sectors, 0);
|
||||
if (map == NULL) {
|
||||
warnx("%s: error: not enough space available on "
|
||||
"device", device_name);
|
||||
|
@ -226,11 +226,31 @@ cmd_add(int argc, char *argv[])
|
|||
name = (uint8_t *)strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
if (size > 0)
|
||||
if (sectors > 0 || size > 0)
|
||||
usage_add();
|
||||
size = strtoll(optarg, &p, 10);
|
||||
if (*p != 0 || size < 1)
|
||||
sectors = strtoll(optarg, &p, 10);
|
||||
if (sectors < 1)
|
||||
usage_add();
|
||||
if (*p == '\0')
|
||||
break;
|
||||
if (*p == 's' || *p == 'S') {
|
||||
if (*(p + 1) == '\0')
|
||||
break;
|
||||
else
|
||||
usage_add();
|
||||
}
|
||||
if (*p == 'b' || *p == 'B') {
|
||||
if (*(p + 1) == '\0') {
|
||||
size = sectors;
|
||||
sectors = 0;
|
||||
break;
|
||||
} else
|
||||
usage_add();
|
||||
}
|
||||
if (dehumanize_number(optarg, &human_num) < 0)
|
||||
usage_add();
|
||||
size = human_num;
|
||||
sectors = 0;
|
||||
break;
|
||||
case 't':
|
||||
if (!uuid_is_nil(&type, NULL))
|
||||
|
@ -260,12 +280,22 @@ cmd_add(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (alignment % secsz != 0) {
|
||||
warnx("Alignment must be a multiple of sector size; ");
|
||||
warnx("Alignment must be a multiple of sector size;");
|
||||
warnx("the sector size for %s is %d bytes.",
|
||||
device_name, secsz);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (size % secsz != 0) {
|
||||
warnx("Size in bytes must be a multiple of sector "
|
||||
"size;");
|
||||
warnx("the sector size for %s is %d bytes.",
|
||||
device_name, secsz);
|
||||
continue;
|
||||
}
|
||||
if (size > 0)
|
||||
sectors = size / secsz;
|
||||
|
||||
add(fd);
|
||||
|
||||
gpt_close(fd);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: gpt.8,v 1.22 2013/12/06 02:31:31 jnemeth Exp $
|
||||
.\" $NetBSD: gpt.8,v 1.23 2013/12/08 09:32:51 jnemeth Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002 Marcel Moolenaar
|
||||
.\" All rights reserved.
|
||||
|
@ -26,7 +26,7 @@
|
|||
.\"
|
||||
.\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
|
||||
.\"
|
||||
.Dd December 5, 2013
|
||||
.Dd December 8, 2013
|
||||
.Dt GPT 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -95,7 +95,7 @@ There is no formalized definition of the different levels yet.
|
|||
.Bl -tag -width indent
|
||||
.\" ==== add ====
|
||||
.It Nm Ic add Oo Fl a Ar alignment Oc Oo Fl b Ar blocknr Oc \
|
||||
Oo Fl i Ar index Oc Oo Fl l Ar label Oc Oo Fl s Ar sectors Oc \
|
||||
Oo Fl i Ar index Oc Oo Fl l Ar label Oc Oo Fl s Ar size Oc \
|
||||
Oo Fl t Ar type Oc Ar device ...
|
||||
The
|
||||
.Ic add
|
||||
|
@ -129,9 +129,15 @@ The
|
|||
option allows the user to specify a label for the partition.
|
||||
.Pp
|
||||
The
|
||||
.Fl s Ar sectors
|
||||
option allows the user to specify the size of the partition in sectors.
|
||||
The minimum size is 1.
|
||||
.Fl s Ar size
|
||||
option allows the user to specify the size of the partition.
|
||||
If there is no suffix, or the suffix is
|
||||
.Sq s
|
||||
or
|
||||
.Sq S
|
||||
then size is in sectors, otherwise size is in bytes which must be
|
||||
a multiple of the device's sector size.
|
||||
The minimum size is 1 sector.
|
||||
.Pp
|
||||
The
|
||||
.Fl t Ar type
|
||||
|
@ -317,7 +323,7 @@ Partitions are removed by clearing the partition type.
|
|||
No other information is changed.
|
||||
.\" ==== resize ====
|
||||
.It Nm Ic resize Fl i Ar index Oo Fl a Ar alignment Oc \
|
||||
Oo Fl s Ar sectors Oc Ar device ...
|
||||
Oo Fl s Ar size Oc Ar device ...
|
||||
The
|
||||
.Ic resize
|
||||
command allows the user to resize a partition.
|
||||
|
@ -327,6 +333,13 @@ The
|
|||
.Fl s
|
||||
option allows the new size to be specified, otherwise the partition will
|
||||
be increased to the maximum available size.
|
||||
If there is no suffix, or the suffix is
|
||||
.Sq s
|
||||
or
|
||||
.Sq S
|
||||
then size is in sectors, otherwise size is in bytes which must be
|
||||
a multiple of the device's sector size.
|
||||
The minimum size is 1 sector.
|
||||
If the
|
||||
.Fl a
|
||||
option is specified then the size will be adjusted to be a multiple of
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
|
||||
#endif
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: resize.c,v 1.6 2013/12/06 02:31:31 jnemeth Exp $");
|
||||
__RCSID("$NetBSD: resize.c,v 1.7 2013/12/08 09:32:51 jnemeth Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -45,11 +45,10 @@ __RCSID("$NetBSD: resize.c,v 1.6 2013/12/06 02:31:31 jnemeth Exp $");
|
|||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
||||
static off_t alignment, size;
|
||||
static off_t alignment, sectors, size;
|
||||
static unsigned int entry;
|
||||
|
||||
const char resizemsg[] = "resize -i index [-a alignment] [-s sectors] "
|
||||
"device ...";
|
||||
const char resizemsg[] = "resize -i index [-a alignment] [-s size] device ...";
|
||||
|
||||
__dead static void
|
||||
usage_resize(void)
|
||||
|
@ -124,16 +123,16 @@ resize(int fd)
|
|||
return;
|
||||
}
|
||||
|
||||
if (size > 0 && size == map->map_size)
|
||||
if (sectors > 0 && sectors == map->map_size)
|
||||
if (alignment == 0 ||
|
||||
(alignment > 0 && size % alignsecs == 0)) {
|
||||
(alignment > 0 && sectors % alignsecs == 0)) {
|
||||
/* nothing to do */
|
||||
warnx("%s: partition does not need resizing",
|
||||
device_name);
|
||||
return;
|
||||
}
|
||||
|
||||
newsize = map_resize(map, size, alignsecs);
|
||||
newsize = map_resize(map, sectors, alignsecs);
|
||||
if (newsize == 0 && alignment > 0) {
|
||||
warnx("%s: could not resize partition with alignment "
|
||||
"constraint", device_name);
|
||||
|
@ -198,11 +197,31 @@ cmd_resize(int argc, char *argv[])
|
|||
usage_resize();
|
||||
break;
|
||||
case 's':
|
||||
if (size > 0)
|
||||
if (sectors > 0 || size > 0)
|
||||
usage_resize();
|
||||
size = strtoll(optarg, &p, 10);
|
||||
if (*p != 0 || size < 1)
|
||||
sectors = strtoll(optarg, &p, 10);
|
||||
if (sectors < 1)
|
||||
usage_resize();
|
||||
if (*p == '\0')
|
||||
break;
|
||||
if (*p == 's' || *p == 'S') {
|
||||
if (*(p + 1) == '\0')
|
||||
break;
|
||||
else
|
||||
usage_resize();
|
||||
}
|
||||
if (*p == 'b' || *p == 'B') {
|
||||
if (*(p + 1) == '\0') {
|
||||
size = sectors;
|
||||
sectors = 0;
|
||||
break;
|
||||
} else
|
||||
usage_resize();
|
||||
}
|
||||
if (dehumanize_number(optarg, &human_num) < 0)
|
||||
usage_resize();
|
||||
size = human_num;
|
||||
sectors = 0;
|
||||
break;
|
||||
default:
|
||||
usage_resize();
|
||||
|
@ -223,12 +242,22 @@ cmd_resize(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (alignment % secsz != 0) {
|
||||
warnx("Alignment must be a multiple of sector size; ");
|
||||
warnx("Alignment must be a multiple of sector size;");
|
||||
warnx("the sector size for %s is %d bytes.",
|
||||
device_name, secsz);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (size % secsz != 0) {
|
||||
warnx("Size in bytes must be a multiple of sector "
|
||||
"size;");
|
||||
warnx("the sector size for %s is %d bytes.",
|
||||
device_name, secsz);
|
||||
continue;
|
||||
}
|
||||
if (size > 0)
|
||||
sectors = size / secsz;
|
||||
|
||||
resize(fd);
|
||||
|
||||
gpt_close(fd);
|
||||
|
|
Loading…
Reference in New Issue