]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: cleanup warnings
authorKarel Zak <kzak@redhat.com>
Fri, 14 Jun 2013 13:17:45 +0000 (15:17 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:01 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdiskdoslabel.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h

index 6360d37ec76db6d0a796a05c9264a2968e68557c..ac7dbb3b4a68fe5fdbce0d3448882ca2b65be747 100644 (file)
@@ -151,57 +151,14 @@ void list_partition_types(struct fdisk_context *cxt)
        putchar('\n');
 }
 
-static int
-test_c(char **m, char *mesg) {
-       int val = 0;
-       if (!*m)
-               fprintf(stderr, _("You must set"));
-       else {
-               fprintf(stderr, " %s", *m);
-               val = 1;
-       }
-       *m = mesg;
-       return val;
-}
-
 int warn_geometry(struct fdisk_context *cxt)
 {
-       char *m = NULL;
-       int prev = 0;
-
-       if (fdisk_is_disklabel(cxt, SGI)) /* cannot set cylinders etc anyway */
-               return 0;
-       if (!cxt->geom.heads)
-               prev = test_c(&m, _("heads"));
-       if (!cxt->geom.sectors)
-               prev = test_c(&m, _("sectors"));
-       if (!cxt->geom.cylinders)
-               prev = test_c(&m, _("cylinders"));
-       if (!m)
-               return 0;
-       fprintf(stderr,
-               _("%s%s.\nYou can do this from the extra functions menu.\n"),
-               prev ? _(" and ") : " ", m);
-       return 1;
-}
-
-void warn_limits(struct fdisk_context *cxt)
-{
-       if (cxt->total_sectors > UINT_MAX && !nowarn) {
-               unsigned long long bytes = cxt->total_sectors * cxt->sector_size;
-               int giga = bytes / 1000000000;
-               int hectogiga = (giga + 50) / 100;
-
-               fprintf(stderr, _("\n"
-"WARNING: The size of this disk is %d.%d TB (%llu bytes).\n"
-"DOS partition table format can not be used on drives for volumes\n"
-"larger than (%llu bytes) for %ld-byte sectors. Use parted(1) and GUID \n"
-"partition table format (GPT).\n\n"),
-                       hectogiga / 10, hectogiga % 10,
-                       bytes,
-                       (sector_t ) UINT_MAX * cxt->sector_size,
-                       cxt->sector_size);
+       if (fdisk_missing_geometry(cxt)) {
+               fdisk_warnx(cxt, _("Incomplete geometry setting. You can do "
+                                  "this from the extra functions menu."));
+               return 1;
        }
+       return 1;
 }
 
 static void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
@@ -227,7 +184,7 @@ static void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
 
 static void delete_partition(struct fdisk_context *cxt, int partnum)
 {
-       if (partnum < 0 || warn_geometry(cxt))
+       if (partnum < 0)
                return;
 
        if (fdisk_delete_partition(cxt, partnum) != 0)
@@ -287,9 +244,7 @@ list_disk_geometry(struct fdisk_context *cxt) {
        }
        printf(_(", %llu sectors\n"), cxt->total_sectors);
 
-       if (is_dos_compatible(cxt)
-           || fdisk_is_disklabel(cxt, SUN)
-           || fdisk_is_disklabel(cxt, SGI))
+       if (fdisk_require_geometry(cxt))
                printf(_("Geometry: %d heads, %llu sectors/track, %llu cylinders\n"),
                       cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
 
@@ -327,9 +282,6 @@ static void list_table(struct fdisk_context *cxt, int xtra)
 
 static void verify(struct fdisk_context *cxt)
 {
-       if (warn_geometry(cxt))
-               return;
-
        fdisk_verify_disklabel(cxt);
 }
 
@@ -338,9 +290,6 @@ static void new_partition(struct fdisk_context *cxt)
        assert(cxt);
        assert(cxt->label);
 
-       if (warn_geometry(cxt))
-               return;
-
        fdisk_add_partition(cxt, NULL);
 }
 
index 361d599014df774a5f8594c5ac3f03e3968013f3..5660828f91b1cbef617d23cce958a4995a3b789b 100644 (file)
@@ -175,8 +175,23 @@ void dos_init(struct fdisk_context *cxt)
        }
 
        warn_geometry(cxt);
-       warn_limits(cxt);
        warn_alignment(cxt);
+
+       if (cxt->total_sectors > UINT_MAX && !nowarn) {
+               unsigned long long bytes = cxt->total_sectors * cxt->sector_size;
+               int giga = bytes / 1000000000;
+               int hectogiga = (giga + 50) / 100;
+
+               fdisk_warnx(cxt, _(
+                       "WARNING: The size of this disk is %d.%d TB (%llu bytes). "
+                       "DOS partition table format can not be used on drives for volumes "
+                       "larger than (%llu bytes) for %ld-byte sectors. Use parted(1) and GUID "
+                       "partition table format (GPT)."),
+                       hectogiga / 10, hectogiga % 10,
+                       bytes,
+                       (sector_t ) UINT_MAX * cxt->sector_size,
+                       cxt->sector_size);
+       }
 }
 
 static int dos_delete_partition(struct fdisk_context *cxt, size_t partnum)
