Hi,
the attached patch (against current git) adds device mapper map type
detection to parted. The gathered information is displayed within
parted. 
This way one can easily see if one is working on e.g. the multipath
device itself or a linear partition mapping of that device (same for
crypto, lvm, ...). It's also needed as a step towards fixing Debian Bug
#440675.
Please apply.
 -- Guido
>From 99941097c218b360a498d9e0a03a60dd3406ee42 Mon Sep 17 00:00:00 2001
From: Guido Guenther <[EMAIL PROTECTED]>
Date: Wed, 23 Apr 2008 15:13:50 +0200
Subject: [PATCH] linux device-mapper map type detection

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 c332cf8..b8e11c5 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 = NULL;
+        uint64_t start, length;
+        char *target_type = NULL;
+        char *params;
+        int r = -1;
+
+        if (!(dmt = 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 = dm_get_next_target(dmt, next, &start, &length,
+                                  &target_type, &params);
+
+        dev->dmtype = strdup(target_type);
+        if(dev->dmtype == NULL)
+                goto bad;
+        r = 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 = 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 == XVD_MAJOR && (dev_minor % 0x10 == 0)) {
                 dev->type = PED_DEVICE_XVD;
@@ -1106,6 +1146,7 @@ static PedDevice*
 linux_new (const char* path)
 {
         PedDevice*      dev;
+        char* type;
 
         PED_ASSERT (path != 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->dmtype) == -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)
         ped_free (dev->arch_specific);
         ped_free (dev->path);
         ped_free (dev->model);
+#ifdef ENABLE_DEVICE_MAPPER
+        ped_free (dev->dmtype);
+#endif
         ped_free (dev);
 }
 
-- 
1.5.5.1

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to