xref: /netbsd-src/sbin/gpt/gpt_uuid.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: gpt_uuid.h,v 1.9 2019/06/30 11:38:16 sevan Exp $	*/
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Christos Zoulas.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 #ifndef _GPT_UUID_H
32 #define _GPT_UUID_H
33 
34 #include <string.h>
35 #include <inttypes.h>
36 #ifndef HAVE_NBTOOL_CONFIG_H
37 #include <sys/disklabel_gpt.h>
38 #else
39 #include <nbinclude/sys/disklabel_gpt.h>
40 #endif
41 
42 /*
43  * We define our own uuid type so that we don't have to mess around
44  * with different uuid implementation (linux+macosx which use an
45  * array, and {Free,Net}BSD who use a struct. We just need minimal
46  * support anyway
47  */
48 
49 // Must match the array in gpt_uuid.c
50 typedef enum {
51 	GPT_TYPE_INVALID = -1,
52 	GPT_TYPE_APPLE_HFS = 0,
53 	GPT_TYPE_APPLE_UFS,
54 	GPT_TYPE_BIOS,
55 	GPT_TYPE_EFI,
56 	GPT_TYPE_FREEBSD,
57 	GPT_TYPE_FREEBSD_SWAP,
58 	GPT_TYPE_FREEBSD_UFS,
59 	GPT_TYPE_FREEBSD_VINUM,
60 	GPT_TYPE_FREEBSD_ZFS,
61 	GPT_TYPE_LINUX_DATA,
62 	GPT_TYPE_LINUX_SWAP,
63 	GPT_TYPE_LINUX_RAID,
64 	GPT_TYPE_LINUX_LVM,
65 	GPT_TYPE_MS_BASIC_DATA,
66 	GPT_TYPE_MS_RESERVED,
67 	GPT_TYPE_NETBSD_CCD,
68 	GPT_TYPE_NETBSD_CGD,
69 	GPT_TYPE_NETBSD_FFS,
70 	GPT_TYPE_NETBSD_LFS,
71 	GPT_TYPE_NETBSD_RAIDFRAME,
72 	GPT_TYPE_NETBSD_SWAP,
73 	GPT_TYPE_VMWARE_VMKCORE,
74 	GPT_TYPE_VMWARE_VMFS,
75 	GPT_TYPE_VMWARE_RESERVED
76 } gpt_type_t;
77 
78 typedef uint8_t gpt_uuid_t[16];
79 extern const gpt_uuid_t gpt_uuid_nil;
80 
81 __BEGIN_DECLS
82 static inline int
83 gpt_uuid_is_nil(const gpt_uuid_t u) {
84 	return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
85 }
86 
87 static inline int
88 gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
89 	return memcmp(u1, u2, sizeof(gpt_uuid_t)) == 0;
90 }
91 
92 static inline void
93 gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
94 	memcpy(u1, u2, sizeof(gpt_uuid_t));
95 }
96 
97 int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
98 
99 void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
100 
101 int gpt_uuid_parse(const char *, gpt_uuid_t);
102 
103 struct gpt;
104 int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
105 
106 /* returns number of entries, callback func may be NULL */
107 size_t gpt_uuid_query(
108     void (*func)(const char *uuid, const char *short_name, const char *desc));
109 
110 void gpt_uuid_help(const char *);
111 
112 __END_DECLS
113 
114 #endif /* _GPT_UUID_T */
115