blob: 0c631e2a73b6f136b7b1d381a5a5e25a13fc8ef1 [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Huang Yingfab1c232010-05-18 14:35:18 +08002/*
3 * UUID/GUID definition
4 *
Andy Shevchenkoe3a93bc2016-05-20 17:01:07 -07005 * Copyright (C) 2010, 2016 Intel Corp.
Huang Yingfab1c232010-05-18 14:35:18 +08006 * Huang Ying <ying.huang@intel.com>
Huang Yingfab1c232010-05-18 14:35:18 +08007 */
Huang Yingfab1c232010-05-18 14:35:18 +08008#ifndef _LINUX_UUID_H_
9#define _LINUX_UUID_H_
10
David Howells607ca462012-10-13 10:46:48 +010011#include <uapi/linux/uuid.h>
Alexey Dobriyandfbc3c6cb2018-02-06 15:37:48 -080012#include <linux/string.h>
Huang Yingfab1c232010-05-18 14:35:18 +080013
Tyler Baicar297b64c2017-06-21 12:17:12 -060014#define UUID_SIZE 16
15
Christoph Hellwig60927bc2017-05-17 09:56:45 +020016typedef struct {
Tyler Baicar297b64c2017-06-21 12:17:12 -060017 __u8 b[UUID_SIZE];
Christoph Hellwigf9727a12017-05-17 10:02:48 +020018} uuid_t;
Christoph Hellwig60927bc2017-05-17 09:56:45 +020019
Christoph Hellwigf9727a12017-05-17 10:02:48 +020020#define UUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
21((uuid_t) \
Christoph Hellwig60927bc2017-05-17 09:56:45 +020022{{ ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff, \
23 ((b) >> 8) & 0xff, (b) & 0xff, \
24 ((c) >> 8) & 0xff, (c) & 0xff, \
25 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
26
Andy Shevchenko2b1b0d62016-05-20 17:01:04 -070027/*
28 * The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
29 * not including trailing NUL.
30 */
31#define UUID_STRING_LEN 36
Tomas Winklerb544f3f2012-05-09 16:38:58 +030032
Christoph Hellwigef40dda2017-05-11 09:01:42 +020033extern const guid_t guid_null;
34extern const uuid_t uuid_null;
35
Christoph Hellwigdf337672017-05-11 14:00:57 +020036static inline bool guid_equal(const guid_t *u1, const guid_t *u2)
37{
38 return memcmp(u1, u2, sizeof(guid_t)) == 0;
39}
40
41static inline void guid_copy(guid_t *dst, const guid_t *src)
42{
43 memcpy(dst, src, sizeof(guid_t));
44}
45
Andy Shevchenko63709fd2017-06-16 21:13:38 +030046static inline bool guid_is_null(const guid_t *guid)
Christoph Hellwigef40dda2017-05-11 09:01:42 +020047{
48 return guid_equal(guid, &guid_null);
49}
50
Christoph Hellwigdf337672017-05-11 14:00:57 +020051static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2)
52{
53 return memcmp(u1, u2, sizeof(uuid_t)) == 0;
54}
55
56static inline void uuid_copy(uuid_t *dst, const uuid_t *src)
57{
58 memcpy(dst, src, sizeof(uuid_t));
59}
60
Andy Shevchenko63709fd2017-06-16 21:13:38 +030061static inline bool uuid_is_null(const uuid_t *uuid)
Christoph Hellwigef40dda2017-05-11 09:01:42 +020062{
63 return uuid_equal(uuid, &uuid_null);
64}
65
Andy Shevchenko8da4b8c2016-05-20 17:01:00 -070066void generate_random_uuid(unsigned char uuid[16]);
67
Christoph Hellwigf9727a12017-05-17 10:02:48 +020068extern void guid_gen(guid_t *u);
69extern void uuid_gen(uuid_t *u);
Huang Yingfab1c232010-05-18 14:35:18 +080070
Andy Shevchenko2b1b0d62016-05-20 17:01:04 -070071bool __must_check uuid_is_valid(const char *uuid);
72
Christoph Hellwigf9727a12017-05-17 10:02:48 +020073extern const u8 guid_index[16];
74extern const u8 uuid_index[16];
Andy Shevchenko2b1b0d62016-05-20 17:01:04 -070075
Christoph Hellwigf9727a12017-05-17 10:02:48 +020076int guid_parse(const char *uuid, guid_t *u);
77int uuid_parse(const char *uuid, uuid_t *u);
78
79/* backwards compatibility, don't use in new code */
Christoph Hellwigf9727a12017-05-17 10:02:48 +020080#define uuid_le_gen(u) guid_gen(u)
Christoph Hellwigf9727a12017-05-17 10:02:48 +020081#define uuid_le_to_bin(guid, u) guid_parse(guid, u)
Christoph Hellwigf9727a12017-05-17 10:02:48 +020082
83static inline int uuid_le_cmp(const guid_t u1, const guid_t u2)
84{
85 return memcmp(&u1, &u2, sizeof(guid_t));
86}
87
Huang Yingfab1c232010-05-18 14:35:18 +080088#endif