read syscall can return less bytes then requested - handle this. This bug is triggered when reading from stdin that comes from remote host Author: Hai Zaar --- mtd-utils-1.2.0/nandwrite.c.orig 2008-12-14 14:56:11.000000000 +0200 +++ mtd-utils-1.2.0/nandwrite.c 2008-12-14 15:11:56.000000000 +0200 @@ -218,6 +218,7 @@ int ret, readlen; int oobinfochanged = 0; struct nand_oobinfo old_oobinfo; + int readcnt = 0; process_options(argc, argv); @@ -405,12 +406,22 @@ } /* Read Page Data from input file */ - if ((cnt = read(ifd, writebuf, readlen)) != readlen) { - if (cnt == 0) // EOF - break; - perror ("File I/O error on input file"); - goto closeall; + readcnt = 0; + while (readcnt < readlen) { + if ((cnt = read(ifd, writebuf + readcnt, readlen - readcnt)) < 0) { + perror ("File I/O error on input file"); + goto closeall; + } else { + if ((cnt == 0) && (readcnt == 0)) { // EOF + break; + } else { + readcnt += cnt; + } + } + } + if ((cnt == 0) && (readcnt == 0)) // EOF + break; if (writeoob) { /* Read OOB data from input file, exit on failure */