xref: /freebsd/contrib/pjdfstest/tests/rename/00.t (revision 61e21613)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/00.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="rename changes file name"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10echo "1..150"
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} 0644
23	expect ${type},0644,1 lstat ${n0} type,mode,nlink
24	inode=`${fstest} lstat ${n0} inode`
25	expect 0 rename ${n0} ${n1}
26	expect ENOENT lstat ${n0} type,mode,nlink
27	expect ${type},${inode},0644,1 lstat ${n1} type,inode,mode,nlink
28	expect 0 link ${n1} ${n0}
29	expect ${type},${inode},0644,2 lstat ${n0} type,inode,mode,nlink
30	expect ${type},${inode},0644,2 lstat ${n1} type,inode,mode,nlink
31	expect 0 rename ${n1} ${n2}
32	expect ${type},${inode},0644,2 lstat ${n0} type,inode,mode,nlink
33	expect ENOENT lstat ${n1} type,mode,nlink
34	expect ${type},${inode},0644,2 lstat ${n2} type,inode,mode,nlink
35	expect 0 unlink ${n0}
36	expect 0 unlink ${n2}
37done
38
39expect 0 mkdir ${n0} 0755
40expect dir,0755 lstat ${n0} type,mode
41inode=`${fstest} lstat ${n0} inode`
42expect 0 rename ${n0} ${n1}
43expect ENOENT lstat ${n0} type,mode
44expect dir,${inode},0755 lstat ${n1} type,inode,mode
45expect 0 rmdir ${n1}
46
47expect 0 create ${n0} 0644
48rinode=`${fstest} lstat ${n0} inode`
49expect regular,0644 lstat ${n0} type,mode
50expect 0 symlink ${n0} ${n1}
51sinode=`${fstest} lstat ${n1} inode`
52expect regular,${rinode},0644 stat ${n1} type,inode,mode
53expect symlink,${sinode} lstat ${n1} type,inode
54expect 0 rename ${n1} ${n2}
55expect regular,${rinode},0644 stat ${n0} type,inode,mode
56expect ENOENT lstat ${n1} type,mode
57expect symlink,${sinode} lstat ${n2} type,inode
58expect 0 unlink ${n0}
59expect 0 unlink ${n2}
60
61# successful rename(2) updates ctime.
62for type in regular dir fifo block char socket symlink; do
63	create_file ${type} ${n0}
64	ctime1=`${fstest} lstat ${n0} ctime`
65	sleep 1
66	expect 0 rename ${n0} ${n1}
67	ctime2=`${fstest} lstat ${n1} ctime`
68	test_check $ctime1 -lt $ctime2
69	if [ "${type}" = "dir" ]; then
70		expect 0 rmdir ${n1}
71	else
72		expect 0 unlink ${n1}
73	fi
74done
75
76# unsuccessful link(2) does not update ctime.
77for type in regular dir fifo block char socket symlink; do
78	create_file ${type} ${n0}
79	ctime1=`${fstest} lstat ${n0} ctime`
80	sleep 1
81	expect EACCES -u 65534 rename ${n0} ${n1}
82	ctime2=`${fstest} lstat ${n0} ctime`
83	test_check $ctime1 -eq $ctime2
84	if [ "${type}" = "dir" ]; then
85		expect 0 rmdir ${n0}
86	else
87		expect 0 unlink ${n0}
88	fi
89done
90
91cd ${cdir}
92expect 0 rmdir ${n3}
93