Jason Ross wrote:
Anyway, the issue I have is that I need to determine where there are gaps between the first sector and last sector (on the entire disk, not on a given partition).

So, for example, using the sample data below, I want to return "2097415 - 69078878" as available sectors.

Hi Jason,

I find the Set::IntSpan module very useful for this type of thing:

#!/usr/bin/perl

use strict;
use warnings;

use Set::IntSpan;

# the last sector on disk
my $end_sect = 71127179;

# The complete range of sectors on the disk
my $range = Set::IntSpan->new( "0-$end_sect" );

# The ranges of used sectors
my $used = Set::IntSpan->new( '0-1048706,1048707-2097414,69078879-71127179' );

# Calculates the remaining unused sectors
my $unused = $range->diff( $used );

print $unused->run_list;

__END__

Sample data
I called this file "in".
If you change the name, you'll need to alter the last line of the script
--------------------------------------------------------------------------
* /dev/dsk/c1t0d0s2 partition map
*
* Dimensions:
*     512 bytes/sector
*     107 sectors/track
*      27 tracks/cylinder
*    2889 sectors/cylinder
*   24622 cylinders
*   24620 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00    1048707   1048707   2097414   /
       1      3    01          0   1048707   1048706
       2      5    00          0  71127180  71127179
       7      8    00   69078879   2048301  71127179   /export/home


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to