Skip to content

Commit d1f4c66

Browse files
lgdacunhigaw
authored andcommitted
util: Added function to find specific UUID in UUID list.
Finds a given UUID in the UUID list returned by identify UUID. Signed-off-by: Leonardo da Cunha <[email protected]>
1 parent 89de650 commit d1f4c66

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/libnvme.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
LIBNVME_1_8 {
3+
global:
4+
nvme_uuid_find;
5+
};
6+
27
LIBNVME_1_7 {
38
global:
49
nvme_init_copy_range_f2;

src/nvme/util.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,25 @@ int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
951951
return 0;
952952
}
953953

954+
int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN])
955+
{
956+
const unsigned char uuid_end[NVME_UUID_LEN] = {0};
957+
958+
if ((!uuid_list) || (!uuid)) {
959+
errno = EINVAL;
960+
return -1;
961+
}
962+
963+
for (int i = 0; i < NVME_ID_UUID_LIST_MAX; i++) {
964+
if (memcmp(uuid, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
965+
return i + 1;
966+
if (memcmp(uuid_end, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
967+
break;
968+
}
969+
errno = ENOENT;
970+
return -1;
971+
}
972+
954973
#ifdef HAVE_NETDB
955974
static bool _nvme_ipaddrs_eq(struct sockaddr *addr1, struct sockaddr *addr2)
956975
{

src/nvme/util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,15 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]);
666666
*/
667667
int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]);
668668

669+
/**
670+
* nvme_uuid_find - Find UUID position on UUID list
671+
* @uuid_list: UUID list returned by identify UUID
672+
* @uuid: Binary encoded input UUID
673+
*
674+
* Return: The array position where given UUID is present, or -1 on failure with errno set.
675+
*/
676+
int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]);
677+
669678
/**
670679
* nvme_ipaddrs_eq - Check if 2 IP addresses are equal.
671680
* @addr1: IP address (can be IPv4 or IPv6)

0 commit comments

Comments
 (0)