rendered paste bodyFrom 6ec0c045fc72c2e90da06442eec21a4c731c415e Mon Sep 17 00:00:00 2001
From: Andrea Adami <andrea.adami@gmail.com>
Date: Wed, 18 Nov 2009 23:25:28 +0100
Subject: [PATCH] zaurus.c: try to use BLKGETSIZE correctly
---
machine/zaurus.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/machine/zaurus.c b/machine/zaurus.c
index 4afd5ff..b339d06 100644
--- a/machine/zaurus.c
+++ b/machine/zaurus.c
@@ -34,7 +34,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-// #include <linux/fs.h>
+#include <linux/fs.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "mtd-user.h"
@@ -144,7 +144,7 @@ int zaurus_read_partinfo(struct zaurus_partinfo_t *partinfo)
const unsigned long start_addr = 0x60004;
const unsigned long length = 36;
- int blocks, bs, fd;
+ int blocks, bs, fd, fd1;
unsigned long mtdsize = 0;
unsigned long end_addr;
unsigned long ofs;
@@ -159,6 +159,12 @@ int zaurus_read_partinfo(struct zaurus_partinfo_t *partinfo)
return -1;
}
+ if ((fd1 = open("/dev/mtdblock1", O_RDONLY)) == -1) {
+ perror("open flash");
+ return -1;
+ }
+
+
/* Fill in MTD device capability structure */
if (ioctl(fd, MEMGETINFO, &meminfo) != 0) {
perror("MEMGETINFO");
@@ -166,15 +172,11 @@ int zaurus_read_partinfo(struct zaurus_partinfo_t *partinfo)
}
/* Get MTD device size */
-#if 0
- if (0 == ioctl(fd, BLKGETSIZE, &mtdsize))
- mtdsize /= 2; /* *(512/1024) */
- else
- mtdsize = 0;
-#else
- mtdsize = lseek(fd, 0, SEEK_END);
- lseek(fd, 0, SEEK_SET);
-#endif
+ if (ioctl(fd1, BLKGETSIZE, &mtdsize) != 0) {
+ perror("BLKGETSIZE");
+ goto closefd1;
+ }
+ mtdsize /= 2; /* *(512/1024) */
/* Make sure device page sizes are valid */
if (!(meminfo.oobsize == 64 && meminfo.writesize == 2048) &&
@@ -250,6 +252,9 @@ closeall:
free(oob.ptr);
closefd:
close(fd);
+closefd1:
+ close(fd1);
+
return -1;
}
--
1.6.4.4