gpt_uuid.h revision 1.4
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
48typedef enum {
49	GPT_TYPE_APPLE_HFS = 0,
50	GPT_TYPE_APPLE_UFS,
51	GPT_TYPE_BIOS,
52	GPT_TYPE_EFI,
53	GPT_TYPE_FREEBSD,
54	GPT_TYPE_FREEBSD_SWAP,
55	GPT_TYPE_FREEBSD_UFS,
56	GPT_TYPE_FREEBSD_VINUM,
57	GPT_TYPE_FREEBSD_ZFS,
58	GPT_TYPE_LINUX_DATA,
59	GPT_TYPE_LINUX_SWAP,
60	GPT_TYPE_LINUX_RAID,
61	GPT_TYPE_LINUX_LVM,
62	GPT_TYPE_MS_BASIC_DATA,
63	GPT_TYPE_MS_RESERVED,
64	GPT_TYPE_NETBSD_CCD,
65	GPT_TYPE_NETBSD_CGD,
66	GPT_TYPE_NETBSD_FFS,
67	GPT_TYPE_NETBSD_LFS,
68	GPT_TYPE_NETBSD_RAIDFRAME,
69	GPT_TYPE_NETBSD_SWAP
70} gpt_type_t;
71
72typedef uint8_t gpt_uuid_t[16];
73extern const gpt_uuid_t gpt_uuid_nil;
74
75__BEGIN_DECLS
76static inline int
77gpt_uuid_is_nil(const gpt_uuid_t u) {
78	return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
79}
80
81static inline int
82gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
83	return memcmp(u1, u2, sizeof(gpt_uuid_t)) == 0;
84}
85
86static inline void
87gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
88	memcpy(u1, u2, sizeof(gpt_uuid_t));
89}
90
91int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
92
93void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
94
95int gpt_uuid_parse(const char *, gpt_uuid_t);
96
97void gpt_uuid_generate(gpt_uuid_t);
98
99__END_DECLS
100
101#endif /* _GPT_UUID_T */
102