SI/ptable.pm
changeset 6 df6ca24871d4
parent 3 1b975c58c5bf
child 7 03ca6d811a17
--- a/SI/ptable.pm	Fri Jan 15 20:40:14 2010 +0100
+++ b/SI/ptable.pm	Fri Jan 15 23:17:23 2010 +0100
@@ -9,10 +9,10 @@
 
 use SI::tools;
 
-sub info($\%) {
+sub save($\%) {
     my ($file, $part) = @_;
 
-    # find major of devmapper
+    # find the major number of the devmapper
     my $devmapper = 0;
     {
         local $/ = undef;
@@ -21,20 +21,27 @@
         ($devmapper) = <$i> =~ /^\s*(\d+)\s+device.mapper\b/m;
     }
 
+    # find the non-removable devices, store their
+    # names as $part->{disks}{DEVICE}
+    # and save the current sfdisk dump of these devices
+    # in @{$dev{DEVICE}}
     my ($current, %dev);
     foreach (`sfdisk -d 2>/dev/null`) {
         chomp;
-        ### $_
-        if (/^# partition table .*?(\/\S+)/) {
-            $current = (stat $1)[6] >> 8 == $devmapper ? undef : $1
-              and push(@{ $dev{$current} }, $_);
-            next;
+        if (/^# partition table .*?(\/\S+\/(\S+))/) {
+	    # skip the removable devices
+	    my ($device, $name) = ($1, $2);
+	    $_ = (grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0];
+	    $current = /==.0./ ? $device : undef;
+	    $part->{disks}{$current} = undef if $current;
+	    next;
         }
         next if not $current;
         push @{ $dev{$current} }, $_;
     }
-    ### partiton tables of useful blockdevices:
+
     ### %dev
+### exit
 
     # process the partition tables
     # and output the tables for relevant devices