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