[parted-devel] libdevmapper support lacking probing support

Otavio Salvador otavio at debian.org
Tue Nov 28 23:22:18 CET 2006


Hello,

While porting the need modules of Debian Intaller to parted 1.8 I
found a missing feature on libdevmapper support.

I'm attaching the current patch that we're using that's based on our
previous lvm2 support patch. It probably isn't the best way to get it
done but it works.

index 86b0f0a..d9b95da 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -401,6 +401,39 @@ next:
         close(fd);
         return 0;
 }
+
+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;
+}
 #endif
 
 static int
@@ -1884,6 +1917,14 @@ linux_probe_all ()
          */
         _probe_standard_devices ();
 
+#ifdef ENABLE_DEVICE_MAPPER
+        /* 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 ();
+#endif
+
  	/* /sys/block is more reliable and consistent; fall back to using
  	 * /proc/partitions if the former is unavailable, however.
  	 */

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio at debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://otavio.ossystems.com.br
---------------------------------------------
"Microsoft sells you Windows ... Linux gives
 you the whole house."



More information about the parted-devel mailing list