xref: /illumos-gate/usr/src/compat/bhyve/uuid.h (revision 99ea293e719ac006d413e4fde6ac0d5cd4dd6c59)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2014 Pluribus Networks Inc.
14  */
15 
16 #ifndef _COMPAT_FREEBSD_UUID_H_
17 #define	_COMPAT_FREEBSD_UUID_H_
18 
19 #include <sys/endian.h>
20 #include <uuid/uuid.h>
21 
22 /* Status codes returned by the functions. */
23 #define	uuid_s_ok			0
24 #define	uuid_s_bad_version		1
25 #define	uuid_s_invalid_string_uuid	2
26 
27 static __inline void
28 uuid_from_string(char *str, uuid_t *uuidp, uint32_t *status)
29 {
30 	if (uuid_parse(str, *uuidp) == 0) {
31 		*status = uuid_s_ok;
32 	} else {
33 		*status = uuid_s_invalid_string_uuid;
34 	}
35 }
36 
37 static __inline void
38 uuid_enc_le(void *buf, uuid_t *uuidp)
39 {
40 	uchar_t	*p;
41 	int	i;
42 
43 	p = buf;
44 	be32enc(p, ((struct uuid *)uuidp)->time_low);
45 	be16enc(p + 4, ((struct uuid *)uuidp)->time_mid);
46 	be16enc(p + 6, ((struct uuid *)uuidp)->time_hi_and_version);
47 	p[8] = ((struct uuid *)uuidp)->clock_seq_hi_and_reserved;
48 	p[9] = ((struct uuid *)uuidp)->clock_seq_low;
49 
50 	for (i = 0; i < 6; i++)
51 		p[10 + i] = ((struct uuid *)uuidp)->node_addr[i];
52 
53 }
54 
55 #endif	/* _COMPAT_FREEBSD_UUID_H_ */
56