VMS::Device

VMS::Device provides access to device information and can allocate, deallocate, mount, dismount, and initialize devices.

use VMS::Device '/.*/';
@type_list = device_types();
@class_list = device_classes();
@dev_list = device_list($DeviceName[, $DeviceClass[, $DeviceType]]);
$DevInfoHashRef = device_info($DeviceName);
$BitmapHashRef = decode_device_bitmap($InfoName, $BitmapValue);
$Status = mount(\%Device_properties);
$Status = dismount($DevName[, \%Dismount_flags]); [Unimplemented]
$DeviceAllocated = allocate($DevName[, $FirstAvail[, $AccMode]]);
$Status = deallocate($DevName[, $AccMode]);
$Status = initialize($DevName[, $VolumeName[, \%DevProperties]]);

This short example program uses VMS::Device to report on available free disk space on locally mounted volumes.

use strict;
use warnings;
use VMS::Device qw(device_list device_info decode_device_bitmap);

my @info =
    grep {
	my $char = decode_device_bitmap("DEVCHAR",$_->{DEVCHAR});
	$char->{MNT} && !$char->{DMT} && !$char->{FOR};
    } map {
	device_info($_);
    } (@ARGV) ? @ARGV : device_list("*","DISK");

die "No devices selected" unless @info;

my ($tot_space, $tot_free, $tot_used, $cnt) = (0, 0, 0, 0);
for (@info) {
    my $tot = $_->{MAXBLOCK};
    my $free = $_->{FREEBLOCKS};
    my $used = $tot - $free;
    my $megs_tot = $tot / 2048;
    my $megs_free = $free / 2048;
    my $megs_used = $used / 2048;
    $tot_space += $tot;
    $tot_free += $free;
    $tot_used += $used;
    if (!$cnt) {
        printf("%25s %-29s %s\n","","Blocks","Bytes");
        printf("%-12s %-12s %-9s %-9s %-9s %-5s %-5s %-5s %-5s\n",
               "Device","Volume","Total","Free","Used","Total","Free","Used",
               "%Used");
    }
    $cnt++;
    for ($megs_free, $megs_used, $megs_tot) {
	if ($_ > 9999) {
	    $_ = int(($_ / 1024) + .5) . "G";
	} else {
	    $_ = int($_ + .5) . "M";
	}
    }
    printf("%-12s %-12s %9d %9d %9d %5s %5s %5s %5.1f\n",
           $_->{DEVNAM},$_->{VOLNAM},$tot,$free,$used,$megs_tot,
           $megs_free,$megs_used,$used/$tot*100);
}
if ($cnt > 1) {
    my $tot_megs = $tot_space / 2048;
    my $tot_free_megs = $tot_free / 2048;
    my $tot_used_megs = $tot_used / 2048;
    printf("\nTotal of %d drive%s\n",scalar(@info),($#info) ? "s" : "");
    printf("      %10d blocks   %6d MB\n",$tot_space,$tot_megs);
    printf("      %10d free     %6d MB\n", $tot_free, $tot_free_megs);
    printf("      %10d used     %6d MB\n", $tot_used, $tot_used_megs);
}

Leave a comment

Your email address will not be published. Required fields are marked *