Hello.
I'm having a bit of an issue with a script I'm working on. The goal is to parse the output of the solaris `prtvtoc` command and do some things based on it. I've got that part down, and am placing the bits I care about into a hash which is best written (I think ... ) as :

    $partition-> {$property} = value

You can see what I mean in the code below...

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.

I think to do that I need to iterate through all the last sectors and find out if ($current_lastsector + 1) is not present in the list of first sectors ....

I'm not sure what the 'best' way to do that is given the structure of the hash (it having the $partition top level is throwing me off) ... and

I'm not convinced putting the startsectors and endsectors into 2 arrays and comparing via that method is a good way to do it (and even if it is, I'm not sure how to do that either ... )

Any thoughts on the 'best' way to do this ?

(Sample data and script are below, any other "optimizations" folks feel like chiming in with are welcome also ;-)

Thanks,
Jason Ross



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






Sample script
--------------------------------------------------------------------------
#!/usr/bin/perl
use strict();

sub get_vtoc($) {
   my $disk = shift;
   my %slices;

   open(IN, "< $disk") or die("$!\n");
      while(<IN>) {
         # make all tabs and spaces a single space
         $_ =~ s/\s+/ /g;
         # strip all leading spaces
         $_ =~ s/^\s+//g;

         # if this is the bytes/sector line, split it
         # and store the bytes per sector as $BPS
         if($_ =~ /bytes\/sector/) {
            our (undef, $BPS, undef) = split(/\s/, $_, 3);
         }

         # skip the the line if it starts with an * or is partition 2
         next if(/^[\*|2]/);

         # split the line into its componant parts
         my($part, $tag, $flag, $fsector,
            $sectcount, $lsector, $mount) = split(/\s/, $_);

         # put the pieces into the slices hash
         $slices{$part} = {
            bps => "$BPS",
            tag => "$tag",
            flag => "$flag",
            part => "$part",
            fsector => "$fsector",
            lsector => "$lsector",
            sectcount => "$sectcount",
            mount => "$mount"
         };
      }
   close(IN);
   return \%slices;
}

sub process_drive($) {
   my $disk = shift;
   my $slices = get_vtoc("$disk");

   while(my ($partition, $properties) = each(%{$slices})) {
      print "Partition: $partition\n";
      while(my ($property, $value) = each(%{$properties})) {
         print "Property: $property => $value\n";
      }
      print "\n"; # just a pretty fire
   }
}

process_drive("./in");

--
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