1#!/usr/local/bin/ksh93 -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27function labelvtoc 28{ 29 typeset disk=$1 30 if [[ -z $disk ]]; then 31 print "no disk is given." 32 return 1 33 fi 34 35 /usr/sbin/format $disk << _EOF >/dev/null 2>&1 36label 37yes 38_EOF 39 40 labeltype=$(/usr/sbin/prtvtoc -fh /dev/${disk}s2 | \ 41 awk '{print $1}' | awk -F= '{print $2}' ) 42 if [[ -z $labeltype ]]; then 43 print "${disk} not exist." 44 return 1 45 fi 46 47 if [[ $labeltype == "34" ]]; then 48 49 typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID:-$$} 50 typeset arch=$(uname -p) 51 52 if [[ $arch == "i386" ]]; then 53 print "label" > $label_file 54 print "0" >> $label_file 55 print "" >> $label_file 56 print "q" >> $label_file 57 print "q" >> $label_file 58 59 fdisk -B /dev/${disk}p0 >/dev/null 2>&1 60 # wait a while for fdisk finishes 61 /usr/sbin/devfsadm > /dev/null 2>&1 62 elif [[ $arch == "sparc" ]]; then 63 print "label" > $label_file 64 print "0" >> $label_file 65 print "" >> $label_file 66 print "" >> $label_file 67 print "" >> $label_file 68 print "q" >> $label_file 69 else 70 print "unknow arch type : $arch" 71 return 1 72 fi 73 74 format -e -s -d $disk -f $label_file 75 typeset -i ret_val=$? 76 rm -f $label_file 77 # 78 # wait the format to finish 79 # 80 /usr/sbin/devfsadm > /dev/null 2>&1 81 if (( ret_val != 0 )); then 82 print "unable to label $disk as VTOC." 83 return 1 84 fi 85 fi 86 87 return 0 88} 89 90cmd=$1 91 92if [[ -z $cmd ]]; then 93 return 0 94fi 95 96shift 97 98 99typeset option 100case $cmd in 101 create|add|attach|detach|replace|remove|online|offline|clear) 102 for arg in $@; do 103 if [[ $arg == "/dev/"* ]]; then 104 arg=${arg#/dev/} 105 fi 106 107 print $arg | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 108 109 if [[ $? -eq 0 ]] ; then 110 labelvtoc $arg 111 if [[ $? -eq 0 ]] ; then 112 arg=${arg}s2 113 fi 114 fi 115 option="${option} $arg" 116 done 117 ;; 118 *) 119 option="$@" 120 ;; 121esac 122 123case $cmd in 124 create|add|attach|replace) 125 if [[ $option != *"-f"* ]]; then 126 cmd="${cmd} -f" 127 fi 128 ;; 129 *) 130 ;; 131esac 132 133print $cmd $option 134