1271294Sngie#!/bin/sh
2271294Sngie# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/11.t 211352 2010-08-15 21:24:17Z pjd $
3271294Sngie
4271294Sngiedesc="mknod creates device files"
5271294Sngie
6271294Sngiedir=`dirname $0`
7271294Sngie. ${dir}/../misc.sh
8271294Sngie
9271294Sngiecase "${os}" in
10271294SngieSunOS)
11271294Sngie	echo "1..40"
12271294Sngie        ;;
13271294Sngie*)
14271294Sngie	echo "1..28"
15271294Sngie	;;
16271294Sngieesac
17271294Sngie
18271294Sngien0=`namegen`
19271294Sngien1=`namegen`
20271294Sngie
21271294Sngieexpect 0 mkdir ${n1} 0755
22271294Sngiecdir=`pwd`
23271294Sngiecd ${n1}
24271294Sngie
25271294Sngiefor type in c b; do
26271294Sngie	case "${type}" in
27271294Sngie	c)
28271294Sngie		stattype="char"
29271294Sngie		;;
30271294Sngie	b)
31271294Sngie		stattype="block"
32271294Sngie		;;
33271294Sngie	esac
34271294Sngie
35271294Sngie	# Create char special with old-style numbers
36271294Sngie	expect 0 mknod ${n0} ${type} 0755 1 2
37271294Sngie	expect ${stattype},0755 lstat ${n0} type,mode
38271294Sngie	expect 1,2 lstat ${n0} major,minor
39271294Sngie	expect EEXIST mknod ${n0} ${type} 0777 3 4
40271294Sngie	expect 0 unlink ${n0}
41271294Sngie
42271294Sngie	case "${os}" in
43271294Sngie	SunOS)
44271294Sngie		# Create char special with new-style numbers
45271294Sngie		expect 0 mknod ${n0} ${type} 0755 4095 4095
46271294Sngie		expect ${stattype},0755 lstat ${n0} type,mode
47271294Sngie		expect 4095,4095 lstat ${n0} major,minor
48271294Sngie		expect EEXIST mknod ${n0} ${type} 0777 4000 4000
49271294Sngie		expect 0 unlink ${n0}
50271294Sngie
51271294Sngie		# mknod returns EINVAL if device's numbers are too big
52271294Sngie		# for 32-bit solaris !!
53271294Sngie		expect EINVAL mknod ${n0} ${type} 0755 4096 262144
54271294Sngie	        ;;
55271294Sngie	esac
56271294Sngie
57271294Sngie	# POSIX: Upon successful completion, mknod(2) shall mark for update the
58271294Sngie	# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and
59271294Sngie	# st_mtime fields of the directory that contains the new entry shall be marked
60271294Sngie	# for update.
61271294Sngie	expect 0 chown . 0 0
62271294Sngie	time=`${fstest} stat . ctime`
63271294Sngie	sleep 1
64271294Sngie	expect 0 mknod ${n0} ${type} 0755 1 2
65271294Sngie	atime=`${fstest} stat ${n0} atime`
66271294Sngie	test_check $time -lt $atime
67271294Sngie	mtime=`${fstest} stat ${n0} mtime`
68271294Sngie	test_check $time -lt $mtime
69271294Sngie	ctime=`${fstest} stat ${n0} ctime`
70271294Sngie	test_check $time -lt $ctime
71271294Sngie	mtime=`${fstest} stat . mtime`
72271294Sngie	test_check $time -lt $mtime
73271294Sngie	ctime=`${fstest} stat . ctime`
74271294Sngie	test_check $time -lt $ctime
75271294Sngie	expect 0 unlink ${n0}
76271294Sngiedone
77271294Sngie
78271294Sngiecd ${cdir}
79271294Sngieexpect 0 rmdir ${n1}
80