]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/common/uuid.c
94fdd737cb8a85c0e83c6a034181b4328855bd42
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2014-2018, Intel Corporation */
5 * uuid.c -- uuid utilities
15 * util_uuid_to_string -- generate a string form of the uuid
18 util_uuid_to_string(const uuid_t u
, char *buf
)
20 int len
; /* size that is returned from sprintf call */
23 LOG(2, "invalid buffer for uuid string");
28 LOG(2, "invalid uuid structure");
32 struct uuid
*uuid
= (struct uuid
*)u
;
33 len
= snprintf(buf
, POOL_HDR_UUID_STR_LEN
,
34 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
35 uuid
->time_low
, uuid
->time_mid
, uuid
->time_hi_and_ver
,
36 uuid
->clock_seq_hi
, uuid
->clock_seq_low
, uuid
->node
[0],
37 uuid
->node
[1], uuid
->node
[2], uuid
->node
[3], uuid
->node
[4],
40 if (len
!= POOL_HDR_UUID_STR_LEN
- 1) {
41 LOG(2, "snprintf(uuid): %d", len
);
49 * util_uuid_from_string -- generate a binary form of the uuid
51 * uuid string read from /proc/sys/kernel/random/uuid. UUID string
53 * f81d4fae-7dec-11d0-a765-00a0c91e6bf6
56 util_uuid_from_string(const char *uuid
, struct uuid
*ud
)
58 if (strlen(uuid
) != 36) {
59 LOG(2, "invalid uuid string");
63 if (uuid
[8] != '-' || uuid
[13] != '-' || uuid
[18] != '-' ||
65 LOG(2, "invalid uuid string");
70 "%08x-%04hx-%04hx-%02hhx%02hhx-"
71 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
72 &ud
->time_low
, &ud
->time_mid
, &ud
->time_hi_and_ver
,
73 &ud
->clock_seq_hi
, &ud
->clock_seq_low
, &ud
->node
[0],
74 &ud
->node
[1], &ud
->node
[2], &ud
->node
[3], &ud
->node
[4],
78 LOG(2, "sscanf(uuid)");