Module Name:    src
Committed By:   jnemeth
Date:           Sun Dec  8 09:32:51 UTC 2013

Modified Files:
        src/sbin/gpt: add.c gpt.8 resize.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/add.c src/sbin/gpt/gpt.8
cvs rdiff -u -r1.6 -r1.7 src/sbin/gpt/resize.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/add.c
diff -u src/sbin/gpt/add.c:1.22 src/sbin/gpt/add.c:1.23
--- src/sbin/gpt/add.c:1.22	Fri Dec  6 02:31:31 2013
+++ src/sbin/gpt/add.c	Sun Dec  8 09:32:51 2013
@@ -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/0
 #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,11 +280,21 @@ 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);
 
Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.22 src/sbin/gpt/gpt.8:1.23
--- src/sbin/gpt/gpt.8:1.22	Fri Dec  6 02:31:31 2013
+++ src/sbin/gpt/gpt.8	Sun Dec  8 09:32:51 2013
@@ -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
 .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 p
 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

Index: src/sbin/gpt/resize.c
diff -u src/sbin/gpt/resize.c:1.6 src/sbin/gpt/resize.c:1.7
--- src/sbin/gpt/resize.c:1.6	Fri Dec  6 02:31:31 2013
+++ src/sbin/gpt/resize.c	Sun Dec  8 09:32:51 2013
@@ -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
 #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,11 +242,21 @@ 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);
 

Reply via email to