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