#!/usr/bin/perl
# Last Update: 24 May 2010
# Designed by: Dusan U. Baljevic (dusan.baljevic@ieee.org)
# Coded by: Dusan U. Baljevic (dusan.baljevic@ieee.org)
#
# Copyright 2010-2015 Dusan Baljevic
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
$ENV{'PATH'} = "/bin:/usr/sbin:/sbin:/usr/bin";
# Enforce strictness
#
if ( eval "require strict" ) {
import strict;
use strict;
}
else {
print "WARN: Perl strict not found\n";
}
use Fcntl;
my $MYDEV = q{};
my $SEEK_SET = 0;
my $BUFSIZE = 512;
my $CKSUM_SEEK = 510;
my $CKSUM_BUFSIZE = 2;
sub Usage {
print < [-h]
-d diskdev Disk device to check label
(example, c7t600508B400102E8E0001500013FB0000d0)
-h Print this help message
MYMSG
;
exit(0);
}
if ( eval "require Getopt::Std" ) {
import Getopt::Std;
getopts( 'd:h', \%opts );
if ( $opts{h} ) {
&Usage;
}
if ( ! "$opts{d}" ) {
print "ERROR: Disk device not selected\n";
&Usage;
exit(1);
}
else {
$MYDEV = "/dev/dsk/$opts{d}s0" || q{};
}
}
else {
warn "ERROR: Perl module Getopt::Std not found\n";
}
sysopen(FH, "$MYDEV", O_RDONLY) or die "ERROR: Cannot open device $MYDEV\n";
if ( sysseek(FH, 0, $SEEK_SET) ) {
sysread(FH, $s, $BUFSIZE) or
die "ERROR: Cannot read from device $MYDEV\n";
close(FH);
}
else {
print "ERROR: Cannot seek in device $MYDEV\n";
}
my $FORMAT = "Z*";
my $FIELDS = unpack($FORMAT, $s);
sysopen(CFH, "$MYDEV", O_RDONLY) or die "ERROR: Cannot open device $MYDEV\n";
if ( sysseek(CFH, 510, $SEEK_SET) ) {
sysread(CFH, $c, $CKSUM_BUFSIZE) or
die "ERROR: Cannot read from device $MYDEV\n";
close(CFH);
}
else {
print "ERROR: Cannot seek in device $MYDEV\n";
}
my $FORMAT = "Z*";
my $FIELDS = unpack($FORMAT, $s);
my $CFORMAT = "S";
my $CFIELDS = unpack($CFORMAT, $c);
print "Device = $MYDEV\n";
print "Current VENDOR STRING = $FIELDS\n";
print "Current checksum = $CFIELDS\n";
exit(0);