#!/bin/csh -f #!/bin/csh -fx # # idr.INSTALL # # Copyright (c) 1990, Sun Microsystems, Inc. All Rights Reserved. # Sun considers its source code as an unpublished, proprietary # trade secret, and it is available only under strict license # provisions. This copyright notice is placed here only to protect # Sun in the event the source is deemed a published work. # Disassembly, decompilation, or other means of reducing the # object code to human readable form is prohibited by the license # agreement under which this code is provided to the user or # company in possession of this copy. # # RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the # Government is subject to restrictions as set forth in # subparagraph (c)(1)(ii) of the Rights in Technical Data and # Computer Software clause at DFARS 52.227-7013 and in similar # clauses in the FAR and NASA FAR Supplement. # # These examples are provided with no warranties of any kind, # including without limitation accuracy and usefulness, and Sun # expressly disclaims all implied warranties of merchantability, # fitness for a particular purpose and non-infringement. In no # event shall Sun be liable for any damages, including without # limitation, direct, special, indirect, or consequential damages # arising out of, or relating to, use of these examples by customer # or any third party. Sun is under no obligation to provide support # to customer. # # # @(#) idr.INSTALL idr.LOAD idr.UNLOAD idr.MKDEV idr.RMDEV: # @(#) idr.INSTALL 1.5 90/02/12 SMI # # # This script may be called by root as: # idr.INSTALL from any directory or /dev/idr.INSTALL # to install the idr driver and make the devices # # This script may be called by /etc/loadable, idr.INSTALL, or root as: # /dev/idr.LOAD [] # to load the idr driver and make the devices # where NIDR is the number of devices to make. # # This script may be called by /etc/loadable, idr.MKDEV, or root as: # /dev/idr.UNLOAD # to remove the idr driver and devices. # # This script may be called by modload as: # /dev/idr.MKDEV # # This script may be called by modunload as: # /dev/idr.RMDEV # or # /dev/idr.RMDEV # # The arg module_id is a small positive integer. # This module id is used to unload the idr driver with modunload. # The module id number is available at any time while the module is loaded # from the modstat command, but for ease of programmable unloading we will # store the id number in the /dev/idr.ID file. # # The arg module_type will always be 0x12345600 unless VDMAGIC_DRV in # vddrv.h changes. Note that for a pseudo device driver (without hardware) # the value for VDMAGIC_PSEUDO would be used. # # The arg block_major is not used by the idr driver. # # The arg char_major is used to make the device nodes. # # # Default number of nodes to make. # This may not match number that a configured in driver can handle. # set DEFAULT_NIDRS = 2 # # Remove any leading components of the pathname. # Check the names although wrong names should not happen. # set MYNAME = $0 set MYNAME = $MYNAME:t if ( $MYNAME != idr.INSTALL && \ $MYNAME != idr.LOAD && $MYNAME != idr.UNLOAD \ && $MYNAME != idr.MKDEV && $MYNAME != idr.RMDEV ) then echo -n "Invocation names: idr.INSTALL idr.LOAD " echo "idr.UNLOAD idr.MKDEV idr.RMDEV" exit 1 endif # # Check for superuser status. # touch /tmp/sutest$$ chown root /tmp/sutest$$ >& /dev/null if ($status != 0) then echo "${MYNAME}: must be super user." rm -f /tmp/sutest$$ exit 1 endif rm -f /tmp/sutest$$ # # Install or upgrade the loadable driver. It is presumed that at this # point two files have been read into the current directory which may # or may not be /dev. They are idr.INSTALL and idr.o. Both may be # symbolic links to another location, such as /sys/sbusdev. # if ($MYNAME == idr.INSTALL) then # # If we are not in /dev, make symbolic links from /dev to here # for idr.INSTALL and idr.o. Symbolic links must be used # because /dev may be a different filesystem. # if ($cwd != /dev) then # # Remove any previous versions of the driver. # rm -f /dev/idr.INSTALL rm -f /dev/idr.o # # Make links to the new driver sources. # ln -s $cwd/idr.INSTALL /dev/idr.INSTALL ln -s $cwd/idr.o /dev/idr.o # # Invoke idr.INSTALL from /dev # cd /dev idr.INSTALL sync # for safety after writing /dev exit $status endif # # Check for an entry in /etc/rc.local to invoke /etc/loadable if # /etc/loadable exists. If this entry does not exist, append it. # This single entry will serve all loadable modules. For safety, # we do not actually edit the /etc/rc.local file. /etc/rc.local # is too critical to the booting process to take chances with!!! # grep -s "/etc/loadable" /etc/rc.local if ($status == 1) then # no match and no error echo "#" >> /etc/rc.local echo "# Load loadable modules." >> /etc/rc.local echo "#" >> /etc/rc.local echo "if [ -f /etc/loadable ]; then" >> /etc/rc.local echo " sh /etc/loadable > /dev/console" \ >> /etc/rc.local echo "fi" >> /etc/rc.local echo "" >> /etc/rc.local endif sync # for safety after writing /etc # # if it does not exist, create /etc/loadable for all to use. # Make it executable and flag it as a borne shell script to # allow calling by root as /etc/loadable. # if (! -e /etc/loadable) then echo ":" > /etc/loadable chmod u+x /etc/loadable endif sync # for safety after writing /etc # # Make an entry in /etc/loadable to invoke /dev/idr.LOAD if # /dev/idr.AUTOLOAD exists. # A maximum of one such entry will be appended. Because this # script can be run multiple times and we do not want to edit # the /etc/loadable file, the automatic loading of idr on reboot # is conditional on both /dev/idr.LOAD and /dev/idr.AUTOLOAD. # grep -s "IDR_DRIVER_INSTALLED" /etc/loadable if ($status == 1) then # no match and no error echo "#" >> /etc/loadable echo "# Load the idr driver if desired." \ >> /etc/loadable echo "#" >> /etc/loadable echo "rm -f /dev/idr.ID" >> /etc/loadable echo "if [ -f /dev/idr.LOAD ]; then" \ >> /etc/loadable echo " if [ -f /dev/idr.AUTOLOAD ]; then" \ >> /etc/loadable echo -n " csh /dev/idr.LOAD" \ >> /etc/loadable echo " # IDR_DRIVER_INSTALLED" >> /etc/loadable echo " fi" >> /etc/loadable echo "fi" >> /etc/loadable echo "" >> /etc/loadable endif sync # for safety after writing /etc # # Automatic modload on reboot is optional. The default is yes. # Ask the installer if automatic loading of the driver is desired. # echo -n "Do you want the idr driver to be automatically loaded " echo -n "during each reboot? [y|n] (y): " set RESPONSE = $< if ("$RESPONSE" != "n" && "$RESPONSE" != "N" \ && "$RESPONSE" != "no" && "$RESPONSE" != "NO") then touch /dev/idr.AUTOLOAD else rm -f /dev/idr.AUTOLOAD endif # # Ask how many idr devices to make. # Store the value for idr.LOAD. # echo -n "How many idr devices do you want? ($DEFAULT_NIDRS): " set RESPONSE = $< if ("$RESPONSE" == "") set RESPONSE = $DEFAULT_NIDRS # check for numeric value @ NUMBER_IDRDEVS = $RESPONSE echo $NUMBER_IDRDEVS >! /dev/idr.NIDRS # # Remove any previous versions of this script. # rm -f /dev/idr.LOAD rm -f /dev/idr.UNLOAD rm -f /dev/idr.MKDEV rm -f /dev/idr.RMDEV # # Since /dev may be a different filesystem, # copy idr.INSTALL to idr.LOAD. # cp /dev/idr.INSTALL /dev/idr.LOAD # # Make the rest of the links. # ln /dev/idr.LOAD /dev/idr.UNLOAD ln /dev/idr.LOAD /dev/idr.MKDEV ln /dev/idr.LOAD /dev/idr.RMDEV # # Do a idr.LOAD to load the driver and make the device nodes. # /dev/idr.LOAD sync # for safety after writing /dev exit $status endif # # Decide how many nodes to make. If an NIDRS arg was passed to # idr.LOAD, then make that many. If no arg passed in but # /dev/idr.NIDRS exists, then make the number contained therein. # Failing that, use the default. Save the NIDRS value in # /dev/idr.NIDRS for use by idr.MKDEV because we cannot pass # it through from modload. # if ($MYNAME == idr.LOAD && $#argv == 1) then # check for numeric value @ NUMBER_IDRDEVS = $1 echo $NUMBER_IDRDEVS >! /dev/idr.NIDRS shift else if (-f /dev/idr.NIDRS) then set NUMBER_IDRDEVS = `cat /dev/idr.NIDRS` else set NUMBER_IDRDEVS = $DEFAULT_NIDRS endif # # Handle invocation as idr.LOAD. # Multiple invocations of idr.LOAD are intended to be benign. # if ($MYNAME == idr.LOAD) then if ($#argv != 0) then # any arg1 was shifted out above echo "Usage: $MYNAME []" exit 1 endif # # Modload the driver, arranging for /dev/idr.MKDEV to be called. # # comment out the MKDEV invocation - something is fishy !!!!! echo -n "idr: " modload /dev/idr.o -entry _idr_vdcmd -exec /dev/idr.MKDEV set exit_status = $status # clean up from modload rm -f /dev/idr sync # for safety after writing /dev exit $exit_status endif # # Handle invocation as idr.UNLOAD. # Multiple invocations of idr.UNLOAD are intended to be benign. # if ($MYNAME == idr.UNLOAD) then if ($#argv != 0) then echo "Usage: $MYNAME" exit 1 endif modunload -id `cat /dev/idr.ID` if ($status == 0) then # remove /dev info after device /dev/idr.RMDEV # unloaded successfully endif sync # for safety after writing /dev exit $status endif # # If we got here, then I was invoked as idr.MKDEV or idr.RMDEV. # # # Check args for idr.MKDEV and idr.RMDEV ... # if ($MYNAME == idr.MKDEV) then if ($#argv != 4) then echo -n "Usage: $MYNAME " echo " " exit 1 endif endif # # At 4.0.3c modunload passes 4 args to the -exec file. # At 4.1 modunload passes 2 args to the -exec file. # #if ($MYNAME == idr.RMDEV) then # if ($#argv != 4 && $#argv != 2) then # echo -n "Usage: $MYNAME " # echo "[ ]" # exit 1 # endif #endif # # Note that even though this is a hex number, no 0x is used in it... # if ("$2" != "12345600") then echo "${MYNAME}: ${2}: bad module type." exit 1 endif # # Handle invocation as idr.MKDEV. # Multiple invocations of idr.MKDEV are intended to be benign. # if ($MYNAME == idr.MKDEV) then set CHARMAJOR = $4 set MODULE_ID = $1 # # If a previous idr driver was loaded, try to unload it. # if (-f /dev/idr.ID) then set OLD_ID = `cat /dev/idr.ID` echo ${MYNAME}: A idr driver was already loaded. echo ${MYNAME}: Removing previous driver number $OLD_ID. /dev/idr.UNLOAD if ($status != 0) then # # At this point the new driver is already loaded, # so we may as well go ahead and use it. The old # one may have failed to unload because it was in # use by a process. # echo -n "${MYNAME}: Unable to remove " echo previous idr driver. endif endif # # Store the module ID for future use... # echo $MODULE_ID >! /dev/idr.ID # # Make the device nodes... # @ THIS_IDR = 0 while ($THIS_IDR < $NUMBER_IDRDEVS) rm -f /dev/idr$THIS_IDR mknod /dev/idr$THIS_IDR c $CHARMAJOR $THIS_IDR chmod 666 /dev/idr$THIS_IDR @ THIS_IDR = $THIS_IDR + 1 end sync # for safety after writing /dev exit 0 endif # # Handle invocation as idr.RMDEV. # Multiple invocations of idr.RMDEV are intended to be benign. # if ($MYNAME == idr.RMDEV) then rm -f /dev/idr.ID # # Remove the device nodes... # rm -f /dev/idr[0-9]* sync # for safety after writing /dev exit 0 endif