xref: /freebsd/contrib/pjdfstest/tests/truncate/00.t (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/00.t 211352 2010-08-15 21:24:17Z pjd $
3
4desc="truncate descrease/increase file size"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..21"
10
11n0=`namegen`
12n1=`namegen`
13
14expect 0 mkdir ${n1} 0755
15cdir=`pwd`
16cd ${n1}
17
18expect 0 create ${n0} 0644
19expect 0 truncate ${n0} 1234567
20expect 1234567 lstat ${n0} size
21expect 0 truncate ${n0} 567
22expect 567 lstat ${n0} size
23expect 0 unlink ${n0}
24
25dd if=/dev/random of=${n0} bs=12345 count=1 >/dev/null 2>&1
26expect 0 truncate ${n0} 23456
27expect 23456 lstat ${n0} size
28expect 0 truncate ${n0} 1
29expect 1 lstat ${n0} size
30expect 0 unlink ${n0}
31
32# successful truncate(2) updates ctime.
33expect 0 create ${n0} 0644
34ctime1=`${fstest} stat ${n0} ctime`
35sleep 1
36expect 0 truncate ${n0} 123
37ctime2=`${fstest} stat ${n0} ctime`
38test_check $ctime1 -lt $ctime2
39expect 0 unlink ${n0}
40
41# unsuccessful truncate(2) does not update ctime.
42expect 0 create ${n0} 0644
43ctime1=`${fstest} stat ${n0} ctime`
44sleep 1
45expect EACCES -u 65534 truncate ${n0} 123
46ctime2=`${fstest} stat ${n0} ctime`
47test_check $ctime1 -eq $ctime2
48expect 0 unlink ${n0}
49
50cd ${cdir}
51expect 0 rmdir ${n1}
52