Thu Dec 20 14:58:10 2018 UTC ()
Add a query function (for external code) to enumerate the know guids.
Add recently added VMware GUIDs to the internal enum type.
Fix some short names (bogus + duplicate).


(martin)
diff -r1.16 -r1.17 src/sbin/gpt/gpt_uuid.c
diff -r1.7 -r1.8 src/sbin/gpt/gpt_uuid.h

cvs diff -r1.16 -r1.17 src/sbin/gpt/gpt_uuid.c (expand / switch to unified diff)

--- src/sbin/gpt/gpt_uuid.c 2018/11/06 04:04:33 1.16
+++ src/sbin/gpt/gpt_uuid.c 2018/12/20 14:58:10 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $ */ 1/* $NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#if HAVE_NBTOOL_CONFIG_H 29#if HAVE_NBTOOL_CONFIG_H
30#include "nbtool_config.h" 30#include "nbtool_config.h"
31#endif 31#endif
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34#ifdef __RCSID 34#ifdef __RCSID
35__RCSID("$NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $"); 35__RCSID("$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $");
36#endif 36#endif
37 37
38#include <err.h> 38#include <err.h>
39#include <fcntl.h> 39#include <fcntl.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <unistd.h> 41#include <unistd.h>
42 42
43#include "map.h" 43#include "map.h"
44#include "gpt.h" 44#include "gpt.h"
45#include "gpt_private.h" 45#include "gpt_private.h"
46 46
47#if defined(HAVE_SYS_ENDIAN_H) || ! defined(HAVE_NBTOOL_CONFIG_H) 47#if defined(HAVE_SYS_ENDIAN_H) || ! defined(HAVE_NBTOOL_CONFIG_H)
48#include <sys/endian.h> 48#include <sys/endian.h>
@@ -77,29 +77,29 @@ static const struct { @@ -77,29 +77,29 @@ static const struct {
77 { GPT_ENT_TYPE_LINUX_DATA, "linux-data", "Linux data" }, 77 { GPT_ENT_TYPE_LINUX_DATA, "linux-data", "Linux data" },
78 { GPT_ENT_TYPE_LINUX_RAID, "linux-raid", "Linux RAID" }, 78 { GPT_ENT_TYPE_LINUX_RAID, "linux-raid", "Linux RAID" },
79 { GPT_ENT_TYPE_LINUX_SWAP, "linux-swap", "Linux swap" }, 79 { GPT_ENT_TYPE_LINUX_SWAP, "linux-swap", "Linux swap" },
80 { GPT_ENT_TYPE_LINUX_LVM, "linux-lvm", "Linux LVM" }, 80 { GPT_ENT_TYPE_LINUX_LVM, "linux-lvm", "Linux LVM" },
81 { GPT_ENT_TYPE_MS_BASIC_DATA, "windows", "Windows basic data" }, 81 { GPT_ENT_TYPE_MS_BASIC_DATA, "windows", "Windows basic data" },
82 { GPT_ENT_TYPE_MS_RESERVED, "windows-reserved", "Windows reserved" }, 82 { GPT_ENT_TYPE_MS_RESERVED, "windows-reserved", "Windows reserved" },
83 { GPT_ENT_TYPE_NETBSD_CCD, "ccd", "NetBSD ccd component" }, 83 { GPT_ENT_TYPE_NETBSD_CCD, "ccd", "NetBSD ccd component" },
84 { GPT_ENT_TYPE_NETBSD_CGD, "cgd", "NetBSD Cryptographic Disk" }, 84 { GPT_ENT_TYPE_NETBSD_CGD, "cgd", "NetBSD Cryptographic Disk" },
85 { GPT_ENT_TYPE_NETBSD_FFS, "ffs", "NetBSD FFSv1/FFSv2" }, 85 { GPT_ENT_TYPE_NETBSD_FFS, "ffs", "NetBSD FFSv1/FFSv2" },
86 { GPT_ENT_TYPE_NETBSD_LFS, "lfs", "NetBSD LFS" }, 86 { GPT_ENT_TYPE_NETBSD_LFS, "lfs", "NetBSD LFS" },
87 { GPT_ENT_TYPE_NETBSD_RAIDFRAME, "raid", 87 { GPT_ENT_TYPE_NETBSD_RAIDFRAME, "raid",
88 "NetBSD RAIDFrame component" }, 88 "NetBSD RAIDFrame component" },
89 { GPT_ENT_TYPE_NETBSD_SWAP, "swap", "NetBSD swap" }, 89 { GPT_ENT_TYPE_NETBSD_SWAP, "swap", "NetBSD swap" },
90 { GPT_ENT_TYPE_VMWARE_VMKCORE, "swap", "VMware VMkernel core dump" }, 90 { GPT_ENT_TYPE_VMWARE_VMKCORE, "vmcore", "VMware VMkernel core dump" },
91 { GPT_ENT_TYPE_VMWARE_VMFS, "swap", "VMware VMFS" }, 91 { GPT_ENT_TYPE_VMWARE_VMFS, "vmfs", "VMware VMFS" },
92 { GPT_ENT_TYPE_VMWARE_RESERVED, "swap", "VMware reserved" }, 92 { GPT_ENT_TYPE_VMWARE_RESERVED, "vmresered", "VMware reserved" },
93}; 93};
94 94
95static void 95static void
96gpt_uuid_to_dce(const gpt_uuid_t buf, struct dce_uuid *uuid) 96gpt_uuid_to_dce(const gpt_uuid_t buf, struct dce_uuid *uuid)
97{ 97{
98 const uint8_t *p = buf; 98 const uint8_t *p = buf;
99 size_t i; 99 size_t i;
100 100
101 uuid->time_low = le32dec(p); 101 uuid->time_low = le32dec(p);
102 uuid->time_mid = le16dec(p + 4); 102 uuid->time_mid = le16dec(p + 4);
103 uuid->time_hi_and_version = le16dec(p + 6); 103 uuid->time_hi_and_version = le16dec(p + 6);
104 uuid->clock_seq_hi_and_reserved = p[8]; 104 uuid->clock_seq_hi_and_reserved = p[8];
105 uuid->clock_seq_low = p[9]; 105 uuid->clock_seq_low = p[9];
@@ -224,26 +224,43 @@ gpt_uuid_parse(const char *s, gpt_uuid_t @@ -224,26 +224,43 @@ gpt_uuid_parse(const char *s, gpt_uuid_t
224 224
225 if (gpt_uuid_parse_numeric(s, &u) != -1) { 225 if (gpt_uuid_parse_numeric(s, &u) != -1) {
226 gpt_dce_to_uuid(&u, uuid); 226 gpt_dce_to_uuid(&u, uuid);
227 return 0; 227 return 0;
228 } 228 }
229 229
230 if (gpt_uuid_parse_symbolic(s, &u) == -1) 230 if (gpt_uuid_parse_symbolic(s, &u) == -1)
231 return -1; 231 return -1;
232 232
233 gpt_dce_to_uuid(&u, uuid); 233 gpt_dce_to_uuid(&u, uuid);
234 return 0; 234 return 0;
235} 235}
236 236
 237size_t
 238gpt_uuid_query(
 239 void (*func)(const char *uuid, const char *short_name, const char *desc))
 240{
 241 size_t i;
 242 char buf[64];
 243
 244 if (func != NULL) {
 245 for (i = 0; i < __arraycount(gpt_nv); i++) {
 246 gpt_uuid_numeric(buf, sizeof(buf), &gpt_nv[i].u);
 247 (*func)(buf, gpt_nv[i].n, gpt_nv[i].d);
 248 }
 249 }
 250 return __arraycount(gpt_nv);
 251}
 252
 253#ifndef GPT_UUID_QUERY_ONLY
237void 254void
238gpt_uuid_help(const char *prefix) 255gpt_uuid_help(const char *prefix)
239{ 256{
240 size_t i; 257 size_t i;
241 258
242 for (i = 0; i < __arraycount(gpt_nv); i++) 259 for (i = 0; i < __arraycount(gpt_nv); i++)
243 printf("%s%18.18s\t%s\n", prefix, gpt_nv[i].n, gpt_nv[i].d); 260 printf("%s%18.18s\t%s\n", prefix, gpt_nv[i].n, gpt_nv[i].d);
244} 261}
245 262
246void 263void
247gpt_uuid_create(gpt_type_t t, gpt_uuid_t u, uint16_t *b, size_t s) 264gpt_uuid_create(gpt_type_t t, gpt_uuid_t u, uint16_t *b, size_t s)
248{ 265{
249 gpt_dce_to_uuid(&gpt_nv[t].u, u); 266 gpt_dce_to_uuid(&gpt_nv[t].u, u);
@@ -313,13 +330,14 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t  @@ -313,13 +330,14 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t
313 return -1; 330 return -1;
314 331
315 /* Set the version number to 4. */ 332 /* Set the version number to 4. */
316 u.time_hi_and_version &= (uint16_t)~0xf000; 333 u.time_hi_and_version &= (uint16_t)~0xf000;
317 u.time_hi_and_version |= 0x4000; 334 u.time_hi_and_version |= 0x4000;
318 335
319 /* Fix the reserved bits. */ 336 /* Fix the reserved bits. */
320 u.clock_seq_hi_and_reserved &= (uint8_t)~0x40; 337 u.clock_seq_hi_and_reserved &= (uint8_t)~0x40;
321 u.clock_seq_hi_and_reserved |= 0x80; 338 u.clock_seq_hi_and_reserved |= 0x80;
322 339
323 gpt_dce_to_uuid(&u, t); 340 gpt_dce_to_uuid(&u, t);
324 return 0; 341 return 0;
325} 342}
 343#endif

