#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# This is a clean script for removable disks
#
# Following is the syntax for calling the script:
# scriptname [-s|-f|-i|-I] devicename [-A|-D] username zonename zonepath
#
# -s for standard cleanup by a user
# -f for forced cleanup by an administrator
# -i for boot-time initialization (when the system is booted with -r)
# mode
#
# $1: devicename - device to be allocated/deallocated, e.g., sr0
#
# $2: -A if cleanup is for allocation, or -D if cleanup is for deallocation.
#
# $3: username - run the script as this user, rather than as the caller.
#
# $4: zonename - zone in which device to be allocated/deallocated
#
# $5: zonepath - root path of zonename
#
# A clean script for a removable media device should prompt the user to
# insert correctly labeled media at allocation time, and ensure that the
# media is ejected at deallocation time.
#
# Unless the clean script is being called for boot-time
# initialization, it may communicate with the user via stdin and
# stdout. To communicate with the user via CDE dialogs, create a
# script or link with the same name, but with ".windowing" appended.
# For example, if the clean script specified in device_allocate is
# script named /etc/security/xyz_clean.windowing exists, it must use
# dialogs. To present dialogs to the user, the dtksh script
#
# using dialogs. A symbolic link disk_clean.windowing points to
# disk_clean.
#
# ####################################################
# ################ Local Functions #################
# ####################################################
#
# Set up for windowing and non-windowing messages
#
{
WINDOWING="yes"
case $VOLUME_MEDIATYPE in
esac
else
fi
else
WINDOWING="no"
fi
}
#
# Display a message for the user. For windowing, user must press OK button
# to continue. For non-windowing, no response is required.
#
fi
}
else
fi
}
else
fi
}
#
#
fi
}
#
#
fi
}
#
# Display an error message, put the device in the error state, and exit.
#
"\n\nDevice has been placed in allocation error state." \
"\nPlease inform system administrator."
fi
exit 1
}
#
# get_reply prompt choice ...
#
prompt=$1; shift
while true
do
read reply
i=0
do
then
return $i
else
i=`expr $i + 1`
fi
done
done
}
#
# Find the first disk slice containing a file system
#
{
# The list of files in device_maps(4) is in an unspecified order.
# To speed up the fstyp(1M) scanning below in most cases, perform
# the search for filesystems as follows:
# 2) Sort the list of files in an order more likely to yield
# numeric order within each group.
if [ $? = 0 ]; then
fi
# For consistency, hsfs filesystems detected at
fi
return
fi
done
}
#
# Find all mountpoints in use for a set of device special files.
# Usage: findmounts devpath ...
#
"ENDOFAWKPGM"
BEGIN {
realdevlist[dev] = 1;
}
}
}
{
mountpoint = $2;
print mountpoint;
}
}
mountpoint = $2;
print mountpoint;
}
}
}
}
#
# Allocate a device.
# Ask the user to make sure the disk is properly labeled.
# Ask if the disk should be mounted.
#
{
if [ $VOLUME_MEDIATYPE = floppy ]; then
# Determine if media is in drive
eject_status="$?"
case $eject_status in
1) # Media is not in drive
if [ $? != 0 ]; then
exit 0
fi;;
3) # Error
"Error checking for media in drive.";;
esac
else
if [ $? != 0 ]; then
exit 0
fi
fi
if [ $? != 0 ]; then
exit 0
fi
if [ $VOLUME_MEDIATYPE = cdrom -o $VOLUME_MEDIATYPE = rmdisk ]; then
# Get the device path and volume name of a partition
fi
fi
fi
# Give ourself write permission on device file so file system gets
# rmmount only cares about permissions not user...
chmod 700 $VOLUME_PATH
# Do the actual mount. VOLUME_* environment variables are inputs to
# rmmount.
rmmount_status="$?"
if [ $rmmount_status -eq 0 ]; then
elif [ $rmmount_status -gt 0 -a $VOLUME_MEDIATYPE != cdrom ]; then
# Try again in readonly mode. cdrom is always mounted ro, so
# no need to try again.
echo "Read-write mount of $DEVICE failed. Mounting read-only."
VOLUME_ACTION=remount; export VOLUME_ACTION
VOLUME_MOUNT_MODE=ro; export VOLUME_MOUNT_MODE
if [ $? -eq 0 ]; then
fi
fi
# Set permissions on directory used by vold, sdtvolcheck, etc.
fi
}
{
if [ $VOLUME_MEDIATYPE = cdrom -o $VOLUME_MEDIATYPE = rmdisk ]; then
if [ -h /$VOLUME_MEDIATYPE/$DEVICE ]; then
# Get the device path and volume name of a partition
VOLUME_PATH=`ls -l /$VOLUME_MEDIATYPE/$DEVICE|\
VOLUME_DEVICE=`mount -p|grep $VOLUME_PATH|\
fi
fi
# Do the actual unmount.
# VOLUME_* environment variables are inputs to rmmount.
rmmount_status="$?"
# Remove symbolic links to mount point
for name in /$VOLUME_MEDIATYPE/*; do
if [ -h $name ]; then
target_device=`echo $target_dir | \
fi
fi
done
else
fi
case $rmmount_status in
1) # still mounted
0) # not mounted
# Eject the media
else
fi
eject_status="$?"
case $eject_status in
0|1|4) # Media has been ejected
case $VOLUME_MEDIATYPE in
esac;;
3) # Media didn't eject
esac
esac
}
#
# Reclaim a device
#
{
eject_status="$?"
case $eject_status in
0) # Media has been ejected
fi
exit 0;;
1) # Media not ejected
fi
exit 0;;
3) # Error
fi
exit 2;;
esac
}
# ####################################################
# ################ Begin main program ################
# ####################################################
MODE="allocate"
SILENT=n
VOLUME_ZONE_PATH="/"
USAGE="Usage: disk_clean [-s|-f|-i|-I] devicename -[A|D] [username] [zonename] [zonepath]"
FLAG=i
#
# Parse the command line arguments
#
while getopts ifsI c
do
case $c in
i)
FLAG=$c;;
f)
FLAG=$c;;
s)
FLAG=$c;;
I)
FLAG=i
silent=y;;
\?)
echo $USAGE
exit 1;;
esac
done
DEVICE=$1
MODE="deallocate"
if [ "$2" = "-A" ]; then
MODE="allocate"
elif [ "$2" = "-D" ]; then
MODE="deallocate"
fi
#get the device_maps information
MAP=`/usr/sbin/list_devices -s -l $DEVICE`
# Set VOLUME_ variables that are inputs to rmmount
# e.g., "cdrom" or "floppy"
if [ "$MEDIATYPE" = "sr" ]; then
VOLUME_MEDIATYPE="cdrom"
elif [ "$MEDIATYPE" = "fd" ]; then
VOLUME_MEDIATYPE="floppy"
elif [ "$MEDIATYPE" = "rmdisk" ]; then
VOLUME_MEDIATYPE="rmdisk"
fi
fi
if [ "$SYMDEV" = "sr" ]; then
elif [ "$SYMDEV" = "fd" ]; then
elif [ "$SYMDEV" = "rmdisk" ]; then
else
fi
if [ "$MODE" = "allocate" ]; then
if [ -n "$3" ]; then # e.g., "joeuser"
VOLUME_USER=$3
else
fi
else
# If there's a directory for the device under /<mediatype>, get the
# user name from there, to use in cleaning up that directory. Otherwise,
# the user name isn't actually used in deallocation.
else
if [ -n "$3" ]; then
VOLUME_USER=$3
else
fi
fi
fi
# e.g., "joeuser-cdrom0/unnamed_cdrom"
if [ "$VOLUME_MEDIATYPE" = "rmdisk" ]; then
else
fi
if [ "$MODE" = "allocate" ]; then
else
if [ "$FLAG" = "i" ] ; then
else
fi
fi
exit $EXIT_STATUS