Don't attempt to create/resize an unaligned partition if the attempt trunk
authorjnemeth <jnemeth@NetBSD.org>
Fri, 06 Dec 2013 02:31:31 +0000
branchtrunk
changeset 222948 ac1ed9663348
parent 222947 9eb77e8da79d
child 222949 f12751e45036
Don't attempt to create/resize an unaligned partition if the attempt to create/resize an aligned one failed. This simplifies the code and prevents surprises. If the user wants an unaligned partition in the case where an aligned one fails, they can simply retry the command without the "-a" option. This change was requested by wiz@, and after some thought I agree with it.
sbin/gpt/add.c
sbin/gpt/gpt.8
sbin/gpt/resize.c
--- a/sbin/gpt/add.c	Fri Dec 06 01:33:37 2013 +0000
+++ b/sbin/gpt/add.c	Fri Dec 06 02:31:31 2013 +0000
@@ -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.21 2013/11/28 01:37:14 jnemeth Exp $");
+__RCSID("$NetBSD: add.c,v 1.22 2013/12/06 02:31:31 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -136,17 +136,15 @@
 		alignsecs = alignment / secsz;
 		map = map_alloc(block, size, alignsecs);
 		if (map == NULL) {
-			warnx("%s: error: not enough space available on device for an aligned partition", device_name);
-			map = map_alloc(block, size, 0);
-			if (map == NULL) {
-				warnx("%s: error: not enough available on device", device_name);
-				return;
-			}
+			warnx("%s: error: not enough space available on "
+			      "device for an aligned partition", device_name);
+			return;
 		}
 	} else {
 		map = map_alloc(block, size, 0);
 		if (map == NULL) {
-			warnx("%s: error: not enough space available on device", device_name);
+			warnx("%s: error: not enough space available on "
+			      "device", device_name);
 			return;
 		}
 	}
--- a/sbin/gpt/gpt.8	Fri Dec 06 01:33:37 2013 +0000
+++ b/sbin/gpt/gpt.8	Fri Dec 06 02:31:31 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.21 2013/11/30 19:43:53 jnemeth Exp $
+.\" $NetBSD: gpt.8,v 1.22 2013/12/06 02:31:31 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 November 30, 2013
+.Dd December 5, 2013
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -110,7 +110,6 @@
 The alignment may have a suffix to indicate its magnitude.
 .Nm
 will attempt to align the partition.
-If it can not, then it will attempt to create an unaligned partition.
 .Pp
 The
 .Fl b Ar blocknr
--- a/sbin/gpt/resize.c	Fri Dec 06 01:33:37 2013 +0000
+++ b/sbin/gpt/resize.c	Fri Dec 06 02:31:31 2013 +0000
@@ -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.5 2013/11/28 01:37:14 jnemeth Exp $");
+__RCSID("$NetBSD: resize.c,v 1.6 2013/12/06 02:31:31 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -134,12 +134,11 @@
 		}
 
 	newsize = map_resize(map, size, alignsecs);
-	if (newsize == 0 && alignment > 0 && size > 0) {
+	if (newsize == 0 && alignment > 0) {
 		warnx("%s: could not resize partition with alignment "
 		      "constraint", device_name);
-		newsize = map_resize(map, size, 0);
-	}
-	if (newsize == 0) {
+		return;
+	} else if (newsize == 0) {
 		warnx("%s: could not resize partition", device_name);
 		return;
 	}