summaryrefslogtreecommitdiffstats
path: root/src/nvme/util.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-02-19 10:38:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-02-19 10:38:18 +0000
commit678392aa6bef5e30cb1b9452978fd0b2ce56c2ee (patch)
tree26ac06227a6fe6571157a8860bac80506f00c5d7 /src/nvme/util.c
parentReleasing debian version 1.7.1-1. (diff)
downloadlibnvme-678392aa6bef5e30cb1b9452978fd0b2ce56c2ee.tar.xz
libnvme-678392aa6bef5e30cb1b9452978fd0b2ce56c2ee.zip
Merging upstream version 1.8.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/nvme/util.c')
-rw-r--r--src/nvme/util.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/nvme/util.c b/src/nvme/util.c
index 45512ff..f091da7 100644
--- a/src/nvme/util.c
+++ b/src/nvme/util.c
@@ -757,7 +757,7 @@ char *kv_keymatch(const char *kv, const char *key)
static size_t read_file(const char * fname, char *buffer, size_t *bufsz)
{
char *p;
- _cleanup_file_ FILE *file;
+ _cleanup_file_ FILE *file = NULL;
size_t len;
file = fopen(fname, "re");
@@ -806,7 +806,7 @@ size_t get_entity_name(char *buffer, size_t bufsz)
size_t get_entity_version(char *buffer, size_t bufsz)
{
- _cleanup_file_ FILE *file;
+ _cleanup_file_ FILE *file = NULL;
size_t num_bytes = 0;
/* /proc/sys/kernel/ostype typically contains the string "Linux" */
@@ -928,7 +928,7 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN])
int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
{
- _cleanup_fd_ int f;
+ _cleanup_fd_ int f = -1;
ssize_t n;
f = open("/dev/urandom", O_RDONLY);
@@ -951,6 +951,25 @@ int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
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)
{