xref: /freebsd/contrib/pjdfstest/tests/truncate/08.t (revision 2a58b312b62f908ec92311d1bd8536dbaeb8e55b)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/08.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="truncate returns EPERM if the named file has its immutable or append-only flag set"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12case "${os}:${fs}" in
13FreeBSD:ZFS)
14	echo "1..22"
15	;;
16FreeBSD:UFS)
17	echo "1..44"
18	;;
19*)
20	quick_exit
21esac
22
23n0=`namegen`
24
25expect 0 create ${n0} 0644
26expect 0 chflags ${n0} SF_IMMUTABLE
27expect EPERM truncate ${n0} 123
28expect 0 stat ${n0} size
29expect 0 chflags ${n0} none
30expect 0 truncate ${n0} 123
31expect 123 stat ${n0} size
32expect 0 unlink ${n0}
33
34expect 0 create ${n0} 0644
35expect 0 chflags ${n0} SF_NOUNLINK
36expect 0 truncate ${n0} 123
37expect 123 stat ${n0} size
38expect 0 chflags ${n0} none
39expect 0 unlink ${n0}
40
41expect 0 create ${n0} 0644
42expect 0 chflags ${n0} SF_APPEND
43todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM."
44expect EPERM truncate ${n0} 123
45todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM."
46expect 0 stat ${n0} size
47expect 0 chflags ${n0} none
48expect 0 truncate ${n0} 123
49expect 123 stat ${n0} size
50expect 0 unlink ${n0}
51
52case "${os}:${fs}" in
53FreeBSD:UFS)
54	expect 0 create ${n0} 0644
55	expect 0 chflags ${n0} UF_IMMUTABLE
56	expect EPERM truncate ${n0} 123
57	expect 0 stat ${n0} size
58	expect 0 chflags ${n0} none
59	expect 0 truncate ${n0} 123
60	expect 123 stat ${n0} size
61	expect 0 unlink ${n0}
62
63	expect 0 create ${n0} 0644
64	expect 0 chflags ${n0} UF_NOUNLINK
65	expect 0 truncate ${n0} 123
66	expect 123 stat ${n0} size
67	expect 0 chflags ${n0} none
68	expect 0 unlink ${n0}
69
70	expect 0 create ${n0} 0644
71	expect 0 chflags ${n0} UF_APPEND
72	expect EPERM truncate ${n0} 123
73	expect 0 stat ${n0} size
74	expect 0 chflags ${n0} none
75	expect 0 truncate ${n0} 123
76	expect 123 stat ${n0} size
77	expect 0 unlink ${n0}
78	;;
79esac
80