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