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>
This commit is contained in:
Karel Zak 2021-06-25 12:58:51 +02:00
parent 35a9b0d577
commit 5efc31f9d8
1 changed files with 27 additions and 1 deletions

View File

@ -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);
}