aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-06-08 15:30:14 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-06-08 15:30:14 +0300
commit92a06994b7c3f146cbdb770b30780e32f021118f (patch)
tree2e655126d20013d522b237a87d2ba1feb1cb8873 /lib
parentd1bc539a3a77bd38f1776d5026277d66b1661c8a (diff)
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 <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libmtd.c13
1 files changed, 11 insertions, 2 deletions
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 */