[PATCH 2/5] ubi-utils: Enable lnum2pnum ioctl in userspace
hujianyang
hujianyang at huawei.com
Tue Jul 29 02:35:16 PDT 2014
Introduce ubi_lnum_to_pnum() to translate lnum into pnum by the
a new ioctl.
Signed-off-by: hujianyang <hujianyang at huawei.com>
---
include/mtd/ubi-user.h | 12 ++++++++++++
ubi-utils/include/libubi.h | 11 +++++++++++
ubi-utils/libubi.c | 12 ++++++++++++
3 files changed, 35 insertions(+)
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 2b50dad..e4f57c6 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -200,6 +200,8 @@
#define UBI_IOCVOLCRBLK _IOW(UBI_VOL_IOC_MAGIC, 7, struct ubi_blkcreate_req)
/* Remove the R/O block device */
#define UBI_IOCVOLRMBLK _IO(UBI_VOL_IOC_MAGIC, 8)
+/* Get pnum of a specified leb */
+#define UBI_IOCEBGETPNUM _IOW(UBI_VOL_IOC_MAGIC, 9, struct ubi_lnum2pnum_req)
/* Maximum MTD device name length supported by UBI */
#define MAX_UBI_MTD_NAME_LEN 127
@@ -437,4 +439,14 @@ struct ubi_blkcreate_req {
int8_t padding[128];
} __attribute__((packed));
+/**
+ * struct ubi_lnum2pnum_req - a data structure used in lnum translate requests.
+ * @lnum: logical eraseblock num to translate
+ * @pnum: physical eraseblock num @lnum mapped
+ */
+struct ubi_lnum2pnum_req {
+ int32_t lnum;
+ int32_t pnum;
+} __attribute__((packed));
+
#endif /* __UBI_USER_H__ */
diff --git a/ubi-utils/include/libubi.h b/ubi-utils/include/libubi.h
index 4d6a7ee..618a6ba 100644
--- a/ubi-utils/include/libubi.h
+++ b/ubi-utils/include/libubi.h
@@ -478,6 +478,17 @@ int ubi_leb_unmap(int fd, int lnum);
*/
int ubi_is_mapped(int fd, int lnum);
+/**
+ * ubi_lnum_to_pnum - get the pnum of a specified leb.
+ * @fd: volume character device file descriptor
+ * @lnum: logical eraseblock number to translate
+ * @pnum: physical eraseblock number to return
+ *
+ * This function return %0 in case of success and %-1 in case of failure. The
+ * pnum of the specified leb is returned by @pnum.
+ */
+int ubi_lnum_to_pnum(int fd, int lnum, int *pnum);
+
#ifdef __cplusplus
}
#endif
diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c
index 1e08b7d..9650b6a 100644
--- a/ubi-utils/libubi.c
+++ b/ubi-utils/libubi.c
@@ -1123,6 +1123,18 @@ int ubi_vol_block_remove(int fd)
return ioctl(fd, UBI_IOCVOLRMBLK);
}
+int ubi_lnum_to_pnum(int fd, int lnum, int *pnum)
+{
+ struct ubi_lnum2pnum_req request;
+
+ request.pnum = -1;
+ request.lnum = lnum;
+ if (ioctl(fd, UBI_IOCEBGETPNUM, &request))
+ return -1;
+ *pnum = request.pnum;
+ return 0;
+}
+
int ubi_update_start(libubi_t desc, int fd, long long bytes)
{
desc = desc;
--
1.8.1.4
More information about the linux-mtd
mailing list