summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-03 13:48:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-12 07:59:59 +0200
commit15e26bb72b334da1830c26917e28ffcac64e8e4c (patch)
treec2d334fe86fb95e1b963172e349ea00a6249ad4f /common
parentfab1f406fdb82f2876f48c3c9e33672c963809e2 (diff)
downloadbarebox-15e26bb72b334da1830c26917e28ffcac64e8e4c.tar.gz
barebox-15e26bb72b334da1830c26917e28ffcac64e8e4c.tar.xz
param: introduce file-list parameter type
DFU, fastboot and incoming mass storage support all use file lists as input, but individually check syntax correctness only on use. A dedicated file list parameter would improve the user experience and makes the code using it easier to handle: the struct file_list can be passed around directly instead of having to parse it first on use. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/file-list.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/common/file-list.c b/common/file-list.c
index cd52b5e045..924903cef7 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -6,6 +6,7 @@
#include <malloc.h>
#include <fs.h>
#include <file-list.h>
+#include <stringlist.h>
#include <linux/err.h>
#define PARSE_DEVICE 0
@@ -109,6 +110,25 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
return file_list_add_entry(files, name, filename, flags);
}
+static const char *flags_to_str(int flags)
+{
+ static char str[sizeof "srcu"];
+ char *s = str;;
+
+ if (flags & FILE_LIST_FLAG_SAFE)
+ *s++ = 's';
+ if (flags & FILE_LIST_FLAG_READBACK)
+ *s++ = 'r';
+ if (flags & FILE_LIST_FLAG_CREATE)
+ *s++ = 'c';
+ if (flags & FILE_LIST_FLAG_UBI)
+ *s++ = 'u';
+
+ *s = '\0';
+
+ return str;
+}
+
struct file_list *file_list_parse(const char *str)
{
struct file_list *files;
@@ -149,3 +169,30 @@ void file_list_free(struct file_list *files)
free(files);
}
+
+char *file_list_to_str(const struct file_list *files)
+{
+ struct file_list_entry *entry;
+ struct string_list sl;
+ char *str;
+
+ if (!files)
+ return strdup("");
+
+ string_list_init(&sl);
+
+ list_for_each_entry(entry, &files->list, list) {
+ int ret = string_list_add_asprintf(&sl, "%s(%s)%s", entry->filename, entry->name,
+ flags_to_str(entry->flags));
+ if (ret) {
+ str = ERR_PTR(ret);
+ goto out;
+ }
+ }
+
+ str = string_list_join(&sl, ",");
+out:
+ string_list_free(&sl);
+
+ return str;
+}