From 876476b7bbf158c64868d379460a7b6bce7e95e0 Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Wed, 14 Mar 2007 14:17:07 +0100 Subject: MTD-Utils: fix handling of ioctl return value in nand-utils Older kernel do not implement the MTDFILEMODE ioctl. In this case nandwrite and nanddump should have used MEMGETOOBSEL in combination with MEMSETOOBSEL. Unfortunately the return value of the unsucessfull ioctl is not -ENOTTY, but -1 and errno contains ENOTTY. This change fixes this issue. I have not tested all cornercases. Would be good if someone could do more careful testing than I did, or maybe reviewing is sufficient in this case. Signed-off-by: Frank Haverkamp Signed-off-by: Josh Boyer --- nandwrite.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index f4c399d..f74581d 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -271,9 +271,12 @@ int main(int argc, char **argv) } if (noecc) { - switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) { - - case -ENOTTY: + ret = ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW); + if (ret == 0) { + oobinfochanged = 2; + } else { + switch (errno) { + case ENOTTY: if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) { perror ("MEMGETOOBSEL"); close (fd); @@ -286,14 +289,11 @@ int main(int argc, char **argv) } oobinfochanged = 1; break; - - case 0: - oobinfochanged = 2; - break; default: perror ("MTDFILEMODE"); close (fd); exit (1); + } } } -- cgit v1.2.3