part-id: Fix DM partition table detection
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 7 Apr 2010 06:56:05 +0000 (08:56 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Wed, 7 Apr 2010 06:56:05 +0000 (08:56 +0200)
If DM_NAME does not end in 'pN' (i. e. is not a partition), do not treat it as
malformed, but just go ahead probing it. This fixes partition table detection
for kpartx'ed DM devices.

Re-enable the test case which originally uncovered this bug.

src/probers/part-id.c
tests/run

index 306eb44..25d91f9 100644 (file)
@@ -291,29 +291,28 @@ get_part_table_device_file (struct udev_device *given_device,
                       if (!isdigit (dm_name[n]))
                         break;
                     }
-                  if (n < 0 || dm_name[n] != 'p')
+                  /* if we have a partition, set partition number and parent device */
+                  if (n > 0 && dm_name[n] == 'p')
                     {
-                      g_printerr ("DM_NAME=`%s' is malformed (expected <name>p<number>)\n", dm_name);
-                      goto out;
-                    }
-                  partition_number = atoi (dm_name + n + 1);
-                  if (partition_number < 1)
-                    {
-                      g_printerr ("Error determining partition number from DM_NAME=`%s'\n", dm_name);
-                      goto out;
-                    }
+                      partition_number = atoi (dm_name + n + 1);
+                      if (partition_number < 1)
+                        {
+                          g_printerr ("Error determining partition number from DM_NAME=`%s'\n", dm_name);
+                          goto out;
+                        }
 
-                  ret = g_strdup (udev_device_get_devnode (mp_device));
-                  offset = offset_sectors * 512;
+                      ret = g_strdup (udev_device_get_devnode (mp_device));
+                      offset = offset_sectors * 512;
 
-                  partition_table_syspath = g_strdup (udev_device_get_syspath (mp_device));
+                      partition_table_syspath = g_strdup (udev_device_get_syspath (mp_device));
 
-                  udev_device_unref (mp_device);
-                  g_free (targets_params);
+                      udev_device_unref (mp_device);
+                      g_free (targets_params);
 
-                  /* TODO: set alignment_offset */
+                      /* TODO: set alignment_offset */
 
-                  goto out;
+                      goto out;
+                    }
                 }
             }
           g_free (targets_params);
index 9803ba4..1bd881a 100755 (executable)
--- a/tests/run
+++ b/tests/run
@@ -1280,9 +1280,9 @@ class LVM(UDisksTestCase):
 
             self.assertEqual(dev_p.Get(I_D, 'DeviceFile'), devname)
             self.assertEqual(dev_p.Get(I_D, 'DeviceIsPartition'), False)
-            # TODO: hmm, these fail.. bug?
-            #self.assertEqual(dev_p.Get(I_D, 'DeviceIsPartitionTable'), True)
-            #self.assertEqual(dev_p.Get(I_D, 'PartitionScheme'), 'mbr')
+            self.assertEqual(dev_p.Get(I_D, 'PartitionScheme'), '')
+            self.assertEqual(dev_p.Get(I_D, 'DeviceIsPartitionTable'), True)
+            self.assertEqual(dev_p.Get(I_D, 'PartitionTableScheme'), 'mbr')
 
             # partition 1 properties
             p1_obj = dbus.SystemBus().get_object('org.freedesktop.UDisks',