Module Name:    src
Committed By:   martin
Date:           Mon Mar 25 20:15:49 UTC 2019

Modified Files:
        src/sbin/gpt: gpt.8 set.c

Log Message:
Allow -b startsec to specify the partition to change for the set subcommand
as well.
Add another option, -N, as a quick way to remove all attributes.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/set.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/gpt.8
diff -u src/sbin/gpt/gpt.8:1.65 src/sbin/gpt/gpt.8:1.66
--- src/sbin/gpt/gpt.8:1.65	Sun Mar 24 13:45:35 2019
+++ src/sbin/gpt/gpt.8	Mon Mar 25 20:15:49 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $
+.\" $NetBSD: gpt.8,v 1.66 2019/03/25 20:15:49 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 March 24, 2019
+.Dd March 25, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -555,7 +555,8 @@ the partitions fit, as
 will automatically adjust.
 However, the new disk must use the same sector size as the old disk.
 .\" ==== set ====
-.It Nm Ic set Fl a Ar attribute Fl i Ar index
+.It Nm Ic set Oo Fl a Ar attribute Oc Oo Fl N Oc Oo Fl i Ar index Oc \
+Oo Fl b Ar startsec Oc
 .It Nm Ic set Fl l
 The
 .Ic set
@@ -567,9 +568,16 @@ The
 .Fl a
 option specifies which attributes to set and may be specified more than once,
 or the attributes can be comma-separated.
+If the
+.Fl N
+option and no
+.Fl a
+option are specified, all attributes are removed.
 The
 .Fl i
-option specifies which entry to update.
+or the
+.Fl b
+option specify which entry to update.
 The possible attributes are
 .Do biosboot Dc ,
 .Do bootme Dc ,

Index: src/sbin/gpt/set.c
diff -u src/sbin/gpt/set.c:1.14 src/sbin/gpt/set.c:1.15
--- src/sbin/gpt/set.c:1.14	Mon Mar 19 09:06:20 2018
+++ src/sbin/gpt/set.c	Mon Mar 25 20:15:49 2019
@@ -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: set.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $");
+__RCSID("$NetBSD: set.c,v 1.15 2019/03/25 20:15:49 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -52,7 +52,8 @@ __RCSID("$NetBSD: set.c,v 1.14 2018/03/1
 static int cmd_set(gpt_t, int, char *[]);
 
 static const char *sethelp[] = {
-	"-a attribute -i index",
+	"-a attribute [-i index] [-b startsec]",
+	"-N [-i index] [-b startsec]",
 	"-l",
 };
 
@@ -70,14 +71,20 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 {
 	int ch;
 	unsigned int entry = 0;
-	uint64_t attributes = 0;
+	uint64_t attributes = 0, clear = 0;
+	off_t start = 0;
+	map_t m;
 
-	while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
+	while ((ch = getopt(argc, argv, "a:b:i:lN")) != -1) {
 		switch(ch) {
 		case 'a':
 			if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
 				return usage();
 			break;
+		case 'b':
+			if (gpt == NULL || gpt_human_get(gpt, &start) == -1)
+				return usage();
+			break;
 		case 'i':
 			if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
 				return usage();
@@ -85,13 +92,28 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 		case 'l':
 			gpt_attr_help("\t");
 			return 0;
+		case 'N':
+			clear = ~clear;
+			break;
 		default:
 			return usage();
 		}
 	}
 
-	if (gpt == NULL || argc != optind)
+	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 (gpt == NULL || argc != optind || (attributes != 0 && clear != 0))
 		return usage();
 
-	return gpt_attr_update(gpt, entry, attributes, 0);
+	return gpt_attr_update(gpt, entry, attributes, clear);
 }

Reply via email to