xref: /freebsd/contrib/pjdfstest/tests/link/00.t (revision cd0d51baaa4509a1db83251a601d34404d20c990)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/link/00.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="link creates hardlinks"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10echo "1..202"
11
12n0=`namegen`
13n1=`namegen`
14n2=`namegen`
15n3=`namegen`
16
17expect 0 mkdir ${n3} 0755
18cdir=`pwd`
19cd ${n3}
20
21for type in regular fifo block char socket; do
22	create_file ${type} ${n0}
23	expect ${type},1 lstat ${n0} type,nlink
24
25	expect 0 link ${n0} ${n1}
26	expect ${type},2 lstat ${n0} type,nlink
27	expect ${type},2 lstat ${n1} type,nlink
28
29	expect 0 link ${n1} ${n2}
30	expect ${type},3 lstat ${n0} type,nlink
31	expect ${type},3 lstat ${n1} type,nlink
32	expect ${type},3 lstat ${n2} type,nlink
33
34	expect 0 chmod ${n1} 0201
35	expect 0 chown ${n1} 65534 65533
36
37	expect ${type},0201,3,65534,65533 lstat ${n0} type,mode,nlink,uid,gid
38	expect ${type},0201,3,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
39	expect ${type},0201,3,65534,65533 lstat ${n2} type,mode,nlink,uid,gid
40
41	expect 0 unlink ${n0}
42	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
43	expect ${type},0201,2,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
44	expect ${type},0201,2,65534,65533 lstat ${n2} type,mode,nlink,uid,gid
45
46	expect 0 unlink ${n2}
47	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
48	expect ${type},0201,1,65534,65533 lstat ${n1} type,mode,nlink,uid,gid
49	expect ENOENT lstat ${n2} type,mode,nlink,uid,gid
50
51	expect 0 unlink ${n1}
52	expect ENOENT lstat ${n0} type,mode,nlink,uid,gid
53	expect ENOENT lstat ${n1} type,mode,nlink,uid,gid
54	expect ENOENT lstat ${n2} type,mode,nlink,uid,gid
55done
56
57# successful link(2) updates ctime.
58for type in regular fifo block char socket; do
59	create_file ${type} ${n0}
60	ctime1=`${fstest} stat ${n0} ctime`
61	dctime1=`${fstest} stat . ctime`
62	dmtime1=`${fstest} stat . mtime`
63	sleep 1
64	expect 0 link ${n0} ${n1}
65	ctime2=`${fstest} stat ${n0} ctime`
66	test_check $ctime1 -lt $ctime2
67	dctime2=`${fstest} stat . ctime`
68	test_check $dctime1 -lt $dctime2
69	dmtime2=`${fstest} stat . mtime`
70	test_check $dctime1 -lt $dmtime2
71	expect 0 unlink ${n0}
72	expect 0 unlink ${n1}
73done
74
75# unsuccessful link(2) does not update ctime.
76for type in regular fifo block char socket; do
77	create_file ${type} ${n0}
78	expect 0 -- chown ${n0} 65534 -1
79	ctime1=`${fstest} stat ${n0} ctime`
80	dctime1=`${fstest} stat . ctime`
81	dmtime1=`${fstest} stat . mtime`
82	sleep 1
83	expect EACCES -u 65534 link ${n0} ${n1}
84	ctime2=`${fstest} stat ${n0} ctime`
85	test_check $ctime1 -eq $ctime2
86	dctime2=`${fstest} stat . ctime`
87	test_check $dctime1 -eq $dctime2
88	dmtime2=`${fstest} stat . mtime`
89	test_check $dctime1 -eq $dmtime2
90	expect 0 unlink ${n0}
91done
92
93cd ${cdir}
94expect 0 rmdir ${n3}
95