The mtd tool use mtd partition name to search /proc/mtd to find the real device name.
Here is a bug when we named two partition names which one's name containers another one, the first one is always be hit. This fix let strstr use string mtd name plus double quotes to make matching more accurate. modified: package/system/mtd/src/mtd.c Signed-off-by: Joe Xue <[email protected]> --- package/system/mtd/src/mtd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c index a660486..916bc63 100644 --- a/package/system/mtd/src/mtd.c +++ b/package/system/mtd/src/mtd.c @@ -63,10 +63,13 @@ int mtd_open(const char *mtd, bool block) int i; int ret; int flags = O_RDWR | O_SYNC; + char name[PATH_MAX]; + + snprintf(name, sizeof(name), "\"%s\"", mtd); if ((fp = fopen("/proc/mtd", "r"))) { while (fgets(dev, sizeof(dev), fp)) { - if (sscanf(dev, "mtd%d:", &i) && strstr(dev, mtd)) { + if (sscanf(dev, "mtd%d:", &i) && strstr(dev, name)) { snprintf(dev, sizeof(dev), "/dev/mtd%s/%d", (block ? "block" : ""), i); if ((ret=open(dev, flags))<0) { snprintf(dev, sizeof(dev), "/dev/mtd%s%d", (block ? "block" : ""), i); -- 1.8.1.2 _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
