@@ -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__ */
@@ -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
@@ -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;
Introduce ubi_lnum_to_pnum() to translate lnum into pnum by the a new ioctl. Signed-off-by: hujianyang <hujianyang@huawei.com> --- include/mtd/ubi-user.h | 12 ++++++++++++ ubi-utils/include/libubi.h | 11 +++++++++++ ubi-utils/libubi.c | 12 ++++++++++++ 3 files changed, 35 insertions(+)