mtd: improve mtd detection

Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 40301
lede-17.01
John Crispin 2014-03-30 09:14:58 +00:00
parent 3ecffab050
commit 00d7e84af6
1 changed files with 3 additions and 1 deletions

View File

@ -67,10 +67,12 @@ int mtd_open(const char *mtd, bool block)
int i; int i;
int ret; int ret;
int flags = O_RDWR | O_SYNC; int flags = O_RDWR | O_SYNC;
char name[PATH_MAX];
snprintf(name, sizeof(name), "\"%s\"", mtd);
if ((fp = fopen("/proc/mtd", "r"))) { if ((fp = fopen("/proc/mtd", "r"))) {
while (fgets(dev, sizeof(dev), fp)) { 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); snprintf(dev, sizeof(dev), "/dev/mtd%s/%d", (block ? "block" : ""), i);
if ((ret=open(dev, flags))<0) { if ((ret=open(dev, flags))<0) {
snprintf(dev, sizeof(dev), "/dev/mtd%s%d", (block ? "block" : ""), i); snprintf(dev, sizeof(dev), "/dev/mtd%s%d", (block ? "block" : ""), i);