Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt Add support for specifying the partition to resize ...



details:   https://anonhg.NetBSD.org/src/rev/a6684ea4cb98
branches:  trunk
changeset: 449801:a6684ea4cb98
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 24 13:31:00 2019 +0000

description:
Add support for specifying the partition to resize via -b startsec
(similar to label and other subcommands). Do not fully add gpt_find
functionality here, as resizing multiple partitions in one go does not
make sense.

diffstat:

 sbin/gpt/gpt.8    |   6 +++---
 sbin/gpt/resize.c |  25 ++++++++++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diffs (84 lines):

diff -r 340a9e4dbb78 -r a6684ea4cb98 sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Sun Mar 24 13:15:42 2019 +0000
+++ b/sbin/gpt/gpt.8    Sun Mar 24 13:31:00 2019 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.63 2018/05/01 21:16:02 kre Exp $
+.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin 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 May 1, 2018
+.Dd March 24, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -466,7 +466,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 \
+.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \
 Oo Fl s Ar size Oc
 The
 .Ic resize
diff -r 340a9e4dbb78 -r a6684ea4cb98 sbin/gpt/resize.c
--- a/sbin/gpt/resize.c Sun Mar 24 13:15:42 2019 +0000
+++ b/sbin/gpt/resize.c Sun Mar 24 13:31:00 2019 +0000
@@ -33,7 +33,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.23 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: resize.c,v 1.24 2019/03/24 13:31:00 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -52,7 +52,7 @@
 static int cmd_resize(gpt_t, int, char *[]);
 
 static const char *resizehelp[] = {
-       "-i index [-a alignment] [-s size]",
+       "[-i index | -b blocknr] [-a alignment] [-s size]",
 };
 
 struct gpt_cmd c_resize = {
@@ -131,17 +131,32 @@
 cmd_resize(gpt_t gpt, int argc, char *argv[])
 {
        int ch;
-       off_t alignment = 0, sectors, size = 0;
+       off_t alignment = 0, sectors, start = 0, size = 0;
        unsigned int entry = 0;
+       map_t m;
 
-       while ((ch = getopt(argc, argv, GPT_AIS)) != -1) {
-               if (gpt_add_ais(gpt, &alignment, &entry, &size, ch) == -1)
+       while ((ch = getopt(argc, argv, GPT_AIS "b:")) != -1) {
+               if (ch == 'b')
+                       gpt_human_get(gpt, &start);
+               else if (gpt_add_ais(gpt, &alignment, &entry, &size, ch) == -1)
                        return usage();
        }
 
        if (argc != optind)
                return usage();
 
+       if (start > 0) {
+               for (m = map_first(gpt); m != NULL; m = m->map_next) {
+                       if (m->map_type != MAP_TYPE_GPT_PART ||
+                           m->map_index < 1)
+                               continue;
+                       if (start != m->map_start)
+                               continue;
+                       entry = m->map_index;
+                       break;
+               }
+       }
+
        if ((sectors = gpt_check_ais(gpt, alignment, entry, size)) == -1)
                return -1;
 



Home | Main Index | Thread Index | Old Index