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