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 @@ -768,6 +768,30 @@ static struct mtd_part_parser *get_parti
16 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
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 + put_partition_parser(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 void register_mtd_parser(struct mtd_part_parser *p)
44 spin_lock(&part_parser_lock);
45 @@ -841,6 +865,38 @@ int parse_mtd_partitions(struct mtd_info
49 +int parse_mtd_partitions_by_type(struct mtd_info *master,
50 + enum mtd_parser_type type,
51 + struct mtd_partition **pparts,
52 + struct mtd_part_parser_data *data)
54 + struct mtd_part_parser *prev = NULL;
58 + struct mtd_part_parser *parser;
60 + parser = get_partition_parser_by_type(type, prev);
64 + ret = (*parser->parse_fn)(master, pparts, data);
67 + put_partition_parser(parser);
69 + "%d %s partitions found on MTD device %s\n",
70 + ret, parser->name, master->name);
79 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
81 int mtd_is_partition(const struct mtd_info *mtd)
83 struct mtd_part *part;
84 --- a/include/linux/mtd/partitions.h
85 +++ b/include/linux/mtd/partitions.h
86 @@ -68,12 +68,17 @@ struct mtd_part_parser_data {
87 * Functions dealing with the various ways of partitioning the space
90 +enum mtd_parser_type {
91 + MTD_PARSER_TYPE_DEVICE = 0,
94 struct mtd_part_parser {
95 struct list_head list;
98 int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
99 struct mtd_part_parser_data *);
100 + enum mtd_parser_type type;
103 extern void register_mtd_parser(struct mtd_part_parser *parser);
104 @@ -87,4 +92,9 @@ uint64_t mtd_get_device_size(const struc
105 extern void __weak arch_split_mtd_part(struct mtd_info *master,
106 const char *name, int offset, int size);
108 +int parse_mtd_partitions_by_type(struct mtd_info *master,
109 + enum mtd_parser_type type,
110 + struct mtd_partition **pparts,
111 + struct mtd_part_parser_data *data);