From deb745f82b93b3bd12273cfb16deb7417fc555ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Tue, 21 Jan 2020 17:11:07 +0100 Subject: [PATCH] Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Petr Å tetiar --- libfstools/mtd.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/libfstools/mtd.c b/libfstools/mtd.c index aae633e..77c71ee 100644 --- a/libfstools/mtd.c +++ b/libfstools/mtd.c @@ -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) -- 2.25.1