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# 27# ident "@(#)zpool_smi.ksh 1.2 09/01/13 SMI" 28# 29 30function labelvtoc 31{ 32 typeset disk=$1 33 if [[ -z $disk ]]; then 34 print "no disk is given." 35 return 1 36 fi 37 38 /usr/sbin/format $disk << _EOF >/dev/null 2>&1 39label 40yes 41_EOF 42 43 labeltype=$(/usr/sbin/prtvtoc -fh /dev/${disk}s2 | \ 44 awk '{print $1}' | awk -F= '{print $2}' ) 45 if [[ -z $labeltype ]]; then 46 print "${disk} not exist." 47 return 1 48 fi 49 50 if [[ $labeltype == "34" ]]; then 51 52 typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID:-$$} 53 typeset arch=$(uname -p) 54 55 if [[ $arch == "i386" ]]; then 56 print "label" > $label_file 57 print "0" >> $label_file 58 print "" >> $label_file 59 print "q" >> $label_file 60 print "q" >> $label_file 61 62 fdisk -B /dev/${disk}p0 >/dev/null 2>&1 63 # wait a while for fdisk finishes 64 /usr/sbin/devfsadm > /dev/null 2>&1 65 elif [[ $arch == "sparc" ]]; then 66 print "label" > $label_file 67 print "0" >> $label_file 68 print "" >> $label_file 69 print "" >> $label_file 70 print "" >> $label_file 71 print "q" >> $label_file 72 else 73 print "unknow arch type : $arch" 74 return 1 75 fi 76 77 format -e -s -d $disk -f $label_file 78 typeset -i ret_val=$? 79 rm -f $label_file 80 # 81 # wait the format to finish 82 # 83 /usr/sbin/devfsadm > /dev/null 2>&1 84 if (( ret_val != 0 )); then 85 print "unable to label $disk as VTOC." 86 return 1 87 fi 88 fi 89 90 return 0 91} 92 93cmd=$1 94 95if [[ -z $cmd ]]; then 96 return 0 97fi 98 99shift 100 101 102typeset option 103case $cmd in 104 create|add|attach|detach|replace|remove|online|offline|clear) 105 for arg in $@; do 106 if [[ $arg == "/dev/"* ]]; then 107 arg=${arg#/dev/} 108 fi 109 110 print $arg | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 111 112 if [[ $? -eq 0 ]] ; then 113 labelvtoc $arg 114 if [[ $? -eq 0 ]] ; then 115 arg=${arg}s2 116 fi 117 fi 118 option="${option} $arg" 119 done 120 ;; 121 *) 122 option="$@" 123 ;; 124esac 125 126case $cmd in 127 create|add|attach|replace) 128 if [[ $option != *"-f"* ]]; then 129 cmd="${cmd} -f" 130 fi 131 ;; 132 *) 133 ;; 134esac 135 136print $cmd $option 137