diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-09-23 21:53:38 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-09-25 13:49:01 +0300 |
commit | f03d42afb0fa7599b626fc0c005424edfd123f99 (patch) | |
tree | 71b9041f118e992da11fb52cd6564466caff1ce8 | |
parent | ae51fdc21dd5b299128ab04786a4f7528e09dae3 (diff) |
libmtd: add lock/unlock helpers
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rw-r--r-- | include/libmtd.h | 24 | ||||
-rw-r--r-- | lib/libmtd.c | 32 |
2 files changed, 56 insertions, 0 deletions
diff --git a/include/libmtd.h b/include/libmtd.h index afaba42..e30c8a6 100644 --- a/include/libmtd.h +++ b/include/libmtd.h @@ -138,6 +138,30 @@ int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd); int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd); /** + * mtd_lock - lock eraseblocks. + * @desc: MTD library descriptor + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to lock + * + * This function locks eraseblock @eb. Returns %0 in case of success and %-1 + * in case of failure. + */ +int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb); + +/** + * mtd_unlock - unlock eraseblocks. + * @desc: MTD library descriptor + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to lock + * + * This function unlocks eraseblock @eb. Returns %0 in case of success and %-1 + * in case of failure. + */ +int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb); + +/** * mtd_erase - erase an eraseblock. * @desc: MTD library descriptor * @mtd: MTD device description object diff --git a/lib/libmtd.c b/lib/libmtd.c index d57ae8f..1b3d597 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -802,6 +802,38 @@ static int mtd_valid_erase_block(const struct mtd_dev_info *mtd, int eb) return 0; } +static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req, + const char *sreq) +{ + int ret; + struct erase_info_user ei; + + ret = mtd_valid_erase_block(mtd, eb); + if (ret) + return ret; + + ei.start = eb * mtd->eb_size; + ei.length = mtd->eb_size; + + ret = ioctl(fd, req, &ei); + if (ret < 0) + return sys_errmsg("%s ioctl failed for eraseblock %d " + "(mtd%d)", sreq, eb, mtd->mtd_num); + + return 0; +} +#define mtd_xlock(mtd, fd, eb, req) mtd_xlock(mtd, fd, eb, req, #req) + +int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb) +{ + return mtd_xlock(mtd, fd, eb, MEMLOCK); +} + +int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb) +{ + return mtd_xlock(mtd, fd, eb, MEMUNLOCK); +} + int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) { int ret; |