Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)"
authorPetr Štetiar <ynezz@true.cz>
Tue, 21 Jan 2020 16:11:07 +0000 (17:11 +0100)
committerPetr Štetiar <ynezz@true.cz>
Tue, 21 Jan 2020 16:12:36 +0000 (17:12 +0100)
This reverts commit f5c7c1813f52e6d7b59ecfb2f9f95e69b05b1980 which needs
more work and testing as it broke at least jffs2 overlays at least on
ath79 platform, marking them as read-only, thus unusable:

 jffs2_build_filesystem(): erasing all blocks after the end marker...
 jffs2: Erase at 0x009e0000 failed immediately: -EROFS. Is the sector locked?

Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/021344.html
Reported-by: Steve Brown <sbrown@ewol.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
libfstools/mtd.c

index aae633e6ff1ff2eb29b2178fb22eb9d128bbcb03..77c71eeb29a3ba7a67c42514b5e17e324baf53d4 100644 (file)
@@ -36,31 +36,20 @@ struct mtd_volume {
 
 static struct driver mtd_driver;
 
-static int mtd_open_device(const char *dev)
-{
-       int ret;
-
-       ret = open(dev, O_RDWR | O_SYNC);
-       if (ret < 0)
-               ret = open(dev, O_RDONLY);
-
-       return ret;
-}
-
 static int mtd_open(const char *mtd, int block)
 {
        FILE *fp;
        char dev[PATH_MAX];
-       int i, ret;
+       int i, ret, flags = O_RDWR | O_SYNC;
 
        if ((fp = fopen("/proc/mtd", "r"))) {
                while (fgets(dev, sizeof(dev), fp)) {
                        if (sscanf(dev, "mtd%d:", &i) && strstr(dev, mtd)) {
                                snprintf(dev, sizeof(dev), "/dev/mtd%s/%d", (block ? "block" : ""), i);
-                               ret = mtd_open_device(dev);
+                               ret = open(dev, flags);
                                if (ret < 0) {
                                        snprintf(dev, sizeof(dev), "/dev/mtd%s%d", (block ? "block" : ""), i);
-                                       ret = mtd_open_device(dev);
+                                       ret = open(dev, flags);
                                }
                                fclose(fp);
                                return ret;
@@ -69,7 +58,7 @@ static int mtd_open(const char *mtd, int block)
                fclose(fp);
        }
 
-       return mtd_open_device(mtd);
+       return open(mtd, flags);
 }
 
 static void mtd_volume_close(struct mtd_volume *p)