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