Home | History | Annotate | Line # | Download | only in gpt
gpt_uuid.h revision 1.7.16.1
      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_VMWARE_VMKCORE,
     72 	GPT_TYPE_VMWARE_VMFS,
     73 	GPT_TYPE_VMWARE_RESERVED
     74 } gpt_type_t;
     75 
     76 typedef uint8_t gpt_uuid_t[16];
     77 extern const gpt_uuid_t gpt_uuid_nil;
     78 
     79 __BEGIN_DECLS
     80 static inline int
     81 gpt_uuid_is_nil(const gpt_uuid_t u) {
     82 	return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
     83 }
     84 
     85 static inline int
     86 gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
     87 	return memcmp(u1, u2, sizeof(gpt_uuid_t)) == 0;
     88 }
     89 
     90 static inline void
     91 gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
     92 	memcpy(u1, u2, sizeof(gpt_uuid_t));
     93 }
     94 
     95 int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
     96 
     97 void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
     98 
     99 int gpt_uuid_parse(const char *, gpt_uuid_t);
    100 
    101 struct gpt;
    102 int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
    103 
    104 /* returns number of entries, callback func may be NULL */
    105 size_t gpt_uuid_query(
    106     void (*func)(const char *uuid, const char *short_name, const char *desc));
    107 
    108 void gpt_uuid_help(const char *);
    109 
    110 __END_DECLS
    111 
    112 #endif /* _GPT_UUID_T */
    113