[PATCH] ubi-utils: ubirsvol: resize volume using all available free space

Zhihao Cheng chengzhihao1 at huawei.com
Sun May 25 19:42:33 PDT 2025


在 2025/5/25 1:26, KAMenyaev at salutedevices.com 写道:
> From: Konstantin Menyaev <KAMenyaev at salutedevices.com>
> 
> useful in resizing last ubi volume,
> some kind of auto-resize ubinize option.
> 
> Signed-off-by: Konstantin Menyaev <KAMenyaev at salutedevices.com>
> ---
>   ubi-utils/ubirsvol.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/ubi-utils/ubirsvol.c b/ubi-utils/ubirsvol.c
> index 73d2f68..55f6794 100644
> --- a/ubi-utils/ubirsvol.c
> +++ b/ubi-utils/ubirsvol.c
> @@ -57,8 +57,10 @@ static const char optionsstr[] =
>   "-N, --name=<volume name>   volume name to resize\n"
>   "-s, --size=<bytes>         volume size volume size in bytes, kilobytes (KiB)\n"
>   "                           or megabytes (MiB)\n"
> +"                           zero size means use all available free bytes\n"
>   "-S, --lebs=<LEBs count>    alternative way to give volume size in logical\n"
>   "                           eraseblocks\n"
> +"                           zero size means use all available free LEBs\n"
>   "-h, -?, --help             print help message\n"
>   "-V, --version              print program version";
>   
> @@ -114,13 +116,13 @@ static int parse_opt(int argc, char * const argv[])
>   		switch (key) {
>   		case 's':
>   			args.bytes = util_get_bytes(optarg);
> -			if (args.bytes <= 0)
> +			if (args.bytes < 0)
>   				return errmsg("bad volume size: \"%s\"", optarg);
>   			break;
>   
>   		case 'S':
>   			args.lebs = simple_strtoull(optarg, &error);
> -			if (error || args.lebs <= 0)
> +			if (error || args.lebs < 0)
>   				return errmsg("bad LEB count: \"%s\"", optarg);
>   			break;
>   
> @@ -233,6 +235,9 @@ int main(int argc, char * const argv[])
>   	if (args.lebs != -1)
>   		args.bytes = (long long)vol_info.leb_size * args.lebs;
>   
> +	if (args.lebs == 0 || args.bytes == 0)
> +		args.bytes = vol_info.rsvd_bytes + dev_info.avail_bytes;
> +

The condition 'if (args.bytes == 0)' is enough. Anyway

Reviewed-by: Zhihao Cheng <chengzhihao1 at huawei.com>
>   	err = ubi_rsvol(libubi, args.node, args.vol_id, args.bytes);
>   	if (err) {
>   		sys_errmsg("cannot UBI resize volume");
> 




More information about the linux-mtd mailing list