diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index 83e81719d..c5734e33f 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -1523,6 +1523,39 @@ static const char *_sanitise_message(char *message) return sanitised_message; } +static void _do_dm_ioctl_unmangle_name(char *name) +{ + char buf[DM_NAME_LEN]; + int r; + + if ((r = unmangle_name(name, DM_NAME_LEN, buf, sizeof(buf), + dm_get_name_mangling_mode())) < 0) + log_debug("_do_dm_ioctl_unmangle_name: failed to " + "unmangle \"%s\"", name); + else if (r) + memcpy(name, buf, strlen(buf) + 1); +} + +static void _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi) +{ + struct dm_names *names; + unsigned next = 0; + char *name; + + if ((name = dmi->name)) + _do_dm_ioctl_unmangle_name(name); + + if (type == DM_DEVICE_LIST && + ((names = ((struct dm_names *) ((char *)dmi + dmi->data_start)))) && + names->dev) { + do { + names = (struct dm_names *)((char *) names + next); + _do_dm_ioctl_unmangle_name(names->name); + next = names->next; + } while (next); + } +} + static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command, unsigned buffer_repeat_count, unsigned retry_repeat_count, @@ -1651,6 +1684,8 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command, _udev_complete(dmt); } + (void) _dm_ioctl_unmangle_names(dmt->type, dmi); + #else /* Userspace alternative for testing */ #endif return dmi; diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index a6220b8e1..e9f84ea4f 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -164,13 +164,22 @@ struct dm_versions { int dm_get_library_version(char *version, size_t size); int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size); int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); -const char *dm_task_get_name(const struct dm_task *dmt); const char *dm_task_get_uuid(const struct dm_task *dmt); struct dm_deps *dm_task_get_deps(struct dm_task *dmt); -struct dm_names *dm_task_get_names(struct dm_task *dmt); struct dm_versions *dm_task_get_versions(struct dm_task *dmt); +/* + * These functions return device-mapper names based on the value + * of the mangling mode set during preceding dm_task_run call: + * - unmangled name for DM_STRING_MANGLING_{AUTO, HEX}, + * - name without any changes for DM_STRING_MANGLING_NONE. + * + * To get mangled or unmangled form of the name directly, use + * dm_task_get_name_mangled or dm_task_get_name_unmangled function. + */ +const char *dm_task_get_name(const struct dm_task *dmt); +struct dm_names *dm_task_get_names(struct dm_task *dmt); int dm_task_set_ro(struct dm_task *dmt); int dm_task_set_newname(struct dm_task *dmt, const char *newname);