Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt Add a "header" subcommand that displays information...
details: https://anonhg.NetBSD.org/src/rev/bb8afe96aee2
branches: trunk
changeset: 341375:bb8afe96aee2
user: jnemeth <jnemeth%NetBSD.org@localhost>
date: Tue Nov 03 02:19:24 2015 +0000
description:
Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
diffstat:
sbin/gpt/Makefile | 4 +-
sbin/gpt/gpt.8 | 10 ++-
sbin/gpt/gpt.c | 14 ++--
sbin/gpt/gpt.h | 1 +
sbin/gpt/header.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 164 insertions(+), 10 deletions(-)
diffs (256 lines):
diff -r 74b5cc83a98b -r bb8afe96aee2 sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Tue Nov 03 02:04:12 2015 +0000
+++ b/sbin/gpt/Makefile Tue Nov 03 02:19:24 2015 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.13 2014/12/29 16:27:06 christos Exp $
+# $NetBSD: Makefile,v 1.14 2015/11/03 02:19:24 jnemeth Exp $
# $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
PROG= gpt
-SRCS= add.c biosboot.c create.c destroy.c gpt.c label.c map.c \
+SRCS= add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \
migrate.c recover.c remove.c resize.c resizedisk.c \
set.c show.c type.c unset.c gpt_uuid.c
MAN= gpt.8
diff -r 74b5cc83a98b -r bb8afe96aee2 sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8 Tue Nov 03 02:04:12 2015 +0000
+++ b/sbin/gpt/gpt.8 Tue Nov 03 02:19:24 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.36 2014/12/06 21:53:55 wiz Exp $
+.\" $NetBSD: gpt.8,v 1.37 2015/11/03 02:19:24 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 December 6, 2014
+.Dd November 2, 2015
.Dt GPT 8
.Os
.Sh NAME
@@ -271,6 +271,12 @@
option instructs
.Nm
to destroy the table in a way that it can be recovered.
+.\" ==== header ====
+.It Nm Ic header Ar device ...
+The
+.Ic header
+command displays size information about the media and information from the
+GPT header if it exists.
.\" ==== 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 \
diff -r 74b5cc83a98b -r bb8afe96aee2 sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c Tue Nov 03 02:04:12 2015 +0000
+++ b/sbin/gpt/gpt.c Tue Nov 03 02:19:24 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.40 2014/12/29 16:27:06 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.41 2015/11/03 02:19:24 jnemeth Exp $");
#endif
#include <sys/param.h>
@@ -553,6 +553,7 @@
{ cmd_biosboot, "biosboot" },
{ cmd_create, "create" },
{ cmd_destroy, "destroy" },
+ { cmd_header, "header" },
{ NULL, "help" },
{ cmd_label, "label" },
{ cmd_migrate, "migrate" },
@@ -576,10 +577,10 @@
usage(void)
{
extern const char addmsg1[], addmsg2[], biosbootmsg[];
- extern const char createmsg[], destroymsg[], labelmsg1[], labelmsg2[];
- extern const char labelmsg3[], migratemsg[], recovermsg[], removemsg1[];
- extern const char removemsg2[], resizemsg[], resizediskmsg[];
- extern const char setmsg[], showmsg[], typemsg1[];
+ extern const char createmsg[], destroymsg[], headermsg[], labelmsg1[];
+ extern const char labelmsg2[], labelmsg3[], migratemsg[], recovermsg[];
+ extern const char removemsg1[], removemsg2[], resizemsg[];
+ extern const char resizediskmsg[], setmsg[], showmsg[], typemsg1[];
extern const char typemsg2[], typemsg3[], unsetmsg[];
#ifndef HAVE_NBTOOL_CONFIG_H
extern const char backupmsg[], restoremsg[];
@@ -615,13 +616,14 @@
" %s\n"
" %s\n"
" %s\n"
+ " %s\n"
" %s\n",
addmsg1, addmsg2,
#ifndef HAVE_NBTOOL_CONFIG_H
backupmsg,
#endif
biosbootmsg, createmsg, destroymsg,
- labelmsg1, labelmsg2, labelmsg3,
+ headermsg, labelmsg1, labelmsg2, labelmsg3,
migratemsg, recovermsg,
removemsg1, removemsg2,
resizemsg, resizediskmsg,
diff -r 74b5cc83a98b -r bb8afe96aee2 sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h Tue Nov 03 02:04:12 2015 +0000
+++ b/sbin/gpt/gpt.h Tue Nov 03 02:19:24 2015 +0000
@@ -82,6 +82,7 @@
int cmd_biosboot(int, char *[]);
int cmd_create(int, char *[]);
int cmd_destroy(int, char *[]);
+int cmd_header(int, char *[]);
int cmd_label(int, char *[]);
int cmd_migrate(int, char *[]);
int cmd_recover(int, char *[]);
diff -r 74b5cc83a98b -r bb8afe96aee2 sbin/gpt/header.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/gpt/header.c Tue Nov 03 02:19:24 2015 +0000
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John Nemeth
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#ifdef __RCSID
+__RCSID("$NetBSD: header.c,v 1.1 2015/11/03 02:19:24 jnemeth Exp $");
+#endif
+
+#include <sys/types.h>
+
+#include <err.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "map.h"
+#include "gpt.h"
+
+const char headermsg[] = "header device ...";
+
+__dead static void
+usage_header(void)
+{
+
+ fprintf(stderr,
+ "usage: %s %s\n", getprogname(), headermsg);
+ exit(1);
+}
+
+static void
+header(void)
+{
+ map_t *gpt;
+ struct gpt_hdr *hdr;
+ char buf[128];
+#ifdef HN_AUTOSCALE
+ char human_num[5];
+#endif
+
+#ifdef HN_AUTOSCALE
+ if (humanize_number(human_num, 5, mediasz,
+ "", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0)
+ human_num[0] = '\0';
+ if (human_num[0] != '\0')
+ printf("Media Size: %llu (%s)\n", (long long unsigned)mediasz,
+ human_num);
+ else
+#endif
+ printf("Media Size: %llu\n", (long long unsigned)mediasz);
+
+ printf("Sector Size: %u\n", secsz);
+
+#ifdef HN_AUTOSCALE
+ if (humanize_number(human_num, 5, mediasz / secsz,
+ "", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0)
+ human_num[0] = '\0';
+ if (human_num[0] != '\0')
+ printf("Number of Sectors: %llu (%s)\n",
+ (long long unsigned)(mediasz / secsz), human_num);
+ else
+#endif
+ printf("Number of Sectors: %llu\n",
+ (long long unsigned)(mediasz / secsz));
+
+ printf("\nHeader Information:\n");
+
+ gpt = map_find(MAP_TYPE_PRI_GPT_HDR);
+ if (gpt == NULL) {
+ printf("- GPT Header not found\n");
+ return;
+ }
+
+ hdr = gpt->map_data;
+ printf("- GPT Revision: %u\n", hdr->hdr_revision);
+ printf("- First Data Sector: %llu\n",
+ (long long unsigned)hdr->hdr_lba_start);
+#ifdef HN_AUTOSCALE
+ if (humanize_number(human_num, 5, hdr->hdr_lba_end,
+ "", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0)
+ human_num[0] = '\0';
+ if (human_num[0] != '\0')
+ printf("- Last Data Sector: %llu (%s)\n",
+ (long long unsigned)hdr->hdr_lba_end, human_num);
+ else
+#endif
+ printf("- Last Data Sector: %llu\n",
+ (long long unsigned)hdr->hdr_lba_end);
+ gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
+ printf("- Media GUID: %s\n", buf);
+ printf("- Number of GPT Entries: %u\n", hdr->hdr_entries);
+}
+
+int
+cmd_header(int argc, char *argv[])
+{
+ int fd;
+
+ if (argc == optind)
+ usage_header();
+
+ while (optind < argc) {
+ fd = gpt_open(argv[optind++]);
+ if (fd == -1) {
+ warn("unable to open device '%s'", device_name);
+ continue;
+ }
+ header();
+
+ gpt_close(fd);
+ }
+
+ return (0);
+}
Home |
Main Index |
Thread Index |
Old Index