Skip to contentSkip to conversation

Fix mtd-utils bugs

PATCH In review Stanley.Miao 5 participants 15 messages Jun 20, 2010 – Aug 30, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Fix mtd-utils bugs

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley.

#1 lore raw

PATCH v3 1/3 clean up the legacy interfaces in nandwrite.c

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

---
 nandwrite.c |  224 +++++++++++++++--------------------------------------------
 1 files changed, 57 insertions(+), 167 deletions(-)
nandwrite.c +57 -167
index 1b4ca3d..eadca54 100644
@@ -34,6 +34,7 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 #include <getopt.h>
 
 #include <asm/types.h>
@@ -45,26 +46,7 @@
 #define MAX_PAGE_SIZE	4096
 #define MAX_OOB_SIZE	128
 
-// oob layouts to pass into the kernel as default
-static struct nand_oobinfo none_oobinfo = {
-	.useecc = MTD_NANDECC_OFF,
-};
-
-static struct nand_oobinfo jffs2_oobinfo = {
-	.useecc = MTD_NANDECC_PLACE,
-	.eccbytes = 6,
-	.eccpos = { 0, 1, 2, 3, 6, 7 }
-};
-
-static struct nand_oobinfo yaffs_oobinfo = {
-	.useecc = MTD_NANDECC_PLACE,
-	.eccbytes = 6,
-	.eccpos = { 8, 9, 10, 13, 14, 15}
-};
-
-static struct nand_oobinfo autoplace_oobinfo = {
-	.useecc = MTD_NANDECC_AUTOPLACE
-};
+#define LINUX_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
 
 static void display_help (void)
 {
@@ -72,13 +54,7 @@ static void display_help (void)
 "Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]\n"
 "Writes to the specified MTD device.\n"
 "\n"
-"  -a, --autoplace         Use auto oob layout\n"
-"  -j, --jffs2             Force jffs2 oob layout (legacy support)\n"
-"  -y, --yaffs             Force yaffs oob layout (legacy support)\n"
-"  -f, --forcelegacy       Force legacy support on autoplacement-enabled mtd\n"
-"                          device\n"
 "  -m, --markbad           Mark blocks bad if write fails\n"
-"  -n, --noecc             Write without ecc\n"
 "  -o, --oob               Image contains oob data\n"
 "  -r, --raw               Image contains the raw oob data dumped by nanddump\n"
 "  -s addr, --start=addr   Set start address (default is 0)\n"
@@ -112,37 +88,49 @@ static int		mtdoffset = 0;
 static bool		quiet = false;
 static bool		writeoob = false;
 static bool		rawoob = false;
-static bool		autoplace = false;
 static bool		markbad = false;
-static bool		forcejffs2 = false;
-static bool		forceyaffs = false;
-static bool		forcelegacy = false;
-static bool		noecc = false;
 static bool		pad = false;
 static int		blockalign = 1; /*default to using 16K block size */
 
+static int get_linux_version(void)
+{
+	int a, b, c, ret, err = 0;
+	struct utsname buf;
+
+	ret = uname(&buf);
+	if (ret == 0) {
+		ret = sscanf(buf.release, "%d.%d.%d", &a, &b, &c);
+		if (ret != 3)
+			err = 1;
+	} else
+		err = 1;
+
+	if (err) {
+		a = b = c = 0xff;
+		fprintf(stderr, "Warning: Can't get linux kernel version."
+				"Set the default version to the latest version.\n");
+	}
+
+	return LINUX_VERSION(a, b, c);
+}
+
 static void process_options (int argc, char * const argv[])
 {
 	int error = 0;
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "ab:fjmnopqrs:y";
+		static const char *short_options = "b:mopqrs:";
 		static const struct option long_options[] = {
 			{"help", no_argument, 0, 0},
 			{"version", no_argument, 0, 0},
-			{"autoplace", no_argument, 0, 'a'},
 			{"blockalign", required_argument, 0, 'b'},
-			{"forcelegacy", no_argument, 0, 'f'},
-			{"jffs2", no_argument, 0, 'j'},
 			{"markbad", no_argument, 0, 'm'},
-			{"noecc", no_argument, 0, 'n'},
 			{"oob", no_argument, 0, 'o'},
 			{"pad", no_argument, 0, 'p'},
 			{"quiet", no_argument, 0, 'q'},
 			{"raw", no_argument, 0, 'r'},
 			{"start", required_argument, 0, 's'},
-			{"yaffs", no_argument, 0, 'y'},
 			{0, 0, 0, 0},
 		};
 
@@ -166,21 +154,6 @@ static void process_options (int argc, char * const argv[])
 			case 'q':
 				quiet = true;
 				break;
-			case 'a':
-				autoplace = true;
-				break;
-			case 'j':
-				forcejffs2 = true;
-				break;
-			case 'y':
-				forceyaffs = true;
-				break;
-			case 'f':
-				forcelegacy = true;
-				break;
-			case 'n':
-				noecc = true;
-				break;
 			case 'm':
 				markbad = true;
 				break;
@@ -258,8 +231,7 @@ int main(int argc, char * const argv[])
 	struct mtd_oob_buf oob;
 	loff_t offs;
 	int ret;
-	int oobinfochanged = 0;
-	struct nand_oobinfo old_oobinfo;
+	struct nand_ecclayout ecclayout;
 	bool failed = true;
 	// contains all the data read from the file so far for the current eraseblock
 	unsigned char *filebuf = NULL;
@@ -316,86 +288,30 @@ int main(int argc, char * const argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	if (autoplace) {
-		/* Read the current oob info */
-		if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
-			perror ("MEMGETOOBSEL");
-			close (fd);
-			exit (EXIT_FAILURE);
-		}
-
-		// autoplace ECC ?
-		if (autoplace && (old_oobinfo.useecc != MTD_NANDECC_AUTOPLACE)) {
-
-			if (ioctl (fd, MEMSETOOBSEL, &autoplace_oobinfo) != 0) {
-				perror ("MEMSETOOBSEL");
-				close (fd);
-				exit (EXIT_FAILURE);
-			}
-			oobinfochanged = 1;
-		}
-	}
-
-	if (noecc)  {
-		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);
-					exit (EXIT_FAILURE);
-				}
-				if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
-					perror ("MEMSETOOBSEL");
-					close (fd);
-					exit (EXIT_FAILURE);
-				}
-				oobinfochanged = 1;
-				break;
-			default:
-				perror ("MTDFILEMODE");
-				close (fd);
-				exit (EXIT_FAILURE);
-			}
-		}
-	}
-
-	/*
-	 * force oob layout for jffs2 or yaffs ?
-	 * Legacy support
-	 */
-	if (forcejffs2 || forceyaffs) {
-		struct nand_oobinfo *oobsel = forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;
 
-		if (autoplace) {
-			fprintf(stderr, "Autoplacement is not possible for legacy -j/-y options\n");
-			goto restoreoob;
-		}
-		if ((old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE) && !forcelegacy) {
-			fprintf(stderr, "Use -f option to enforce legacy placement on autoplacement enabled mtd device\n");
-			goto restoreoob;
-		}
-		if (meminfo.oobsize == 8) {
-			if (forceyaffs) {
-				fprintf (stderr, "YAFSS cannot operate on 256 Byte page size");
-				goto restoreoob;
-			}
-			/* Adjust number of ecc bytes */
-			jffs2_oobinfo.eccbytes = 3;
+	oob.length = meminfo.oobsize;
+	oob.ptr =  oobbuf;
+
+	memset(&ecclayout, 0, sizeof(ecclayout));
+	if (get_linux_version() > LINUX_VERSION(2, 6, 17)) {
+		if (ioctl(fd, ECCGETLAYOUT, &ecclayout) != 0) {
+			perror("ECCGETLAYOUT");
+			close(fd);
+			exit(EXIT_FAILURE);
 		}
+	} else {
+		struct nand_oobinfo oi;
 
-		if (ioctl (fd, MEMSETOOBSEL, oobsel) != 0) {
-			perror ("MEMSETOOBSEL");
-			goto restoreoob;
+		if (ioctl(fd, MEMGETOOBSEL, &oi) != 0) {
+			perror("MEMGETOOBSEL");
+			close(fd);
+			exit(EXIT_FAILURE);
 		}
+		memcpy(&ecclayout.eccpos, &oi.eccpos, sizeof(oi.eccpos));
+		memcpy(&ecclayout.oobfree, &oi.oobfree, sizeof(oi.oobfree));
+		ecclayout.eccbytes = oi.eccbytes;
 	}
 
-	oob.length = meminfo.oobsize;
-	oob.ptr = noecc ? oobreadbuf : oobbuf;
-
 	/* Determine if we are reading from standard input or from a file. */
 	if (strcmp(img, standard_input) == 0) {
 		ifd = STDIN_FILENO;
@@ -559,6 +475,8 @@ int main(int argc, char * const argv[])
 		}
 
 		if (writeoob) {
+			int i, start, len;
+			int tags_pos = 0;
 			oobreadbuf = writebuf + meminfo.writesize;
 
 			// Read more data for the OOB from the input if there isn't enough in the buffer
@@ -595,40 +513,19 @@ int main(int argc, char * const argv[])
 				}
 			}
 
-			if (noecc) {
-				oob.ptr = oobreadbuf;
-			} else {
-				int i, start, len;
-				int tags_pos = 0;
-				/*
-				 *  We use autoplacement and have the oobinfo with the autoplacement
-				 * information from the kernel available
-				 *
-				 * Modified to support out of order oobfree segments,
-				 * such as the layout used by diskonchip.c
-				 */
-				if (!oobinfochanged && (old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE)) {
-					for (i = 0;old_oobinfo.oobfree[i][1]; i++) {
-						/* Set the reserved bytes to 0xff */
-						start = old_oobinfo.oobfree[i][0];
-						len = old_oobinfo.oobfree[i][1];
-						if (rawoob)
-							memcpy(oobbuf + start,
-									oobreadbuf + start, len);
-						else
-							memcpy(oobbuf + start,
-									oobreadbuf + tags_pos, len);
-						tags_pos += len;
-					}
-				} else {
-					/* Set at least the ecc byte positions to 0xff */
-					start = old_oobinfo.eccbytes;
-					len = meminfo.oobsize - start;
+			for (i = 0; ecclayout.oobfree[i].length; i++) {
+				/* Set the reserved bytes to 0xff */
+				start = ecclayout.oobfree[i].offset;
+				len = ecclayout.oobfree[i].length;
+				if (rawoob)
 					memcpy(oobbuf + start,
-							oobreadbuf + start,
-							len);
-				}
+							oobreadbuf + start, len);
+				else
+					memcpy(oobbuf + start,
+							oobreadbuf + tags_pos, len);
+				tags_pos += len;
 			}
+
 			/* Write OOB data first, as ecc will be placed in there*/
 			oob.start = mtdoffset;
 			if (ioctl(fd, MEMWRITEOOB, &oob) != 0) {
@@ -687,13 +584,6 @@ closeall:
 	close(ifd);
 
 restoreoob:
-	if (oobinfochanged == 1) {
-		if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
-			perror ("MEMSETOOBSEL");
-			close (fd);
-			exit (EXIT_FAILURE);
-		}
-	}
 
 	close(fd);
 
Signature · 1 line
1.5.4.3
#2 lore raw

PATCH v3 2/3 Discard the legacy interface MEMGETOOBSEL in flash_eraseall

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Now update flash_eraseall to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

---
 flash_eraseall.c |   79 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 50 insertions(+), 29 deletions(-)
flash_eraseall.c +50 -29
index a22fc49..b8068c0 100644
@@ -35,6 +35,7 @@
 #include <getopt.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <sys/utsname.h>
 #include "crc32.h"
 
 #include <mtd/mtd-user.h>
@@ -43,6 +44,8 @@
 #define PROGRAM "flash_eraseall"
 #define VERSION "$Revision: 1.22 $"
 
+#define LINUX_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
+
 static const char *exe_name;
 static const char *mtd_device;
 static int quiet;		/* true -- don't output progress */
@@ -55,6 +58,28 @@ static void display_version (void);
 static struct jffs2_unknown_node cleanmarker;
 int target_endian = __BYTE_ORDER;
 
+static int get_linux_version(void)
+{
+	int a, b, c, ret, err = 0;
+	struct utsname buf;
+
+	ret = uname(&buf);
+	if (ret == 0) {
+		ret = sscanf(buf.release, "%d.%d.%d", &a, &b, &c);
+		if (ret != 3)
+			err = 1;
+	} else
+		err = 1;
+
+	if (err) {
+		a = b = c = 0xff;
+		fprintf(stderr, "Warning: Can't get linux kernel version."
+				"Set the default version to the latest version.\n");
+	}
+
+	return LINUX_VERSION(a, b, c);
+}
+
 int main (int argc, char *argv[])
 {
 	mtd_info_t meminfo;
@@ -84,41 +109,37 @@ int main (int argc, char *argv[])
 		if (!isNAND)
 			cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
 		else {
-			struct nand_oobinfo oobinfo;
-
-			if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
-				fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", exe_name, mtd_device);
-				return 1;
-			}
+			struct nand_ecclayout ecclayout;
 
-			/* Check for autoplacement */
-			if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
-				/* Get the position of the free bytes */
-				if (!oobinfo.oobfree[0][1]) {
-					fprintf (stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
+			memset(&ecclayout, 0, sizeof(ecclayout));
+			if (get_linux_version() > LINUX_VERSION(2, 6, 17)) {
+				if (ioctl(fd, ECCGETLAYOUT, &ecclayout) != 0) {
+					fprintf(stderr,	"%s: %s: unable to get NAND oob layout\n", \
+							exe_name, mtd_device);
 					return 1;
 				}
-				clmpos = oobinfo.oobfree[0][0];
-				clmlen = oobinfo.oobfree[0][1];
-				if (clmlen > 8)
-					clmlen = 8;
 			} else {
-				/* Legacy mode */
-				switch (meminfo.oobsize) {
-					case 8:
-						clmpos = 6;
-						clmlen = 2;
-						break;
-					case 16:
-						clmpos = 8;
-						clmlen = 8;
-						break;
-					case 64:
-						clmpos = 16;
-						clmlen = 8;
-						break;
+				struct nand_oobinfo oi;
+
+				if (ioctl(fd, MEMGETOOBSEL, &oi) != 0) {
+					fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", \
+							exe_name, mtd_device);
+					return 1;
 				}
+				memcpy(&ecclayout.eccpos, &oi.eccpos, sizeof(oi.eccpos));
+				memcpy(&ecclayout.oobfree, &oi.oobfree, sizeof(oi.oobfree));
+				ecclayout.eccbytes = oi.eccbytes;
+			}
+
+			/* Get the position of the free bytes */
+			if (!ecclayout.oobfree[0].length) {
+				fprintf(stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
+				return 1;
 			}
+			clmpos = ecclayout.oobfree[0].offset;
+			clmlen = ecclayout.oobfree[0].length;
+			if (clmlen > 8)
+				clmlen = 8;
 			cleanmarker.totlen = cpu_to_je32(8);
 		}
 		cleanmarker.hdr_crc =  cpu_to_je32 (crc32 (0, &cleanmarker,  sizeof (struct jffs2_unknown_node) - 4));
Signature · 1 line
1.5.4.3
#3 lore raw

PATCH v3 3/3 Place the cleanmarker in OOB area according to the mode MTD_OOB_AUTO

The jffs2 filesystem writes the cleanmarker according to the mode MTD_OOB_AUTO, so flash_eraseall should arrange the layout of the cleanmarker according to the mode MTD_OOB_AUTO too.

---
 flash_eraseall.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)
flash_eraseall.c +22 -18
index b8068c0..374edd7 100644
@@ -34,7 +34,7 @@
 #include <time.h>
 #include <getopt.h>
 #include <sys/ioctl.h>
-#include <sys/mount.h>
+#include <sys/param.h>
 #include <sys/utsname.h>
 #include "crc32.h"
 
@@ -83,9 +83,11 @@ static int get_linux_version(void)
 int main (int argc, char *argv[])
 {
 	mtd_info_t meminfo;
-	int fd, clmpos = 0, clmlen = 8;
+	int fd;
 	erase_info_t erase;
 	int isNAND, bbtest = 1;
+	unsigned char oobbuf[128];
+	memset(oobbuf, 0xFF, 128);
 
 	process_options(argc, argv);
 
@@ -106,11 +108,18 @@ int main (int argc, char *argv[])
 	if (jffs2) {
 		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
 		cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
-		if (!isNAND)
+		if (!isNAND) {
 			cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
-		else {
+			cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, \
+						sizeof(struct jffs2_unknown_node) - 4));
+		} else {
+			int already_read, num, i, start;
 			struct nand_ecclayout ecclayout;
 
+			cleanmarker.totlen = cpu_to_je32(8);
+			cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, \
+						sizeof(struct jffs2_unknown_node) - 4));
+
 			memset(&ecclayout, 0, sizeof(ecclayout));
 			if (get_linux_version() > LINUX_VERSION(2, 6, 17)) {
 				if (ioctl(fd, ECCGETLAYOUT, &ecclayout) != 0) {
@@ -130,19 +139,14 @@ int main (int argc, char *argv[])
 				memcpy(&ecclayout.oobfree, &oi.oobfree, sizeof(oi.oobfree));
 				ecclayout.eccbytes = oi.eccbytes;
 			}
-
-			/* Get the position of the free bytes */
-			if (!ecclayout.oobfree[0].length) {
-				fprintf(stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
-				return 1;
+			already_read = 0;
+			for (i = 0; (already_read < 8) && ecclayout.oobfree[i].length; i++) {
+				num = MIN(8 - already_read, ecclayout.oobfree[i].length);
+				start = ecclayout.oobfree[i].offset;
+				memcpy(oobbuf + start, (unsigned char *)&cleanmarker + already_read, num);
+				already_read += num;
 			}
-			clmpos = ecclayout.oobfree[0].offset;
-			clmlen = ecclayout.oobfree[0].length;
-			if (clmlen > 8)
-				clmlen = 8;
-			cleanmarker.totlen = cpu_to_je32(8);
 		}
-		cleanmarker.hdr_crc =  cpu_to_je32 (crc32 (0, &cleanmarker,  sizeof (struct jffs2_unknown_node) - 4));
 	}
 
 	for (erase.start = 0; erase.start < meminfo.size; erase.start += meminfo.erasesize) {
@@ -182,9 +186,9 @@ int main (int argc, char *argv[])
 		/* write cleanmarker */
 		if (isNAND) {
 			struct mtd_oob_buf oob;
-			oob.ptr = (unsigned char *) &cleanmarker;
-			oob.start = erase.start + clmpos;
-			oob.length = clmlen;
+			oob.ptr = oobbuf;
+			oob.start = erase.start;
+			oob.length = meminfo.oobsize;
 			if (ioctl (fd, MEMWRITEOOB, &oob) != 0) {
 				fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
 				continue;
Signature · 1 line
1.5.4.3
#4 lore raw
In reply to Stanley.Miao

Any other comments ?

Stanley.

Quoted 24 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw
Quoted 1 line · stanley.miao

Any other comments ?

I'll pick this as when I find few hours to go through the MTD ML.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
Tested-by on v3 1/1
#6 lore raw
In reply to Stanley.Miao
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Tested with linux-2.6.32 (flash_eraseall -j finaly works now)

As a special bonus, here is simple patch on top of your patchset making flash_eraseall smaller:

From: Ladislav Michl <[email protected]>

Returning from main() instead of using exit() makes code more readable and smaller (ARM EABI binary sizes)

text data bss dec hex filename

  10345     372      44   10761    2a09 flash_eraseall
  10286     368      44   10698    29ca flash_eraseall.noexit
---
 flash_eraseall.c |  197 ++++++++++++++++++++++++-------------------------------
 1 file changed, 89 insertions(+), 108 deletions(-)
flash_eraseall.c +89 -108
@@ -49,15 +49,45 @@
 static const char *exe_name;
 static const char *mtd_device;
 static int quiet;		/* true -- don't output progress */
-static int jffs2;		// format for jffs2 usage
-
-static void process_options (int argc, char *argv[]);
-void show_progress (mtd_info_t *meminfo, erase_info_t *erase);
-static void display_help (void);
-static void display_version (void);
+static int jffs2;		/* format for jffs2 usage */
 static struct jffs2_unknown_node cleanmarker;
 int target_endian = __BYTE_ORDER;
 
+static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
+{
+	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
+		meminfo->erasesize / 1024, erase->start,
+		(unsigned long long) erase->start * 100 / meminfo->size);
+	fflush(stdout);
+}
+
+static void display_help(void)
+{
+	printf("Usage: %s [OPTION] MTD_DEVICE\n"
+			"Erases all of the specified MTD device.\n"
+			"\n"
+			"  -j, --jffs2    format the device for jffs2\n"
+			"  -q, --quiet    don't display progress messages\n"
+			"      --silent   same as --quiet\n"
+			"      --help     display this help and exit\n"
+			"      --version  output version information and exit\n",
+			exe_name);
+}
+
+static void display_version(void)
+{
+	printf(PROGRAM " " VERSION "\n"
+			"\n"
+			"Copyright (C) 2000 Arcom Control Systems Ltd\n"
+			"\n"
+			PROGRAM " comes with NO WARRANTY\n"
+			"to the extent permitted by law.\n"
+			"\n"
+			"You may redistribute copies of " PROGRAM "\n"
+			"under the terms of the GNU General Public Licence.\n"
+			"See the file `COPYING' for more information.\n");
+}
+
 static int get_linux_version(void)
 {
 	int a, b, c, ret, err = 0;
@@ -80,23 +110,73 @@
 	return LINUX_VERSION(a, b, c);
 }
 
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
 {
 	mtd_info_t meminfo;
 	int fd;
 	erase_info_t erase;
 	int isNAND, bbtest = 1;
+	int error = 0;
 	unsigned char oobbuf[128];
 	memset(oobbuf, 0xFF, 128);
 
-	process_options(argc, argv);
+	exe_name = argv[0];
+	for (;;) {
+		int option_index = 0;
+		static const char *short_options = "jq";
+		static const struct option long_options[] = {
+			{"help", no_argument, 0, 0},
+			{"version", no_argument, 0, 0},
+			{"jffs2", no_argument, 0, 'j'},
+			{"quiet", no_argument, 0, 'q'},
+			{"silent", no_argument, 0, 'q'},
+
+			{0, 0, 0, 0},
+		};
+
+		int c = getopt_long(argc, argv, short_options,
+				long_options, &option_index);
+		if (c == EOF)
+			break;
+
+		switch (c) {
+		case 0:
+			switch (option_index) {
+			case 0:
+				display_help();
+				return 0;
+			case 1:
+				display_version();
+				return 0;
+			}
+			break;
+		case 'q':
+			quiet = 1;
+			break;
+		case 'j':
+			jffs2 = 1;
+			break;
+		case '?':
+			error = 1;
+			break;
+		}
+	}
+	if (optind == argc) {
+		fprintf(stderr, "%s: no MTD device specified\n", exe_name);
+		error = 1;
+	}
+	if (error) {
+		fprintf(stderr, "Try `%s --help' for more information.\n",
+				exe_name);
+		return 1;
+	}
+	mtd_device = argv[optind];
 
 	if ((fd = open(mtd_device, O_RDWR)) < 0) {
 		fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));
 		return 1;
 	}
 
-
 	if (ioctl(fd, MEMGETINFO, &meminfo) != 0) {
 		fprintf(stderr, "%s: %s: unable to get MTD device info\n", exe_name, mtd_device);
 		return 1;
@@ -213,102 +293,3 @@
 
 	return 0;
 }
-
-
-void process_options (int argc, char *argv[])
-{
-	int error = 0;
-
-	exe_name = argv[0];
-
-	for (;;) {
-		int option_index = 0;
-		static const char *short_options = "jq";
-		static const struct option long_options[] = {
-			{"help", no_argument, 0, 0},
-			{"version", no_argument, 0, 0},
-			{"jffs2", no_argument, 0, 'j'},
-			{"quiet", no_argument, 0, 'q'},
-			{"silent", no_argument, 0, 'q'},
-
-			{0, 0, 0, 0},
-		};
-
-		int c = getopt_long(argc, argv, short_options,
-				long_options, &option_index);
-		if (c == EOF) {
-			break;
-		}
-
-		switch (c) {
-			case 0:
-				switch (option_index) {
-					case 0:
-						display_help();
-						break;
-					case 1:
-						display_version();
-						break;
-				}
-				break;
-			case 'q':
-				quiet = 1;
-				break;
-			case 'j':
-				jffs2 = 1;
-				break;
-			case '?':
-				error = 1;
-				break;
-		}
-	}
-	if (optind == argc) {
-		fprintf(stderr, "%s: no MTD device specified\n", exe_name);
-		error = 1;
-	}
-	if (error) {
-		fprintf(stderr, "Try `%s --help' for more information.\n",
-				exe_name);
-		exit(1);
-	}
-
-	mtd_device = argv[optind];
-}
-
-void show_progress (mtd_info_t *meminfo, erase_info_t *erase)
-{
-	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
-		meminfo->erasesize / 1024, erase->start,
-		(unsigned long long) erase->start * 100 / meminfo->size);
-	fflush(stdout);
-}
-
-void display_help (void)
-{
-	printf("Usage: %s [OPTION] MTD_DEVICE\n"
-			"Erases all of the specified MTD device.\n"
-			"\n"
-			"  -j, --jffs2    format the device for jffs2\n"
-			"  -q, --quiet    don't display progress messages\n"
-			"      --silent   same as --quiet\n"
-			"      --help     display this help and exit\n"
-			"      --version  output version information and exit\n",
-			exe_name);
-	exit(0);
-}
-
-
-void display_version (void)
-{
-	printf(PROGRAM " " VERSION "\n"
-			"\n"
-			"Copyright (C) 2000 Arcom Control Systems Ltd\n"
-			"\n"
-			PROGRAM " comes with NO WARRANTY\n"
-			"to the extent permitted by law.\n"
-			"\n"
-			"You may redistribute copies of " PROGRAM "\n"
-			"under the terms of the GNU General Public Licence.\n"
-			"See the file `COPYING' for more information.\n");
-	exit(0);
-}
#7 lore raw
Quoted 17 lines · Ladislav Michl
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Quoted 7 lines

Tested with linux-2.6.32 (flash_eraseall -j finaly works now)

As a special bonus, here is simple patch on top of your patchset making flash_eraseall smaller:

FYI, this patch is still sitting in my mailbox and waiting - Stanley's stuff was not merged, and this patch depends on that. So, if you can make it to be independent, please, re-send. Stanley said he'd re-send the patch.

But also there is some ongoing discussion to deprecate ECCGETLAYOUT, but I did not read it yet.

Artem.

#8 lore raw
Quoted 22 lines · Artem Bityutskiy
Quoted 21 lines · Ladislav Michl
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Tested with linux-2.6.32 (flash_eraseall -j finaly works now)

Quoted 8 lines
Quoted 3 lines

As a special bonus, here is simple patch on top of your patchset making flash_eraseall smaller:

FYI, this patch is still sitting in my mailbox and waiting - Stanley's stuff was not merged, and this patch depends on that. So, if you can make it to be independent, please, re-send. Stanley said he'd re-send the patch.

Here it is based on the top of current git. Updated only, compile tested only...

Returning from main() instead of using exit() makes code more readable and smaller (ARM EABI binary sizes)

text data bss dec hex filename

  28882     436      44   29362    72b2 flash_eraseall
  28827     432      44   29303    7277 flash_eraseall.noexit
---
 flash_eraseall.c |  193 +++++++++++++++++++++++++------------------------------
 1 file changed, 89 insertions(+), 104 deletions(-)
flash_eraseall.c +89 -104
index a2a6b0a..5740719 100644
@@ -47,24 +47,107 @@
 static const char *exe_name;
 static const char *mtd_device;
 static int quiet;		/* true -- don't output progress */
-static int jffs2;		// format for jffs2 usage
+static int jffs2;		/* format for jffs2 usage */
 
-static void process_options (int argc, char *argv[]);
-void show_progress (struct mtd_dev_info *mtd, uint64_t start);
-static void display_help (void);
-static void display_version (void);
 static struct jffs2_unknown_node cleanmarker;
 int target_endian = __BYTE_ORDER;
 
+static void show_progress (struct mtd_dev_info *mtd, uint64_t start)
+{
+	printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
+		mtd->eb_size / 1024, (unsigned long long)start,
+		(unsigned long long) start * 100 / mtd->size);
+	fflush(stdout);
+}
+
+static void display_help (void)
+{
+	printf("Usage: %s [OPTION] MTD_DEVICE\n"
+			"Erases all of the specified MTD device.\n"
+			"\n"
+			"  -j, --jffs2    format the device for jffs2\n"
+			"  -q, --quiet    don't display progress messages\n"
+			"      --silent   same as --quiet\n"
+			"      --help     display this help and exit\n"
+			"      --version  output version information and exit\n",
+			exe_name);
+}
+
+
+static void display_version (void)
+{
+	printf(PROGRAM " " VERSION "\n"
+			"\n"
+			"Copyright (C) 2000 Arcom Control Systems Ltd\n"
+			"\n"
+			PROGRAM " comes with NO WARRANTY\n"
+			"to the extent permitted by law.\n"
+			"\n"
+			"You may redistribute copies of " PROGRAM "\n"
+			"under the terms of the GNU General Public Licence.\n"
+			"See the file `COPYING' for more information.\n");
+}
+
 int main (int argc, char *argv[])
 {
 	libmtd_t mtd_desc;
 	struct mtd_dev_info mtd;
 	int fd, clmpos = 0, clmlen = 8, eb;
 	int isNAND, bbtest = 1;
+	int error = 0;
 	uint64_t offset = 0;
 
-	process_options(argc, argv);
+	exe_name = argv[0];
+	for (;;) {
+		int option_index = 0;
+		static const char *short_options = "jq";
+		static const struct option long_options[] = {
+			{"help", no_argument, 0, 0},
+			{"version", no_argument, 0, 0},
+			{"jffs2", no_argument, 0, 'j'},
+			{"quiet", no_argument, 0, 'q'},
+			{"silent", no_argument, 0, 'q'},
+
+			{0, 0, 0, 0},
+		};
+
+		int c = getopt_long(argc, argv, short_options,
+				long_options, &option_index);
+		if (c == EOF)
+			break;
+
+		switch (c) {
+		case 0:
+			switch (option_index) {
+			case 0:
+				display_help();
+				return 0;
+			case 1:
+				display_version();
+				return 0;
+			}
+			break;
+		case 'q':
+			quiet = 1;
+			break;
+		case 'j':
+			jffs2 = 1;
+			break;
+		case '?':
+			error = 1;
+			break;
+		}
+	}
+	if (optind == argc) {
+		fprintf(stderr, "%s: no MTD device specified\n", exe_name);
+		error = 1;
+	}
+	if (error) {
+		fprintf(stderr, "Try `%s --help' for more information.\n",
+				exe_name);
+		return 1;
+	}
+	mtd_device = argv[optind];
 
 	mtd_desc = libmtd_open();
 	if (mtd_desc == NULL) {
@@ -191,101 +274,3 @@ int main (int argc, char *argv[])
 	return 0;
 }
 
-
-void process_options (int argc, char *argv[])
-{
-	int error = 0;
-
-	exe_name = argv[0];
-
-	for (;;) {
-		int option_index = 0;
-		static const char *short_options = "jq";
-		static const struct option long_options[] = {
-			{"help", no_argument, 0, 0},
-			{"version", no_argument, 0, 0},
-			{"jffs2", no_argument, 0, 'j'},
-			{"quiet", no_argument, 0, 'q'},
-			{"silent", no_argument, 0, 'q'},
-
-			{0, 0, 0, 0},
-		};
-
-		int c = getopt_long(argc, argv, short_options,
-				long_options, &option_index);
-		if (c == EOF) {
-			break;
-		}
-
-		switch (c) {
-			case 0:
-				switch (option_index) {
-					case 0:
-						display_help();
-						break;
-					case 1:
-						display_version();
-						break;
-				}
-				break;
-			case 'q':
-				quiet = 1;
-				break;
-			case 'j':
-				jffs2 = 1;
-				break;
-			case '?':
-				error = 1;
-				break;
-		}
-	}
-	if (optind == argc) {
-		fprintf(stderr, "%s: no MTD device specified\n", exe_name);
-		error = 1;
-	}
-	if (error) {
-		fprintf(stderr, "Try `%s --help' for more information.\n",
-				exe_name);
-		exit(1);
-	}
-
-	mtd_device = argv[optind];
-}
-
-void show_progress (struct mtd_dev_info *mtd, uint64_t start)
-{
-	printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
-		mtd->eb_size / 1024, (unsigned long long)start,
-		(unsigned long long) start * 100 / mtd->size);
-	fflush(stdout);
-}
-
-void display_help (void)
-{
-	printf("Usage: %s [OPTION] MTD_DEVICE\n"
-			"Erases all of the specified MTD device.\n"
-			"\n"
-			"  -j, --jffs2    format the device for jffs2\n"
-			"  -q, --quiet    don't display progress messages\n"
-			"      --silent   same as --quiet\n"
-			"      --help     display this help and exit\n"
-			"      --version  output version information and exit\n",
-			exe_name);
-	exit(0);
-}
-
-
-void display_version (void)
-{
-	printf(PROGRAM " " VERSION "\n"
-			"\n"
-			"Copyright (C) 2000 Arcom Control Systems Ltd\n"
-			"\n"
-			PROGRAM " comes with NO WARRANTY\n"
-			"to the extent permitted by law.\n"
-			"\n"
-			"You may redistribute copies of " PROGRAM "\n"
-			"under the terms of the GNU General Public Licence.\n"
-			"See the file `COPYING' for more information.\n");
-	exit(0);
-}
#9 lore raw
Quoted 5 lines · Ladislav Michl

Here it is based on the top of current git. Updated only, compile tested only...

Returning from main() instead of using exit() makes code more readable and smaller (ARM EABI binary sizes)

Quoted 8 lines

text data bss dec hex filename

  28882     436      44   29362    72b2 flash_eraseall
  28827     432      44   29303    7277 flash_eraseall.noexit
---
 flash_eraseall.c |  193 +++++++++++++++++++++++++------------------------------
 1 file changed, 89 insertions(+), 104 deletions(-)

Invented a subject line myself (you missed it) and pushed to mtd-utils.git, thank you!

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#10 lore raw
In reply to Stanley.Miao
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley,

I'd like to first take patches from Kevin, which move libmtd from ubi-utils and make mtd utilities like flash_eraseall start using libmtd.

It would be nice then if you enhanced limbtd to serve your perposes and also used it, instead of direct ioctl calls. libmtd should also be used to get information about which features are supported.

Will this upset you much :-) ?

You can find Kevin's patches I refer in the MTD miling list. The last series to the date are:

[PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory

Could you please take a look at them, review them, then when everyone is happy, we merge them to mtd-utils, then you can do your changes on top, and we also add the patch from Ladislav on top.

Does this sound OK for you?

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#11 lore raw
Quoted 15 lines · Artem Bityutskiy

Stanley,

I'd like to first take patches from Kevin, which move libmtd from ubi-utils and make mtd utilities like flash_eraseall start using libmtd.

It would be nice then if you enhanced limbtd to serve your perposes and also used it, instead of direct ioctl calls. libmtd should also be used to get information about which features are supported.

Will this upset you much :-) ?

You can find Kevin's patches I refer in the MTD miling list. The last series to the date are:

Quoted 8 lines

[PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory

Could you please take a look at them, review them, then when everyone is happy, we merge them to mtd-utils, then you can do your changes on top, and we also add the patch from Ladislav on top.

Does this sound OK for you?

OK, I will rebase my patch on Kevin's.

Stanley.

#12 lore raw
In reply to Stanley.Miao
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley, sorry that this all takes so long time, I do not have enough time. Basically, Kevin's patches are almost there, I sent him 2 other patches, as soon as he reviews them, they should go in. Then you can start using libmtd for your purposes as well. You'll need to extend it a bit, though.

Vs. uname() - I do not really like this idea, because kernel version does not cover the case when ECCGETLAYOUT is back-ported to older kernels.

Try to use similar technique as Kevin used - just call ECCGETLAYOUT ioctl, and if it returns ENOTTY, this ioctl is not supported. See also offs64_ioctl flag handling in my patches to Kevin (sent 1 yesterday, and 1 today).

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#13 lore raw
Quoted 23 lines · Artem Bityutskiy
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 6 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley, sorry that this all takes so long time, I do not have enough time. Basically, Kevin's patches are almost there, I sent him 2 other patches, as soon as he reviews them, they should go in. Then you can start using libmtd for your purposes as well. You'll need to extend it a bit, though.

Quoted 8 lines

Vs. uname() - I do not really like this idea, because kernel version does not cover the case when ECCGETLAYOUT is back-ported to older kernels.

Try to use similar technique as Kevin used - just call ECCGETLAYOUT ioctl, and if it returns ENOTTY, this ioctl is not supported. See also offs64_ioctl flag handling in my patches to Kevin (sent 1 yesterday, and 1 today).

Just a reminder than now we have Kevin's patches in and you can do your things on top.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#14 lore raw

Sorry for taking so long time. I am busy with our project recently. I have seen you merged Kavin's patches. I will read them and add my patches based on them as soon as possible.

Stanley.

Quoted 40 lines · Artem Bityutskiy
Quoted 24 lines · Artem Bityutskiy
Quoted 9 lines · Stanley.Miao

Changes from V2:
1, Get the linux version via uname() according to Joakim Tjernlund. 2, Set the default version the latest version according to Joakim Tjernlund.

The "struct nand_oobinfo" is able to record only 32 ECC code positions,which is not enough for many big NAND chips. Therefore, this structure is replaced by "struct nand_ecclayout" in linux kernel from the version 2.6.17. Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT.

Quoted 7 lines

Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to keep compatible with the old linux kernel, a linux version detection function is added.

YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", "forcejffs2", "forceyaffs" anymore. Now clean them up.

Stanley, sorry that this all takes so long time, I do not have enough time. Basically, Kevin's patches are almost there, I sent him 2 other patches, as soon as he reviews them, they should go in. Then you can start using libmtd for your purposes as well. You'll need to extend it a bit, though.

Quoted 9 lines

Vs. uname() - I do not really like this idea, because kernel version does not cover the case when ECCGETLAYOUT is back-ported to older kernels.

Try to use similar technique as Kevin used - just call ECCGETLAYOUT ioctl, and if it returns ENOTTY, this ioctl is not supported. See also offs64_ioctl flag handling in my patches to Kevin (sent 1 yesterday, and 1 today).

Just a reminder than now we have Kevin's patches in and you can do your things on top.