From patchwork Tue Dec 16 10:18:34 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Bityutskiy X-Patchwork-Id: 14209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 63666DDF32 for ; Tue, 16 Dec 2008 21:22:53 +1100 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.68 #1 (Red Hat Linux)) id 1LCX3R-0005k3-Mt; Tue, 16 Dec 2008 10:21:29 +0000 Received: from smtp.nokia.com ([192.100.105.134] helo=mgw-mx09.nokia.com) by bombadil.infradead.org with esmtps (Exim 4.68 #1 (Red Hat Linux)) id 1LCX3P-0005jx-OJ for linux-mtd@lists.infradead.org; Tue, 16 Dec 2008 10:21:28 +0000 Received: from esebh107.NOE.Nokia.com (esebh107.ntc.nokia.com [172.21.143.143]) by mgw-mx09.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id mBGAEFNR022389; Tue, 16 Dec 2008 04:21:22 -0600 Received: from vaebh102.NOE.Nokia.com ([10.160.244.23]) by esebh107.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 16 Dec 2008 12:20:54 +0200 Received: from vaebe112.NOE.Nokia.com ([10.160.244.81]) by vaebh102.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 16 Dec 2008 12:20:53 +0200 Received: from [172.21.41.64] ([172.21.41.64]) by vaebe112.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 16 Dec 2008 12:20:50 +0200 Subject: Re: [PATCH] nandwrite - handle situation when read returns less bytes the expected From: Artem Bityutskiy To: Hai Zaar In-Reply-To: <76d9e2a30812160040u263e275aqa04c0e4b726365cc@mail.gmail.com> References: <76d9e2a30812140559y6ade25c0jf55fd8a7b299e83a@mail.gmail.com> <1229408910.4911.72.camel@sauron> <76d9e2a30812160040u263e275aqa04c0e4b726365cc@mail.gmail.com> Date: Tue, 16 Dec 2008 12:18:34 +0200 Message-Id: <1229422714.17960.2.camel@sauron> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 (2.22.3.1-1.fc9) X-OriginalArrivalTime: 16 Dec 2008 10:20:50.0151 (UTC) FILETIME=[F7DD3770:01C95F67] X-Nokia-AV: Clean X-Spam-Score: -4.0 (----) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (-4.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -4.0 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [192.100.105.134 listed in list.dnswl.org] Cc: linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.9 Precedence: list Reply-To: dedekind@infradead.org List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On Tue, 2008-12-16 at 10:40 +0200, Hai Zaar wrote: > On Tue, Dec 16, 2008 at 8:28 AM, Artem Bityutskiy > 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 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 --- 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; /*