Module Name: src
Committed By: jnemeth
Date: Mon Sep 29 05:56:43 UTC 2014
Modified Files:
src/sbin/gpt: biosboot.c gpt.8 label.c remove.c type.c
Log Message:
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sbin/gpt/biosboot.c
cvs rdiff -u -r1.31 -r1.32 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/label.c
cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/remove.c
cvs rdiff -u -r1.1 -r1.2 src/sbin/gpt/type.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/biosboot.c
diff -u src/sbin/gpt/biosboot.c:1.8 src/sbin/gpt/biosboot.c:1.9
--- src/sbin/gpt/biosboot.c:1.8 Fri Sep 26 05:34:15 2014
+++ src/sbin/gpt/biosboot.c Mon Sep 29 05:56:43 2014
@@ -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 uint64_t size;
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 @@ biosboot(int fd)
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 @@ biosboot(int fd)
warnx("error: cannot update Protective MBR");
return;
}
+
+ printf("partition %d marked as bootable\n", i + 1);
}
int
@@ -263,7 +272,7 @@ cmd_biosboot(int argc, char *argv[])
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 @@ cmd_biosboot(int argc, char *argv[])
if (*p != 0 || entry < 1)
usage_biosboot();
break;
+ case 'L':
+ if (label != NULL)
+ usage_biosboot();
+ label = (uint8_t *)strdup(optarg);
+ break;
default:
usage_biosboot();
}
Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.31 src/sbin/gpt/gpt.8:1.32
--- src/sbin/gpt/gpt.8:1.31 Sun Sep 28 08:14:51 2014
+++ src/sbin/gpt/gpt.8 Mon Sep 29 05:56:43 2014
@@ -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 @@ command.
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 @@ The
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 @@ to destroy the table in a way that it ca
.\" ==== 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 @@ The
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 @@ It is very useful in case the primary la
.\" ==== 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 @@ The order of precedence for the options
.\" ==== 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
Index: src/sbin/gpt/label.c
diff -u src/sbin/gpt/label.c:1.14 src/sbin/gpt/label.c:1.15
--- src/sbin/gpt/label.c:1.14 Thu Nov 28 01:37:14 2013
+++ src/sbin/gpt/label.c Mon Sep 29 05:56:43 2014
@@ -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 int all;
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 @@ label(int fd)
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 @@ cmd_label(int argc, char *argv[])
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 @@ cmd_label(int argc, char *argv[])
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 @@ cmd_label(int argc, char *argv[])
}
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)
Index: src/sbin/gpt/remove.c
diff -u src/sbin/gpt/remove.c:1.12 src/sbin/gpt/remove.c:1.13
--- src/sbin/gpt/remove.c:1.12 Thu Nov 28 01:37:14 2013
+++ src/sbin/gpt/remove.c Mon Sep 29 05:56:43 2014
@@ -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 int all;
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 @@ rem(int fd)
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 @@ cmd_remove(int argc, char *argv[])
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 @@ cmd_remove(int argc, char *argv[])
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 @@ cmd_remove(int argc, char *argv[])
}
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)
Index: src/sbin/gpt/type.c
diff -u src/sbin/gpt/type.c:1.1 src/sbin/gpt/type.c:1.2
--- src/sbin/gpt/type.c:1.1 Sun Sep 28 08:14:51 2014
+++ src/sbin/gpt/type.c Mon Sep 29 05:56:43 2014
@@ -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: type.c,v 1.1 2014/09/28 08:14:51 jnemeth Exp $");
+__RCSID("$NetBSD: type.c,v 1.2 2014/09/29 05:56:43 jnemeth Exp $");
#endif
#include <sys/types.h>
@@ -48,9 +48,11 @@ static int all;
static uuid_t type, newtype;
static off_t block, size;
static unsigned int entry;
+static uint8_t *label;
const char typemsg1[] = "type -a -T newtype device ...";
-const char typemsg2[] = "type [-b blocknr] [-i index] [-s sectors] [-t type]";
+const char typemsg2[] = "type [-b blocknr] [-i index] [-L label] "
+ "[-s sectors] [-t type]";
const char typemsg3[] = " -T newtype device ...";
__dead static void
@@ -113,6 +115,12 @@ chtype(int fd)
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))
@@ -155,7 +163,7 @@ cmd_type(int argc, char *argv[])
int64_t human_num;
/* Get the type options */
- while ((ch = getopt(argc, argv, "ab:i:s:t:T:")) != -1) {
+ while ((ch = getopt(argc, argv, "ab:i:L:s:t:T:")) != -1) {
switch(ch) {
case 'a':
if (all > 0)
@@ -178,6 +186,11 @@ cmd_type(int argc, char *argv[])
if (*p != 0 || entry < 1)
usage_type();
break;
+ case 'L':
+ if (label != NULL)
+ usage_type();
+ label = (uint8_t *)strdup(optarg);
+ break;
case 's':
if (size > 0)
usage_type();
@@ -203,7 +216,8 @@ cmd_type(int argc, char *argv[])
}
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_type();
if (uuid_is_nil(&newtype, NULL))
usage_type();