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