All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ketil Froyn <ketil@froyn.name>
To: linux-mtd@lists.infradead.org
Subject: Suggested patch: reset errno after isatty()
Date: Tue, 2 Nov 2010 15:37:13 +0100	[thread overview]
Message-ID: <AANLkTimwumfui-_T1ScDYwMLKbNh1ia-SDMUg56wTfN5@mail.gmail.com> (raw)

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)

             reply	other threads:[~2010-11-02 14:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-02 14:37 Ketil Froyn [this message]
2010-11-03  8:23 ` Suggested patch: reset errno after isatty() Matthieu CASTET
2010-11-03 13:16   ` Ketil Froyn
2010-11-06  8:54     ` Mike Frysinger
2010-11-07 22:36       ` Ketil Froyn
2010-11-09  9:40         ` Mike Frysinger
2010-11-13 11:07         ` Artem Bityutskiy
2010-11-13 11:55           ` Artem Bityutskiy
2010-11-17 15:50             ` Ketil Froyn
2010-11-18 11:13               ` Ketil Froyn
2010-11-24  7:50                 ` Mike Frysinger
2010-11-24  9:59                   ` Ketil Froyn
2010-11-24 14:12                     ` Artem Bityutskiy
2010-11-24 14:30                       ` Ketil Froyn
2010-11-24 21:36                         ` Mike Frysinger
2010-11-25  8:58                           ` Ketil Froyn
2010-11-29 15:07                             ` 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=AANLkTimwumfui-_T1ScDYwMLKbNh1ia-SDMUg56wTfN5@mail.gmail.com \
    --to=ketil@froyn.name \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.