1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# 28# Copyright (c) 2013 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/tests/functional/devices/devices.cfg 32. $STF_SUITE/include/libtest.shlib 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 -n / | $AWK '{print $3}') 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/dsk/${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 -lhF ufs | \ 68 $GREP "^/dev/dsk" | \ 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/dsk/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 $($GETMAJOR mm) 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