Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt Add an "uuid" command to generate a new UUID for a ...



details:   https://anonhg.NetBSD.org/src/rev/d82aec1367dc
branches:  trunk
changeset: 452262:d82aec1367dc
user:      jnemeth <jnemeth%NetBSD.org@localhost>
date:      Tue Jun 25 04:53:40 2019 +0000

description:
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.

diffstat:

 sbin/gpt/Makefile |    4 +-
 sbin/gpt/gpt.8    |   23 +++++++++-
 sbin/gpt/main.c   |    8 ++-
 sbin/gpt/uuid.c   |  114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 142 insertions(+), 7 deletions(-)

diffs (216 lines):

diff -r 016e1a88220b -r d82aec1367dc sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Tue Jun 25 04:25:11 2019 +0000
+++ b/sbin/gpt/Makefile Tue Jun 25 04:53:40 2019 +0000
@@ -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 @@
 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
diff -r 016e1a88220b -r d82aec1367dc sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Tue Jun 25 04:25:11 2019 +0000
+++ b/sbin/gpt/gpt.8    Tue Jun 25 04:53:40 2019 +0000
@@ -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 @@
 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
diff -r 016e1a88220b -r d82aec1367dc sbin/gpt/main.c
--- a/sbin/gpt/main.c   Tue Jun 25 04:25:11 2019 +0000
+++ b/sbin/gpt/main.c   Tue Jun 25 04:53:40 2019 +0000
@@ -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 @@
        c_set,
        c_show,
        c_type,
-       c_unset;
+       c_unset,
+       c_uuid;
 
 static const struct gpt_cmd *cmdsw[] = {
        &c_add,
@@ -97,6 +98,7 @@
        &c_show,
        &c_type,
        &c_unset,
+       &c_uuid,
        &c_null,
 };
 
diff -r 016e1a88220b -r d82aec1367dc sbin/gpt/uuid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/gpt/uuid.c   Tue Jun 25 04:53:40 2019 +0000
@@ -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;
+}



Home | Main Index | Thread Index | Old Index