1 /* Public domain. */
2 
3 #ifndef _LINUX_UUID_H
4 #define _LINUX_UUID_H
5 
6 #include <linux/string.h>
7 
8 #define UUID_STRING_LEN 36
9 #define UUID_SIZE	16
10 
11 typedef struct {
12 	uint8_t guid[UUID_SIZE];
13 } guid_t;
14 
15 static inline void
import_guid(guid_t * dst,const uint8_t * src)16 import_guid(guid_t *dst, const uint8_t *src)
17 {
18 	memcpy(&dst->guid, src, sizeof(dst->guid));
19 }
20 
21 static inline void
export_guid(uint8_t * dst,const guid_t * src)22 export_guid(uint8_t *dst, const guid_t *src)
23 {
24 	memcpy(dst, &src->guid, sizeof(src->guid));
25 }
26 
27 static inline void
guid_copy(guid_t * dst,const guid_t * src)28 guid_copy(guid_t *dst, const guid_t *src)
29 {
30 	memcpy(&dst->guid, &src->guid, sizeof(dst->guid));
31 }
32 
33 static inline bool
guid_equal(const guid_t * a,const guid_t * b)34 guid_equal(const guid_t *a, const guid_t *b)
35 {
36 	return memcmp(&a->guid, &b->guid, sizeof(a->guid)) == 0;
37 }
38 
39 static inline bool
guid_is_null(const guid_t * a)40 guid_is_null(const guid_t *a)
41 {
42 	return memchr_inv(&a->guid, 0, sizeof(a->guid)) == NULL;
43 }
44 
45 static inline void
guid_gen(guid_t * a)46 guid_gen(guid_t *a)
47 {
48 	arc4random_buf(&a->guid, sizeof(a->guid));
49 	a->guid[6] = (a->guid[6] & 0x0f) | 0x40;
50 	a->guid[8] = (a->guid[8] & 0x3f) | 0x80;
51 }
52 
53 #endif
54