mtd_write(int imagefd, const char *mtd)
{
int fd, result;
mtd_write(int imagefd, const char *mtd)
{
int fd, result;
fd = mtd_check_open(mtd);
if(fd < 0) {
fd = mtd_check_open(mtd);
if(fd < 0) {
for (;;) {
/* buffer may contain data already (from trx check) */
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) {
+ fprintf(stderr, "No more data left\n");
+ break;
+ }
+
+ buflen += r;
+ } while (buflen < erasesize);
+ if (buflen == 0)
+ break;
if (jffs2file) {
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {
if (jffs2file) {
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {
- /* not enough data - eof */
- if (buflen < erasesize)
- break;
-
buflen = 0;
}
if (!quiet)
buflen = 0;
}
if (!quiet)