]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) add extra check for First/Last LBA
authorKarel Zak <kzak@redhat.com>
Thu, 23 Apr 2015 10:32:36 +0000 (12:32 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Apr 2015 10:32:36 +0000 (12:32 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.c
libfdisk/src/gpt.c

index 67fa1d18f3c914e32dc40a9da8aeb2109d63a15e..9daf98cc39f60da21302adadd7853c9b68c56c25 100644 (file)
@@ -1216,7 +1216,8 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
                if (!sf->quiet)
                        fputs(_("Checking that no-one is using this disk right now ..."), stdout);
                if (is_device_used(sf)) {
-                       fputs(_(" FAILED\n\n"), stdout);
+                       if (!sf->quiet)
+                               fputs(_(" FAILED\n\n"), stdout);
 
                        fdisk_warnx(sf->cxt, _(
                        "This disk is currently in use - repartitioning is probably a bad idea.\n"
@@ -1225,7 +1226,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
 
                        if (!sf->force)
                                errx(EXIT_FAILURE, _("Use the --force flag to overrule all checks."));
-               } else
+               } else if (!sf->quiet)
                        fputs(_(" OK\n\n"), stdout);
        }
 
index fd49c1349b4dc8acc10b47e492f3ec4a906ec649..a7766da60478c9f4bb5dc9c7a13ea62b79f25c98 100644 (file)
@@ -2182,6 +2182,21 @@ static int gpt_add_partition(
                goto done;
        }
 
+       /* Be paranoid and check agains on-disk setting rather than against libfdisk cxt */
+       if (user_l > le64_to_cpu(pheader->last_usable_lba)) {
+               fdisk_warnx(cxt, _("The last usable GPT sector is %ju, but %ju is requested."),
+                               le64_to_cpu(pheader->last_usable_lba), user_l);
+               rc = -EINVAL;
+               goto done;
+       }
+
+       if (user_f < le64_to_cpu(pheader->first_usable_lba)) {
+               fdisk_warnx(cxt, _("The first usable GPT sector is %ju, but %ju is requested."),
+                               le64_to_cpu(pheader->first_usable_lba), user_f);
+               rc = -EINVAL;
+               goto done;
+       }
+
        assert(!FDISK_IS_UNDEF(user_l));
        assert(!FDISK_IS_UNDEF(user_f));