2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-03-02 00:59:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* UUID types and functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPDK_UUID_H
|
|
|
|
#define SPDK_UUID_H
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
|
|
|
#include "spdk/assert.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct spdk_uuid {
|
|
|
|
union {
|
|
|
|
uint8_t raw[16];
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
SPDK_STATIC_ASSERT(sizeof(struct spdk_uuid) == 16, "Incorrect size");
|
|
|
|
|
|
|
|
#define SPDK_UUID_STRING_LEN 37 /* 36 characters + null terminator */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert UUID in textual format into a spdk_uuid.
|
|
|
|
*
|
2018-06-18 14:39:39 +00:00
|
|
|
* \param[out] uuid User-provided UUID buffer.
|
2018-03-02 00:59:50 +00:00
|
|
|
* \param uuid_str UUID in textual format in C string.
|
2018-04-09 02:17:38 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, or negative errno on failure.
|
2018-03-02 00:59:50 +00:00
|
|
|
*/
|
|
|
|
int spdk_uuid_parse(struct spdk_uuid *uuid, const char *uuid_str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert UUID in spdk_uuid into lowercase textual format.
|
|
|
|
*
|
|
|
|
* \param uuid_str User-provided string buffer to write the textual format into.
|
2018-04-09 02:17:38 +00:00
|
|
|
* \param uuid_str_size Size of uuid_str buffer. Must be at least SPDK_UUID_STRING_LEN.
|
2018-03-02 00:59:50 +00:00
|
|
|
* \param uuid UUID to convert to textual format.
|
2018-04-09 02:17:38 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, or negative errno on failure.
|
2018-03-02 00:59:50 +00:00
|
|
|
*/
|
|
|
|
int spdk_uuid_fmt_lower(char *uuid_str, size_t uuid_str_size, const struct spdk_uuid *uuid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two UUIDs.
|
|
|
|
*
|
2018-04-09 02:17:38 +00:00
|
|
|
* \param u1 UUID 1.
|
|
|
|
* \param u2 UUID 2.
|
|
|
|
*
|
|
|
|
* \return 0 if u1 == u2, less than 0 if u1 < u2, greater than 0 if u1 > u2.
|
2018-03-02 00:59:50 +00:00
|
|
|
*/
|
|
|
|
int spdk_uuid_compare(const struct spdk_uuid *u1, const struct spdk_uuid *u2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a new UUID.
|
|
|
|
*
|
2018-06-18 14:39:39 +00:00
|
|
|
* \param[out] uuid User-provided UUID buffer to fill.
|
2018-03-02 00:59:50 +00:00
|
|
|
*/
|
|
|
|
void spdk_uuid_generate(struct spdk_uuid *uuid);
|
|
|
|
|
2023-02-22 11:48:55 +00:00
|
|
|
/**
|
|
|
|
* Generate a new UUID using SHA1 hash.
|
|
|
|
*
|
|
|
|
* \param[out] uuid User-provided UUID buffer to fill.
|
|
|
|
* \param ns_uuid Well-known namespace UUID for generated UUID.
|
|
|
|
* \param name Arbitrary, binary string.
|
|
|
|
* \param len Length of binary string.
|
|
|
|
*
|
|
|
|
* \return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int spdk_uuid_generate_sha1(struct spdk_uuid *uuid, struct spdk_uuid *ns_uuid, const char *name,
|
|
|
|
size_t len);
|
|
|
|
|
2018-12-06 04:20:51 +00:00
|
|
|
/**
|
|
|
|
* Copy a UUID.
|
|
|
|
*
|
|
|
|
* \param src Source UUID to copy from.
|
|
|
|
* \param dst Destination UUID to store.
|
|
|
|
*/
|
|
|
|
void spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src);
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|