diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:05:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:05:25 +0000 |
commit | d3b6c0269abf2332f6f4b43760524b040ca58ff8 (patch) | |
tree | 6a0ebdb4cb3c7b76c824f021d9f3624d16037457 /src/nvme/sysfs.c | |
parent | Adding upstream version 1.8. (diff) | |
download | libnvme-upstream/1.9.tar.xz libnvme-upstream/1.9.zip |
Adding upstream version 1.9.upstream/1.9
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/nvme/sysfs.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/nvme/sysfs.c b/src/nvme/sysfs.c new file mode 100644 index 0000000..ea4f0e2 --- /dev/null +++ b/src/nvme/sysfs.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +#include <stdio.h> +#include <stdlib.h> + +#include "private.h" + +#define PATH_UUID_IBM "/proc/device-tree/ibm,partition-uuid" +#define PATH_SYSFS_BLOCK "/sys/block" +#define PATH_SYSFS_SLOTS "/sys/bus/pci/slots" +#define PATH_SYSFS_NVME_SUBSYSTEM "/sys/class/nvme-subsystem" +#define PATH_SYSFS_NVME "/sys/class/nvme" +#define PATH_DMI_ENTRIES "/sys/firmware/dmi/entries" + +static const char *make_sysfs_dir(const char *path) +{ + char *basepath = getenv("LIBNVME_SYSFS_PATH"); + char *str; + + if (!basepath) + return path; + + if (asprintf(&str, "%s%s", basepath, path) < 0) + return NULL; + + return str; +} + +const char *nvme_subsys_sysfs_dir(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_SYSFS_NVME_SUBSYSTEM); +} + +const char *nvme_ctrl_sysfs_dir(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_SYSFS_NVME); +} + +const char *nvme_ns_sysfs_dir(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_SYSFS_BLOCK); +} + +const char *nvme_slots_sysfs_dir(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_SYSFS_SLOTS); +} + +const char *nvme_uuid_ibm_filename(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_UUID_IBM); +} + +const char *nvme_dmi_entries_dir(void) +{ + static const char *str; + + if (str) + return str; + + return str = make_sysfs_dir(PATH_DMI_ENTRIES); +} |