forked from zfsonlinux/fstest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.sh
153 lines (134 loc) · 2.78 KB
/
misc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# $FreeBSD: src/tools/regression/fstest/tests/misc.sh,v 1.1 2007/01/17 01:42:08 pjd Exp $
ntest=1
name253="_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_12"
name255="${name253}34"
name256="${name255}5"
path1021="${name255}/${name255}/${name255}/${name253}"
path1023="${path1021}/x"
path1024="${path1023}x"
echo ${dir} | egrep '^/' >/dev/null 2>&1
if [ $? -eq 0 ]; then
maindir="${dir}/../.."
else
maindir="`pwd`/${dir}/../.."
fi
fstest="${maindir}/fstest"
. ${maindir}/tests/conf
run_getconf()
{
if val=$(getconf "${1}" .); then
if [ "$value" = "undefined" ]; then
echo "${1} is undefined"
exit 1
fi
else
echo "Failed to get ${1}"
exit 1
fi
echo $val
}
name_max_val=$(run_getconf NAME_MAX)
path_max_val=$(run_getconf PATH_MAX)
name_max="_"
i=1
while test $i -lt $name_max_val ; do
name_max="${name_max}x"
i=$(($i+1))
done
num_of_dirs=$(( ($path_max_val + $name_max_val) / ($name_max_val + 1) - 1 ))
long_dir="${name_max}"
i=1
while test $i -lt $num_of_dirs ; do
long_dir="${long_dir}/${name_max}"
i=$(($i+1))
done
long_dir="${long_dir}/x"
too_long="${long_dir}/${name_max}"
create_too_long()
{
mkdir -p ${long_dir}
}
unlink_too_long()
{
rm -rf ${name_max}
}
expect()
{
e="${1}"
shift
tmp=fstest_$$.err
r=`${fstest} $* 2>${tmp} | tail -1`
echo "${r}" | egrep '^'${e}'$' >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ok ${ntest}"
else
echo "not ok ${ntest}"
echo "# ${ntest}: expected '${e}', received '${r}'"
echo "# ${ntest}: executed '${fstest} '" "$@" "'"
awk '{print "# '${ntest}': err: " $0;}' ${tmp}
fi
rm ${tmp}
ntest=`expr $ntest + 1`
}
jexpect()
{
s="${1}"
d="${2}"
e="${3}"
shift 3
r=`jail -s ${s} / fstest 127.0.0.1 /bin/sh -c "cd ${d} && ${fstest} $* 2>/dev/null" | tail -1`
echo "${r}" | egrep '^'${e}'$' >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ok ${ntest}"
else
echo "not ok ${ntest}"
fi
ntest=`expr $ntest + 1`
}
test_check()
{
if [ $* ]; then
echo "ok ${ntest}"
else
echo "not ok ${ntest}"
echo "# ${ntest}: failed check: '$*'"
fi
ntest=`expr $ntest + 1`
}
namegen()
{
if [ ${os} == 'Darwin' ] ; then
echo "fstest_`dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5 | cut -f1 -d' '`"
else
echo "fstest_`dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5sum | cut -f1 -d' '`"
fi
}
quick_exit()
{
echo "1..1"
echo "ok 1"
exit 0
}
supported()
{
case "${1}" in
chflags)
if [ '(' ${os} != "FreeBSD" -a ${os} != "Darwin" ')' -o ${fs} != "UFS" ]; then
return 1
fi
;;
lchmod)
if [ ${os} != "FreeBSD" ]; then
return 1
fi
;;
esac
return 0
}
require()
{
if supported ${1}; then
return
fi
quick_exit
}