#! /usr/bin/perl -w
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)README	1.1	00/10/31 SMI"
#
# This directory contains RCM scripts.
# This file may be used as a template for an RCM script.
# This file itself is not executable as it contains pseudo code.
# For more information on RCM scripts see the man page rcmscript(4).
#

use strict;

my ($cmd, $rsrc, %dispatch);

# dispatch table for RCM commands
%dispatch = (
	"scriptinfo"	=>	\&do_scriptinfo,
	"register"	=>	\&do_register,
	"resourceinfo"	=>	\&do_resourceinfo,
	"queryremove"	=>	\&do_queryremove,
	"preremove"	=>	\&do_preremove,
	"undoremove"	=>	\&do_undoremove,
	"postremove"	=>	\&do_postremove
);

sub do_scriptinfo
{
	print "rcm_script_version=1\n";
	print "rcm_script_func_info=script functionality description here\n";

	#
	# optionally specify command timeout value in seconds to override
	# the default timeout value.
	# Eg:
	#   print "rcm_cmd_timeout=10\n";
	#

	exit (0);
}

sub do_register
{
	#
	# register all resource names of interest using
	# print "rcm_resource_name=resourcename\n";
	# Eg: to register /dev/rmt/0 and /dev/dsk/c1t1d0s0
	#   print "rcm_resource_name=/dev/rmt/0\n";
	#   print "rcm_resource_name=/dev/dsk/c1t1d0s0\n";
	#

	register all resource names of interest
	if (successful) {
		exit (0);
	} else {
		# an error occurred while while executing this command
		print "rcm_failure_reason=specify the reason here\n";
		exit (1);
	}
}

sub do_resourceinfo
{
	#
	# specify the resource usage information of the given resource $rsrc
	#

	print "rcm_resource_usage_info=resource usage information here\n";
	if (successful) {
		exit (0);
	} else {
		# an error occurred while while executing this command
		print "rcm_failure_reason=specify the reason here\n";
		exit (1);
	}
	exit (0);
}

sub do_queryremove
{
	#
	# Called before removing the specified resource from the system
	# to query if the script will be able to release the resource.
	# The script does not actually release the resource.
	# If $ENV{'RCM_ENV_FORCE'} is 'TRUE' the script should check
	# if the resource can be released by force.
	#

	if (the script will be able to release $rsrc) {
		exit (0);
	} else {
		# the script will not be able to release $rsrc
		print "rcm_failure_reason=specify the reason here\n";
		exit (3);
	}

	#
	# if an error occurred while while executing this command
	#   print "rcm_failure_reason=specify the reason here\n";
	#   exit (1);
	#
}

sub do_preremove
{
	#
	# Called before the specified resource is removed from the system.
	# If $ENV{'RCM_ENV_FORCE'} is 'TRUE' the script must make extra
	# effort to release the resource.
	#

	if (removing $rsrc is acceptable to the script) {
		Release the resource, including closing the device if the
		device is currently opened.
		if (successful) {
			exit (0);
		} else {
			# an error occurred while while executing this command
			print "rcm_failure_reason=specify the reason here\n";
			exit (1);
		}
	} else {
		# removing $rsrc is not acceptable to the script
		print "rcm_failure_reason=specify the reason here\n";
		exit (3);
	}

}

sub do_undoremove
{
	#
	# Called to restore the state of the resource to the same state
	# the resource was in prior to calling preremove.
	#

	undo the operations done in the preremove command for $rsrc
	if (successful) {
		exit (0);
	} else {
		# an error occurred while while executing this command
		print "rcm_failure_reason=specify the reason here\n";
		exit (1);
	}
}

sub do_postremove
{
	#
	# Called after the resource has been removed from the system.
	#

	do any post remove clean up for $rsrc
	if (successful) {
		exit (0);
	} else {
		# an error occurred while while executing this command
		print "rcm_failure_reason=specify the reason here\n";
		exit (1);
	}
}

$cmd = $ARGV[0];
if (defined($ARGV[1])) {
	# resource name
	$rsrc = $ARGV[1];
}

if (defined($dispatch{$cmd})) {
	&{$dispatch{$cmd}};
} else {
	# unsupported command
	exit (2);
}

