]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: don't use FAT as MBR
authorKarel Zak <kzak@redhat.com>
Wed, 17 Jul 2019 10:11:38 +0000 (12:11 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Jul 2019 10:11:38 +0000 (12:11 +0200)
The current libfdisk MBR detection is too weak, the result is that it
reuses MBR from FAT. The correct behavior is to create a new MBR, wipe
first sector (on write) and warn about obsolete FAT superblock.

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c
libfdisk/src/dos.c

index 770aa4d5203ec8f7f2199a12274a4957a0854686..bc284f34e2af21b31efd3e3c474473a536355822 100644 (file)
@@ -619,14 +619,20 @@ static int fdisk_assign_fd(struct fdisk_context *cxt, int fd,
        if (fdisk_read_firstsector(cxt) < 0)
                goto fail;
 
+       /* warn about obsolete stuff on the device if we aren't in list-only */
+       if (!fdisk_is_listonly(cxt) && fdisk_check_collisions(cxt) < 0)
+               goto fail;
+
        fdisk_probe_labels(cxt);
        fdisk_apply_label_device_properties(cxt);
 
-       /* warn about obsolete stuff on the device if we aren't in
-        * list-only mode and there is not PT yet */
-       if (!fdisk_is_listonly(cxt) && !fdisk_has_label(cxt)
-           && fdisk_check_collisions(cxt) < 0)
-               goto fail;
+       /* Don't report collision if there is already a valid partition table.
+        * The bootbits are wiped when we create a *new* partition table only. */
+       if (fdisk_is_ptcollision(cxt) && fdisk_has_label(cxt)) {
+               cxt->pt_collision = 0;
+               free(cxt->collision);
+               cxt->collision = NULL;
+       }
 
        DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]",
                              fname, readonly ? "READ-ONLY" : "READ-WRITE"));
index 6dc276e8a64dbe6bd728f70efe629508c93c5fd9..bd964db15987a4c0c54db56ca9f6d29f264466d4 100644 (file)
@@ -814,6 +814,10 @@ static int dos_probe_label(struct fdisk_context *cxt)
        if (!mbr_is_valid_magic(cxt->firstsector))
                return 0;
 
+       /* ignore disks with FAT */
+       if (cxt->collision && strcmp(cxt->collision, "vfat") == 0)
+               return 0;
+
        dos_init(cxt);
 
        get_partition_table_geometry(cxt, &h, &s);