7 |
7 |
8 $ENV{LC_ALL} = "C"; |
8 $ENV{LC_ALL} = "C"; |
9 |
9 |
10 use SI::tools; |
10 use SI::tools; |
11 |
11 |
12 sub info($\%) { |
12 sub save($\%) { |
13 my ($file, $part) = @_; |
13 my ($file, $part) = @_; |
14 |
14 |
15 # find major of devmapper |
15 # find the major number of the devmapper |
16 my $devmapper = 0; |
16 my $devmapper = 0; |
17 { |
17 { |
18 local $/ = undef; |
18 local $/ = undef; |
19 open(my ($i), "/proc/devices") |
19 open(my ($i), "/proc/devices") |
20 or die "ERR: Can't open /proc/devices: $!\n"; |
20 or die "ERR: Can't open /proc/devices: $!\n"; |
21 ($devmapper) = <$i> =~ /^\s*(\d+)\s+device.mapper\b/m; |
21 ($devmapper) = <$i> =~ /^\s*(\d+)\s+device.mapper\b/m; |
22 } |
22 } |
23 |
23 |
|
24 # find the non-removable devices, store their |
|
25 # names as $part->{disks}{DEVICE} |
|
26 # and save the current sfdisk dump of these devices |
|
27 # in @{$dev{DEVICE}} |
24 my ($current, %dev); |
28 my ($current, %dev); |
25 foreach (`sfdisk -d 2>/dev/null`) { |
29 foreach (`sfdisk -d 2>/dev/null`) { |
26 chomp; |
30 chomp; |
27 ### $_ |
31 if (/^# partition table .*?(\/\S+\/(\S+))/) { |
28 if (/^# partition table .*?(\/\S+)/) { |
32 # skip the removable devices |
29 $current = (stat $1)[6] >> 8 == $devmapper ? undef : $1 |
33 my ($device, $name) = ($1, $2); |
30 and push(@{ $dev{$current} }, $_); |
34 $_ = (grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0]; |
31 next; |
35 $current = /==.0./ ? $device : undef; |
|
36 $part->{disks}{$current} = undef if $current; |
|
37 next; |
32 } |
38 } |
33 next if not $current; |
39 next if not $current; |
34 push @{ $dev{$current} }, $_; |
40 push @{ $dev{$current} }, $_; |
35 } |
41 } |
36 ### partiton tables of useful blockdevices: |
42 |
37 ### %dev |
43 ### %dev |
|
44 ### exit |
38 |
45 |
39 # process the partition tables |
46 # process the partition tables |
40 # and output the tables for relevant devices |
47 # and output the tables for relevant devices |
41 foreach my $dev (keys %dev) { |
48 foreach my $dev (keys %dev) { |
42 ($_ = $dev) =~ s/^.*\///; |
49 ($_ = $dev) =~ s/^.*\///; |