Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt "0" is not guaranteed to be unique



details:   https://anonhg.NetBSD.org/src/rev/002a77f382ad
branches:  trunk
changeset: 332674:002a77f382ad
user:      jnemeth <jnemeth%NetBSD.org@localhost>
date:      Fri Oct 03 00:51:31 2014 +0000

description:
"0" is not guaranteed to be unique

diffstat:

 sbin/gpt/create.c   |   6 +++---
 sbin/gpt/gpt_uuid.c |  20 ++++++++++++++++++--
 sbin/gpt/gpt_uuid.h |   2 ++
 sbin/gpt/migrate.c  |   6 +++---
 4 files changed, 26 insertions(+), 8 deletions(-)

diffs (117 lines):

diff -r 24754c60682a -r 002a77f382ad sbin/gpt/create.c
--- a/sbin/gpt/create.c Fri Oct 03 00:00:11 2014 +0000
+++ b/sbin/gpt/create.c Fri Oct 03 00:51:31 2014 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: create.c,v 1.10 2014/09/30 17:59:59 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.11 2014/10/03 00:51:31 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -174,7 +174,7 @@
        hdr->hdr_lba_alt = htole64(last);
        hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
        hdr->hdr_lba_end = htole64(last - blocks - 1LL);
-       gpt_uuid_copy(hdr->hdr_guid, gpt_uuid_nil);
+       gpt_uuid_create_new(hdr->hdr_guid);
        hdr->hdr_lba_table = htole64(tbl->map_start);
        hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent));
        if (le32toh(hdr->hdr_entries) > parts)
@@ -183,7 +183,7 @@
 
        ent = tbl->map_data;
        for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
-               gpt_uuid_copy(ent[i].ent_guid, gpt_uuid_nil);
+               gpt_uuid_create_new(ent[i].ent_guid);
        }
 
        hdr->hdr_crc_table = htole32(crc32(ent, le32toh(hdr->hdr_entries) *
diff -r 24754c60682a -r 002a77f382ad sbin/gpt/gpt_uuid.c
--- a/sbin/gpt/gpt_uuid.c       Fri Oct 03 00:00:11 2014 +0000
+++ b/sbin/gpt/gpt_uuid.c       Fri Oct 03 00:51:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gpt_uuid.c,v 1.5 2014/10/02 21:27:41 apb Exp $ */
+/*     $NetBSD: gpt_uuid.c,v 1.6 2014/10/03 00:51:31 jnemeth 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.5 2014/10/02 21:27:41 apb Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.6 2014/10/03 00:51:31 jnemeth Exp $");
 #endif
 
 #include <stdio.h>
@@ -44,6 +44,11 @@
 #include <sys/endian.h>
 #endif
 
+#if !defined(HAVE_NBTOOL_CONFIG_H)
+#include <sys/types.h>
+#include <sys/uuid.h>
+#endif
+
 const gpt_uuid_t gpt_uuid_nil;
 
 struct dce_uuid {
@@ -230,3 +235,14 @@
        if (b)
                utf8_to_utf16((const uint8_t *)gpt_nv[t].d, b, s / sizeof(*b));
 }
+
+#if !defined(HAVE_NBTOOL_CONFIG_H)
+void
+gpt_uuid_create_new(gpt_uuid_t t)
+{
+       struct uuid u;
+
+       uuidgen(&u, 1);
+       gpt_dce_to_uuid((struct dce_uuid *)&u, t);
+}
+#endif
diff -r 24754c60682a -r 002a77f382ad sbin/gpt/gpt_uuid.h
--- a/sbin/gpt/gpt_uuid.h       Fri Oct 03 00:00:11 2014 +0000
+++ b/sbin/gpt/gpt_uuid.h       Fri Oct 03 00:51:31 2014 +0000
@@ -91,6 +91,8 @@
 
 int gpt_uuid_parse(const char *, gpt_uuid_t);
 
+void gpt_uuid_create_new(gpt_uuid_t);
+
 __END_DECLS
 
 #endif /* _GPT_UUID_T */
diff -r 24754c60682a -r 002a77f382ad sbin/gpt/migrate.c
--- a/sbin/gpt/migrate.c        Fri Oct 03 00:00:11 2014 +0000
+++ b/sbin/gpt/migrate.c        Fri Oct 03 00:51:31 2014 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: migrate.c,v 1.19 2014/09/30 17:59:59 christos Exp $");
+__RCSID("$NetBSD: migrate.c,v 1.20 2014/10/03 00:51:31 jnemeth Exp $");
 #endif
 
 #include <sys/types.h>
@@ -335,7 +335,7 @@
        hdr->hdr_lba_alt = htole64(tpg->map_start);
        hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
        hdr->hdr_lba_end = htole64(lbt->map_start - 1LL);
-       gpt_uuid_copy(hdr->hdr_guid, gpt_uuid_nil);
+       gpt_uuid_create_new(hdr->hdr_guid);
        hdr->hdr_lba_table = htole64(tbl->map_start);
        hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent));
        if (le32toh(hdr->hdr_entries) > parts)
@@ -344,7 +344,7 @@
 
        ent = tbl->map_data;
        for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
-               gpt_uuid_copy(ent[i].ent_guid, gpt_uuid_nil);
+               gpt_uuid_create_new(ent[i].ent_guid);
        }
 
        /* Mirror partitions. */



Home | Main Index | Thread Index | Old Index