Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <lab...



details:   https://anonhg.NetBSD.org/src/rev/843014be49ba
branches:  trunk
changeset: 332573:843014be49ba
user:      jnemeth <jnemeth%NetBSD.org@localhost>
date:      Mon Sep 29 05:56:43 2014 +0000

description:
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option

diffstat:

 sbin/gpt/biosboot.c |  24 +++++++++++++++++++-----
 sbin/gpt/gpt.8      |  24 ++++++++++++++++++------
 sbin/gpt/label.c    |  23 ++++++++++++++++++-----
 sbin/gpt/remove.c   |  23 ++++++++++++++++++-----
 sbin/gpt/type.c     |  22 ++++++++++++++++++----
 5 files changed, 91 insertions(+), 25 deletions(-)

diffs (truncated from 364 to 300 lines):

diff -r 5ba1768fd1d4 -r 843014be49ba sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c       Sun Sep 28 18:59:43 2014 +0000
+++ b/sbin/gpt/biosboot.c       Mon Sep 29 05:56:43 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosboot.c,v 1.8 2014/09/26 05:34:15 jnemeth Exp $ */
+/*     $NetBSD: biosboot.c,v 1.9 2014/09/29 05:56:43 jnemeth Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.8 2014/09/26 05:34:15 jnemeth Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.9 2014/09/29 05:56:43 jnemeth Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -65,8 +65,10 @@
 
 static char *bootpath;
 static unsigned int entry;
+static uint8_t *label;
 
-const char biosbootmsg[] = "biosboot [-c bootcode] [-i index] device ...";
+const char biosbootmsg[] = "biosboot [-c bootcode] [-i index] "
+       "[-L label] device ...";
 
 __dead static void
 usage_biosboot(void)
@@ -196,8 +198,13 @@
                if (entry > 0 && m->map_index == entry)
                        break;
 
+               if (label != NULL)
+                       if (strcmp((char *)label,
+                           (char *)utf16_to_utf8(ent->ent_name)) == 0)
+                               break;
+
                /* next, partition as could be specified by wedge */
-               if (entry < 1 && size > 0 &&
+               if (entry < 1 && label == NULL && size > 0 &&
                    m->map_start == start && m->map_size == (off_t)size)
                        break;
        }
@@ -252,6 +259,8 @@
                warnx("error: cannot update Protective MBR");
                return;
        }
+
+       printf("partition %d marked as bootable\n", i + 1);
 }
 
 int
@@ -263,7 +272,7 @@
        char *dev, *p;
        int ch, fd;
 
