aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2016-10-04 15:02:00 +0200
committerKarel Zak <kzak@redhat.com>2016-10-04 15:02:00 +0200
commitcf9b302d461fedb9b653a82eaa367da35547be07 (patch)
treee85acbde8ce3e243bcfb55af3950acd54fdf7636
parent23f75093264aae5d58d61016cb1a29d8ebdfa157 (diff)
downloadutil-linux-cf9b302d461fedb9b653a82eaa367da35547be07.tar.gz
cfdisk: fix mountpoint detection
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--disk-utils/cfdisk.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 495741fe35..5e70a234b5 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1201,16 +1201,24 @@ inline static int extra_insert_pair(struct cfdisk_line *l, const char *name, con
return rc;
}
-#ifdef HAVE_LIBMOUNT
-static char *get_mountpoint(struct cfdisk *cf, const char *uuid, const char *label)
+#ifndef HAVE_LIBMOUNT
+static char *get_mountpoint( struct cfdisk *cf __attribute__((unused)),
+ const char *tagname __attribute__((unused)),
+ const char *tagdata __attribute__((unused)))
+{
+ return NULL;
+}
+#else
+static char *get_mountpoint(struct cfdisk *cf, const char *tagname, const char *tagdata)
{
struct libmnt_fs *fs = NULL;
char *target = NULL;
int mounted = 0;
- assert(uuid || label);
+ assert(tagname);
+ assert(tagdata);
- DBG(UI, ul_debug("asking for mountpoint [uuid=%s, label=%s]", uuid, label));
+ DBG(UI, ul_debug("asking for mountpoint [%s=%s]", tagname, tagdata));
if (!cf->mntcache)
cf->mntcache = mnt_new_cache();
@@ -1225,9 +1233,7 @@ static char *get_mountpoint(struct cfdisk *cf, const char *uuid, const char *lab
}
if (cf->mtab)
- fs = mnt_table_find_tag(cf->mtab,
- uuid ? "UUID" : "LABEL",
- uuid ? : label, MNT_ITER_FORWARD);
+ fs = mnt_table_find_tag(cf->mtab, tagname, tagdata, MNT_ITER_FORWARD);
/* 2nd try fstab */
if (!fs) {
@@ -1239,9 +1245,7 @@ static char *get_mountpoint(struct cfdisk *cf, const char *uuid, const char *lab
}
}
if (cf->fstab)
- fs = mnt_table_find_tag(cf->fstab,
- uuid ? "UUID" : "LABEL",
- uuid ? : label, MNT_ITER_FORWARD);
+ fs = mnt_table_find_tag(cf->fstab, tagname, tagdata, MNT_ITER_FORWARD);
} else
mounted = 1;
@@ -1261,18 +1265,22 @@ static void extra_prepare_data(struct cfdisk *cf)
struct fdisk_partition *pa = get_current_partition(cf);
struct cfdisk_line *l = &cf->lines[cf->lines_idx];
char *data = NULL;
- char *devuuid = NULL, *devlabel = NULL;
+ char *mountpoint = NULL;
DBG(UI, ul_debug("preparing extra data"));
/* string data should not equal an empty string */
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_NAME, &data) && data) {
extra_insert_pair(l, _("Partition name:"), data);
+ if (!mountpoint)
+ mountpoint = get_mountpoint(cf, "PARTLABEL", data);
free(data);
}
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_UUID, &data) && data) {
extra_insert_pair(l, _("Partition UUID:"), data);
+ if (!mountpoint)
+ mountpoint = get_mountpoint(cf, "PARTUUID", data);
free(data);
}
@@ -1314,11 +1322,15 @@ static void extra_prepare_data(struct cfdisk *cf)
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSUUID, &data) && data) {
extra_insert_pair(l, _("Filesystem UUID:"), data);
+ if (!mountpoint)
+ mountpoint = get_mountpoint(cf, "UUID", data);
free(data);
}
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSLABEL, &data) && data) {
extra_insert_pair(l, _("Filesystem LABEL:"), data);
+ if (!mountpoint)
+ mountpoint = get_mountpoint(cf, "LABEL", data);
free(data);
}
if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSTYPE, &data) && data) {
@@ -1326,17 +1338,10 @@ static void extra_prepare_data(struct cfdisk *cf)
free(data);
}
-#ifdef HAVE_LIBMOUNT
- if (devuuid || devlabel) {
- data = get_mountpoint(cf, devuuid, devlabel);
- if (data) {
- extra_insert_pair(l, _("Mountpoint:"), data);
- free(data);
- }
+ if (mountpoint) {
+ extra_insert_pair(l, _("Mountpoint:"), mountpoint);
+ free(mountpoint);
}
-#endif /* HAVE_LIBMOUNT */
- free(devlabel);
- free(devuuid);
}
static int ui_draw_extra(struct cfdisk *cf)