401-mtd-add-support-for-different-partition-parser-types.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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
  5. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  6. ---
  7. drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
  8. include/linux/mtd/partitions.h | 11 ++++++++
  9. 2 files changed, 67 insertions(+)
  10. --- a/drivers/mtd/mtdpart.c
  11. +++ b/drivers/mtd/mtdpart.c
  12. @@ -740,6 +740,30 @@ static struct mtd_part_parser *get_parti
  13. #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
  14. +static struct mtd_part_parser *
  15. +get_partition_parser_by_type(enum mtd_parser_type type,
  16. + struct mtd_part_parser *start)
  17. +{
  18. + struct mtd_part_parser *p, *ret = NULL;
  19. +
  20. + spin_lock(&part_parser_lock);
  21. +
  22. + p = list_prepare_entry(start, &part_parsers, list);
  23. + if (start)
  24. + put_partition_parser(start);
  25. +
  26. + list_for_each_entry_continue(p, &part_parsers, list) {
  27. + if (p->type == type && try_module_get(p->owner)) {
  28. + ret = p;
  29. + break;
  30. + }
  31. + }
  32. +
  33. + spin_unlock(&part_parser_lock);
  34. +
  35. + return ret;
  36. +}
  37. +
  38. void register_mtd_parser(struct mtd_part_parser *p)
  39. {
  40. spin_lock(&part_parser_lock);
  41. @@ -868,6 +892,38 @@ int parse_mtd_partitions(struct mtd_info
  42. return err;
  43. }
  44. +int parse_mtd_partitions_by_type(struct mtd_info *master,
  45. + enum mtd_parser_type type,
  46. + struct mtd_partition **pparts,
  47. + struct mtd_part_parser_data *data)
  48. +{
  49. + struct mtd_part_parser *prev = NULL;
  50. + int ret = 0;
  51. +
  52. + while (1) {
  53. + struct mtd_part_parser *parser;
  54. +
  55. + parser = get_partition_parser_by_type(type, prev);
  56. + if (!parser)
  57. + break;
  58. +
  59. + ret = (*parser->parse_fn)(master, pparts, data);
  60. +
  61. + if (ret > 0) {
  62. + put_partition_parser(parser);
  63. + printk(KERN_NOTICE
  64. + "%d %s partitions found on MTD device %s\n",
  65. + ret, parser->name, master->name);
  66. + break;
  67. + }
  68. +
  69. + prev = parser;
  70. + }
  71. +
  72. + return ret;
  73. +}
  74. +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
  75. +
  76. int mtd_is_partition(const struct mtd_info *mtd)
  77. {
  78. struct mtd_part *part;
  79. --- a/include/linux/mtd/partitions.h
  80. +++ b/include/linux/mtd/partitions.h
  81. @@ -68,12 +68,17 @@ struct mtd_part_parser_data {
  82. * Functions dealing with the various ways of partitioning the space
  83. */
  84. +enum mtd_parser_type {
  85. + MTD_PARSER_TYPE_DEVICE = 0,
  86. +};
  87. +
  88. struct mtd_part_parser {
  89. struct list_head list;
  90. struct module *owner;
  91. const char *name;
  92. int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
  93. struct mtd_part_parser_data *);
  94. + enum mtd_parser_type type;
  95. };
  96. extern void register_mtd_parser(struct mtd_part_parser *parser);
  97. @@ -87,4 +92,9 @@ uint64_t mtd_get_device_size(const struc
  98. extern void __weak arch_split_mtd_part(struct mtd_info *master,
  99. const char *name, int offset, int size);
  100. +int parse_mtd_partitions_by_type(struct mtd_info *master,
  101. + enum mtd_parser_type type,
  102. + struct mtd_partition **pparts,
  103. + struct mtd_part_parser_data *data);
  104. +
  105. #endif