xref: /freebsd/contrib/pjdfstest/tests/ftruncate/00.t (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/ftruncate/00.t 219439 2011-03-09 23:11:30Z pjd $
3
4desc="ftruncate descrease/increase file size"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..26"
10
11n0=`namegen`
12n1=`namegen`
13
14expect 0 mkdir ${n1} 0755
15cdir=`pwd`
16cd ${n1}
17
18expect 0 create ${n0} 0644
19expect 0 open ${n0} O_RDWR : ftruncate 0 1234567
20expect 1234567 lstat ${n0} size
21expect 0 open ${n0} O_WRONLY : ftruncate 0 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 open ${n0} O_RDWR : ftruncate 0 23456
27expect 23456 lstat ${n0} size
28expect 0 open ${n0} O_WRONLY : ftruncate 0 1
29expect 1 lstat ${n0} size
30expect 0 unlink ${n0}
31
32# successful ftruncate(2) updates ctime.
33expect 0 create ${n0} 0644
34ctime1=`${fstest} stat ${n0} ctime`
35sleep 1
36expect 0 open ${n0} O_RDWR : ftruncate 0 123
37ctime2=`${fstest} stat ${n0} ctime`
38test_check $ctime1 -lt $ctime2
39expect 0 unlink ${n0}
40
41# unsuccessful ftruncate(2) does not update ctime.
42expect 0 create ${n0} 0644
43ctime1=`${fstest} stat ${n0} ctime`
44sleep 1
45expect EINVAL -u 65534 open ${n0} O_RDONLY : ftruncate 0 123
46ctime2=`${fstest} stat ${n0} ctime`
47test_check $ctime1 -eq $ctime2
48expect 0 unlink ${n0}
49
50# third argument should not affect permission.
51expect 0 open ${n0} O_CREAT,O_RDWR 0 : ftruncate 0 0
52expect 0 unlink ${n0}
53expect 0 chmod . 0777
54expect 0 -u 65534 open ${n0} O_CREAT,O_RDWR 0 : ftruncate 0 0
55expect 0 unlink ${n0}
56
57cd ${cdir}
58expect 0 rmdir ${n1}
59