Finds a given UUID in the UUID list returned by identify UUID.
Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>
# SPDX-License-Identifier: LGPL-2.1-or-later
+LIBNVME_1_8 {
+ global:
+ nvme_uuid_find;
+};
+
LIBNVME_1_7 {
global:
nvme_init_copy_range_f2;
return 0;
}
+int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN])
+{
+ const unsigned char uuid_end[NVME_UUID_LEN] = {0};
+
+ if ((!uuid_list) || (!uuid)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ for (int i = 0; i < NVME_ID_UUID_LIST_MAX; i++) {
+ if (memcmp(uuid, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
+ return i + 1;
+ if (memcmp(uuid_end, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
+ break;
+ }
+ errno = ENOENT;
+ return -1;
+}
+
#ifdef HAVE_NETDB
static bool _nvme_ipaddrs_eq(struct sockaddr *addr1, struct sockaddr *addr2)
{
*/
int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]);
+/**
+ * nvme_uuid_find - Find UUID position on UUID list
+ * @uuid_list: UUID list returned by identify UUID
+ * @uuid: Binary encoded input UUID
+ *
+ * Return: The array position where given UUID is present, or -1 on failure with errno set.
+ */
+int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]);
+
/**
* nvme_ipaddrs_eq - Check if 2 IP addresses are equal.
* @addr1: IP address (can be IPv4 or IPv6)