mtd: add get offset and size function for partition query
PATCH 1/1 mtd: add get offset and size function for partition query
Since we add add_mtd_partitions and mtd_del_partition kenrel api to facilitate the mtd repartition job. It would be nice to add another two api to know the offset and size of each partition.
Signed-off-by Lei Wen <[email protected]>
--- drivers/mtd/mtdpart.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 2 ++ 2 files changed, 38 insertions(+), 0 deletions(-)
drivers/mtd/mtdpart.c +36 -0
@@ -655,6 +655,42 @@ int add_mtd_partitions(struct mtd_info *master, }EXPORT_SYMBOL (add_mtd_partitions); +uint64_t get_mtd_offset (struct mtd_info *master,int partno) +{ +struct mtd_part *slave, *next; +uint64_t ret =ULLONG_MAX ; + +mutex_lock (&mtd_partitions_mutex); +list_for_each_entry_safe (slave, next, &mtd_partitions, list) +if ((slave->master == master) && + (slave->mtd.index == partno)) { + ret = slave->offset; +break ; + } +mutex_unlock (&mtd_partitions_mutex); + +return ret; +} +EXPORT_SYMBOL_GPL (get_mtd_offset); + +uint64_t get_mtd_size (struct mtd_info *master,int partno) +{ +struct mtd_part *slave, *next; +uint64_t ret =ULLONG_MAX ; + +mutex_lock (&mtd_partitions_mutex); +list_for_each_entry_safe (slave, next, &mtd_partitions, list) +if ((slave->master == master) && + (slave->mtd.index == partno)) { + ret = slave->mtd.size; +break ; + } +mutex_unlock (&mtd_partitions_mutex); + +return ret; +} +EXPORT_SYMBOL_GPL (get_mtd_size); +static DEFINE_SPINLOCK (part_parser_lock);static LIST_HEAD (part_parsers);
include/linux/mtd/partitions.h +2 -0
@@ -93,5 +93,7 @@ int mtd_is_master(struct mtd_info *mtd);int mtd_add_partition (struct mtd_info *master,char *name,long long offset,long long length);int mtd_del_partition (struct mtd_info *master,int partno); +uint64_t get_mtd_offset (struct mtd_info *master,int partno); +uint64_t get_mtd_size (struct mtd_info *master,int partno);#endif
Signature · 1 line
1.7.0.4