xref: /netbsd-src/sbin/gpt/gpt_uuid.h (revision 197ad8595bc33bb540d9eb584e068051e209bc61)
1 /*	$NetBSD: gpt_uuid.h,v 1.11 2024/08/19 17:15:38 christos 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 gpt_nv 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_MS_RECOVERY,
68 	GPT_TYPE_NETBSD_CCD,
69 	GPT_TYPE_NETBSD_CGD,
70 	GPT_TYPE_NETBSD_FFS,
71 	GPT_TYPE_NETBSD_LFS,
72 	GPT_TYPE_NETBSD_RAIDFRAME,
73 	GPT_TYPE_NETBSD_SWAP,
74 	GPT_TYPE_OPENBSD_DATA,
75 	GPT_TYPE_VMWARE_VMKCORE,
76 	GPT_TYPE_VMWARE_VMFS,
77 	GPT_TYPE_VMWARE_RESERVED
78 } gpt_type_t;
79 
80 typedef uint8_t gpt_uuid_t[16];
81 extern const gpt_uuid_t gpt_uuid_nil;
82 
83 __BEGIN_DECLS
84 static inline int
85 gpt_uuid_is_nil(const gpt_uuid_t u) {
86 	return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
87 }
88 
89 static inline int
90 gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
91 	return memcmp(u1, u2, sizeof(gpt_uuid_t)) == 0;
92 }
93 
94 static inline void
95 gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
96 	memcpy(u1, u2, sizeof(gpt_uuid_t));
97 }
98 
99 int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
100 
101 void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
102 
103 int gpt_uuid_parse(const char *, gpt_uuid_t);
104 
105 struct gpt;
106 int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
107 
108 /* returns number of entries, callback func may be NULL */
109 size_t gpt_uuid_query(
110     void (*func)(const char *uuid, const char *short_name, const char *desc));
111 
112 void gpt_uuid_help(const char *);
113 
114 __END_DECLS
115 
116 #endif /* _GPT_UUID_T */
117