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