-       while ((ch = getopt(argc, argv, "c:i:")) != -1) {
+       while ((ch = getopt(argc, argv, "c:i:L:")) != -1) {
                switch(ch) {
                case 'c':
                        if (bootpath != NULL)
@@ -278,6 +287,11 @@
                        if (*p != 0 || entry < 1)
                                usage_biosboot();
                        break;
+               case 'L':
+                       if (label != NULL)
+                               usage_biosboot();
+                       label = (uint8_t *)strdup(optarg);
+                       break;
                default:
                        usage_biosboot();
                }
diff -r 5ba1768fd1d4 -r 843014be49ba sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Sun Sep 28 18:59:43 2014 +0000
+++ b/sbin/gpt/gpt.8    Mon Sep 29 05:56:43 2014 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.31 2014/09/28 08:14:51 jnemeth Exp $
+.\" $NetBSD: gpt.8,v 1.32 2014/09/29 05:56:43 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 September 28, 2014
+.Dd September 29, 2014
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -162,7 +162,8 @@
 The format is a plist.
 It should not be modified.
 .\" ==== biosboot ====
-.It Nm Ic biosboot Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc Ar device ...
+.It Nm Ic biosboot Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \
+Oo Fl L Ar label Oc Ar device ...
 The
 .Ic biosboot
 command allows the user to configure the partition that contains the
@@ -182,6 +183,11 @@
 option selects the partition that should contain the primary
 bootstrap code, as installed via
 .Xr installboot 8 .
+The
+.Fl L
+option selects the partition by label.
+If there are multiple partitions with the same label, it will use the
+first one found.
 .\" ==== create ====
 .It Nm Ic create Oo Fl fp Oc Ar device ...
 The
@@ -216,7 +222,7 @@
 .\" ==== label ====
 .It Nm Ic label Oo Fl a Oc Ao Fl f Ar file | Fl l Ar label Ac Ar device ...
 .It Nm Ic label Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \
-Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc \
+Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc \
 Ao Fl f Ar file | Fl l Ar label Ac Ar device ...
 The
 .Ic label
@@ -237,6 +243,11 @@
 option selects the partition with the given partition number.
 .Pp
 The
+.Fl L Ar label
+option selects all partitions that have the given label.
+This can cause multiple partitions to be relabeled.
+.Pp
+The
 .Fl s Ar sectors
 option selects all partitions that have the given size.
 This can cause multiple partitions to be labeled.
@@ -320,7 +331,7 @@
 .\" ==== remove ====
 .It Nm Ic remove Oo Fl a Oc Ar device ...
 .It Nm Ic remove Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \
-Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc Ar device ...
+Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc Ar device ...
 The
 .Ic remove
 command allows the user to remove any and all partitions that match the
@@ -460,7 +471,8 @@
 .\" ==== type ====
 .It Nm Ic type Oo Fl a Oc Fl T Ar newtype Ar device ...
 .It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \
-Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc Fl T Ar newtype Ar device ...
+Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc \
+Fl T Ar newtype Ar device ...
 The
 .Ic type
 command allows the user to change the type of any and all partitions
diff -r 5ba1768fd1d4 -r 843014be49ba sbin/gpt/label.c
--- a/sbin/gpt/label.c  Sun Sep 28 18:59:43 2014 +0000
+++ b/sbin/gpt/label.c  Mon Sep 29 05:56:43 2014 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: label.c,v 1.14 2013/11/28 01:37:14 jnemeth Exp $");
+__RCSID("$NetBSD: label.c,v 1.15 2014/09/29 05:56:43 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -48,10 +48,11 @@
 static uuid_t type;
 static off_t block, size;
 static unsigned int entry;
-static uint8_t *name;
+static uint8_t *name, *xlabel;
 
 const char labelmsg1[] = "label -a <-l label | -f file> device ...";
-const char labelmsg2[] = "label [-b blocknr] [-i index] [-s sectors]";
+const char labelmsg2[] = "label [-b blocknr] [-i index] [-L label] "
+       "[-s sectors]";
 const char labelmsg3[] = "      [-t uuid] <-l label | -f file> device ...";
 
 __dead static void
@@ -113,6 +114,12 @@
                hdr = gpt->map_data;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
+
+               if (xlabel != NULL)
+                       if (strcmp((char *)xlabel,
+                           (char *)utf16_to_utf8(ent->ent_name)) != 0)
+                               continue;
+
                le_uuid_dec(ent->ent_type, &uuid);
                if (!uuid_is_nil(&type, NULL) &&
                    !uuid_equal(&type, &uuid, NULL))
@@ -184,7 +191,7 @@
        int64_t human_num;
 
        /* Get the label options */
-       while ((ch = getopt(argc, argv, "ab:f:i:l:s:t:")) != -1) {
+       while ((ch = getopt(argc, argv, "ab:f:i:L:l:s:t:")) != -1) {
                switch(ch) {
                case 'a':
                        if (all > 0)
@@ -212,6 +219,11 @@
                        if (*p != 0 || entry < 1)
                                usage_label();
                        break;
+               case 'L':
+                       if (xlabel != NULL)
+                               usage_label();
+                       xlabel = (uint8_t *)strdup(optarg);
+                       break;
                case 'l':
                        if (name != NULL)
                                usage_label();
@@ -236,7 +248,8 @@
        }
 
        if (!all ^
-           (block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL)))
+           (block > 0 || entry > 0 || xlabel != NULL || size > 0 ||
+           !uuid_is_nil(&type, NULL)))
                usage_label();
 
        if (name == NULL || argc == optind)
diff -r 5ba1768fd1d4 -r 843014be49ba sbin/gpt/remove.c
--- a/sbin/gpt/remove.c Sun Sep 28 18:59:43 2014 +0000
+++ b/sbin/gpt/remove.c Mon Sep 29 05:56:43 2014 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: remove.c,v 1.12 2013/11/28 01:37:14 jnemeth Exp $");
+__RCSID("$NetBSD: remove.c,v 1.13 2014/09/29 05:56:43 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -48,10 +48,11 @@
 static uuid_t type;
 static off_t block, size;
 static unsigned int entry;
+static uint8_t *label;
 
 const char removemsg1[] = "remove -a device ...";
-const char removemsg2[] = "remove [-b blocknr] [-i index] [-s sectors] "
-       "[-t type] device ...";
+const char removemsg2[] = "remove [-b blocknr] [-i index] [-L label] "
+       "[-s sectors] [-t type] device ...";
 
 __dead static void
 usage_remove(void)
@@ -112,6 +113,12 @@
                hdr = gpt->map_data;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
+
+               if (label != NULL)
+                       if (strcmp((char *)label,
+                           (char *)utf16_to_utf8(ent->ent_name)) != 0)
+                               continue;
+
                le_uuid_dec(ent->ent_type, &uuid);
                if (!uuid_is_nil(&type, NULL) &&
                    !uuid_equal(&type, &uuid, NULL))
@@ -156,7 +163,7 @@
        int64_t human_num;
 
        /* Get the remove options */
-       while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
+       while ((ch = getopt(argc, argv, "ab:i:L:s:t:")) != -1) {
                switch(ch) {
                case 'a':
                        if (all > 0)
@@ -179,6 +186,11 @@
                        if (*p != 0 || entry < 1)
                                usage_remove();
                        break;
+               case 'L':
+                       if (label != NULL)
+                               usage_remove();
+                       label = (uint8_t *)strdup(optarg);
+                       break;
                case 's':
                        if (size > 0)
                                usage_remove();
@@ -198,7 +210,8 @@
        }
 
        if (!all ^
-           (block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL)))
+           (block > 0 || entry > 0 || label != NULL || size > 0 ||
+           !uuid_is_nil(&type, NULL)))
                usage_remove();
 
        if (argc == optind)
diff -r 5ba1768fd1d4 -r 843014be49ba sbin/gpt/type.c
--- a/sbin/gpt/type.c   Sun Sep 28 18:59:43 2014 +0000
+++ b/sbin/gpt/type.c   Mon Sep 29 05:56:43 2014 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");



Home | Main Index | Thread Index | Old Index