]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: ubirsvol: resize volume using all available free space
authorKonstantin Menyaev <KAMenyaev@salutedevices.com>
Sat, 24 May 2025 17:26:39 +0000 (20:26 +0300)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 2 Jun 2025 05:25:34 +0000 (07:25 +0200)
useful in resizing last ubi volume,
some kind of auto-resize ubinize option.

Signed-off-by: Konstantin Menyaev <KAMenyaev@salutedevices.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubi-utils/ubirsvol.c

index 73d2f68710025e15732441f6076c981cad6d7703..55f67944ff1701cc72c3b3ff1e78172baf08b380 100644 (file)
@@ -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;
+
        err = ubi_rsvol(libubi, args.node, args.vol_id, args.bytes);
        if (err) {
                sys_errmsg("cannot UBI resize volume");