]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/devices/devices_common.kshlib
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / devices / devices_common.kshlib
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, 2016 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 character file according to parameter.
36 #
37 # $1 device file type
38 # $2 file name
39 # $3 device path (used for 'b' device type)
40 #
41 function create_dev_file
42 {
43         typeset filetype=$1
44         typeset filename=$2
45         typeset devstr=$3
46
47         case $filetype in
48         b)
49                 case $(uname) in
50                 Linux)
51                         #
52                         # stat(1) --format=FORMAT tokens
53                         # %t - major device type in hex
54                         # %T - minor device type in hex
55                         #
56                         major=$(stat --dereference --format="%t" "$devstr")
57                         minor=$(stat --dereference --format="%T" "$devstr")
58                         log_must mknod $filename b "0x${major}" "0x${minor}"
59                         ;;
60                 *)
61                         #
62                         # Get the device file information. i.e:
63                         # $devstr:      block special (28/768)
64                         #
65                         devstr=$(file $devstr)
66                         major=${devstr##*\(}
67                         major=${major%%/*}
68                         minor=${devstr##*/}
69                         minor=${minor%\)}
70                         log_must mknod $filename b $major $minor
71                         ;;
72                 esac
73                 ;;
74         c)
75                 #
76                 # Create device file '/dev/null', $devstr is unused.
77                 #
78                 case $(uname) in
79                 Linux)
80                         #
81                         # stat(1) --format=FORMAT tokens
82                         # %t - major device type in hex
83                         # %T - minor device type in hex
84                         #
85                         major=$(stat --format="%t" /dev/null)
86                         minor=$(stat --format="%T" /dev/null)
87                         log_must mknod $filename c "0x${major}" "0x${minor}"
88                         ;;
89                 FreeBSD)
90                         #
91                         # Create device file '/dev/null'
92                         #
93                         major=13
94                         minor=2
95                         log_must mknod $filename b $major $minor
96                         ;;
97                 *)
98                         major=$(getmajor mm)
99                         minor=2
100                         log_must mknod $filename b $major $minor
101                         ;;
102                 esac
103                 ;;
104         *)
105                 log_fail "'$filetype' is wrong."
106                 ;;
107         esac
108
109         return 0
110 }
111
112 function 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.out1
118         log_must rm -f $TESTDIR/$TESTFILE1.out2
119 }