1# vim: filetype=sh 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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27# ident "@(#)devices_common.kshlib 1.3 07/03/14 SMI" 28# 29 30. $STF_SUITE/include/libtest.kshlib 31 32# 33# Create block file or charactor file according to parameter. 34# 35# $1 device file type 36# $2 file name 37# 38function create_dev_file 39{ 40 typeset filetype=$1 41 typeset filename=$2 42 43 case $filetype in 44 b) 45 devtype=$($DF -T / | $AWK '{print $2}') 46 case $devtype in 47 zfs) 48 rootpool=$($DF / | \ 49 $AWK '{print $2}') 50 rootpool=${rootpool#\(} 51 rootpool=${rootpool%%/*} 52 53 devstr=$(get_disklist $rootpool) 54 devstr=$($ECHO "$devstr" | \ 55 $AWK '{print $1}') 56 [[ -z $devstr ]] && \ 57 log_fail "Can not get block device file." 58 devstr=/dev/${devstr} 59 ;; 60 ufs) 61 # 62 # Get the existing block device file in current system. 63 # And bring out the first one. 64 # 65 devstr=$($DF -lht ufs | \ 66 $GREP "^/dev/" | \ 67 $AWK '{print $1}') 68 devstr=$($ECHO "$devstr" | \ 69 $AWK '{print $1}') 70 [[ -z $devstr ]] && \ 71 log_fail "Can not get block device file." 72 ;; 73 *) 74 log_unsupported "Unsupported fstype " \ 75 "for / ($devtype)," \ 76 "only ufs|zfs is supported." 77 ;; 78 esac 79 80 # 81 # Get the device file information. i.e: 82 # /dev/c0t0d0s0: block special (28/768) 83 # 84 devstr=$($FILE $devstr) 85 86 # 87 # Bring out major and minor number. 88 # 89 major=${devstr##*\(} 90 major=${major%%/*} 91 minor=${devstr##*/} 92 minor=${minor%\)} 93 94 log_must $MKNOD $filename b $major $minor 95 ;; 96 c) 97 # 98 # Create device file '/dev/null' 99 # 100 log_must $MKNOD $filename c 13 2 101 ;; 102 *) 103 log_fail "'$filetype' is wrong." 104 ;; 105 esac 106 107 return 0 108} 109 110function cleanup 111{ 112 log_must $ZFS set devices=on $TESTPOOL/$TESTFS 113 log_must $RM -f $TESTDIR/$TESTFILE1 114 log_must $RM -f $TESTDIR/$TESTFILE2 115 log_must $RM -f $TESTDIR/$TESTFILE1.out 116 log_must $RM -f $TESTDIR/$TESTFILE2.out 117} 118 119