Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/uuid.h
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | ||||
* | * | ||||
* Copyright (c) 2021 The FreeBSD Foundation | * Copyright (c) 2021,2023 The FreeBSD Foundation | ||||
* | * | ||||
* This software was developed by Björn Zeeb under sponsorship from | * This software was developed by Björn Zeeb under sponsorship from | ||||
* the FreeBSD Foundation. | * the FreeBSD Foundation. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
Show All 15 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#ifndef _LINUXKPI_LINUX_UUID_H | #ifndef _LINUXKPI_LINUX_UUID_H | ||||
#define _LINUXKPI_LINUX_UUID_H | #define _LINUXKPI_LINUX_UUID_H | ||||
#include <linux/random.h> | |||||
#define UUID_STRING_LEN 36 | #define UUID_STRING_LEN 36 | ||||
#define GUID_INIT(x0_3, x4_5, x6_7, x8, x9, x10, x11, x12, x13, x14, x15) \ | #define GUID_INIT(x0_3, x4_5, x6_7, x8, x9, x10, x11, x12, x13, x14, x15) \ | ||||
((guid_t) { .x = { \ | ((guid_t) { .x = { \ | ||||
[0] = (x0_3) & 0xff, \ | [0] = (x0_3) & 0xff, \ | ||||
[1] = ((x0_3) >> 8) & 0xff, \ | [1] = ((x0_3) >> 8) & 0xff, \ | ||||
[2] = ((x0_3) >> 16) & 0xff, \ | [2] = ((x0_3) >> 16) & 0xff, \ | ||||
[3] = ((x0_3) >> 24) & 0xff, \ | [3] = ((x0_3) >> 24) & 0xff, \ | ||||
Show All 9 Lines | ((guid_t) { .x = { \ | ||||
[13] = (x13), \ | [13] = (x13), \ | ||||
[14] = (x14), \ | [14] = (x14), \ | ||||
[15] = (x15) \ | [15] = (x15) \ | ||||
}}) | }}) | ||||
typedef struct { | typedef struct { | ||||
char x[16]; | char x[16]; | ||||
} guid_t; | } guid_t; | ||||
static inline void | |||||
guid_gen(guid_t *g) | |||||
{ | |||||
get_random_bytes(g, 16); | |||||
g->x[7] = (g->x[7] & 0x0f) | 0x40; | |||||
g->x[8] = (g->x[8] & 0x3f) | 0x80; | |||||
} | |||||
static inline void | |||||
guid_copy(guid_t *dst, const guid_t *src) | |||||
{ | |||||
memcpy(dst, src, sizeof(*dst)); | |||||
} | |||||
#endif /* _LINUXKPI_LINUX_UUID_H */ | #endif /* _LINUXKPI_LINUX_UUID_H */ |