@@ -1562,7 +1577,6 @@ struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt)
        lb->nparttypes = ARRAY_SIZE(dos_parttypes);
 
        lb->flags |= FDISK_LABEL_FL_ADDPART_NOPARTNO;
-       lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY;
 
        return lb;
 }
@@ -1579,6 +1593,8 @@ int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable)
                return -EINVAL;
 
        dos->compatible = enable;
+       if (enable)
+               lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY;
        return 0;
 }
 
index 6c90e993014655f0a7a30e2204a93adc2277b77c..32af51f88e8ec508f7edc2a773189d34066a0ff4 100644 (file)
@@ -80,6 +80,24 @@ int fdisk_write_disklabel(struct fdisk_context *cxt)
        return cxt->label->op->write(cxt);
 }
 
+int fdisk_require_geometry(struct fdisk_context *cxt)
+{
+       assert(cxt);
+       assert(cxt->label);
+
+       return cxt->label->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY ? 1 : 0;
+}
+
+int fdisk_missing_geometry(struct fdisk_context *cxt)
+{
+       assert(cxt);
+       assert(cxt->label);
+
+       return (fdisk_require_geometry(cxt) &&
+                   (!cxt->geom.heads || !cxt->geom.sectors
+                                     || !cxt->geom.cylinders));
+}
+
 /**
  * fdisk_verify_disklabel:
  * @cxt: fdisk context
@@ -94,6 +112,8 @@ int fdisk_verify_disklabel(struct fdisk_context *cxt)
                return -EINVAL;
        if (!cxt->label->op->verify)
                return -ENOSYS;
+       if (fdisk_missing_geometry(cxt))
+               return -EINVAL;
 
        return cxt->label->op->verify(cxt);
 }
@@ -137,6 +157,8 @@ int fdisk_add_partition(struct fdisk_context *cxt,
                return -EINVAL;
        if (!cxt->label->op->part_add)
                return -ENOSYS;
+       if (fdisk_missing_geometry(cxt))
+               return -EINVAL;
 
        if (!(cxt->label->flags & FDISK_LABEL_FL_ADDPART_NOPARTNO)) {
                int rc = fdisk_ask_partnum(cxt, &partnum, 1);
index bd3fc60dfcecb282d34aee9f1f9c6a01f4ea3862..aec9ecacdd41ccdd3ef792e898cae5d243ede3b6 100644 (file)
@@ -111,6 +111,9 @@ extern size_t fdisk_get_nparttypes(struct fdisk_context *cxt);
 extern int fdisk_is_parttype_string(struct fdisk_context *cxt);
 
 /* label.c */
+extern int fdisk_require_geometry(struct fdisk_context *cxt);
+extern int fdisk_missing_geometry(struct fdisk_context *cxt);
+
 extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
 
 extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l);