From f1e870c3e9a1a80be7a1d886d61ccac0f8e97e10 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Sat, 17 Jul 2010 20:08:33 +0300 Subject: libmtd: support MEMERASE64 This patch is base on Kevin Cernekee's patch posted to the MTD mailing list. It adds MEMERASE64 support to the 'mtd_erase()' call. Now it first tries to use MEMERASE64, and if that is not supported, falls back to the old MEMERASE ioctl. This patch also introduces an 'offs64_ioctl' flag to the libmtd descriptor. However, we cannot initialize it in 'libmtd_open()', because we need an MTD device node, which we do not have in 'libmtd_open()'. Thus, we firs mark this flag as "uninitialized", and at the first invocation of 'mtd_erase()' we initialize it. This also means that we have to pass the limbtd descriptor to 'mtd_erase()', to save the flag value. This, in turn, requires tweaking 'mtd_erase()' users. This is not very nice, but good enough so far. Signed-off-by: Artem Bityutskiy --- lib/libmtd_int.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/libmtd_int.h') diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h index 7de4b42..bb48d35 100644 --- a/lib/libmtd_int.h +++ b/lib/libmtd_int.h @@ -43,6 +43,10 @@ extern "C" { #define MTD_REGION_CNT "numeraseregions" #define MTD_FLAGS "flags" +#define OFFS64_IOCTLS_UNKNOWN 0 +#define OFFS64_IOCTLS_NOT_SUPPORTED 1 +#define OFFS64_IOCTLS_SUPPORTED 2 + /** * libmtd - MTD library description data structure. * @sysfs_mtd: MTD directory in sysfs @@ -58,6 +62,19 @@ extern "C" { * @mtd_region_cnt: count of additional erase regions file pattern * @mtd_flags: MTD device flags file pattern * @sysfs_supported: non-zero if sysfs is supported by MTD + * @offs64_ioctls: %OFFS64_IOCTLS_SUPPORTED if 64-bit %MEMERASE64, + * %MEMREADOOB64, %MEMWRITEOOB64 MTD device ioctls are + * supported, %OFFS64_IOCTLS_NOT_SUPPORTED if not, and + * %OFFS64_IOCTLS_UNKNOWN if it is not known yet; + * + * Note, we cannot find out whether 64-bit ioctls are supported by MTD when we + * are initializing the library, because this requires an MTD device node. + * Indeed, we have to actually call the ioctl and check for %ENOTTY to find + * out whether it is supported or not. + * + * Thus, we leave %offs64_ioctls uninitialized in 'libmtd_open()', and + * initialize it later, when corresponding libmtd function is used, and when + * we actually have a device node and can invoke an ioctl command on it. */ struct libmtd { @@ -74,6 +91,7 @@ struct libmtd char *mtd_region_cnt; char *mtd_flags; unsigned int sysfs_supported:1; + unsigned int offs64_ioctls:2; }; int legacy_libmtd_open(void); -- cgit v1.2.3