]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) be more explicit in fdisk_verify_disklabel() output
authorKarel Zak <kzak@redhat.com>
Wed, 27 May 2020 15:46:49 +0000 (17:46 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 27 May 2020 15:49:26 +0000 (17:49 +0200)
Let's print number of detected errors or "No errors detected." for
MBR. We already use the same for GPT.

The patch also modifies fdisk_verify_disklabel() return code to inform
caller about number of issues.

Addresses: https://github.com/karelzak/util-linux/issues/1051
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c
libfdisk/src/gpt.c
libfdisk/src/label.c

index bc7477b8e63f12e3d905cd640f7004759e474e50..176969883547abfa10f7ed8e2ce9c14abdcf56fd 100644 (file)
@@ -1628,6 +1628,7 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
                       last[cxt->label->nparts_max];
        struct dos_partition *p;
        struct fdisk_dos_label *l = self_label(cxt);
+       int nerrors = 0;
 
        assert(fdisk_is_label(cxt, DOS));
 
@@ -1639,10 +1640,12 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
                if (p && is_used_partition(p) && !IS_EXTENDED(p->sys_ind)) {
                        check_consistency(cxt, p, i);
                        assert(pe);
-                       if (get_abs_partition_start(pe) < first[i])
+                       if (get_abs_partition_start(pe) < first[i]) {
                                fdisk_warnx(cxt, _(
                                        "Partition %zu: bad start-of-data."),
                                         i + 1);
+                               nerrors++;
+                       }
 
                        check(cxt, i + 1, p->eh, p->es, p->ec, last[i]);
                        total += last[i] + 1 - first[i];
@@ -1657,6 +1660,7 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
                                        fdisk_warnx(cxt, _("Partition %zu: "
                                                "overlaps partition %zu."),
                                                j + 1, i + 1);
+                                       nerrors++;
 
                                        total += first[i] >= first[j] ?
                                                first[i] : first[j];
@@ -1680,28 +1684,37 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
                        assert(p);
 
                        if (!p->sys_ind) {
-                               if (i != 4 || i + 1 < cxt->label->nparts_max)
+                               if (i != 4 || i + 1 < cxt->label->nparts_max) {
                                        fdisk_warnx(cxt,
                                                _("Partition %zu: empty."),
                                                i + 1);
+                                       nerrors++;
+                               }
                        } else if (first[i] < l->ext_offset
                                   || last[i] > e_last) {
 
                                fdisk_warnx(cxt, _("Logical partition %zu: "
                                        "not entirely in partition %zu."),
                                        i + 1, l->ext_index + 1);
+                               nerrors++;
                        }
                }
        }
 
-       if (total > n_sectors)
-               fdisk_warnx(cxt, _("Total allocated sectors %llu greater "
-                       "than the maximum %llu."), total, n_sectors);
-       else if (total < n_sectors)
-               fdisk_warnx(cxt, _("Remaining %lld unallocated %ld-byte "
-                       "sectors."), n_sectors - total, cxt->sector_size);
+       if (!nerrors) {
+               fdisk_info(cxt, _("No errors detected."));
+               if (total > n_sectors)
+                       fdisk_info(cxt, _("Total allocated sectors %llu greater "
+                               "than the maximum %llu."), total, n_sectors);
+               else if (total < n_sectors)
+                       fdisk_info(cxt, _("Remaining %lld unallocated %ld-byte "
+                               "sectors."), n_sectors - total, cxt->sector_size);
+       } else
+               fdisk_warnx(cxt,
+                       P_("%d error detected.", "%d errors detected.", nerrors),
+                       nerrors);
 
-       return 0;
+       return nerrors;
 }
 
 /*
index 25555a3958ceda369589010fa619495cb9ae7cf5..233bf8aa70d4a6329b6a0a92fac266c4b2c473d9 100644 (file)
@@ -2229,7 +2229,7 @@ static int gpt_verify_disklabel(struct fdisk_context *cxt)
                        P_("%d error detected.", "%d errors detected.", nerror),
                        nerror);
 
-       return 0;
+       return nerror;
 }
 
 /* Delete a single GPT partition, specified by partnum. */
index 8e428daed1cee1ed98138073da80db6d6e415c13..186df4880db3ed1fc7169281d4d143c8120ab2cf 100644 (file)
@@ -269,7 +269,7 @@ int fdisk_write_disklabel(struct fdisk_context *cxt)
  *
  * Verifies the partition table.
  *
- * Returns: 0 on success, otherwise, a corresponding error.
+ * Returns: 0 on success, <1 runtime or option errors, >0 number of detected issues
  */
 int fdisk_verify_disklabel(struct fdisk_context *cxt)
 {