From patchwork Tue Nov 2 14:37:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ketil Froyn X-Patchwork-Id: 69889 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 722C0B70AF for ; Wed, 3 Nov 2010 01:40:15 +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 1PDHzD-0005ED-LO; Tue, 02 Nov 2010 14:37:19 +0000 Received: from mail-gx0-f177.google.com ([209.85.161.177]) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PDHzA-0005Du-88 for linux-mtd@lists.infradead.org; Tue, 02 Nov 2010 14:37:17 +0000 Received: by gxk25 with SMTP id 25so4408035gxk.36 for ; Tue, 02 Nov 2010 07:37:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.219.2 with SMTP id hs2mr2453068qcb.276.1288708634029; Tue, 02 Nov 2010 07:37:14 -0700 (PDT) Received: by 10.229.183.204 with HTTP; Tue, 2 Nov 2010 07:37:13 -0700 (PDT) Date: Tue, 2 Nov 2010 15:37:13 +0100 Message-ID: Subject: Suggested patch: reset errno after isatty() From: Ketil Froyn To: linux-mtd@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20101102_103716_398995_90EF70FE X-CRM114-Status: GOOD ( 10.71 ) 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.161.177 listed in list.dnswl.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 isatty() uses an ioctl and the resulting error code to determine if an fd is a tty or not. If it isn't, errno is set to ENOTTY. Later in the code, pread() fails, or rather returns 0 immediately. When this happens, the following perror("pread") tells me: pread: Not a typewriter which is the wrong error. Here's strace showing the issue: open("/sdcard/mtd5.dump", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0644) = 4 ioctl(4, TCGETS or SNDCTL_TMR_TIMEBASE, 0xbee43ab0) = -1 ENOTTY (Not a typewriter) write(2, "Block size 131072, page size 204"..., 47) = 47 write(2, "Dumping data starting at 0x00000"..., 64) = 64 ioctl(3, 0x40084d0b, 0xbee43c30) = 0 pread(3, "", 2048, 0) = 0 write(2, "pread", 5) = 5 write(2, ": ", 2) = 2 write(2, "Not a typewriter", 16) = 16 write(2, "\n", 1) = 1 And the included patch (below, against v1.4.1, but simple enough) should take care of it. Though if someone knows what could be causing the pread() to keep failing, I'd be interested in hearing it! And the mtd device is reported as having a page size of 2048 and oob size 56, so to get even this far I added that as a valid page size. Isn't it? diff --git a/nanddump.c b/nanddump.c index 709b2db..ba370ad 100644 --- a/nanddump.c +++ b/nanddump.c @@ -374,6 +374,7 @@ int main(int argc, char * const argv[]) close(fd); exit(EXIT_FAILURE); } + errno = 0; /* Initialize start/end addresses and block size */ if (length)