From d1bc539a3a77bd38f1776d5026277d66b1661c8a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 7 Jun 2011 11:28:02 -0400 Subject: libmtd: add helper funcs for getting regioninfo and locked info This extends the libmtd with the helper functions: mtd_regioninfo: interface to MEMGETREGIONINFO mtd_islocked: interface to MEMISLOCKED Users of these functions will follow shortly ... Artem: do not print error message in mtd_islocked() Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- lib/libmtd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/libmtd.c') diff --git a/lib/libmtd.c b/lib/libmtd.c index a651808..2573cc7 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -883,6 +883,33 @@ int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) return 0; } +int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo) +{ + int ret; + + if (regidx < 0) { + errno = ENODEV; + return -1; + } + + ret = ioctl(fd, MEMGETREGIONINFO, reginfo); + if (ret < 0) + return sys_errmsg("%s ioctl failed for erase region %d", + "MEMGETREGIONINFO", regidx); + + return 0; +} + +int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb) +{ + erase_info_t ei; + + ei.start = eb * mtd->eb_size; + ei.length = mtd->eb_size; + + return ioctl(fd, MEMISLOCKED, &ei); +} + /* Patterns to write to a physical eraseblock when torturing it */ static uint8_t patterns[] = {0xa5, 0x5a, 0x0}; -- cgit v1.2.3