|
|
@@ -96,15 +96,19 @@ int jffs2_skip_bytes=0;
|
|
|
int mtdtype = 0;
|
|
|
uint32_t opt_trxmagic = TRX_MAGIC;
|
|
|
|
|
|
-int mtd_open(const char *mtd, bool block)
|
|
|
+int mtd_open(const char *mtd, bool block, bool write_mode)
|
|
|
{
|
|
|
FILE *fp;
|
|
|
char dev[PATH_MAX];
|
|
|
int i;
|
|
|
int ret;
|
|
|
- int flags = O_RDWR | O_SYNC;
|
|
|
+ int flags = O_RDONLY;
|
|
|
char name[PATH_MAX];
|
|
|
|
|
|
+ if(write_mode) {
|
|
|
+ flags = O_RDWR | O_SYNC;
|
|
|
+ }
|
|
|
+
|
|
|
snprintf(name, sizeof(name), "\"%s\"", mtd);
|
|
|
if ((fp = fopen("/proc/mtd", "r"))) {
|
|
|
while (fgets(dev, sizeof(dev), fp)) {
|
|
|
@@ -124,12 +128,12 @@ int mtd_open(const char *mtd, bool block)
|
|
|
return open(mtd, flags);
|
|
|
}
|
|
|
|
|
|
-int mtd_check_open(const char *mtd)
|
|
|
+int mtd_check_open(const char *mtd, bool write_mode)
|
|
|
{
|
|
|
struct mtd_info_user mtdInfo;
|
|
|
int fd;
|
|
|
|
|
|
- fd = mtd_open(mtd, false);
|
|
|
+ fd = mtd_open(mtd, false, write_mode);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
return -1;
|
|
|
@@ -253,7 +257,7 @@ static int mtd_check(const char *mtd)
|
|
|
next++;
|
|
|
}
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, true);
|
|
|
if (fd < 0)
|
|
|
return 0;
|
|
|
|
|
|
@@ -290,7 +294,7 @@ mtd_unlock(const char *mtd)
|
|
|
next++;
|
|
|
}
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, true);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
exit(1);
|
|
|
@@ -321,7 +325,7 @@ mtd_erase(const char *mtd)
|
|
|
if (quiet < 2)
|
|
|
fprintf(stderr, "Erasing %s ...\n", mtd);
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, true);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
exit(1);
|
|
|
@@ -357,7 +361,7 @@ mtd_dump(const char *mtd, int part_offset, int size)
|
|
|
if (quiet < 2)
|
|
|
fprintf(stderr, "Dumping %s ...\n", mtd);
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, false);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
return -1;
|
|
|
@@ -416,7 +420,7 @@ mtd_verify(const char *mtd, char *file)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, false);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
return -1;
|
|
|
@@ -551,7 +555,7 @@ resume:
|
|
|
next++;
|
|
|
}
|
|
|
|
|
|
- fd = mtd_check_open(mtd);
|
|
|
+ fd = mtd_check_open(mtd, true);
|
|
|
if(fd < 0) {
|
|
|
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
|
|
|
exit(1);
|