Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * UUID/GUID definition
0004  *
0005  * Copyright (C) 2010, 2016 Intel Corp.
0006  *  Huang Ying <ying.huang@intel.com>
0007  */
0008 #ifndef _LINUX_UUID_H_
0009 #define _LINUX_UUID_H_
0010 
0011 #include <uapi/linux/uuid.h>
0012 #include <linux/string.h>
0013 
0014 #define UUID_SIZE 16
0015 
0016 typedef struct {
0017     __u8 b[UUID_SIZE];
0018 } uuid_t;
0019 
0020 #define UUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)          \
0021 ((uuid_t)                               \
0022 {{ ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff, \
0023    ((b) >> 8) & 0xff, (b) & 0xff,                   \
0024    ((c) >> 8) & 0xff, (c) & 0xff,                   \
0025    (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
0026 
0027 /*
0028  * The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
0029  * not including trailing NUL.
0030  */
0031 #define UUID_STRING_LEN     36
0032 
0033 extern const guid_t guid_null;
0034 extern const uuid_t uuid_null;
0035 
0036 static inline bool guid_equal(const guid_t *u1, const guid_t *u2)
0037 {
0038     return memcmp(u1, u2, sizeof(guid_t)) == 0;
0039 }
0040 
0041 static inline void guid_copy(guid_t *dst, const guid_t *src)
0042 {
0043     memcpy(dst, src, sizeof(guid_t));
0044 }
0045 
0046 static inline void import_guid(guid_t *dst, const __u8 *src)
0047 {
0048     memcpy(dst, src, sizeof(guid_t));
0049 }
0050 
0051 static inline void export_guid(__u8 *dst, const guid_t *src)
0052 {
0053     memcpy(dst, src, sizeof(guid_t));
0054 }
0055 
0056 static inline bool guid_is_null(const guid_t *guid)
0057 {
0058     return guid_equal(guid, &guid_null);
0059 }
0060 
0061 static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2)
0062 {
0063     return memcmp(u1, u2, sizeof(uuid_t)) == 0;
0064 }
0065 
0066 static inline void uuid_copy(uuid_t *dst, const uuid_t *src)
0067 {
0068     memcpy(dst, src, sizeof(uuid_t));
0069 }
0070 
0071 static inline void import_uuid(uuid_t *dst, const __u8 *src)
0072 {
0073     memcpy(dst, src, sizeof(uuid_t));
0074 }
0075 
0076 static inline void export_uuid(__u8 *dst, const uuid_t *src)
0077 {
0078     memcpy(dst, src, sizeof(uuid_t));
0079 }
0080 
0081 static inline bool uuid_is_null(const uuid_t *uuid)
0082 {
0083     return uuid_equal(uuid, &uuid_null);
0084 }
0085 
0086 void generate_random_uuid(unsigned char uuid[16]);
0087 void generate_random_guid(unsigned char guid[16]);
0088 
0089 extern void guid_gen(guid_t *u);
0090 extern void uuid_gen(uuid_t *u);
0091 
0092 bool __must_check uuid_is_valid(const char *uuid);
0093 
0094 extern const u8 guid_index[16];
0095 extern const u8 uuid_index[16];
0096 
0097 int guid_parse(const char *uuid, guid_t *u);
0098 int uuid_parse(const char *uuid, uuid_t *u);
0099 
0100 /* backwards compatibility, don't use in new code */
0101 static inline int uuid_le_cmp(const guid_t u1, const guid_t u2)
0102 {
0103     return memcmp(&u1, &u2, sizeof(guid_t));
0104 }
0105 
0106 #endif