Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sbin/gpt Pull up following revision(s) (requested by jnem...
details: https://anonhg.NetBSD.org/src/rev/44de220420b1
branches: netbsd-7
changeset: 799396:44de220420b1
user: snj <snj%NetBSD.org@localhost>
date: Tue Jun 02 19:49:38 2015 +0000
description:
Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
diffstat:
sbin/gpt/Makefile | 20 ++-
sbin/gpt/add.c | 29 +-
sbin/gpt/backup.c | 60 +++---
sbin/gpt/biosboot.c | 40 +++-
sbin/gpt/create.c | 17 +-
sbin/gpt/destroy.c | 10 +-
sbin/gpt/drvctl.c | 134 +++++++++++++++++
sbin/gpt/gpt.8 | 142 ++++++++++++++++-
sbin/gpt/gpt.c | 343 +++++++++++++------------------------------
sbin/gpt/gpt.h | 32 ++-
sbin/gpt/gpt_uuid.c | 274 +++++++++++++++++++++++++++++++++++
sbin/gpt/gpt_uuid.h | 98 ++++++++++++
sbin/gpt/label.c | 40 +++-
sbin/gpt/map.c | 6 +-
sbin/gpt/migrate.c | 100 +++++-------
sbin/gpt/recover.c | 6 +-
sbin/gpt/remove.c | 44 +++-
sbin/gpt/resize.c | 11 +-
sbin/gpt/resizedisk.c | 292 +++++++++++++++++++++++++++++++++++++
sbin/gpt/restore.c | 390 ++++++++++++++++++++++++++++++++++++-------------
sbin/gpt/set.c | 11 +-
sbin/gpt/show.c | 118 +++-----------
sbin/gpt/type.c | 243 +++++++++++++++++++++++++++++++
sbin/gpt/unset.c | 11 +-
24 files changed, 1842 insertions(+), 629 deletions(-)
diffs (truncated from 3653 to 300 lines):
diff -r 7f64d2770083 -r 44de220420b1 sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Tue Jun 02 14:51:11 2015 +0000
+++ b/sbin/gpt/Makefile Tue Jun 02 19:49:38 2015 +0000
@@ -1,12 +1,26 @@
-# $NetBSD: Makefile,v 1.8 2014/08/10 18:27:15 jnemeth Exp $
+# $NetBSD: Makefile,v 1.8.2.1 2015/06/02 19:49:38 snj Exp $
# $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
PROG= gpt
-SRCS= add.c backup.c biosboot.c create.c destroy.c gpt.c label.c map.c \
- migrate.c recover.c remove.c resize.c restore.c set.c show.c unset.c
+SRCS= add.c biosboot.c create.c destroy.c gpt.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
+.if (${HOSTPROG:U} == "")
+SRCS+= backup.c restore.c
LDADD+= -lprop -lutil
DPADD+= ${LIBPROP} ${LIBUTIL}
+.if ${USE_DRVCTL:Uno} == "yes"
+CPPFLAGS+=-DUSE_DRVCTL
+SRCS+=drvctl.c
+.else
+.PATH: ${.CURDIR}/../fsck
+CPPFLAGS+=-I${.CURDIR}/../fsck
+SRCS+=partutil.c
+.endif
+.endif
+
+
.include <bsd.prog.mk>
diff -r 7f64d2770083 -r 44de220420b1 sbin/gpt/add.c
--- a/sbin/gpt/add.c Tue Jun 02 14:51:11 2015 +0000
+++ b/sbin/gpt/add.c Tue Jun 02 19:49:38 2015 +0000
@@ -24,12 +24,16 @@
* 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 __FBSDID
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: add.c,v 1.24 2013/12/10 01:05:00 jnemeth Exp $");
+__RCSID("$NetBSD: add.c,v 1.24.4.1 2015/06/02 19:49:38 snj Exp $");
#endif
#include <sys/types.h>
@@ -40,12 +44,11 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <inttypes.h>
#include "map.h"
#include "gpt.h"
-static uuid_t type;
+static gpt_uuid_t type;
static off_t alignment, block, sectors, size;
static unsigned int entry;
static uint8_t *name;
@@ -67,7 +70,6 @@
static void
add(int fd)
{
- uuid_t uuid;
map_t *gpt, *tpg;
map_t *tbl, *lbt;
map_t *map;
@@ -110,8 +112,7 @@
i = entry - 1;
ent = (void*)((char*)tbl->map_data + i *
le32toh(hdr->hdr_entsz));
- le_uuid_dec(ent->ent_type, &uuid);
- if (!uuid_is_nil(&uuid, NULL)) {
+ if (!gpt_uuid_is_nil(ent->ent_type)) {
warnx("%s: error: entry at index %u is not free",
device_name, entry);
return;
@@ -121,8 +122,7 @@
for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
ent = (void*)((char*)tbl->map_data + i *
le32toh(hdr->hdr_entsz));
- le_uuid_dec(ent->ent_type, &uuid);
- if (uuid_is_nil(&uuid, NULL))
+ if (gpt_uuid_is_nil(ent->ent_type))
break;
}
if (i == le32toh(hdr->hdr_entries)) {
@@ -149,7 +149,7 @@
}
}
- le_uuid_enc(ent->ent_type, &type);
+ gpt_uuid_copy(ent->ent_type, type);
ent->ent_lba_start = htole64(map->map_start);
ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
if (name != NULL)
@@ -166,7 +166,7 @@
hdr = tpg->map_data;
ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz));
- le_uuid_enc(ent->ent_type, &type);
+ gpt_uuid_copy(ent->ent_type, type);
ent->ent_lba_start = htole64(map->map_start);
ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
if (name != NULL)
@@ -253,9 +253,9 @@
sectors = 0;
break;
case 't':
- if (!uuid_is_nil(&type, NULL))
+ if (!gpt_uuid_is_nil(type))
usage_add();
- if (parse_uuid(optarg, &type) != 0)
+ if (gpt_uuid_parse(optarg, type) != 0)
usage_add();
break;
default:
@@ -267,9 +267,8 @@
usage_add();
/* Create NetBSD FFS partitions by default. */
- if (uuid_is_nil(&type, NULL)) {
- static const uuid_t nb_ffs = GPT_ENT_TYPE_NETBSD_FFS;
- type = nb_ffs;
+ if (gpt_uuid_is_nil(type)) {
+ gpt_uuid_create(GPT_TYPE_NETBSD_FFS, type, NULL, 0);
}
while (optind < argc) {
diff -r 7f64d2770083 -r 44de220420b1 sbin/gpt/backup.c
--- a/sbin/gpt/backup.c Tue Jun 02 14:51:11 2015 +0000
+++ b/sbin/gpt/backup.c Tue Jun 02 19:49:38 2015 +0000
@@ -24,12 +24,16 @@
* 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 __FBSDID
__FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: backup.c,v 1.1 2013/12/19 06:46:51 jnemeth Exp $");
+__RCSID("$NetBSD: backup.c,v 1.1.6.1 2015/06/02 19:49:38 snj Exp $");
#endif
#include <sys/bootblock.h>
@@ -66,7 +70,6 @@
static void
backup(void)
{
- uuid_t u;
map_t *m;
struct mbr *mbr;
struct gpt_ent *ent;
@@ -77,11 +80,15 @@
prop_data_t propdata;
prop_number_t propnum;
prop_string_t propstr;
- char *propext, *s;
+ char *propext, *s, buf[128];
bool rc;
props = prop_dictionary_create();
PROP_ERR(props);
+ propnum = prop_number_create_integer(secsz);
+ PROP_ERR(propnum);
+ rc = prop_dictionary_set(props, "sector_size", propnum);
+ PROP_ERR(rc);
m = map_first();
while (m != NULL) {
switch (m->map_type) {
@@ -139,6 +146,11 @@
propnum = prop_number_create_unsigned_integer(mbr->mbr_part[i].part_esect);
PROP_ERR(propnum);
rc = prop_dictionary_set(mbr_dict,
+ "end_sector", propnum);
+ PROP_ERR(rc);
+ propnum = prop_number_create_unsigned_integer(mbr->mbr_part[i].part_ecyl);
+ PROP_ERR(propnum);
+ rc = prop_dictionary_set(mbr_dict,
"end_cylinder", propnum);
PROP_ERR(rc);
propnum = prop_number_create_unsigned_integer(le16toh(mbr->mbr_part[i].part_start_lo));
@@ -188,10 +200,9 @@
rc = prop_dictionary_set(type_dict, "revision",
propnum);
PROP_ERR(rc);
- le_uuid_dec(hdr->hdr_guid, &u);
- uuid_to_string(&u, &s, NULL);
- propstr = prop_string_create_cstring(s);
- free(s);
+ gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+ hdr->hdr_guid);
+ propstr = prop_string_create_cstring(buf);
PROP_ERR(propstr);
rc = prop_dictionary_set(type_dict, "guid", propstr);
PROP_ERR(rc);
@@ -207,12 +218,11 @@
type_dict = prop_dictionary_create();
PROP_ERR(type_dict);
ent = m->map_data;
- gpt_array = NULL;
+ gpt_array = prop_array_create();
+ PROP_ERR(gpt_array);
for (i = 1, ent = m->map_data;
(char *)ent < (char *)(m->map_data) +
m->map_size * secsz; i++, ent++) {
- if (uuid_is_nil((uuid_t *)&ent->ent_type, NULL))
- continue;
gpt_dict = prop_dictionary_create();
PROP_ERR(gpt_dict);
propnum = prop_number_create_integer(i);
@@ -220,17 +230,15 @@
rc = prop_dictionary_set(gpt_dict, "index",
propnum);
PROP_ERR(propnum);
- le_uuid_dec(ent->ent_type, &u);
- uuid_to_string(&u, &s, NULL);
- propstr = prop_string_create_cstring(s);
- free(s);
+ gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+ ent->ent_type);
+ propstr = prop_string_create_cstring(buf);
PROP_ERR(propstr);
rc = prop_dictionary_set(gpt_dict, "type",
propstr);
- le_uuid_dec(ent->ent_guid, &u);
- uuid_to_string(&u, &s, NULL);
- propstr = prop_string_create_cstring(s);
- free(s);
+ gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+ ent->ent_guid);
+ propstr = prop_string_create_cstring(buf);
PROP_ERR(propstr);
rc = prop_dictionary_set(gpt_dict, "guid",
propstr);
@@ -258,19 +266,13 @@
"name", propstr);
PROP_ERR(rc);
}
- if (gpt_array == NULL) {
- gpt_array = prop_array_create();
- PROP_ERR(gpt_array);
- }
rc = prop_array_add(gpt_array, gpt_dict);
PROP_ERR(rc);
}
- if (gpt_array != NULL) {
- rc = prop_dictionary_set(type_dict,
- "gpt_array", gpt_array);
- PROP_ERR(rc);
- prop_object_release(gpt_array);
- }
+ rc = prop_dictionary_set(type_dict,
+ "gpt_array", gpt_array);
+ PROP_ERR(rc);
+ prop_object_release(gpt_array);
rc = prop_dictionary_set(props, "GPT_TBL", type_dict);
PROP_ERR(rc);
prop_object_release(type_dict);
@@ -282,6 +284,7 @@
PROP_ERR(propext);
prop_object_release(props);
fputs(propext, stdout);
+ free(propext);
}
int
@@ -298,7 +301,6 @@
warn("unable to open device '%s'", device_name);
continue;
}
-
backup();
gpt_close(fd);
diff -r 7f64d2770083 -r 44de220420b1 sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c Tue Jun 02 14:51:11 2015 +0000
+++ b/sbin/gpt/biosboot.c Tue Jun 02 19:49:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: biosboot.c,v 1.7 2013/11/27 01:47:53 jnemeth Exp $ */
+/* $NetBSD: biosboot.c,v 1.7.4.1 2015/06/02 19:49:38 snj Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,28 +31,32 @@
* POSSIBILITY OF SUCH DAMAGE.
Home |
Main Index |
Thread Index |
Old Index