Module Name: src Committed By: jnemeth Date: Tue Jun 25 04:53:41 UTC 2019
Modified Files: src/sbin/gpt: Makefile gpt.8 main.c Added Files: src/sbin/gpt: uuid.c Log Message: Add an "uuid" command to generate a new UUID for a portion. The primary intention is for use for after cloning disks to prevent collisions. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/Makefile cvs rdiff -u -r1.68 -r1.69 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/main.c cvs rdiff -u -r0 -r1.1 src/sbin/gpt/uuid.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/Makefile diff -u src/sbin/gpt/Makefile:1.18 src/sbin/gpt/Makefile:1.19 --- src/sbin/gpt/Makefile:1.18 Thu Dec 3 02:02:43 2015 +++ src/sbin/gpt/Makefile Tue Jun 25 04:53:40 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.18 2015/12/03 02:02:43 christos Exp $ +# $NetBSD: Makefile,v 1.19 2019/06/25 04:53:40 jnemeth Exp $ # $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $ .include <bsd.own.mk> @@ -7,7 +7,7 @@ WARNS=6 PROG= gpt SRCS= add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \ main.c migrate.c recover.c remove.c resize.c resizedisk.c \ - set.c show.c type.c unset.c gpt_uuid.c + set.c show.c type.c unset.c gpt_uuid.c uuid.c MAN= gpt.8 #LINKS= ${BINDIR}/gpt ${BINDIR}/gptlabel Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.68 src/sbin/gpt/gpt.8:1.69 --- src/sbin/gpt/gpt.8:1.68 Thu Apr 4 13:55:40 2019 +++ src/sbin/gpt/gpt.8 Tue Jun 25 04:53:40 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.68 2019/04/04 13:55:40 martin Exp $ +.\" $NetBSD: gpt.8,v 1.69 2019/06/25 04:53:40 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 April 4, 2019 +.Dd June 22, 2019 .Dt GPT 8 .Os .Sh NAME @@ -693,6 +693,25 @@ code. They may be used by .Nx code in the future. +.\" ==== uuid ==== +.It Nm Ic uuid Oo Fl a Oc +.It Nm Ic uuid 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 +The +.Ic uuid +command allows the user to change the UUID of any and all partitions +that match the selection. +It uses the same selection options as the +.Ic label +command. +See above for a description of these options. +If +.Fl a +is used, then the header UUID is changed as well. +.Pp +The primary purpose of this command is for use after cloning a disk to +prevent collisions when both disks are used in the same system. +.\" ==== end of commands ==== .El .Sh EXIT STATUS The Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.12 src/sbin/gpt/main.c:1.13 --- src/sbin/gpt/main.c:1.12 Mon Aug 27 15:50:39 2018 +++ src/sbin/gpt/main.c Tue Jun 25 04:53:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $ */ +/* $NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $"); +__RCSID("$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $"); #endif #include <stdio.h> @@ -73,7 +73,8 @@ extern const struct gpt_cmd c_set, c_show, c_type, - c_unset; + c_unset, + c_uuid; static const struct gpt_cmd *cmdsw[] = { &c_add, @@ -97,6 +98,7 @@ static const struct gpt_cmd *cmdsw[] = { &c_show, &c_type, &c_unset, + &c_uuid, &c_null, }; Added files: Index: src/sbin/gpt/uuid.c diff -u /dev/null src/sbin/gpt/uuid.c:1.1 --- /dev/null Tue Jun 25 04:53:41 2019 +++ src/sbin/gpt/uuid.c Tue Jun 25 04:53:40 2019 @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * 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 AUTHOR ``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 AUTHOR 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 __FBSDID +__FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $"); +#endif +#ifdef __RCSID +__RCSID("$NetBSD: uuid.c,v 1.1 2019/06/25 04:53:40 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" +#include "gpt_private.h" + +static int cmd_uuid(gpt_t, int, char *[]); + +static const char *uuidhelp[] = { + "-a", + "[-b blocknr] [-i index] [-L label] [-s sectors] [-t type]", +}; + +struct gpt_cmd c_uuid = { + "uuid", + cmd_uuid, + uuidhelp, __arraycount(uuidhelp), + GPT_SYNC, +}; + +#define usage() gpt_usage(NULL, &c_uuid) + +static void +change_ent(struct gpt_ent *ent, void *v, int backup) +{ + static gpt_uuid_t uuidstore; + + if (!backup) + gpt_uuid_generate(NULL, uuidstore); + memmove(ent->ent_guid, uuidstore, sizeof(ent->ent_guid)); +} + +static void +change_hdr(struct gpt_hdr *hdr, void *v, int backup) +{ + static gpt_uuid_t uuidstore; + + if (!backup) + gpt_uuid_generate(NULL, uuidstore); + memmove(hdr->hdr_guid, uuidstore, sizeof(hdr->hdr_guid)); +} + +static int +cmd_uuid(gpt_t gpt, int argc, char *argv[]) +{ + int ch, rc; + struct gpt_find find; + + memset(&find, 0, sizeof(find)); + find.msg = "UUID changed"; + + /* Get the uuid options */ + while ((ch = getopt(argc, argv, GPT_FIND)) != -1) { + if (gpt == NULL || gpt_add_find(gpt, &find, ch) == -1) + return usage(); + } + + if (gpt == NULL || argc != optind) + return usage(); + + rc = gpt_change_ent(gpt, &find, change_ent, NULL); + if (rc != 0) + return rc; + + if (find.all) + return gpt_change_hdr(gpt, &find, change_hdr, NULL); + + return 0; +}