I've attached a new lvm/dm dpatch which has been updated for parted 1.7.1.

Regards,
David
#! /bin/sh -e
## lvm2.dpatch by Andres Salomon <[EMAIL PROTECTED]>
##
## DP: Find LVM2 devices by looking in /dev/mapper
## DP: Closes: #247174
## DP: Upstream objected to merging, will stay debian specific for now.
## DP: Patch generalized by David Härdeman <[EMAIL PROTECTED]>
## DP: Now covers all types of device-mapper devices (dm-crypt, lvm, etc)
## DP: Refreshed for 1.7.1

. `dirname $0`/DPATCH

@DPATCH@
diff -urNad parted-1.7.1~/include/parted/device.h 
parted-1.7.1/include/parted/device.h
--- parted-1.7.1~/include/parted/device.h       2006-05-25 19:28:43.000000000 
+0200
+++ parted-1.7.1/include/parted/device.h        2006-05-31 21:48:03.000000000 
+0200
@@ -42,7 +42,8 @@
         PED_DEVICE_FILE         = 5,
         PED_DEVICE_ATARAID      = 6,
         PED_DEVICE_I2O          = 7,
-        PED_DEVICE_UBD          = 8
+        PED_DEVICE_UBD          = 8,
+        PED_DEVICE_DM           = 9
 } PedDeviceType;
 
 typedef struct _PedDevice PedDevice;
diff -urNad parted-1.7.1~/libparted/arch/linux.c 
parted-1.7.1/libparted/arch/linux.c
--- parted-1.7.1~/libparted/arch/linux.c        2006-05-08 20:08:37.000000000 
+0200
+++ parted-1.7.1/libparted/arch/linux.c 2006-05-31 22:05:20.000000000 +0200
@@ -270,6 +270,37 @@
 }
 
 static int
+_is_dm_major (int major)
+{
+       FILE*           proc_devices;
+       static int      dm_major = 0;
+       int             tmp_major;
+       char            buf [512];
+       char            dev_name [32];
+
+       if (!dm_major) {
+               /* Obtain the major number for lvm devices; this is listed in
+                * /proc/devices, under the device-mapper entry.
+                */
+
+               proc_devices = fopen ("/proc/devices", "r");
+               if (!proc_devices)
+                       return 0;
+
+               while (fgets (buf, 512, proc_devices)) {
+                       if (sscanf (buf, "%d %31s", &tmp_major, dev_name) == 2 
&&
+                           strcmp (dev_name, "device-mapper") == 0) {
+                               dm_major = tmp_major;
+                               break;
+                       }
+               }
+               fclose (proc_devices);
+       }
+
+       return major == dm_major;
+}
+
+static int
 _device_stat (PedDevice* dev, struct stat * dev_stat)
 {
         PED_ASSERT (dev != NULL, return 0);
@@ -324,6 +355,8 @@
                 dev->type = PED_DEVICE_CPQARRAY;
         } else if (dev_major == UBD_MAJOR && (dev_minor % 0x10 == 0)) {
                 dev->type = PED_DEVICE_UBD;
+       } else if (_is_dm_major (dev_major)) {
+               dev->type = PED_DEVICE_DM;
         } else {
                 dev->type = PED_DEVICE_UNKNOWN;
         }
@@ -925,6 +958,11 @@
                         goto error_free_dev;
                 break;
 
+       case PED_DEVICE_DM:
+               if (!init_generic (dev, _("Linux device-mapper")))
+                       goto error_free_dev;
+               break;
+
         case PED_DEVICE_FILE:
                 if (!init_file (dev))
                         goto error_free_arch_specific;
@@ -1498,6 +1536,39 @@
 }
 
 static int
+_probe_dm_devices ()
+{
+       DIR*            mapper_dir;
+       struct dirent*  dent;
+       char            buf [512];      /* readdir(3) claims d_name[256] */
+       struct stat     st;
+
+       mapper_dir = opendir ("/dev/mapper");
+       if (!mapper_dir)
+               return 0;
+
+       /* Search the /dev/mapper directory for devices w/ the same major
+        * number that was returned from _probe_lvm_major().
+        */
+       while ((dent = readdir (mapper_dir))) {
+               if (strcmp (dent->d_name, ".")  == 0 ||
+                   strcmp (dent->d_name, "..") == 0)
+                       continue;
+
+               snprintf (buf, sizeof (buf), "/dev/mapper/%s", dent->d_name);
+
+               if (stat (buf, &st) != 0)
+                       continue;
+
+               if (_is_dm_major(major(st.st_rdev)))
+                       _ped_device_probe (buf);
+       }
+       closedir (mapper_dir);
+
+       return 1;
+}
+
+static int
 _probe_proc_partitions ()
 {
         FILE*           proc_part_file;
@@ -1640,6 +1711,12 @@
        else
                _probe_standard_devices ();
 
+       /* device-mapper devices aren't listed in /proc/partitions; or, if they 
are,
+        * they're listed as dm-X.  So, instead of relying on that, we do
+        * our own checks.
+        */
+       _probe_dm_devices ();
+
        /* /sys/block is more reliable and consistent; fall back to using
         * /proc/partitions if the former is unavailable, however.
         */
@@ -1665,6 +1742,8 @@
                 /* replace /disc with /path%d */
                 strcpy (result, dev->path);
                 snprintf (result + path_len - 5, 16, "/part%d", num);
+       } else if (dev->type == PED_DEVICE_DM) {
+               strcpy (result, dev->path);
         } else if (dev->type == PED_DEVICE_DAC960
                         || dev->type == PED_DEVICE_CPQARRAY
                         || dev->type == PED_DEVICE_ATARAID
@@ -1926,7 +2005,8 @@
 static int
 linux_disk_commit (PedDisk* disk)
 {
-        if (disk->dev->type != PED_DEVICE_FILE) {
+        if (disk->dev->type != PED_DEVICE_FILE &&
+           disk->dev->type != PED_DEVICE_DM) {
                 /* The ioctl() command BLKPG_ADD_PARTITION does not notify
                  * the devfs system; consequently, /proc/partitions will not
                  * be up to date, and the proper links in /dev are not

Reply via email to