]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: properly handle out-of-order partitions during resize
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 14 Nov 2023 16:53:29 +0000 (17:53 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 14 Nov 2023 20:55:36 +0000 (21:55 +0100)
Fixes #2580

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
disk-utils/cfdisk.c

index 9cf03464258a4bf7479a7f97468183345abe474a..11b7faef752843d391d62068a75b1deaa4813a67 100644 (file)
@@ -2458,18 +2458,17 @@ static int main_menu_action(struct cfdisk *cf, int key)
        }
        case 'r': /* resize */
        {
-               struct fdisk_partition *npa, *next;
                uint64_t size, max_size, secs;
+               struct fdisk_partition *npa;
 
                if (fdisk_partition_is_freespace(pa) || !fdisk_partition_has_start(pa))
                        return -EINVAL;
 
-               size = fdisk_partition_get_size(pa);
-
-               /* is the next freespace? */
-               next = fdisk_table_get_partition(cf->table, cf->lines_idx + 1);
-               if (next && fdisk_partition_is_freespace(next))
-                       size += fdisk_partition_get_size(next);
+               rc = fdisk_partition_get_max_size(cf->cxt,
+                                                 fdisk_partition_get_partno(pa),
+                                                 &size);
+               if (rc)
+                       return rc;
 
                size *= fdisk_get_sector_size(cf->cxt);
                max_size = size;