SI/ptable.pm
changeset 12 a1aee1136609
parent 10 23dd30396607
child 13 2e3ad71484ea
--- a/SI/ptable.pm	Sun Jan 17 16:40:08 2010 +0100
+++ b/SI/ptable.pm	Mon Jan 18 20:35:27 2010 +0100
@@ -15,21 +15,33 @@
     my ($file, $devs) = @_;
 
     # find the non-removable devices
+
     my ($current, $of);
     foreach (`sfdisk -d 2>/dev/null`) {
         chomp;
-        if (/^# partition table .*?(\/\S+\/(\S+))/) {
-	    # skip the removable devices
-	    my ($device, $name) = ($1, $2);
-	    verbose("device $device");
+
+	# new entry, new disk
+        if (my ($device, $name) = /^# partition table .*?(\/\S+\/(\S+))/) {
+	    verbose("scanning device $device");
+
 	    if ((grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0] !~ /==.0./) {
 		    $current = undef;
 		    verbose("skipping (removable)\n");
 		    next;
 	    }
 
+	    # if it looks like a device mapper, we'll have to remember
+	    # this
+	    if ($device =~ /\/dev\/dm-/) {
+		if (my $alias = find_by_devid("/dev/mapper", (stat $device)[6])) {
+		    verbose("(alias $device)");
+		    $devs->{disk}{$alias}{dm} = $device;
+		    $device = $alias;
+		}
+	    }
+
 	    # save in our data structure
-	    verbose("scanning\n");
+	    verbose("\n");
 	    $current = $device;
 	    push @{$devs->{disk}{$current}{pt}}, $_;
 
@@ -40,17 +52,23 @@
 
 	    next;
         }
+
         next if not $current;
+
 	push @{$devs->{disk}{$current}{pt}}, $_;
 	print $of "$_\n";
 
-	if (/^(\/dev\/\S+)\s*:/) {
-	    $devs->{volume}{$1} = {};
+	# if it looks like a partition (volume), then
+	# save it
+	if (my ($dev, $id) = /^(\/dev\/\S+)\s*:.*\sId=\s*(\d+)/) {
+	    if (my $dm = $devs->{disk}{$current}{dm}) {
+		$dev =~ s/$dm/$current/;
+	    }
+	    $devs->{volume}{$dev}{fstype} = $id;
 	}
 
     }
 
-### $devs
     return;
 }
 1;