cmd: ubi: add a command to rename volume
PATCH v2 1/1 cmd: ubi: add a command to rename volume
This commit add the command ubi rename to rename an ubi volume. The format of the command is: ubi rename <oldname> <newname>. To enable this command, the option CMD_UBI_RENAME must be selected.
--- cmd/Kconfig | 8 ++++++++ cmd/ubi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
Changelog:
v2:
- added an option CMD_UBI_RENAME (feedback from Wolfgang)
cmd/Kconfig +8 -0
@@ -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 <oldname> <newname> + config CMD_UBIFS tristate "Enable UBIFS - Unsorted block images filesystem commands" depends on CMD_UBI
cmd/ubi.c +43 -0
61 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 1/1 cmd: ubi: add a command to rename volume
Hi Philippe,
Quoted 2 lines · Philippe Reynes
This commit add the command ubi rename to rename an ubi volume.
adds
Quoted 79 lines
The format of the command is: ubi rename <oldname> <newname>. To enable this command, the option
CMD_UBI_RENAMEmust be selected.Signed-off-by Philippe Reynes <[email protected]>--- cmd/Kconfig | 8 ++++++++ cmd/ubi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)Changelog:
v2:
- added an optionCMD_UBI_RENAME(feedback from Wolfgang)cmd/Kconfig +8
-0@@ -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 <oldname> <newname> + config CMD_UBIFS tristate "Enable UBIFS - Unsorted block images filesystem commands" depends on CMD_UBIcmd/ubi.c +35
-0@@ -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 ;
cmd/ubi.c static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 642
Quoted 4 lines
cmd/ubi.c +1
-0@@ -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
Can you use IS_ENABLED(CONFIG_...) and drop the #ifdef way above?
cmd/ubi.c static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 646
Quoted 4 lines
cmd/ubi.c +4
-0+if (strncmp (argv[1 ],"rename" ,6 ) ==0 ) +return ubi_rename_vol (argv[2 ], argv[3 ]); +#endif +
[..]
Regards,
Simon
PATCH v2 1/1 cmd: ubi: add a command to rename volume
Hi Simon,
Quoted 92 lines
Hi Philippe,
Quoted 2 lines · Philippe Reynes
This commit add the command ubi rename to rename an ubi volume.
adds
Quoted 83 lines
The format of the command is: ubi rename <oldname> <newname>. To enable this command, the option
CMD_UBI_RENAMEmust be selected.Signed-off-by Philippe Reynes <[email protected]>---
cmd/Kconfig | 8 ++++++++cmd/ubi.c| 43 +++++++++++++++++++++++++++++++++++++++++++2 files changed, 51 insertions(+)Changelog:
v2:
- added an optionCMD_UBI_RENAME(feedback from Wolfgang)cmd/Kconfig +0
-0@@ -2172,6 +2172,14 @@ config CMD_UBIIt is also strongly encouraged to also enable
CONFIG_MTDto get full partition support.cmd/Kconfig +8
-0+config CMD_UBI_RENAME + bool "Enable rename" + depends on CMD_UBI + default n + help + Enable a "ubi" command to rename ubi volume: + ubi rename <oldname> <newname> +config
CMD_UBIFS
tristate "Enable UBIFS - Unsorted block images filesystem commands" depends onCMD_UBIcmd/ubi.c +35
-0@@ -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 ]); }
Quoted 3 lines
cmd/ubi.c static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, · line 643
Quoted 1 line
cmd/ubi.c +1
-0+#ifdef CONFIG_CMD_UBI_RENAME Can you use
IS_ENABLED(CONFIG_...)and drop the #ifdef way above?
I've sent a v3 where I use IS_ENABLED instead of #ifdef.
But I've kept a #if IS_ENABLED(...) around the function ubi_rename_vol. Otherwise if this option is not enabled, there is a warning when building :
CC cmd/ubi.ocmd/ubi.c:254:12: warning: 'ubi_rename_vol' defined but not used [-Wunused-function]
static int ubi_rename_vol(char *oldname, char *newname)
^~~~~~~~~~~~~~
Quoted 8 lines
cmd/ubi.c static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 646
Quoted 4 lines
cmd/ubi.c +4
-0+if (strncmp (argv[1 ],"rename" ,6 ) ==0 ) +return ubi_rename_vol (argv[2 ], argv[3 ]); +#endif +[..]
Regards,
Simon
Regards,
Philippe
PATCH v2 1/1 cmd: ubi: add a command to rename volume
Quoted 4 lines · Philippe REYNES
Quoted 3 lines
Quoted 1 line
+#ifdef
CONFIG_CMD_UBI_RENAMECan you use
IS_ENABLED(CONFIG_...)and drop the #ifdef way above?
Quoted 8 lines
I've sent a v3 where I use
IS_ENABLEDinstead of #ifdef.
But I've kept a #ifIS_ENABLED(...)around the functionubi_rename_vol. Otherwise if this option is not enabled, there is a warning when building :CC
cmd/ubi.ocmd/ubi.c:254:12: warning: 'ubi_rename_vol' defined but not used [-Wunused-function]
static intubi_rename_vol(char *oldname, char *newname)^~~~~~~~~~~~~~
Use C
if (IS_ENABLED(CONFIG_...) && !strcmp(cmd, "rename"))
not cpp
#if IS_ENABLED(CONFIG_...)
if (!strcmp(cmd, "rename"))
That way the compiler sees ubi_rename_vol is used, but also knows that it is dead code that can be eliminated. Less ifdeffery (none, actually), and the code in ubi_rename_vol gets compile coverage regardless of configuration.
Rasmus
PATCH v2 1/1 cmd: ubi: add a command to rename volume
Hi Rasmus,
Quoted 22 lines · Philippe REYNES
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
+#ifdef
CONFIG_CMD_UBI_RENAMECan you use
IS_ENABLED(CONFIG_...)and drop the #ifdef way above?I've sent a v3 where I use
IS_ENABLEDinstead of #ifdef.
But I've kept a #ifIS_ENABLED(...)around the functionubi_rename_vol. Otherwise if this option is not enabled, there is a warning when building :Quoted 5 lines
CC
cmd/ubi.ocmd/ubi.c:254:12: warning: 'ubi_rename_vol' defined but not used [-Wunused-function]
static intubi_rename_vol(char *oldname, char *newname)^~~~~~~~~~~~~~Use C
if (
IS_ENABLED(CONFIG_...)&& !strcmp(cmd, "rename"))not cpp
Quoted 7 lines
#if
IS_ENABLED(CONFIG_...)
if (!strcmp(cmd, "rename"))That way the compiler sees
ubi_rename_volis used, but also knows that it is dead code that can be eliminated. Less ifdeffery (none, actually), and the code inubi_rename_volgets compile coverage regardless of configuration.
Thanks a lot for this explanation.
I have sent a v4. And it works as expected, without the #if ... before the function ubi_rename_vol, there isn't a warning if ubi rename is not enabled in the config.
Quoted 1 line
Rasmus
Regards,
Philippe