From 92a06994b7c3f146cbdb770b30780e32f021118f Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 8 Jun 2011 15:30:14 +0300 Subject: libmtd: improve mtd_islocked interface This patch first of all, re-names 'mtd_islocked()' into 'mtd_is_locked()' since this seems to be the name Mike wanted, and it looks a bit nicer. This patch also makes 'mtd_is_locked()' print an error message if it fails. I'm not sure if it is good idea for a library to do so, but all functions do this, so it certainly _not_ a good idea to be inconsistent. However, for the special case, when the the "is locked" ioctl is not supported or is not valid for this device, we do not print an error message and return ENOTSUPP error code. Thus, the user can distinguish between real errors and non-fatal "not supported" cases. Signed-off-by: Artem Bityutskiy --- lib/libmtd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libmtd.c b/lib/libmtd.c index 2573cc7..c34874e 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -900,14 +900,23 @@ int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo) return 0; } -int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb) +int mtd_is_locked(const struct mtd_dev_info *mtd, int fd, int eb) { + int ret; erase_info_t ei; ei.start = eb * mtd->eb_size; ei.length = mtd->eb_size; - return ioctl(fd, MEMISLOCKED, &ei); + ret = ioctl(fd, MEMISLOCKED, &ei); + if (ret < 0) { + if (errno != ENOTTY && errno != EOPNOTSUPP) + return mtd_ioctl_error(mtd, eb, "MEMISLOCKED"); + else + errno = EOPNOTSUPP; + } + + return ret; } /* Patterns to write to a physical eraseblock when torturing it */ -- cgit v1.2.3