diff options
Diffstat (limited to 'common/file-list.c')
-rw-r--r-- | common/file-list.c | 47 |
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; +} |