cvs diff -r1.7 -r1.8 src/sbin/gpt/gpt_uuid.h (expand / switch to unified diff)

--- src/sbin/gpt/gpt_uuid.h 2015/12/06 04:27:05 1.7
+++ src/sbin/gpt/gpt_uuid.h 2018/12/20 14:58:10 1.8
@@ -57,27 +57,30 @@ typedef enum { @@ -57,27 +57,30 @@ typedef enum {
57 GPT_TYPE_FREEBSD_VINUM, 57 GPT_TYPE_FREEBSD_VINUM,
58 GPT_TYPE_FREEBSD_ZFS, 58 GPT_TYPE_FREEBSD_ZFS,
59 GPT_TYPE_LINUX_DATA, 59 GPT_TYPE_LINUX_DATA,
60 GPT_TYPE_LINUX_SWAP, 60 GPT_TYPE_LINUX_SWAP,
61 GPT_TYPE_LINUX_RAID, 61 GPT_TYPE_LINUX_RAID,
62 GPT_TYPE_LINUX_LVM, 62 GPT_TYPE_LINUX_LVM,
63 GPT_TYPE_MS_BASIC_DATA, 63 GPT_TYPE_MS_BASIC_DATA,
64 GPT_TYPE_MS_RESERVED, 64 GPT_TYPE_MS_RESERVED,
65 GPT_TYPE_NETBSD_CCD, 65 GPT_TYPE_NETBSD_CCD,
66 GPT_TYPE_NETBSD_CGD, 66 GPT_TYPE_NETBSD_CGD,
67 GPT_TYPE_NETBSD_FFS, 67 GPT_TYPE_NETBSD_FFS,
68 GPT_TYPE_NETBSD_LFS, 68 GPT_TYPE_NETBSD_LFS,
69 GPT_TYPE_NETBSD_RAIDFRAME, 69 GPT_TYPE_NETBSD_RAIDFRAME,
70 GPT_TYPE_NETBSD_SWAP 70 GPT_TYPE_NETBSD_SWAP,
 71 GPT_TYPE_VMWARE_VMKCORE,
 72 GPT_TYPE_VMWARE_VMFS,
 73 GPT_TYPE_VMWARE_RESERVED
71} gpt_type_t; 74} gpt_type_t;
72 75
73typedef uint8_t gpt_uuid_t[16]; 76typedef uint8_t gpt_uuid_t[16];
74extern const gpt_uuid_t gpt_uuid_nil; 77extern const gpt_uuid_t gpt_uuid_nil;
75 78
76__BEGIN_DECLS 79__BEGIN_DECLS
77static inline int 80static inline int
78gpt_uuid_is_nil(const gpt_uuid_t u) { 81gpt_uuid_is_nil(const gpt_uuid_t u) {
79 return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0; 82 return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
80} 83}
81 84
82static inline int 85static inline int
83gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) { 86gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
@@ -88,18 +91,22 @@ static inline void @@ -88,18 +91,22 @@ static inline void
88gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) { 91gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
89 memcpy(u1, u2, sizeof(gpt_uuid_t)); 92 memcpy(u1, u2, sizeof(gpt_uuid_t));
90} 93}
91 94
92int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t); 95int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
93 96
94void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t); 97void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
95 98
96int gpt_uuid_parse(const char *, gpt_uuid_t); 99int gpt_uuid_parse(const char *, gpt_uuid_t);
97 100
98struct gpt; 101struct gpt;
99int gpt_uuid_generate(struct gpt *, gpt_uuid_t); 102int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
100 103
 104/* returns number of entries, callback func may be NULL */
 105size_t gpt_uuid_query(
 106 void (*func)(const char *uuid, const char *short_name, const char *desc));
 107
101void gpt_uuid_help(const char *); 108void gpt_uuid_help(const char *);
102 109
103__END_DECLS 110__END_DECLS
104 111
105#endif /* _GPT_UUID_T */ 112#endif /* _GPT_UUID_T */