Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt For the add and resize subcommands, change the -s o...



details:   https://anonhg.NetBSD.org/src/rev/ef44490f0c8e
branches:  trunk
changeset: 325138:ef44490f0c8e
user:      jnemeth <jnemeth%NetBSD.org@localhost>
date:      Sun Dec 08 09:32:51 2013 +0000

description:
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.

diffstat:

 sbin/gpt/add.c    |  48 +++++++++++++++++++++++++++++++++++++++---------
 sbin/gpt/gpt.8    |  27 ++++++++++++++++++++-------
 sbin/gpt/resize.c |  51 ++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 99 insertions(+), 27 deletions(-)

diffs (277 lines):

diff -r 47885209c414 -r ef44490f0c8e sbin/gpt/add.c
--- a/sbin/gpt/add.c    Sun Dec 08 08:55:27 2013 +0000
+++ b/sbin/gpt/add.c    Sun Dec 08 09:32:51 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.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 @@
 #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 @@
 
        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 @@
                        name = (uint8_t *)strdup(optarg);
                        break;
                case 's':
-                       if (size > 0)
+                       if (sectors > 0 || size > 0)
+                               usage_add();
+                       sectors = strtoll(optarg, &p, 10);
+                       if (sectors < 1)
                                usage_add();
-                       size = strtoll(optarg, &p, 10);
-                       if (*p != 0 || size < 1)
+                       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 @@
                }
 
                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);
diff -r 47885209c414 -r ef44490f0c8e sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Sun Dec 08 08:55:27 2013 +0000
+++ b/sbin/gpt/gpt.8    Sun Dec 08 09:32:51 2013 +0000
@@ -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 @@
 .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 @@
 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 @@
 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 @@
 .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
diff -r 47885209c414 -r ef44490f0c8e sbin/gpt/resize.c
--- a/sbin/gpt/resize.c Sun Dec 08 08:55:27 2013 +0000
+++ b/sbin/gpt/resize.c Sun Dec 08 09:32:51 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.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 @@
 #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 @@
                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 @@
                                usage_resize();
                        break;
                case 's':
-                       if (size > 0)
+                       if (sectors > 0 || size > 0)
+                               usage_resize();
+                       sectors = strtoll(optarg, &p, 10);
+                       if (sectors < 1)
                                usage_resize();
-                       size = strtoll(optarg, &p, 10);
-                       if (*p != 0 || size < 1)
+                       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 @@
                }
 
                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);



Home | Main Index | Thread Index | Old Index