aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2021-06-25 12:58:51 +0200
committerKarel Zak <kzak@redhat.com>2021-06-25 12:58:51 +0200
commit5efc31f9d8c7c95a2895e8d10052be11a66ec569 (patch)
tree2afb3461e75e2717a385cea4e346f0e662fb6209
parent35a9b0d5772efb815e3a0ff04f21a7afd0bcdd8f (diff)
downloadutil-linux-5efc31f9d8c7c95a2895e8d10052be11a66ec569.tar.gz
cfdisk: optimize mountpoint detection for PARTUUID
Don't check fstab (and udev symplinks) for new UUIDs. Fixes: https://github.com/karelzak/util-linux/issues/1331 Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--disk-utils/cfdisk.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index d7a9a4e3dc..c1b28889f6 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1331,6 +1331,25 @@ static inline int iszero(const char *str)
return !p || *p == '\0';
}
+static int has_uuid(struct fdisk_table *tb, const char *uuid)
+{
+ struct fdisk_partition *pa;
+ struct fdisk_iter *itr;
+ int rc = 0;
+
+ if (!tb || !uuid || fdisk_table_is_empty(tb))
+ return 0;
+
+ itr = fdisk_new_iter(FDISK_ITER_FORWARD);
+ while (rc == 0 && fdisk_table_next_partition(tb, itr, &pa) == 0) {
+ const char *x = fdisk_partition_get_uuid(pa);
+ if (x)
+ rc = strcmp(x, uuid) == 0;
+ }
+ fdisk_free_iter(itr);
+ return rc;
+}
+
static void extra_prepare_data(struct cfdisk *cf)
{
struct fdisk_partition *pa = get_current_partition(cf);
@@ -1350,7 +1369,14 @@ static void extra_prepare_data(struct cfdisk *cf)
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_UUID, &data) && data) {
extra_insert_pair(l, _("Partition UUID:"), data);
- if (!mountpoint)
+
+ /* Search for mountpoint by PARTUUID= means that we need to
+ * check fstab and convert PARTUUID to the device name. This is
+ * unnecessary and overkill for newly created partitions. Let's
+ * check if the UUID already exist in the old layout, otherwise
+ * ignore it.
+ */
+ if (!mountpoint && has_uuid(cf->original_layout, data))
mountpoint = get_mountpoint(cf, "PARTUUID", data);
free(data);
}