[PATCH 3/4] mtd-utils: fetch erasereg in legacy library

Marian Rotariu marian_rotariu at mentor.com
Tue Apr 26 02:30:23 PDT 2016


Signed-off-by: Marian Rotariu <marian_rotariu at mentor.com>
---
 lib/libmtd_legacy.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index 233a92e..5f2db9c 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -233,7 +233,7 @@ int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd)
 {
 	struct stat st;
 	struct mtd_info_user ui;
-	int fd, ret;
+	int fd, ret, region_cnt, i;
 	loff_t offs = 0;
 	struct proc_parse_info pi;
 
@@ -282,6 +282,32 @@ int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd)
 	} else
 		mtd->bb_allowed = 1;
 
+	ret = ioctl(fd, MEMGETREGIONCOUNT, &region_cnt);
+	if (ret == -1) {
+		if (errno != EOPNOTSUPP) {
+			sys_errmsg("MEMGETREGIONCOUNT ioctl failed");
+			goto out_close;
+		}
+		errno = 0;
+		mtd->region_cnt = 0;
+	} else
+		mtd->region_cnt = region_cnt;
+
+	if (mtd->region_cnt) {
+		mtd->reginfo = calloc(mtd->region_cnt,
+				sizeof(struct region_info_user));
+		if (!mtd->reginfo) {
+			errno = ENOMEM;
+			goto out_close;
+		}
+
+		for (i = 0; i < mtd->region_cnt; i++) {
+			ret = mtd_regioninfo(fd, i, &(mtd->reginfo[i]));
+			if (ret)
+				goto out_close;
+		}
+	}
+
 	mtd->type = ui.type;
 	mtd->size = ui.size;
 	mtd->eb_size = ui.erasesize;
-- 
1.9.1




More information about the linux-mtd mailing list