From d0c2953303e0427a0edd262a46a290924bf19601 Mon Sep 17 00:00:00 2001 From: djm Date: Sun, 20 Jul 2008 21:57:51 +0000 Subject: [PATCH] fill in variant and version components of the UUID pretty-print the UUID in RFC4122 form --- sys/dev/softraid.c | 24 +++++++++++++++++------- sys/dev/softraidvar.h | 6 +++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index b727b104ace..2513b349a78 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.117 2008/07/19 22:41:58 marco Exp $ */ +/* $OpenBSD: softraid.c,v 1.118 2008/07/20 21:57:51 djm Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -2423,18 +2423,28 @@ sr_checksum(struct sr_softc *sc, void *src, void *md5, u_int32_t len) void sr_uuid_get(struct sr_uuid *uuid) { - /* XXX replace with idgen32 */ arc4random_buf(uuid->sui_id, sizeof(uuid->sui_id)); + /* UUID version 4: random */ + uuid->sui_id[6] &= 0x0f; + uuid->sui_id[6] |= 0x40; + /* RFC4122 variant */ + uuid->sui_id[8] &= 0x3f; + uuid->sui_id[8] |= 0x80; } void sr_uuid_print(struct sr_uuid *uuid, int cr) { - int i; - - for (i = 0; i < SR_UUID_MAX; i++) - printf("%x%s", uuid->sui_id[i], - i < SR_UUID_MAX - 1 ? ":" : ""); + printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x", + uuid->sui_id[0], uuid->sui_id[1], + uuid->sui_id[2], uuid->sui_id[3], + uuid->sui_id[4], uuid->sui_id[5], + uuid->sui_id[6], uuid->sui_id[7], + uuid->sui_id[8], uuid->sui_id[9], + uuid->sui_id[10], uuid->sui_id[11], + uuid->sui_id[12], uuid->sui_id[13], + uuid->sui_id[14], uuid->sui_id[15]); if (cr) printf("\n"); diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h index 1b87e3e6a77..6af7eb14268 100644 --- a/sys/dev/softraidvar.h +++ b/sys/dev/softraidvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: softraidvar.h,v 1.61 2008/07/19 22:41:58 marco Exp $ */ +/* $OpenBSD: softraidvar.h,v 1.62 2008/07/20 21:57:51 djm Exp $ */ /* * Copyright (c) 2006 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -21,9 +21,9 @@ #include -#define SR_UUID_MAX 4 +#define SR_UUID_MAX 16 struct sr_uuid { - u_int32_t sui_id[SR_UUID_MAX]; + u_int8_t sui_id[SR_UUID_MAX]; } __packed; #define SR_META_SIZE 64 /* save space at chunk beginning */ -- 2.20.1