summaryrefslogtreecommitdiff
path: root/nanddump.c
diff options
context:
space:
mode:
authorFrank Haverkamp <haver@vnet.ibm.com>2007-03-14 14:17:07 +0100
committerJosh Boyer <jwboyer@gmail.com>2007-03-15 08:07:47 -0500
commit876476b7bbf158c64868d379460a7b6bce7e95e0 (patch)
treea380ad1eabfd0cc810743139707395dbf672f4e6 /nanddump.c
parent12d798a29a9a376ef495f527b1785317e3ae3d37 (diff)
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 <haver@vnet.ibm.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
Diffstat (limited to 'nanddump.c')
-rw-r--r--nanddump.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/nanddump.c b/nanddump.c
index 463ddcc..f1b58a9 100644
--- a/nanddump.c
+++ b/nanddump.c
@@ -171,7 +171,7 @@ int main(int argc, char **argv)
{
unsigned long ofs, end_addr = 0;
unsigned long long blockstart = 1;
- int i, fd, ofd, bs, badblock = 0;
+ int ret, i, fd, ofd, bs, badblock = 0;
struct mtd_oob_buf oob = {0, 16, oobbuf};
mtd_info_t meminfo;
char pretty_buf[80];
@@ -208,9 +208,12 @@ int main(int argc, char **argv)
oob.length = meminfo.oobsize;
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);
@@ -223,14 +226,11 @@ int main(int argc, char **argv)
}
oobinfochanged = 1;
break;
-
- case 0:
- oobinfochanged = 2;
- break;
default:
perror ("MTDFILEMODE");
close (fd);
exit (1);
+ }
}
} else {