[PATCH] linux device-mapper map type detection
Guido Guenther
agx at sigxcpu.org
Wed Apr 23 13:13:50 UTC 2008
detect the type of the device map and add it to the displayed type
information
---
include/parted/device.h | 3 ++
libparted/arch/linux.c | 48 +++++++++++++++++++++++++++++++++++++++++++=
+++-
2 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/include/parted/device.h b/include/parted/device.h
index 2a9679f..64b4a0a 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -72,6 +72,9 @@ struct _PedDevice {
PedDeviceType type; /**< SCSI, IDE, etc.
\deprecated \sa PedDeviceType=
*/
+#ifdef ENABLE_DEVICE_MAPPER
+ char* dmtype; /**< device map target type */
+#endif
long long sector_size; /**< logical sector size */
long long phys_sector_size; /**< physical sector size =
*/
PedSector length; /**< device length (LBA) */
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 4195c6a..7f9614b 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -302,6 +302,39 @@ _is_sx8_major (int major)
#ifdef ENABLE_DEVICE_MAPPER
static int
+_dm_maptype (PedDevice* dev)
+{
+ struct dm_task *dmt;
+ void *next =3D NULL;
+ uint64_t start, length;
+ char *target_type =3D NULL;
+ char *params;
+ int r =3D -1;
+
+ if (!(dmt =3D dm_task_create(DM_DEVICE_TABLE)))
+ return r;
+
+ if (!dm_task_set_name(dmt, dev->path))
+ goto bad;
+
+ dm_task_no_open_count(dmt);
+
+ if (!dm_task_run(dmt))
+ goto bad;
+
+ next =3D dm_get_next_target(dmt, next, &start, &length,
+ &target_type, ¶ms);
+
+ dev->dmtype =3D strdup(target_type);
+ if(dev->dmtype =3D=3D NULL)
+ goto bad;
+ r =3D 0;
+bad:
+ dm_task_destroy(dmt);
+ return r;
+}
+
+static int
readFD (int fd, char **buf)
{
char* p;
@@ -489,6 +522,13 @@ _device_probe_type (PedDevice* dev)
#ifdef ENABLE_DEVICE_MAPPER
} else if (_is_dm_major(dev_major)) {
dev->type =3D PED_DEVICE_DM;
+ if (_dm_maptype(dev)) {
+ ped_exception_throw (
+ PED_EXCEPTION_BUG,
+ PED_EXCEPTION_CANCEL,
+ _("Unable to determine the dm type of %s."=
),
+ dev->path);
+ }
#endif
} else if (dev_major =3D=3D XVD_MAJOR && (dev_minor % 0x10 =3D=3D =
0)) {
dev->type =3D PED_DEVICE_XVD;
@@ -1106,6 +1146,7 @@ static PedDevice*
linux_new (const char* path)
{
PedDevice* dev;
+ char* type;
PED_ASSERT (path !=3D NULL, return NULL);
@@ -1189,7 +1230,9 @@ linux_new (const char* path)
#ifdef ENABLE_DEVICE_MAPPER
case PED_DEVICE_DM:
- if (!init_generic (dev, _("Linux device-mapper")))
+ if (asprintf(&type, _("Linux device-mapper (%s)"), dev->dm=
type) =3D=3D -1)
+ goto error_free_arch_specific;
+ if (!init_generic (dev, type))
goto error_free_arch_specific;
break;
#endif
@@ -1228,6 +1271,9 @@ linux_destroy (PedDevice* dev)
free (dev->arch_specific);
free (dev->path);
free (dev->model);
+#ifdef ENABLE_DEVICE_MAPPER
+ free (dev->dmtype);
+#endif
free (dev);
}
--
1.5.6.rc0.30.g7c3f3
More information about the parted-devel
mailing list