1 From 02cff0ccaa6d364f5c1eeea83f47ac80ccc967d4 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Tue, 3 Sep 2013 18:11:50 +0200
4 Subject: [PATCH] mtd: add support for different partition parser types
6 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
8 drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
9 include/linux/mtd/partitions.h | 11 ++++++++
10 2 files changed, 67 insertions(+)
12 --- a/drivers/mtd/mtdpart.c
13 +++ b/drivers/mtd/mtdpart.c
14 @@ -996,6 +996,62 @@ void mtd_part_parser_cleanup(struct mtd_
18 +static struct mtd_part_parser *
19 +get_partition_parser_by_type(enum mtd_parser_type type,
20 + struct mtd_part_parser *start)
22 + struct mtd_part_parser *p, *ret = NULL;
24 + spin_lock(&part_parser_lock);
26 + p = list_prepare_entry(start, &part_parsers, list);
28 + mtd_part_parser_put(start);
30 + list_for_each_entry_continue(p, &part_parsers, list) {
31 + if (p->type == type && try_module_get(p->owner)) {
37 + spin_unlock(&part_parser_lock);
42 +int parse_mtd_partitions_by_type(struct mtd_info *master,
43 + enum mtd_parser_type type,
44 + const struct mtd_partition **pparts,
45 + struct mtd_part_parser_data *data)
47 + struct mtd_part_parser *prev = NULL;
51 + struct mtd_part_parser *parser;
53 + parser = get_partition_parser_by_type(type, prev);
57 + ret = (*parser->parse_fn)(master, pparts, data);
60 + mtd_part_parser_put(parser);
62 + "%d %s partitions found on MTD device %s\n",
63 + ret, parser->name, master->name);
72 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
74 int mtd_is_partition(const struct mtd_info *mtd)
76 struct mtd_part *part;
77 --- a/include/linux/mtd/partitions.h
78 +++ b/include/linux/mtd/partitions.h
79 @@ -61,11 +61,14 @@ struct mtd_part_parser_data {
85 * Functions dealing with the various ways of partitioning the space
88 +enum mtd_parser_type {
89 + MTD_PARSER_TYPE_DEVICE = 0,
92 struct mtd_part_parser {
93 struct list_head list;
95 @@ -73,6 +76,7 @@ struct mtd_part_parser {
96 int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
97 struct mtd_part_parser_data *);
98 void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
99 + enum mtd_parser_type type;
102 /* Container for passing around a set of parsed partitions */
103 @@ -105,4 +109,9 @@ uint64_t mtd_get_device_size(const struc
104 extern void __weak arch_split_mtd_part(struct mtd_info *master,
105 const char *name, int offset, int size);
107 +int parse_mtd_partitions_by_type(struct mtd_info *master,
108 + enum mtd_parser_type type,
109 + const struct mtd_partition **pparts,
110 + struct mtd_part_parser_data *data);