mtd: improve mtd detection
Signed-off-by: John Crispin <blogic@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@40301 3c298f89-4303-0410-b956-a3cf2f4a3e73master
parent
a273f66de7
commit
74e9dde7b0
|
@ -67,10 +67,12 @@ 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);
|
||||
|
|
Loading…
Reference in New Issue