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