Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt Add listing commands for type, set and unset.
details: https://anonhg.NetBSD.org/src/rev/c0043c5396ac
branches: trunk
changeset: 342097:c0043c5396ac
user: christos <christos%NetBSD.org@localhost>
date: Sun Dec 06 00:39:26 2015 +0000
description:
Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
diffstat:
sbin/gpt/gpt.8 | 34 ++++++++++++++----
sbin/gpt/gpt.c | 95 +++++++++++++++++++++++++++++++++++++++++++++-------
sbin/gpt/gpt.h | 4 +-
sbin/gpt/gpt_uuid.c | 13 ++++++-
sbin/gpt/gpt_uuid.h | 2 +
sbin/gpt/set.c | 10 +++-
sbin/gpt/show.c | 23 +++--------
sbin/gpt/type.c | 8 +++-
sbin/gpt/unset.c | 9 +++-
9 files changed, 150 insertions(+), 48 deletions(-)
diffs (truncated from 424 to 300 lines):
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8 Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/gpt.8 Sun Dec 06 00:39:26 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.41 2015/12/02 12:36:53 christos Exp $
+.\" $NetBSD: gpt.8,v 1.42 2015/12/06 00:39:26 christos Exp $
.\"
.\" Copyright (c) 2002 Marcel Moolenaar
.\" All rights reserved.
@@ -488,26 +488,33 @@
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 Fl l
The
.Ic set
command sets various partition attributes.
The
+.Fl l
+flag lists all available attributes.
+The
.Fl a
-option specifies which attributes to set and may be specified more than once.
+option specifies which attributes to set and may be specified more than once,
+or the attributes can be comma-separated.
The
.Fl i
option specifies which entry to update.
The possible attributes are
.Do biosboot Dc ,
.Do bootme Dc ,
-.Do bootonce Dc , and
-.Do bootfailed Dc .
+.Do bootonce Dc ,
+.Do bootfailed Dc ,
+.Do noblockio Dc , and
+.Do required Dc .
The biosboot flag is used to indicate which partition should be booted
by legacy BIOS boot code.
See the
.Ic biosboot
command for more information.
-The other three attributes are for compatibility with
+The other attributes are for compatibility with
.Fx
and are not currently used by any
.Nx
@@ -546,8 +553,10 @@
.\" ==== type ====
.It Nm Ic type Oo Fl a Oc Fl T Ar newtype
.It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \
+.It Nm Ic type 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 t Ar type Oc \
Fl T Ar newtype
+.It Nm Ic type Fl l
The
.Ic type
command allows the user to change the type of any and all partitions
@@ -556,12 +565,19 @@
.Ic label
command.
See above for a description of these options.
+The
+.Fl l
+flag lists available types.
.\" ==== unset ====
.It Nm Ic unset Fl a Ar attribute Fl i Ar index
+.It Nm Ic unset Fl l
The
.Ic unset
command unsets various partition attributes.
The
+.Fl l
+flag lists all available attributes.
+The
.Fl a
option specifies which attributes to unset and may be specified more than once.
The
@@ -570,14 +586,16 @@
The possible attributes are
.Do biosboot Dc ,
.Do bootme Dc ,
-.Do bootonce Dc , and
-.Do bootfailed Dc .
+.Do bootonce Dc ,
+.Do bootfailed Dc ,
+.Do noblockio Dc , and
+.Do required Dc .
The biosboot flag is used to indicate which partition should be booted
by legacy BIOS boot code.
See the
.Ic biosboot
command for more information.
-The other three attributes are for compatibility with
+The other attributes are for compatibility with
.Fx
and are not currently used by any
.Nx
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/gpt.c Sun Dec 06 00:39:26 2015 +0000
@@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.63 2015/12/04 16:46:24 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.64 2015/12/06 00:39:26 christos Exp $");
#endif
#include <sys/param.h>
@@ -1076,21 +1076,90 @@
return size / gpt->secsz;
return 0;
}
+
+static const struct nvd {
+ const char *name;
+ uint64_t mask;
+ const char *description;
+} gpt_attr[] = {
+ {
+ "biosboot",
+ GPT_ENT_ATTR_LEGACY_BIOS_BOOTABLE,
+ "Legacy BIOS boot partition",
+ },
+ {
+ "bootme",
+ GPT_ENT_ATTR_BOOTME,
+ "Bootable partition",
+ },
+ {
+ "bootfailed",
+ GPT_ENT_ATTR_BOOTFAILED,
+ "Partition that marked bootonce failed to boot",
+ },
+ {
+ "bootonce",
+ GPT_ENT_ATTR_BOOTONCE,
+ "Attempt to boot this partition only once",
+ },
+ {
+ "noblockio",
+ GPT_ENT_ATTR_NO_BLOCK_IO_PROTOCOL,
+ "UEFI won't recognize file system for block I/O",
+ },
+ {
+ "required",
+ GPT_ENT_ATTR_REQUIRED_PARTITION,
+ "Partition required for platform to function",
+ },
+};
+
int
-gpt_attr_get(uint64_t *attributes)
+gpt_attr_get(gpt_t gpt, uint64_t *attributes)
{
- if (strcmp(optarg, "biosboot") == 0)
- *attributes |= GPT_ENT_ATTR_LEGACY_BIOS_BOOTABLE;
- else if (strcmp(optarg, "bootme") == 0)
- *attributes |= GPT_ENT_ATTR_BOOTME;
- else if (strcmp(optarg, "bootonce") == 0)
- *attributes |= GPT_ENT_ATTR_BOOTONCE;
- else if (strcmp(optarg, "bootfailed") == 0)
- *attributes |= GPT_ENT_ATTR_BOOTFAILED;
- else
- return -1;
- return 0;
+ size_t i;
+ int rv = 0;
+ char *ptr;
+
+ *attributes = 0;
+
+ for (ptr = strtok(optarg, ","); ptr; ptr = strtok(NULL, ",")) {
+ for (i = 0; i < __arraycount(gpt_attr); i++)
+ if (strcmp(gpt_attr[i].name, ptr) == 0)
+ break;
+ if (i == __arraycount(gpt_attr)) {
+ gpt_warnx(gpt, "Unregognized attribute `%s'", ptr);
+ rv = -1;
+ } else
+ *attributes |= gpt_attr[i].mask;
+ }
+ return rv;
}
+
+void
+gpt_attr_help(const char *prefix)
+{
+ size_t i;
+
+ for (i = 0; i < __arraycount(gpt_attr); i++)
+ printf("%s%10.10s\t%s\n", prefix, gpt_attr[i].name,
+ gpt_attr[i].description);
+}
+
+const char *
+gpt_attr_list(char *buf, size_t len, uint64_t attributes)
+{
+ size_t i;
+ strlcpy(buf, "", len);
+
+ for (i = 0; i < __arraycount(gpt_attr); i++)
+ if (attributes & gpt_attr[i].mask) {
+ strlcat(buf, buf[0] ? "," : "", len);
+ strlcat(buf, gpt_attr[i].name, len);
+ }
+ return buf;
+}
+
int
gpt_attr_update(gpt_t gpt, u_int entry, uint64_t set, uint64_t clr)
{
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/gpt.h Sun Dec 06 00:39:26 2015 +0000
@@ -119,7 +119,9 @@
int gpt_add_ais(gpt_t, off_t *, u_int *, off_t *, int);
off_t gpt_check_ais(gpt_t, off_t, u_int, off_t);
-int gpt_attr_get(uint64_t *);
+int gpt_attr_get(gpt_t, uint64_t *);
+const char *gpt_attr_list(char *, size_t, uint64_t);
+void gpt_attr_help(const char *);
int gpt_attr_update(gpt_t, u_int, uint64_t, uint64_t);
int gpt_uint_get(u_int *);
int gpt_human_get(off_t *);
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/gpt_uuid.c
--- a/sbin/gpt/gpt_uuid.c Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/gpt_uuid.c Sun Dec 06 00:39:26 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gpt_uuid.c,v 1.12 2015/12/03 02:02:43 christos Exp $ */
+/* $NetBSD: gpt_uuid.c,v 1.13 2015/12/06 00:39:26 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.12 2015/12/03 02:02:43 christos Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.13 2015/12/06 00:39:26 christos Exp $");
#endif
#include <err.h>
@@ -231,6 +231,15 @@
}
void
+gpt_uuid_help(const char *prefix)
+{
+ size_t i;
+
+ for (i = 0; i < __arraycount(gpt_nv); i++)
+ printf("%s%18.18s\t%s\n", prefix, gpt_nv[i].n, gpt_nv[i].d);
+}
+
+void
gpt_uuid_create(gpt_type_t t, gpt_uuid_t u, uint16_t *b, size_t s)
{
gpt_dce_to_uuid(&gpt_nv[t].u, u);
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/gpt_uuid.h
--- a/sbin/gpt/gpt_uuid.h Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/gpt_uuid.h Sun Dec 06 00:39:26 2015 +0000
@@ -97,6 +97,8 @@
struct gpt;
int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
+void gpt_uuid_help(const char *);
+
__END_DECLS
#endif /* _GPT_UUID_T */
diff -r 7e604304efde -r c0043c5396ac sbin/gpt/set.c
--- a/sbin/gpt/set.c Sun Dec 06 00:38:30 2015 +0000
+++ b/sbin/gpt/set.c Sun Dec 06 00:39:26 2015 +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: set.c,v 1.11 2015/12/03 02:02:43 christos Exp $");
+__RCSID("$NetBSD: set.c,v 1.12 2015/12/06 00:39:26 christos Exp $");
#endif
#include <sys/types.h>
@@ -53,6 +53,7 @@
static const char *sethelp[] = {
"-a attribute -i index",
+ "-l",
};
struct gpt_cmd c_set = {
@@ -71,16 +72,19 @@
unsigned int entry = 0;
uint64_t attributes = 0;
- while ((ch = getopt(argc, argv, "a:i:")) != -1) {
+ while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
switch(ch) {
Home |
Main Index |
Thread Index |
Old Index