From: Petr Štetiar Date: Tue, 21 Jan 2020 16:11:07 +0000 (+0100) Subject: Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)" X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=deb745f82b93b3bd12273cfb16deb7417fc555ef;p=oweals%2Ffstools.git Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)" 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 --- 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)