X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/82cd54f3ea9325bbd7958526f261ef6121896270..85545a1d5a01821af290e54c7efbfc05d5a1d6f7:/package/mtd/src/mtd.c?ds=inline diff --git a/package/mtd/src/mtd.c b/package/mtd/src/mtd.c index 18c3e9709..a19f71806 100644 --- a/package/mtd/src/mtd.c +++ b/package/mtd/src/mtd.c @@ -18,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id$ * * The code is based on the linux-mtd examples. */ @@ -138,9 +137,11 @@ int mtd_write_buffer(int fd, const char *buf, int offset, int length) static int image_check(int imagefd, const char *mtd) { + int ret = 1; #ifdef target_brcm - return trx_check(imagefd, mtd, buf, &buflen); + ret = trx_check(imagefd, mtd, buf, &buflen); #endif + return ret; } static int mtd_check(const char *mtd) @@ -246,7 +247,7 @@ static int mtd_write(int imagefd, const char *mtd) { int fd, result; - size_t r, w, e; + ssize_t r, w, e; fd = mtd_check_open(mtd); if(fd < 0) { @@ -263,11 +264,25 @@ mtd_write(int imagefd, const char *mtd) for (;;) { /* buffer may contain data already (from trx check) */ - r = read(imagefd, buf + buflen, erasesize - buflen); - if (r < 0) - break; + do { + r = read(imagefd, buf + buflen, erasesize - buflen); + if (r < 0) { + if ((errno == EINTR) || (errno == EAGAIN)) + continue; + else { + perror("read"); + break; + } + } + + if (r == 0) + break; - buflen += r; + buflen += r; + } while (buflen < erasesize); + + if (buflen == 0) + break; if (jffs2file) { if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) { @@ -309,10 +324,6 @@ mtd_write(int imagefd, const char *mtd) } w += buflen; - /* not enough data - eof */ - if (buflen < erasesize) - break; - buflen = 0; } if (!quiet)