13 |
13 |
14 sub volumes($\%) { |
14 sub volumes($\%) { |
15 my ($file, $devs) = @_; |
15 my ($file, $devs) = @_; |
16 |
16 |
17 # find the non-removable devices |
17 # find the non-removable devices |
|
18 |
18 my ($current, $of); |
19 my ($current, $of); |
19 foreach (`sfdisk -d 2>/dev/null`) { |
20 foreach (`sfdisk -d 2>/dev/null`) { |
20 chomp; |
21 chomp; |
21 if (/^# partition table .*?(\/\S+\/(\S+))/) { |
22 |
22 # skip the removable devices |
23 # new entry, new disk |
23 my ($device, $name) = ($1, $2); |
24 if (my ($device, $name) = /^# partition table .*?(\/\S+\/(\S+))/) { |
24 verbose("device $device"); |
25 verbose("scanning device $device"); |
|
26 |
25 if ((grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0] !~ /==.0./) { |
27 if ((grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0] !~ /==.0./) { |
26 $current = undef; |
28 $current = undef; |
27 verbose("skipping (removable)\n"); |
29 verbose("skipping (removable)\n"); |
28 next; |
30 next; |
29 } |
31 } |
30 |
32 |
|
33 # if it looks like a device mapper, we'll have to remember |
|
34 # this |
|
35 if ($device =~ /\/dev\/dm-/) { |
|
36 if (my $alias = find_by_devid("/dev/mapper", (stat $device)[6])) { |
|
37 verbose("(alias $device)"); |
|
38 $devs->{disk}{$alias}{dm} = $device; |
|
39 $device = $alias; |
|
40 } |
|
41 } |
|
42 |
31 # save in our data structure |
43 # save in our data structure |
32 verbose("scanning\n"); |
44 verbose("\n"); |
33 $current = $device; |
45 $current = $device; |
34 push @{$devs->{disk}{$current}{pt}}, $_; |
46 push @{$devs->{disk}{$current}{pt}}, $_; |
35 |
47 |
36 # and open the outfile |
48 # and open the outfile |
37 my $f = sprintf ">$file", $name; |
49 my $f = sprintf ">$file", $name; |
38 $of = new IO::File $f or die "ERR: Can't open $f: $!\n"; |
50 $of = new IO::File $f or die "ERR: Can't open $f: $!\n"; |
39 print $of "$_\n"; |
51 print $of "$_\n"; |
40 |
52 |
41 next; |
53 next; |
42 } |
54 } |
|
55 |
43 next if not $current; |
56 next if not $current; |
|
57 |
44 push @{$devs->{disk}{$current}{pt}}, $_; |
58 push @{$devs->{disk}{$current}{pt}}, $_; |
45 print $of "$_\n"; |
59 print $of "$_\n"; |
46 |
60 |
47 if (/^(\/dev\/\S+)\s*:/) { |
61 # if it looks like a partition (volume), then |
48 $devs->{volume}{$1} = {}; |
62 # save it |
|
63 if (my ($dev, $id) = /^(\/dev\/\S+)\s*:.*\sId=\s*(\d+)/) { |
|
64 if (my $dm = $devs->{disk}{$current}{dm}) { |
|
65 $dev =~ s/$dm/$current/; |
|
66 } |
|
67 $devs->{volume}{$dev}{fstype} = $id; |
49 } |
68 } |
50 |
69 |
51 } |
70 } |
52 |
71 |
53 ### $devs |
|
54 return; |
72 return; |
55 } |
73 } |
56 1; |
74 1; |
57 # vim:sts=4 sw=4 aw ai si: |
75 # vim:sts=4 sw=4 aw ai si: |