--- bin/block-devices 2009/05/01 12:00:18 12 +++ bin/block-devices 2009/05/01 12:11:44 13 @@ -6,16 +6,20 @@ 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 { @@ -37,10 +41,16 @@ 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; } }