#ident	" @(#)addbadblocks	1.3 - 87/05/21 "
#menu# enter bad sector information
#help#
#help# This procedure gives you the opportunity to enter known bad
#help# areas on your disk.  To do this, you will need to know the
#help# information that was printed onto the console when the bad area
#help# was encountered.  This should include a drive and controller
#help# number and an absolute sector number.
#help
#help# You will be asked a series of questions about the bad area
#help# and then it will be added to the system's bad block list.


#Ask the user to enter bad block information that they have
#gathered from the console during normal operations.  The error
#message that is printed on the console when a bad block is
#encountered includes drive name and controller and absolute
#sector number.  When we have gathered this information from the
#user, we make a mkpart call to add the new information to the
#bad block list on the vtoc.  Note that we only support bad
#sectors in the Unix area of the disk, since no-one else reads
#the vtoc and alttbl.


trap 'exit 0' 1 2 15
flags="-qq -t -k$$"

echo '\nAnytime you want to quit, type "q".
If you are not sure how to answer any prompt, type "?" for help,
or see the appropriate manual.
\nIf a default appears in the question, press <RETURN> for the default.
'

while  true
do
    while true
    do
	echo "Enter the drive number: "
	read drivenum junk
	if [ "$drivenum" -ne "0" -a "$drivenum" -ne "1" ]
	then
	    echo "drive number must be either 0 or 1, try again"
	else
	    break
	fi
    done

    while true
    do
	echo "Enter the controller number: "
	read controller junk
	if [ "$controller" -ne "0" -a "$controller" -ne "1" ]
	then
	    echo "controller number must be either 0 or 1, try again"
	else
	    break
	fi
    done

	if [ "$drivenum" = "0" -a "$controller" = "0" ]
	then
		diskname="disk0"
	else
		diskname="disk$drivenum$controller"
	fi

	abs_sector=`checkre ${flags} -H'
	This is the absolute sector # that was printed on the console.' \
		-fe "Enter absolute sector number [?,q]: " \
		'^[0-9]*$' 'Answer contains an illegal character.
	Only numbers are permitted.' \
		'[0-9][0-9]*' 'You must enter a value.' `

	echo "\\nThis is the information for the bad area:
	Drive # :               ${drivenum}
	Controller # :          ${controller}
	Absolute Sector # :     ${abs_sector}
	Disk Name:              ${diskname}"
	case `checklist ${flags} -fep 'Do you want to install or skip this entry [i, s, q]?' install skip` in
	install )
		/etc/mkpart -A ${abs_sector} ${diskname}
		;;
	skip )
		;;
	esac

	if  checkyn ${flags} -f 'Do you want to add another bad area?'
	then
		continue
	fi
	break
done
