From patchwork Tue Jul 29 09:35:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hujianyang X-Patchwork-Id: 374383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 59E551400DD for ; Tue, 29 Jul 2014 19:38:00 +1000 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XC3pn-00027f-TA; Tue, 29 Jul 2014 09:36:39 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XC3pj-0001zT-Pu for linux-mtd@lists.infradead.org; Tue, 29 Jul 2014 09:36:38 +0000 Received: from 172.24.2.119 (EHLO szxeml412-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXH52992; Tue, 29 Jul 2014 17:35:28 +0800 (CST) Received: from [127.0.0.1] (10.111.68.144) by szxeml412-hub.china.huawei.com (10.82.67.91) with Microsoft SMTP Server id 14.3.158.1; Tue, 29 Jul 2014 17:35:17 +0800 Message-ID: <53D76AD4.1010206@huawei.com> Date: Tue, 29 Jul 2014 17:35:16 +0800 From: hujianyang User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: linux-mtd Subject: [PATCH 2/5] ubi-utils: Enable lnum2pnum ioctl in userspace References: <53D7677A.6000905@huawei.com> In-Reply-To: <53D7677A.6000905@huawei.com> X-Originating-IP: [10.111.68.144] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140729_023636_174039_03D8901A X-CRM114-Status: GOOD ( 11.72 ) X-Spam-Score: -1.4 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [119.145.14.65 listed in list.dnswl.org] -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Bill Pringlemeir , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Introduce ubi_lnum_to_pnum() to translate lnum into pnum by the a new ioctl. Signed-off-by: hujianyang --- 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;