1100966Siwasaki#!/bin/sh
2100966Siwasaki# $FreeBSD$
3100966Siwasaki
4151937Sjkimdesc="mknod creates device files"
5100966Siwasaki
6100966Siwasakidir=`dirname $0`
7100966Siwasaki. ${dir}/../misc.sh
8100966Siwasaki
9100966Siwasakicase "${os}" in
10100966SiwasakiSunOS)
11100966Siwasaki	echo "1..40"
12151937Sjkim        ;;
13100966Siwasaki*)
14100966Siwasaki	echo "1..28"
15100966Siwasaki	;;
16100966Siwasakiesac
17100966Siwasaki
18100966Siwasakin0=`namegen`
19100966Siwasakin1=`namegen`
20100966Siwasaki
21100966Siwasakiexpect 0 mkdir ${n1} 0755
22100966Siwasakicdir=`pwd`
23100966Siwasakicd ${n1}
24100966Siwasaki
25100966Siwasakifor type in c b; do
26100966Siwasaki	case "${type}" in
27100966Siwasaki	c)
28100966Siwasaki		stattype="char"
29100966Siwasaki		;;
30100966Siwasaki	b)
31100966Siwasaki		stattype="block"
32100966Siwasaki		;;
33100966Siwasaki	esac
34100966Siwasaki
35100966Siwasaki	# Create char special with old-style numbers
36100966Siwasaki	expect 0 mknod ${n0} ${type} 0755 1 2
37100966Siwasaki	expect ${stattype},0755 lstat ${n0} type,mode
38100966Siwasaki	expect 1,2 lstat ${n0} major,minor
39100966Siwasaki	expect EEXIST mknod ${n0} ${type} 0777 3 4
40100966Siwasaki	expect 0 unlink ${n0}
41100966Siwasaki
42100966Siwasaki	case "${os}" in
43100966Siwasaki	SunOS)
44100966Siwasaki		# Create char special with new-style numbers
45100966Siwasaki		expect 0 mknod ${n0} ${type} 0755 4095 4095
46100966Siwasaki		expect ${stattype},0755 lstat ${n0} type,mode
47100966Siwasaki		expect 4095,4095 lstat ${n0} major,minor
48100966Siwasaki		expect EEXIST mknod ${n0} ${type} 0777 4000 4000
49100966Siwasaki		expect 0 unlink ${n0}
50100966Siwasaki
51100966Siwasaki		# mknod returns EINVAL if device's numbers are too big
52100966Siwasaki		# for 32-bit solaris !!
53100966Siwasaki		expect EINVAL mknod ${n0} ${type} 0755 4096 262144
54100966Siwasaki	        ;;
55100966Siwasaki	esac
56100966Siwasaki
57100966Siwasaki	# POSIX: Upon successful completion, mknod(2) shall mark for update the
58100966Siwasaki	# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and
59100966Siwasaki	# st_mtime fields of the directory that contains the new entry shall be marked
60100966Siwasaki	# for update.
61100966Siwasaki	expect 0 chown . 0 0
62100966Siwasaki	time=`${fstest} stat . ctime`
63100966Siwasaki	sleep 1
64100966Siwasaki	expect 0 mknod ${n0} ${type} 0755 1 2
65100966Siwasaki	atime=`${fstest} stat ${n0} atime`
66100966Siwasaki	test_check $time -lt $atime
67100966Siwasaki	mtime=`${fstest} stat ${n0} mtime`
68100966Siwasaki	test_check $time -lt $mtime
69100966Siwasaki	ctime=`${fstest} stat ${n0} ctime`
70100966Siwasaki	test_check $time -lt $ctime
71100966Siwasaki	mtime=`${fstest} stat . mtime`
72100966Siwasaki	test_check $time -lt $mtime
73100966Siwasaki	ctime=`${fstest} stat . ctime`
74100966Siwasaki	test_check $time -lt $ctime
75100966Siwasaki	expect 0 unlink ${n0}
76100966Siwasakidone
77100966Siwasaki
78100966Siwasakicd ${cdir}
79100966Siwasakiexpect 0 rmdir ${n1}
80100966Siwasaki