]> www.infradead.org Git - mtd-utils.git/commitdiff
libmtd: add helper funcs for getting regioninfo and locked info
authorMike Frysinger <vapier@gentoo.org>
Tue, 7 Jun 2011 15:28:02 +0000 (11:28 -0400)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 8 Jun 2011 11:58:14 +0000 (14:58 +0300)
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 <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
include/libmtd.h
lib/libmtd.c

index e30c8a6ba0bb8746c86b5928d6dd0564ef5e5417..727524633035ca94086c2c46cbfaeec990427141 100644 (file)
@@ -35,6 +35,9 @@ extern "C" {
 /* MTD library descriptor */
 typedef void * libmtd_t;
 
+/* Forward decls */
+struct region_info_user;
+
 /**
  * @mtd_dev_cnt: count of MTD devices in system
  * @lowest_mtd_num: lowest MTD device number in system
@@ -173,6 +176,31 @@ int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb);
  */
 int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb);
 
+/**
+ * mtd_regioninfo - get information about an erase region.
+ * @fd: MTD device node file descriptor
+ * @regidx: index of region to look up
+ * @reginfo: the region information is returned here
+ *
+ * This function gets information about an erase region defined by the
+ * @regidx index and saves this information in the @reginfo object.
+ * Returns %0 in case of success and %-1 in case of failure. If the
+ * @regidx is not valid or unavailable, errno is set to @ENODEV.
+ */
+int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo);
+
+/**
+ * mtd_islocked - see if the specified eraseblock is locked.
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: eraseblock to check
+ *
+ * This function checks to see if eraseblock @eb of MTD device described
+ * by @fd is locked. Returns %0 if it is unlocked, %1 if it is locked, and
+ * %-1 in case of failure.
+ */
+int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb);
+
 /**
  * mtd_torture - torture an eraseblock.
  * @desc: MTD library descriptor
index a6518083af7eae5f7b3c69adfc2dc0040d74b2fe..2573cc787f30e2ad993f530e68021724212b3cf6 100644 (file)
@@ -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};