12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# $FreeBSD$ 242fae26bdSAlan Somers 252fae26bdSAlan Somers# 262fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 272fae26bdSAlan Somers# Use is subject to license terms. 282fae26bdSAlan Somers# 292fae26bdSAlan Somers# ident "@(#)zpool_smi.ksh 1.2 09/01/13 SMI" 302fae26bdSAlan Somers# 312fae26bdSAlan Somers 322fae26bdSAlan Somersfunction labelvtoc 332fae26bdSAlan Somers{ 342fae26bdSAlan Somers typeset disk=$1 352fae26bdSAlan Somers if [[ -z $disk ]]; then 362fae26bdSAlan Somers print "no disk is given." 372fae26bdSAlan Somers return 1 382fae26bdSAlan Somers fi 392fae26bdSAlan Somers 402fae26bdSAlan Somers /usr/sbin/format $disk << _EOF >/dev/null 2>&1 412fae26bdSAlan Somerslabel 422fae26bdSAlan Somersyes 432fae26bdSAlan Somers_EOF 442fae26bdSAlan Somers 45*5a2fc464SAndriy Gapon labeltype=$(/usr/sbin/prtvtoc -fh /dev/${disk}s2 | \ 462fae26bdSAlan Somers awk '{print $1}' | awk -F= '{print $2}' ) 472fae26bdSAlan Somers if [[ -z $labeltype ]]; then 482fae26bdSAlan Somers print "${disk} not exist." 492fae26bdSAlan Somers return 1 502fae26bdSAlan Somers fi 512fae26bdSAlan Somers 522fae26bdSAlan Somers if [[ $labeltype == "34" ]]; then 532fae26bdSAlan Somers 542fae26bdSAlan Somers typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID:-$$} 552fae26bdSAlan Somers typeset arch=$(uname -p) 562fae26bdSAlan Somers 572fae26bdSAlan Somers if [[ $arch == "i386" ]]; then 582fae26bdSAlan Somers print "label" > $label_file 592fae26bdSAlan Somers print "0" >> $label_file 602fae26bdSAlan Somers print "" >> $label_file 612fae26bdSAlan Somers print "q" >> $label_file 622fae26bdSAlan Somers print "q" >> $label_file 632fae26bdSAlan Somers 64*5a2fc464SAndriy Gapon fdisk -B /dev/${disk}p0 >/dev/null 2>&1 652fae26bdSAlan Somers # wait a while for fdisk finishes 662fae26bdSAlan Somers /usr/sbin/devfsadm > /dev/null 2>&1 672fae26bdSAlan Somers elif [[ $arch == "sparc" ]]; then 682fae26bdSAlan Somers print "label" > $label_file 692fae26bdSAlan Somers print "0" >> $label_file 702fae26bdSAlan Somers print "" >> $label_file 712fae26bdSAlan Somers print "" >> $label_file 722fae26bdSAlan Somers print "" >> $label_file 732fae26bdSAlan Somers print "q" >> $label_file 742fae26bdSAlan Somers else 752fae26bdSAlan Somers print "unknow arch type : $arch" 762fae26bdSAlan Somers return 1 772fae26bdSAlan Somers fi 782fae26bdSAlan Somers 792fae26bdSAlan Somers format -e -s -d $disk -f $label_file 802fae26bdSAlan Somers typeset -i ret_val=$? 812fae26bdSAlan Somers rm -f $label_file 822fae26bdSAlan Somers # 832fae26bdSAlan Somers # wait the format to finish 842fae26bdSAlan Somers # 852fae26bdSAlan Somers /usr/sbin/devfsadm > /dev/null 2>&1 862fae26bdSAlan Somers if (( ret_val != 0 )); then 872fae26bdSAlan Somers print "unable to label $disk as VTOC." 882fae26bdSAlan Somers return 1 892fae26bdSAlan Somers fi 902fae26bdSAlan Somers fi 912fae26bdSAlan Somers 922fae26bdSAlan Somers return 0 932fae26bdSAlan Somers} 942fae26bdSAlan Somers 952fae26bdSAlan Somerscmd=$1 962fae26bdSAlan Somers 972fae26bdSAlan Somersif [[ -z $cmd ]]; then 982fae26bdSAlan Somers return 0 992fae26bdSAlan Somersfi 1002fae26bdSAlan Somers 1012fae26bdSAlan Somersshift 1022fae26bdSAlan Somers 1032fae26bdSAlan Somers 1042fae26bdSAlan Somerstypeset option 1052fae26bdSAlan Somerscase $cmd in 1062fae26bdSAlan Somers create|add|attach|detach|replace|remove|online|offline|clear) 1072fae26bdSAlan Somers for arg in $@; do 108*5a2fc464SAndriy Gapon if [[ $arg == "/dev/"* ]]; then 109*5a2fc464SAndriy Gapon arg=${arg#/dev/} 1102fae26bdSAlan Somers fi 1112fae26bdSAlan Somers 1122fae26bdSAlan Somers print $arg | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 1132fae26bdSAlan Somers 1142fae26bdSAlan Somers if [[ $? -eq 0 ]] ; then 1152fae26bdSAlan Somers labelvtoc $arg 1162fae26bdSAlan Somers if [[ $? -eq 0 ]] ; then 1172fae26bdSAlan Somers arg=${arg}s2 1182fae26bdSAlan Somers fi 1192fae26bdSAlan Somers fi 1202fae26bdSAlan Somers option="${option} $arg" 1212fae26bdSAlan Somers done 1222fae26bdSAlan Somers ;; 1232fae26bdSAlan Somers *) 1242fae26bdSAlan Somers option="$@" 1252fae26bdSAlan Somers ;; 1262fae26bdSAlan Somersesac 1272fae26bdSAlan Somers 1282fae26bdSAlan Somerscase $cmd in 1292fae26bdSAlan Somers create|add|attach|replace) 1302fae26bdSAlan Somers if [[ $option != *"-f"* ]]; then 1312fae26bdSAlan Somers cmd="${cmd} -f" 1322fae26bdSAlan Somers fi 1332fae26bdSAlan Somers ;; 1342fae26bdSAlan Somers *) 1352fae26bdSAlan Somers ;; 1362fae26bdSAlan Somersesac 1372fae26bdSAlan Somers 1382fae26bdSAlan Somersprint $cmd $option 139