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