summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-10-19 15:07:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-10-19 15:07:40 +0200
commita10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2 (patch)
treecd4f007c081b7693424411cea71cb6c9e98ff379 /common
parent7f04124c149fa4d8e8f657907c581f10987003e2 (diff)
parent05761813eff43493ee0519f0699a396de3f007a5 (diff)
downloadbarebox-a10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2.tar.gz
barebox-a10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2.tar.xz
Merge branch 'for-next/usbgadget'
Diffstat (limited to 'common')
-rw-r--r--common/bbu.c15
-rw-r--r--common/file-list.c72
2 files changed, 73 insertions, 14 deletions
diff --git a/common/bbu.c b/common/bbu.c
index 031c433820..3b372263b1 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -30,6 +30,21 @@
static LIST_HEAD(bbu_image_handlers);
+int bbu_handlers_iterate(int (*fn)(struct bbu_handler *, void *), void *ctx)
+{
+ struct bbu_handler *handler;
+
+ list_for_each_entry(handler, &bbu_image_handlers, list) {
+ int ret;
+
+ ret = fn(handler, ctx);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
int bbu_force(struct bbu_data *data, const char *fmt, ...)
{
va_list args;
diff --git a/common/file-list.c b/common/file-list.c
index 90c0f429c5..8d61b76cbb 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -1,3 +1,16 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2.
+ *
+ * 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.
+ */
+
+#define pr_fmt(fmt) "file_list: " fmt
+
#include <common.h>
#include <malloc.h>
#include <fs.h>
@@ -8,12 +21,44 @@
#define PARSE_NAME 1
#define PARSE_FLAGS 2
+struct file_list_entry *file_list_entry_by_name(struct file_list *files, const char *name)
+{
+ struct file_list_entry *entry;
+
+ file_list_for_each_entry(files, entry) {
+ if (!strcmp(entry->name, name))
+ return entry;
+ }
+
+ return NULL;
+}
+
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+ unsigned long flags)
+{
+ struct file_list_entry *entry;
+
+ entry = file_list_entry_by_name(files, name);
+ if (entry)
+ return -EEXIST;
+
+ entry = xzalloc(sizeof(*entry));
+
+ entry->name = xstrdup(name);
+ entry->filename = xstrdup(filename);
+ entry->flags = flags;
+
+ list_add_tail(&entry->list, &files->list);
+
+ return 0;
+}
+
static int file_list_parse_one(struct file_list *files, const char *partstr, const char **endstr)
{
int i = 0, state = PARSE_DEVICE;
char filename[PATH_MAX];
char name[PATH_MAX];
- struct file_list_entry *entry = xzalloc(sizeof(*entry));
+ unsigned long flags = 0;
memset(filename, 0, sizeof(filename));
memset(name, 0, sizeof(name));
@@ -39,15 +84,16 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
case PARSE_FLAGS:
switch (*partstr) {
case 's':
- entry->flags |= FILE_LIST_FLAG_SAFE;
+ flags |= FILE_LIST_FLAG_SAFE;
break;
case 'r':
- entry->flags |= FILE_LIST_FLAG_READBACK;
+ flags |= FILE_LIST_FLAG_READBACK;
break;
case 'c':
- entry->flags |= FILE_LIST_FLAG_CREATE;
+ flags |= FILE_LIST_FLAG_CREATE;
break;
default:
+ pr_err("Unknown flag '%c'\n", *partstr);
return -EINVAL;
}
break;
@@ -57,18 +103,16 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
partstr++;
}
- if (state != PARSE_FLAGS)
+ if (state != PARSE_FLAGS) {
+ pr_err("Missing ')'\n");
return -EINVAL;
+ }
- entry->name = xstrdup(name);
- entry->filename = xstrdup(filename);
if (*partstr == ',')
partstr++;
*endstr = partstr;
- list_add_tail(&entry->list, &files->list);
-
- return 0;
+ return file_list_add_entry(files, name, filename, flags);
}
struct file_list *file_list_parse(const char *str)
@@ -82,9 +126,9 @@ struct file_list *file_list_parse(const char *str)
INIT_LIST_HEAD(&files->list);
while (*str) {
- if (file_list_parse_one(files, str, &endptr)) {
- printf("parse error\n");
- ret = -EINVAL;
+ ret = file_list_parse_one(files, str, &endptr);
+ if (ret) {
+ pr_err("parse error\n");
goto out;
}
str = endptr;
@@ -94,7 +138,7 @@ struct file_list *file_list_parse(const char *str)
return files;
out:
- free(files);
+ file_list_free(files);
return ERR_PTR(ret);
}