]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) support partition and MBR overlap
authorKarel Zak <kzak@redhat.com>
Tue, 27 Jul 2021 09:40:32 +0000 (11:40 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Jul 2021 09:40:32 +0000 (11:40 +0200)
Let's support this crazy use-case in expert menu, because it's normal
for removable FAT disks, etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 10a9984b0fece8fbc906954c2a85bee8fa7dfc1c..2e89c01c73953c099da48d3424564577422783fc 100644 (file)
@@ -2615,10 +2615,11 @@ int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i)
                return 0;
        }
 
-       /* the default start is at the second sector of the disk or at the
-        * second sector of the extended partition
+       /* The safe start is at the second sector, but some use-cases require
+        * to have MBR within the first partition , so default to the first
+        * sector of the disk or at the second sector of the extended partition
         */
-       free_start = pe->offset ? pe->offset + 1 : 1;
+       free_start = pe->offset ? pe->offset + 1 : 0;
 
        curr_start = get_abs_partition_start(pe);
 
@@ -2658,6 +2659,11 @@ int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i)
                dos_partition_set_start(p, new);
 
                partition_set_changed(cxt, i, 1);
+
+               if (new == 0)
+                       fdisk_info(cxt, _("The new beginning of the partition overlaps the disk "
+                                         "label area. Be very careful when using the partition. "
+                                         "You can lose all your partitions on the disk."));
        }
 
        return rc;