xref: /freebsd/sys/contrib/openzfs/include/sys/uuid.h (revision 271171e0)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License, Version 1.0 only
6eda14cbcSMatt Macy  * (the "License").  You may not use this file except in compliance
7eda14cbcSMatt Macy  * with the License.
8eda14cbcSMatt Macy  *
9eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
11eda14cbcSMatt Macy  * See the License for the specific language governing permissions
12eda14cbcSMatt Macy  * and limitations under the License.
13eda14cbcSMatt Macy  *
14eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
15eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
17eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
18eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
19eda14cbcSMatt Macy  *
20eda14cbcSMatt Macy  * CDDL HEADER END
21eda14cbcSMatt Macy  */
22eda14cbcSMatt Macy /*
23eda14cbcSMatt Macy  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24eda14cbcSMatt Macy  * Use is subject to license terms.
25eda14cbcSMatt Macy  */
26eda14cbcSMatt Macy 
27eda14cbcSMatt Macy #ifndef	_SYS_UUID_H
28eda14cbcSMatt Macy #define	_SYS_UUID_H
29eda14cbcSMatt Macy 
30eda14cbcSMatt Macy #ifdef	__cplusplus
31eda14cbcSMatt Macy extern "C" {
32eda14cbcSMatt Macy #endif
33eda14cbcSMatt Macy 
34eda14cbcSMatt Macy /*
35eda14cbcSMatt Macy  * The copyright in this file is taken from the original Leach
36eda14cbcSMatt Macy  * & Salz UUID specification, from which this implementation
37eda14cbcSMatt Macy  * is derived.
38eda14cbcSMatt Macy  */
39eda14cbcSMatt Macy 
40eda14cbcSMatt Macy /*
41eda14cbcSMatt Macy  * Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
42eda14cbcSMatt Macy  * Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
43eda14cbcSMatt Macy  * Digital Equipment Corporation, Maynard, Mass.  Copyright (c) 1998
44eda14cbcSMatt Macy  * Microsoft.  To anyone who acknowledges that this file is provided
45eda14cbcSMatt Macy  * "AS IS" without any express or implied warranty: permission to use,
46eda14cbcSMatt Macy  * copy, modify, and distribute this file for any purpose is hereby
47eda14cbcSMatt Macy  * granted without fee, provided that the above copyright notices and
48eda14cbcSMatt Macy  * this notice appears in all source code copies, and that none of the
49eda14cbcSMatt Macy  * names of Open Software Foundation, Inc., Hewlett-Packard Company,
50eda14cbcSMatt Macy  * or Digital Equipment Corporation be used in advertising or
51eda14cbcSMatt Macy  * publicity pertaining to distribution of the software without
52eda14cbcSMatt Macy  * specific, written prior permission.  Neither Open Software
53eda14cbcSMatt Macy  * Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital
54eda14cbcSMatt Macy  * Equipment Corporation makes any representations about the
55eda14cbcSMatt Macy  * suitability of this software for any purpose.
56eda14cbcSMatt Macy  */
57eda14cbcSMatt Macy 
58eda14cbcSMatt Macy #include <sys/types.h>
59eda14cbcSMatt Macy #include <sys/byteorder.h>
60eda14cbcSMatt Macy 
61eda14cbcSMatt Macy typedef struct {
62eda14cbcSMatt Macy 	uint8_t		nodeID[6];
63eda14cbcSMatt Macy } uuid_node_t;
64eda14cbcSMatt Macy 
65eda14cbcSMatt Macy /*
66eda14cbcSMatt Macy  * The uuid type used throughout when referencing uuids themselves
67eda14cbcSMatt Macy  */
68eda14cbcSMatt Macy struct uuid {
69eda14cbcSMatt Macy 	uint32_t	time_low;
70eda14cbcSMatt Macy 	uint16_t	time_mid;
71eda14cbcSMatt Macy 	uint16_t	time_hi_and_version;
72eda14cbcSMatt Macy 	uint8_t		clock_seq_hi_and_reserved;
73eda14cbcSMatt Macy 	uint8_t		clock_seq_low;
74eda14cbcSMatt Macy 	uint8_t		node_addr[6];
75eda14cbcSMatt Macy };
76eda14cbcSMatt Macy 
77eda14cbcSMatt Macy #define	UUID_PRINTABLE_STRING_LENGTH 37
78eda14cbcSMatt Macy 
79eda14cbcSMatt Macy /*
80eda14cbcSMatt Macy  * Convert a uuid to/from little-endian format
81eda14cbcSMatt Macy  */
82eda14cbcSMatt Macy #define	UUID_LE_CONVERT(dest, src)					\
83eda14cbcSMatt Macy {									\
84eda14cbcSMatt Macy 	(dest) = (src);							\
85eda14cbcSMatt Macy 	(dest).time_low = LE_32((dest).time_low);			\
86eda14cbcSMatt Macy 	(dest).time_mid = LE_16((dest).time_mid);			\
87eda14cbcSMatt Macy 	(dest).time_hi_and_version = LE_16((dest).time_hi_and_version);	\
88eda14cbcSMatt Macy }
89eda14cbcSMatt Macy 
90eda14cbcSMatt Macy #ifdef __cplusplus
91eda14cbcSMatt Macy }
92eda14cbcSMatt Macy #endif
93eda14cbcSMatt Macy 
94eda14cbcSMatt Macy #endif /* _SYS_UUID_H */
95