From patchwork Wed Nov 3 13:16:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ketil Froyn X-Patchwork-Id: 70004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E4A7DB6F11 for ; Thu, 4 Nov 2010 00:17:04 +1100 (EST) Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PDdC9-0007Lu-WC; Wed, 03 Nov 2010 13:16:06 +0000 Received: from mail-qw0-f49.google.com ([209.85.216.49]) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PDdC6-0007La-HD for linux-mtd@lists.infradead.org; Wed, 03 Nov 2010 13:16:03 +0000 Received: by qwh6 with SMTP id 6so17110qwh.36 for ; Wed, 03 Nov 2010 06:16:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.172.214 with SMTP id m22mr3219309qaz.25.1288790161703; Wed, 03 Nov 2010 06:16:01 -0700 (PDT) Received: by 10.229.183.204 with HTTP; Wed, 3 Nov 2010 06:16:01 -0700 (PDT) In-Reply-To: <4CD11C03.3090207@parrot.com> References: <4CD11C03.3090207@parrot.com> Date: Wed, 3 Nov 2010 14:16:01 +0100 Message-ID: Subject: Re: Suggested patch: reset errno after isatty() From: Ketil Froyn To: Matthieu CASTET X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20101103_091602_665489_622162C5 X-CRM114-Status: GOOD ( 10.93 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.49 listed in list.dnswl.org] Cc: "linux-mtd@lists.infradead.org" X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list 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 Wed, Nov 3, 2010 at 9:23 AM, Matthieu CASTET wrote: > Why errno is checked when pread return 0 ? > Errno should be checked only when return is -1. Good point, and I guess that was why I was getting weird errors in the first place, because errno was checked when no error had occurred. Odd that pread() returned 0 when trying to read on my android device - maybe a bionic bug? This code has been rewritten, but the new master isn't working for me (yet). This patch against v1.4.1 seems to have solved my problems for now. I've just replaced pread() with read(), because it works, and fixed up the error checking. /* ECC stats available ? */ --- a/nanddump.c +++ b/nanddump.c @@ -412,10 +412,25 @@ int main(int argc, char * const argv[]) memset (readbuf, 0xff, bs); } else { /* Read page data and exit on failure */ - if (pread(fd, readbuf, bs, ofs) != bs) { - perror("pread"); - goto closeall; - } + do { + ret = read(fd, readbuf, bs); + if (ret == -1) { + if (errno == EAGAIN || errno == EINTR) { + continue; + } + perror("read"); + goto closeall; + } + if (ret == 0) { + printf("No more data to read\n"); + break; + } + if (ret != bs) { + fprintf(stderr, "read() got wrong number of bytes: got %i, expected %i\n", ret, bs); + goto closeall; + } + break; + } while (1); }