From: Michael Olbrich <m.olbrich@pengutronix.de>
To: oss-tools@pengutronix.de
Cc: Michael Olbrich <m.olbrich@pengutronix.de>
Subject: [OSS-Tools] [PATCH 2/4] state: implement helper to find device path from diskuuid
Date: Mon, 24 Jan 2022 12:21:41 +0100 [thread overview]
Message-ID: <20220124112143.3016473-3-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <20220124112143.3016473-1-m.olbrich@pengutronix.de>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
I didn't find a good place for this helper. It has nothing to do with
device trees and I didn't want to add it to code that is shared with
barebox. If there is a better place for it then I don't mind moving it.
Michael
Makefile.am | 1 +
src/barebox-state-compat.c | 64 ++++++++++++++++++++++++++++++++++++++
src/libbb.h | 2 ++
3 files changed, 67 insertions(+)
create mode 100644 src/barebox-state-compat.c
diff --git a/Makefile.am b/Makefile.am
index d53ee7c6f9c3..a9eb0fd304eb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -55,6 +55,7 @@ barebox_state_SOURCES = \
src/barebox-state/state.c \
src/barebox-state/state.h \
src/barebox-state/state_variables.c \
+ src/barebox-state-compat.c \
src/barebox-state.c \
src/barebox-state.h \
\
diff --git a/src/barebox-state-compat.c b/src/barebox-state-compat.c
new file mode 100644
index 000000000000..1ed8fefa2253
--- /dev/null
+++ b/src/barebox-state-compat.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2022 Pengutronix, Michael Olbrich <m.olbrich@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <libudev.h>
+
+int devpath_from_diskuuid(const char *diskuuid, char **devpath)
+{
+ struct udev *udev;
+ struct udev_enumerate *enumerate;
+ struct udev_list_entry *devices, *dev_list_entry;
+ int ret = 0;
+
+ udev = udev_new();
+ if (!udev) {
+ fprintf(stderr, "Can't create udev\n");
+ return -ENODEV;
+ }
+
+ enumerate = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(enumerate, "block");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
+ udev_list_entry_foreach(dev_list_entry, devices) {
+ const char *path, *devtype, *outpath, *uuid;
+ struct udev_device *device;
+
+ path = udev_list_entry_get_name(dev_list_entry);
+ device = udev_device_new_from_syspath(udev, path);
+
+ /* distinguish device (disk) from partitions */
+ devtype = udev_device_get_devtype(device);
+ if (!devtype)
+ continue;
+ if (strcmp(devtype, "disk"))
+ continue;
+
+ uuid = udev_device_get_property_value(device, "ID_PART_TABLE_UUID");
+ if (!strcmp(uuid, diskuuid)) {
+ outpath = udev_device_get_devnode(device);
+ *devpath = strdup(outpath);
+ goto out;
+ }
+ }
+ ret = -ENODEV;
+
+out:
+ udev_enumerate_unref(enumerate);
+ udev_unref(udev);
+
+ return ret;
+}
diff --git a/src/libbb.h b/src/libbb.h
index 9f9d32d12d94..5350341d2281 100644
--- a/src/libbb.h
+++ b/src/libbb.h
@@ -3,4 +3,6 @@
#include <dt/common.h>
+int devpath_from_diskuuid(const char *diskuuid, char **devpath);
+
#endif
--
2.30.2
_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de
next prev parent reply other threads:[~2022-01-24 11:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 11:21 [OSS-Tools] [PATCH 0/4] improve barebox-state support on EFI system Michael Olbrich
2022-01-24 11:21 ` [OSS-Tools] [PATCH 1/4] state: support deep probe Michael Olbrich
2022-01-24 11:21 ` Michael Olbrich [this message]
2022-01-24 11:21 ` [OSS-Tools] [PATCH 3/4] state: support backend-diskuuid / backend-offset Michael Olbrich
2022-01-24 11:21 ` [OSS-Tools] [PATCH 4/4] state: automatically find state.dtb in the ESP Michael Olbrich
2022-02-05 23:37 ` [OSS-Tools] [PATCH 0/4] improve barebox-state support on EFI system Roland Hieber
2022-02-06 7:22 ` Michael Olbrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220124112143.3016473-3-m.olbrich@pengutronix.de \
--to=m.olbrich@pengutronix.de \
--cc=oss-tools@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox