public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind@infradead.org>
To: Hai Zaar <haizaar@haizaar.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] nandwrite - handle situation when read returns less bytes the expected
Date: Tue, 16 Dec 2008 12:18:34 +0200	[thread overview]
Message-ID: <1229422714.17960.2.camel@sauron> (raw)
In-Reply-To: <76d9e2a30812160040u263e275aqa04c0e4b726365cc@mail.gmail.com>

On Tue, 2008-12-16 at 10:40 +0200, Hai Zaar wrote:
> On Tue, Dec 16, 2008 at 8:28 AM, Artem Bityutskiy
> <dedekind@infradead.org> wrote:
> >
> > Your patch does not apply. It looks like it is not against the latest
> > mtd-utils. How about this patch?
> Yes, my patch is against mtd-utils-1.2.0. Yours is surely better since
> it covers oob reading as well.

Would be nice if you tried my patch and confirmed it works, because I
did not test it.

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Subject: [PATCH] nandwrite: correct data reading

The "read" syscall does not necessarily return all the requested
data, in which case the caller has to try again and read more.
Take this into account when reading input data.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 nandwrite.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/nandwrite.c b/nandwrite.c
index fc23e85..b4bc871 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -262,7 +262,6 @@ int main(int argc, char * const argv[])
 	struct nand_oobinfo old_oobinfo;
 
 	process_options(argc, argv);
-
 	erase_buffer(oobbuf, sizeof(oobbuf));
 
 	if (pad && writeoob) {
@@ -438,6 +437,8 @@ int main(int argc, char * const argv[])
 	 * length or zero.
 	 */
 	while (imglen && (mtdoffset < meminfo.size)) {
+		int tinycnt = 0;
+
 		// new eraseblock , check for bad block(s)
 		// Stay in the loop to be sure if the mtdoffset changes because
 		// of a bad block, that the next block that will be written to
@@ -484,15 +485,17 @@ int main(int argc, char * const argv[])
 			}
 
 			/* Read Page Data from input file */
-			if ((cnt = read(ifd, writebuf, readlen)) != readlen) {
-				if (cnt == 0)	// EOF
+			while(tinycnt < readlen) {
+				cnt = read(ifd, writebuf + tinycnt, readlen - tinycnt);
+				if (cnt == 0) { // EOF
 					break;
-				perror ("File I/O error on input file");
-				goto closeall;
+				} else if (cnt < 0) {
+					perror ("File I/O error on input file");
+					goto closeall;
+				}
+				tinycnt += cnt;
 			}
 		} else {
-			int tinycnt = 0;
-
 			while(tinycnt < readlen) {
 				cnt = read(ifd, writebuf + tinycnt, readlen - tinycnt);
 				if (cnt == 0) { // EOF
@@ -522,11 +525,18 @@ int main(int argc, char * const argv[])
 		}
 
 		if (writeoob) {
-			/* Read OOB data from input file, exit on failure */
-			if ((cnt = read(ifd, oobreadbuf, meminfo.oobsize)) != meminfo.oobsize) {
-				perror ("File I/O error on input file");
-				goto closeall;
+			tinycnt = 0;
+			while(tinycnt < readlen) {
+				cnt = read(ifd, oobreadbuf + tinycnt, meminfo.oobsize - tinycnt);
+				if (cnt == 0) { // EOF
+					break;
+				} else if (cnt < 0) {
+					perror ("File I/O error on input file");
+					goto closeall;
+				}
+				tinycnt += cnt;
 			}
+
 			if (!noecc) {
 				int i, start, len;
 				/*
-- 
1.5.4.3

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

  reply	other threads:[~2008-12-16 10:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-14 13:59 [PATCH] nandwrite - handle situation when read returns less bytes the expected Hai Zaar
2008-12-16  6:28 ` Artem Bityutskiy
2008-12-16  8:40   ` Hai Zaar
2008-12-16 10:18     ` Artem Bityutskiy [this message]
2008-12-24 14:48       ` Hai Zaar
2008-12-26 12:43         ` Artem Bityutskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1229422714.17960.2.camel@sauron \
    --to=dedekind@infradead.org \
    --cc=haizaar@haizaar.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox