From patchwork Fri Mar 20 09:55:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe REYNES X-Patchwork-Id: 1258777 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=softathome.com Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48kK001Yf4z9sSR for ; Fri, 20 Mar 2020 20:55:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C083801D2; Fri, 20 Mar 2020 10:55:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 5153781286; Fri, 20 Mar 2020 10:55:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from vrout30.yaziba.net (vrout30.yaziba.net [185.56.204.33]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9916A800DF for ; Fri, 20 Mar 2020 10:55:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=philippe.reynes@softathome.com Received: from mtaout20.int.yaziba.net (mtaout20.int.yaziba.net [10.4.20.37]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by vrout30.yaziba.net (mx10.yaziba.net) with ESMTPS id E035251E66; Fri, 20 Mar 2020 10:55:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mtaout20.int.yaziba.net (Postfix) with ESMTP id ECB7E160413; Fri, 20 Mar 2020 10:55:13 +0100 (CET) Received: from mtaout20.int.yaziba.net ([127.0.0.1]) by localhost (mtaout20.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YF9qEDe0Opdi; Fri, 20 Mar 2020 10:55:13 +0100 (CET) Received: from sahnlpt0333.softathome.com (lfbn-idf3-1-1227-240.w92-170.abo.wanadoo.fr [92.170.165.240]) by mtaout20.int.yaziba.net (Postfix) with ESMTPSA id 937BD16032E; Fri, 20 Mar 2020 10:55:13 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, hs@denx.de, sr@denx.de, joe.hershberger@ni.com, wd@denx.de Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v2] cmd: ubi: add a command to rename volume Date: Fri, 20 Mar 2020 10:55:11 +0100 Message-Id: <1584698111-19384-1-git-send-email-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.7.4 X-CLAMAV-SCAN: ok X-VRSPAM-SCORE: 0 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeguddgtdelucetufdoteggodetrfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffosedttdertdertddtnecuhfhrohhmpefrhhhilhhiphhpvgcutfgvhihnvghsuceophhhihhlihhpphgvrdhrvgihnhgvshesshhofhhtrghthhhomhgvrdgtohhmqeenucfkphepledvrddujedtrdduieehrddvgedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhht X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean This commit add the command ubi rename to rename an ubi volume. The format of the command is: ubi rename . To enable this command, the option CMD_UBI_RENAME must be selected. Signed-off-by: Philippe Reynes --- cmd/Kconfig | 8 ++++++++ cmd/ubi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) Changelog: v2: - added an option CMD_UBI_RENAME (feedback from Wolfgang) diff --git a/cmd/Kconfig b/cmd/Kconfig index 6403bc4..1564694 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2172,6 +2172,14 @@ config CMD_UBI It is also strongly encouraged to also enable CONFIG_MTD to get full partition support. +config CMD_UBI_RENAME + bool "Enable rename" + depends on CMD_UBI + default n + help + Enable a "ubi" command to rename ubi volume: + ubi rename + config CMD_UBIFS tristate "Enable UBIFS - Unsorted block images filesystem commands" depends on CMD_UBI diff --git a/cmd/ubi.c b/cmd/ubi.c index cecf251..4885661 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -251,6 +251,41 @@ out_err: return err; } +#ifdef CONFIG_CMD_UBI_RENAME +static int ubi_rename_vol(char *oldname, char *newname) +{ + struct ubi_volume *vol; + struct ubi_rename_entry rename; + struct ubi_volume_desc desc; + struct list_head list; + + vol = ubi_find_volume(oldname); + if (!vol) { + printf("%s: volume %s doesn't exist\n", __func__, oldname); + return ENODEV; + } + + printf("Rename UBI volume %s to %s\n", oldname, newname); + + if (ubi->ro_mode) { + printf("%s: ubi device is in read-only mode\n", __func__); + return EROFS; + } + + rename.new_name_len = strlen(newname); + strcpy(rename.new_name, newname); + rename.remove = 0; + desc.vol = vol; + desc.mode = 0; + rename.desc = &desc; + INIT_LIST_HEAD(&rename.list); + INIT_LIST_HEAD(&list); + list_add(&rename.list, &list); + + return ubi_rename_volumes(ubi, &list); +} +#endif /* CONFIG_CMD_UBI_RENAME */ + static int ubi_volume_continue_write(char *volume, void *buf, size_t size) { int err = 1; @@ -604,6 +639,11 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return ubi_remove_vol(argv[2]); } +#ifdef CONFIG_CMD_UBI_RENAME + if (strncmp(argv[1], "rename", 6) == 0) + return ubi_rename_vol(argv[2], argv[3]); +#endif + if (strncmp(argv[1], "skipcheck", 9) == 0) { /* E.g., change skip_check flag */ if (argc == 4) { @@ -692,6 +732,9 @@ U_BOOT_CMD( " - Read volume to address with size\n" "ubi remove[vol] volume" " - Remove volume\n" +#ifdef CONFIG_CMD_UBI_RENAME + "ubi rename oldname newname\n" +#endif "ubi skipcheck volume on/off - Set or clear skip_check flag in volume header\n" "[Legends]\n" " volume: character name\n"