heh. i didn't realize i sucked this bad =)

On 9/1/05, John W. Krahn <[EMAIL PROTECTED]> 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).
>
> How do you determine which partitions to skip and which not to skip?

Well, my initial thought was to skip partition 2 entirely (which is
reserved in Solaris as a means to address the entire disk, and would
therefore bork up the calculations). I've since realized that I can't
quite do that, I need to at least check if part2 is the only one
present first. Either way, it won't be part of the calculations
though.

Really, I should check all the partitions and see if the difference
between start and end sectors is == the total number of sectors ...

>
> > use strict();
>
> You are telling perl to load the 'strict' module and then you are telling the
> 'strict' module not to do anything (with the empty parentheses.) Why use the
> module if you don't want it to do anything?

*doh* . thanks.


> > sub get_vtoc($) {
>
> You really, really, *REALLY* shouldn't use "prototypes". If you want to check
> the arguments passed to your subroutine you should do something like this:
>
>  @_ == 1 or die "Wrong number of arguments passed to get_vtoc().\n";
>
>
> "Far More Than Everything You've Ever Wanted to Know about Prototypes in Perl"
> http://library.n0i.net/programming/perl/articles/fm_prototypes/

A very good read, noted and changed.


>
> > # 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);
>
> our() is lexically scoped just like my() and the only reason that this
> actually works is because strict is turned off and $BPS is a package variable.
>  To make this work correctly with strict you have to declare $BPS outside of
> the while loop.
>
> If you use split correctly that could be written as:
>
>  $BPS = ( split )[ 1 ];
>
> Then you wouldn't need the substitutions at the beginning of the loop.
>
> However *I* would write it like this:
>
>  if ( /(\d+)\s+bytes\/sector/ ) {
>  $BPS = $1;
>  }

I think this is the best example of regexp backreferencing I've seen.
At last, they make sense to me =)

I've changed this in the real script, and a few other places elsewhere to boot!

> > }
> >
> > # skip the the line if it starts with an * or is partition 2
> > next if(/^[\*|2]/);
>
> Your comment is incorrect, it should read "if it starts with an * or a | or is
> partition 2". Regular expression meta-characters are not special in a
> character class so you probably meant /^[*2]/.

I did indeed mean that. And now that you've got it working the right
way I realize it's totally not what I wanted. I need to leave the 2
out of it, because if partition 2 is the only one defined, I need to
return it. Many thanks for helping me catch this.

>
> > # 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"
>
> perldoc -q quoting
>
> Found in /usr/lib/perl5/5.8.6/pod/perlfaq4.pod
>  What's wrong with always quoting "$vars"?

Read ... I don't quite get it, but I understood enough to realize that
I needed to unquote them or potentially suffer difficult to trace
errors later on. Done.


> This appears to do what you want (although there may be a module that does
> this better):
>
>  my @sec_range;
>  for my $sectors ( map [ @{ $_ }{ 'fsector', 'lsector' } ],
>  sort { $a->{ fsector } <=> $b->{ fsector } }
>  values %$slices ) {
>
>  if ( @sec_range && $sec_range[ -1 ][ 1 ] == $sectors->[ 0 ] - 1 ) {
>  $sec_range[ -1 ][ 1 ] = $sectors->[ 1 ];
>  }
>  else {
>  push @sec_range, $sectors;
>  }
>  }
>
>  print "Available sectors:\n";
>  print "\t0 - ", $sec_range[0][0]-1, "\n" if $sec_range[0][0];
>  print "\t", $sec_range[$_-1][1]+1, ' - ', $sec_range[$_][0]-1, "\n"
>  for 1 .. $#sec_range;


This does indeed do the right thing on the sample data. I'm working
through it slowly, and I kinda get it. I gotta admit, I'm lost in the
crypticism, but it looks like it  throws the firstsectors and
lastsectors into a hash, sorts the keys and values independantly, then
compares ?

I'm trying it on a second drive however, and am getting results that
don't look right ...

That drive has the following partitions defined:

*                                  First          Sector      Last
* Partition  Tag  Flags    Sector       Count       Sector       Mount Directory
      0        2    00         1048707     68030172  69078878   /
      1        3    01          0               1048707   1048706
      2        5    00          0               71127180  71127179
      7        8    00          69078879   2048301  71127179    /export/home


I would expect the script to return no available sectors, but am
getting this instead:

Available sectors:
       1048707 - -1
       71127180 - 1048706

Still looking into why, not sure, since I'm just trying to figure out
which end is up =0)

Thanks for the input and guidance. I'll keep hacking away on this and
see if I can't get it to work, now that I've got an idea on how to
start.

- jason

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