[PATCH] mtd: add get offset and size function for partition query

Lei Wen leiwen at marvell.com
Mon Sep 27 11:04:44 EDT 2010


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 <leiwen at marvell.com>
---
 drivers/mtd/mtdpart.c          |   36 ++++++++++++++++++++++++++++++++++++
 include/linux/mtd/partitions.h |    2 ++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 726c287..4548168 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -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);
 
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index ffab9a6..03333ec 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -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
-- 
1.7.0.4




More information about the linux-mtd mailing list