1166065Spjd#!/bin/sh
2166065Spjd# $FreeBSD$
3166065Spjd
4166065Spjddesc="link creates hardlinks"
5166065Spjd
6166065Spjddir=`dirname $0`
7166065Spjd. ${dir}/../misc.sh
8166065Spjd
9211186Spjdecho "1..202"
10166065Spjd
11166065Spjdn0=`namegen`
12166065Spjdn1=`namegen`
13166065Spjdn2=`namegen`
14166065Spjdn3=`namegen`
15166065Spjd
16166065Spjdexpect 0 mkdir ${n3} 0755
17166065Spjdcdir=`pwd`
18166065Spjdcd ${n3}
19166065Spjd
20211180Spjdfor type in regular fifo block char socket; do
21211186Spjd	create_file ${type} ${n0}
22211180Spjd	expect ${type},1 lstat ${n0} type,nlink
23166065Spjd
24211180Spjd	expect 0 link ${n0} ${n1}
25211180Spjd	expect ${type},2 lstat ${n0} type,nlink
26211180Spjd	expect ${type},2 lstat ${n1} type,nlink
27166065Spjd
28211180Spjd	expect 0 link ${n1} ${n2}
29211180Spjd	expect ${type},3 lstat ${n0} type,nlink
30211180Spjd	expect ${type},3 lstat ${n1} type,nlink
31211180Spjd	expect ${type},3 lstat ${n2} type,nlink
32166065Spjd
33211180Spjd	expect 0 chmod ${n1} 0201
34211180Spjd	expect 0 chown ${n1} 65534 65533
35166065Spjd
36211180Spjd	expect ${type},0201,3,65534,65533 lstat ${n0} type,mode,nlink,uid,gid
37211180Spjd	expect ${type},0201,3,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
38211180Spjd	expect ${type},0201,3,65534,65533 lstat ${n2} type,mode,nlink,uid,gid
39166065Spjd
40211180Spjd	expect 0 unlink ${n0}
41211180Spjd	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
42211180Spjd	expect ${type},0201,2,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
43211180Spjd	expect ${type},0201,2,65534,65533 lstat ${n2} type,mode,nlink,uid,gid
44166065Spjd
45211180Spjd	expect 0 unlink ${n2}
46211180Spjd	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
47211180Spjd	expect ${type},0201,1,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
48211180Spjd	expect ENOENT lstat ${n2} type,mode,nlink,uid,gid
49166065Spjd
50211180Spjd	expect 0 unlink ${n1}
51211180Spjd	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
52211180Spjd	expect ENOENT lstat ${n1} type,mode,nlink,uid,gid
53211180Spjd	expect ENOENT lstat ${n2} type,mode,nlink,uid,gid
54211180Spjddone
55166065Spjd
56166065Spjd# successful link(2) updates ctime.
57211180Spjdfor type in regular fifo block char socket; do
58211186Spjd	create_file ${type} ${n0}
59211180Spjd	ctime1=`${fstest} stat ${n0} ctime`
60211180Spjd	dctime1=`${fstest} stat . ctime`
61211180Spjd	dmtime1=`${fstest} stat . mtime`
62211180Spjd	sleep 1
63211180Spjd	expect 0 link ${n0} ${n1}
64211180Spjd	ctime2=`${fstest} stat ${n0} ctime`
65211180Spjd	test_check $ctime1 -lt $ctime2
66211180Spjd	dctime2=`${fstest} stat . ctime`
67211180Spjd	test_check $dctime1 -lt $dctime2
68211180Spjd	dmtime2=`${fstest} stat . mtime`
69211180Spjd	test_check $dctime1 -lt $dmtime2
70211180Spjd	expect 0 unlink ${n0}
71211180Spjd	expect 0 unlink ${n1}
72211180Spjddone
73166065Spjd
74166065Spjd# unsuccessful link(2) does not update ctime.
75211180Spjdfor type in regular fifo block char socket; do
76211186Spjd	create_file ${type} ${n0}
77211180Spjd	expect 0 -- chown ${n0} 65534 -1
78211180Spjd	ctime1=`${fstest} stat ${n0} ctime`
79211180Spjd	dctime1=`${fstest} stat . ctime`
80211180Spjd	dmtime1=`${fstest} stat . mtime`
81211180Spjd	sleep 1
82211180Spjd	expect EACCES -u 65534 link ${n0} ${n1}
83211180Spjd	ctime2=`${fstest} stat ${n0} ctime`
84211180Spjd	test_check $ctime1 -eq $ctime2
85211180Spjd	dctime2=`${fstest} stat . ctime`
86211180Spjd	test_check $dctime1 -eq $dctime2
87211180Spjd	dmtime2=`${fstest} stat . mtime`
88211180Spjd	test_check $dctime1 -eq $dmtime2
89211180Spjd	expect 0 unlink ${n0}
90211180Spjddone
91166065Spjd
92166065Spjdcd ${cdir}
93166065Spjdexpect 0 rmdir ${n3}
94