eraseinfo ioctl patch
Kári Davíðsson
kd at flaga.is
Fri Mar 23 11:34:11 EST 2001
Hi,
Here are couple of new ioctl that export the erase bloack size to
userspace as well as small program that uses those ioctl to read and
display them on stdout.
K.D.
diff -urN --exclude *.o mtd/include/linux/mtd/mtd.h
mtd-20010320/include/linux/mtd/mtd.h
--- mtd/include/linux/mtd/mtd.h Sat Mar 17 23:00:09 2001
+++ mtd-20010320/include/linux/mtd/mtd.h Fri Mar 23 16:15:58 2001
@@ -77,17 +77,27 @@
u_int32_t eccsize;
};
+struct region_info_user {
+ u_int32_t offset; /* At which this region
starts, from the beginning of the MTD */
+ u_int32_t erasesize; /* For this region */
+ u_int32_t numblocks; /* Number of blocks of erasesize
in this region */
+ u_int32_t regionindex;
+};
+
#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
#define MEMERASE _IOW('M', 2, struct erase_info_user)
#define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
#define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
#define MEMLOCK _IOW('M', 5, struct erase_info_user)
#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
+#define MEMGETREGIONCOUNT _IOW('M', 7, int)
+#define MEMGETREGIONINFO _IOW('M', 8, struct region_info_user)
#ifndef __KERNEL__
typedef struct mtd_info_user mtd_info_t;
typedef struct erase_info_user erase_info_t;
+typedef struct region_info_user region_info_t;
/* User-space ioctl definitions */
diff -urN --exclude *.o mtd/kernel/mtdchar.c
mtd-20010320/kernel/mtdchar.c
--- mtd/kernel/mtdchar.c Thu Feb 1 23:00:03 2001
+++ mtd-20010320/kernel/mtdchar.c Fri Mar 23 16:01:25 2001
@@ -293,6 +293,26 @@
}
switch (cmd) {
+ case MEMGETREGIONCOUNT :
+ if(copy_to_user((int *) arg, &(mtd->numeraseregions),
sizeof(int)))
+ return -EFAULT;
+ break;
+ case MEMGETREGIONINFO :
+ {
+ struct mtd_erase_region_info * kr;
+ struct region_info_user * ur;
+ kr = (struct mtd_erase_region_info *) arg;
+ ur = (struct region_info_user *) arg;
+
+ if( ur->regionindex >= mtd->numeraseregions)
+ return -EFAULT;
+
+ if(copy_to_user( (struct mtd_erase_region_info *) arg,
+ &(mtd->eraseregions[ur->regionindex]),
+ sizeof(struct mtd_erase_region_info)))
+ return -EFAULT;
+ break;
+ }
case MEMGETINFO:
if (copy_to_user((struct mtd_info *)arg, mtd,
sizeof(struct mtd_info_user)))
diff -urN --exclude *.o mtd/util/Makefile mtd-20010320/util/Makefile
--- mtd/util/Makefile Thu Mar 15 23:00:07 2001
+++ mtd-20010320/util/Makefile Fri Mar 23 16:12:03 2001
@@ -1,6 +1,6 @@
-CFLAGS=-I../include -O2 -Wall
+CFLAGS+=-I../include -O2 -Wall
-TARGETS = ftl_format erase eraseall nftldump nanddump doc_loadbios
nftl_format mkfs.jffs ftl_check nandtest nandwrite mkfs.jffs2 lock
unlock
+TARGETS = ftl_format erase eraseall nftldump nanddump doc_loadbios
nftl_format mkfs.jffs ftl_check nandtest nandwrite mkfs.jffs2 lock
unlock einfo
SYMLINKS = crc32.h crc32.c compr_rtime.c compr_rubin.c compr.c
pushpull.c pushpull.h histo_mips.h compr_rubin.h
diff -urN --exclude *.o mtd/util/einfo.c mtd-20010320/util/einfo.c
--- mtd/util/einfo.c Thu Jan 1 00:00:00 1970
+++ mtd-20010320/util/einfo.c Fri Mar 23 16:24:29 2001
@@ -0,0 +1,50 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+
+#include <linux/mtd/mtd.h>
+
+int main(int argc,char *argv[])
+{
+ int regcount;
+ int Fd;
+
+ if (1 >= argc)
+ {
+ fprintf(stderr,"You must specify a device\n");
+ return 16;
+ }
+
+ // Open and size the device
+ if ((Fd = open(argv[1],O_RDWR)) < 0)
+ {
+ fprintf(stderr,"File open error\n");
+ return 8;
+ }
+
+ if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0)
+ {
+ int i;
+ region_info_t reginfo;
+ printf("Device %s has %d erase regions\n", argv[1], regcount);
+ for(i = 0; i < regcount; i++)
+ {
+ reginfo.regionindex = i;
+ if(ioctl(Fd, MEMGETREGIONINFO, ®info) == 0)
+ {
+ printf("Region %d is at %x with size %x and
has %x blocks\n",
+ i, reginfo.offset,
reginfo.erasesize, reginfo.numblocks);
+ }
+ else
+ {
+ printf("Strange can not read region %d from a
%d region device\n",
+ i, regcount);
+ }
+ }
+ }
+ return 0;
+}
To unsubscribe, send "unsubscribe mtd" to majordomo at infradead.org
More information about the linux-mtd
mailing list