From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-in-15.arcor-online.net ([151.189.21.55]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnMSv-000716-1w for barebox@lists.infradead.org; Fri, 23 Sep 2016 09:08:18 +0000 Received: from mail-in-15-z2.arcor-online.net (mail-in-15-z2.arcor-online.net [151.189.8.32]) by mx.arcor.de (Postfix) with ESMTP id 3sgSF62f2XzC18d for ; Fri, 23 Sep 2016 11:07:54 +0200 (CEST) From: Giorgio Dal Molin Date: Fri, 23 Sep 2016 11:07:39 +0200 Message-Id: <20160923090739.25517-3-iw3gtf@arcor.de> In-Reply-To: <20160923090739.25517-1-iw3gtf@arcor.de> References: <20160923090739.25517-1-iw3gtf@arcor.de> In-Reply-To: <20160922080408.rpqeithibjfga2rm@pengutronix.de> References: <20160922080408.rpqeithibjfga2rm@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 2/2] mtd: ubi: commands: added the new command 'ubirename'. To: barebox@lists.infradead.org Cc: Giorgio Dal Molin Signed-off-by: Giorgio Dal Molin --- commands/ubi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/commands/ubi.c b/commands/ubi.c index 7c55195..3c5729e 100644 --- a/commands/ubi.c +++ b/commands/ubi.c @@ -328,3 +328,74 @@ BAREBOX_CMD_START(ubirmvol) BAREBOX_CMD_GROUP(CMD_GRP_PART) BAREBOX_CMD_HELP(cmd_ubirmvol_help) BAREBOX_CMD_END + +static int get_vol_id(u32 ubi_num, const char *name) +{ + struct ubi_volume_desc *desc; + struct ubi_volume_info vi; + + desc = ubi_open_volume_nm(ubi_num, name, UBI_READONLY); + if(IS_ERR(desc)) + return PTR_ERR(desc); + + ubi_get_volume_info(desc, &vi); + + return vi.vol_id; +}; + +static int do_ubirename(int argc, char *argv[]) +{ + struct ubi_rnvol_req req; + u32 ubi_num; + int i, j, fd, ret; + + if ((argc < 4) || (argc % 2)) + return COMMAND_ERROR_USAGE; + + req.count = (argc / 2) - 1; + if (req.count > UBI_MAX_RNVOL) { + printf("too many volume renames. (max: %u)\n", UBI_MAX_RNVOL); + return COMMAND_ERROR_USAGE; + } + + fd = open(argv[1], O_WRONLY); + if (fd < 0) { + perror("open ubi dev"); + return 1; + } + + ret = ioctl(fd, UBI_IOCGETUBINUM, &ubi_num); + if (ret) { + perror("failed to get the ubi num"); + return COMMAND_ERROR_USAGE; + } + close(fd); + + for(i=2, j=0; i