diff options
author | jow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2009-04-26 20:42:36 +0000 |
---|---|---|
committer | jow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2009-04-26 20:42:36 +0000 |
commit | d7b9dc5572c4ff1f91dd71582333fd0ebe98506d (patch) | |
tree | 184a64b54ba0809a0a0d14c4ba7a79b8fe91ef27 /package/unvram/src/nvram.c | |
parent | 9f70f9f3b94be85a28439fd57c912966b32bd6f6 (diff) |
[package] unvram: make it work on bcm47xx, also look for /dev/mtdblockX
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@15429 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/unvram/src/nvram.c')
-rw-r--r-- | package/unvram/src/nvram.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/package/unvram/src/nvram.c b/package/unvram/src/nvram.c index 4dfe0a959..a5f1d4350 100644 --- a/package/unvram/src/nvram.c +++ b/package/unvram/src/nvram.c @@ -409,6 +409,7 @@ const char * nvram_find_mtd(void) int i, esz; char dev[PATH_MAX]; char *path = NULL; + struct stat s; // "/dev/mtdblock/" + ( 0 < x < 99 ) + \0 = 19 if( (path = (char *) malloc(19)) == NULL ) @@ -416,12 +417,30 @@ const char * nvram_find_mtd(void) if ((fp = fopen("/proc/mtd", "r"))) { while (fgets(dev, sizeof(dev), fp)) { - if (strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz)) { - if( (path = (char *) malloc(19)) != NULL ) + if (strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz)) + { + nvram_erase_size = esz; + + sprintf(dev, "/dev/mtdblock/%d", i); + if( stat(dev, &s) > -1 && (s.st_mode & S_IFBLK) ) + { + if( (path = (char *) malloc(strlen(dev)+1)) != NULL ) + { + strncpy(path, dev, strlen(dev)+1); + break; + } + } + else { - nvram_erase_size = esz; - snprintf(path, 19, "/dev/mtdblock/%d", i); - break; + sprintf(dev, "/dev/mtdblock%d", i); + if( stat(dev, &s) > -1 && (s.st_mode & S_IFBLK) ) + { + if( (path = (char *) malloc(strlen(dev)+1)) != NULL ) + { + strncpy(path, dev, strlen(dev)+1); + break; + } + } } } } |