summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-03 13:48:59 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-12 08:00:00 +0200
commit00e5e596df0b6db478bad982fd38867bd5582e76 (patch)
tree68b5df02138483a3e54b01b69532d9576c3e7841
parent49697b065a04d5a5713ba90626dc4259fd007232 (diff)
downloadbarebox-00e5e596df0b6db478bad982fd38867bd5582e76.tar.gz
barebox-00e5e596df0b6db478bad982fd38867bd5582e76.tar.xz
file_list: add file_list_detect_all()
This is a common theme along the code that uses file_lists. Add a function that abstracts it. This could later be used to simplify this operation in the fastboot code. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-15-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/file-list.c17
-rw-r--r--include/file-list.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/common/file-list.c b/common/file-list.c
index 55e6f0e6b6..05f44514fb 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -8,6 +8,7 @@
#include <file-list.h>
#include <stringlist.h>
#include <linux/err.h>
+#include <driver.h>
#define PARSE_DEVICE 0
#define PARSE_NAME 1
@@ -217,3 +218,19 @@ out:
return str;
}
+
+int file_list_detect_all(const struct file_list *files)
+{
+ struct file_list_entry *fentry;
+ struct stat s;
+ int i = 0;
+
+ list_for_each_entry(fentry, &files->list, list) {
+ if (stat(fentry->filename, &s))
+ continue;
+ if (device_detect_by_name(devpath_to_name(fentry->filename)) == 0)
+ i++;
+ }
+
+ return i;
+}
diff --git a/include/file-list.h b/include/file-list.h
index be97a49b7a..7e2a4d9205 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -30,6 +30,8 @@ int file_list_add_entry(struct file_list *files, const char *name, const char *f
struct file_list *file_list_dup(struct file_list *old);
+int file_list_detect_all(const struct file_list *files);
+
struct file_list_entry *file_list_entry_by_name(struct file_list *files, const char *name);
#define file_list_for_each_entry(files, entry) \