mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-24 00:14:05 +02:00
mtd: improve support for reading input from a pipe. fixes sysupgrade
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@12706 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
c789f9720c
commit
8114ef99e3
@ -246,7 +246,7 @@ static int
|
|||||||
mtd_write(int imagefd, const char *mtd)
|
mtd_write(int imagefd, const char *mtd)
|
||||||
{
|
{
|
||||||
int fd, result;
|
int fd, result;
|
||||||
size_t r, w, e;
|
ssize_t r, w, e;
|
||||||
|
|
||||||
fd = mtd_check_open(mtd);
|
fd = mtd_check_open(mtd);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
@ -263,11 +263,27 @@ mtd_write(int imagefd, const char *mtd)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* buffer may contain data already (from trx check) */
|
/* buffer may contain data already (from trx check) */
|
||||||
r = read(imagefd, buf + buflen, erasesize - buflen);
|
do {
|
||||||
if (r < 0)
|
r = read(imagefd, buf + buflen, erasesize - buflen);
|
||||||
break;
|
if (r < 0) {
|
||||||
|
if ((errno == EINTR) || (errno == EAGAIN))
|
||||||
|
continue;
|
||||||
|
else {
|
||||||
|
perror("read");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buflen += r;
|
if (r == 0) {
|
||||||
|
fprintf(stderr, "No more data left\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buflen += r;
|
||||||
|
} while (buflen < erasesize);
|
||||||
|
|
||||||
|
if (buflen == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
if (jffs2file) {
|
if (jffs2file) {
|
||||||
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {
|
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {
|
||||||
@ -309,10 +325,6 @@ mtd_write(int imagefd, const char *mtd)
|
|||||||
}
|
}
|
||||||
w += buflen;
|
w += buflen;
|
||||||
|
|
||||||
/* not enough data - eof */
|
|
||||||
if (buflen < erasesize)
|
|
||||||
break;
|
|
||||||
|
|
||||||
buflen = 0;
|
buflen = 0;
|
||||||
}
|
}
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
|
Loading…
Reference in New Issue
Block a user