From: Karel Zak Date: Fri, 14 Jun 2013 13:17:45 +0000 (+0200) Subject: fdisk: cleanup warnings X-Git-Tag: v2.24-rc1~181 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b52b94c3e383234645301717dc4731cee1528de;p=thirdparty%2Futil-linux.git fdisk: cleanup warnings Signed-off-by: Karel Zak --- diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index 6360d37ec7..ac7dbb3b4a 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -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); } diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 361d599014..5660828f91 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -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; } diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 6c90e99301..32af51f88e 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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); diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index bd3fc60dfc..aec9ecacdd 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -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);