hdparm -t `block-devices`
+ sfdisk -l `block-devices with-partitions`
+
=cut
use warnings;
use strict;
#use autodie;
+my $with_partitions = { true => 1 } if grep { m/with.?partitions/ } @ARGV;
+
open(my $proc, '<', '/proc/partitions');
my @header;
-my $last_device;
+my $last_device = '';
my $name2col;
sub col {
next unless $_;
my $device = col 'name', $_;
- if ( $last_device && substr( $device, 0, length($last_device) ) eq $last_device ) {
- warn "# partition $device\n";
+ my $device_like_last = substr( $device, 0, length($last_device) );
+ if ( $last_device && $device_like_last eq $last_device ) {
+ if ( $with_partitions ) {
+ print "/dev/$device_like_last\n" if ! $with_partitions->{ $device_like_last }++;
+ } else {
+ warn "# partition $device\n";
+ }
} else {
- print '/dev/', $last_device = $device, $/;
+ print "/dev/$device\n" unless $with_partitions;
+ $last_device = $device;
}
}