summaryrefslogtreecommitdiffstats
path: root/tools/regression/fstest/tests/open/00.t
blob: 48bc27a28c7d68c3237561a9eb52376b65d275c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# $FreeBSD$

desc="open opens (and eventually creates) a file"

dir=`dirname $0`
. ${dir}/../misc.sh

echo "1..45"

n0=`namegen`
n1=`namegen`

expect 0 mkdir ${n1} 0755
cdir=`pwd`
cd ${n1}

expect 0 open ${n0} O_CREAT,O_WRONLY 0755
expect regular,0755 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 open ${n0} O_CREAT,O_WRONLY 0151
expect regular,0151 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
expect regular,0100 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
expect regular,0305 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
expect regular,0244 lstat ${n0} type,mode
expect 0 unlink ${n0}

expect 0 chown . 65535 65535
expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
expect 65535,65535 lstat ${n0} uid,gid
expect 0 unlink ${n0}
expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
expect 65535,65535 lstat ${n0} uid,gid
expect 0 unlink ${n0}
expect 0 chmod . 0777
expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
expect 65534,65535 lstat ${n0} uid,gid
expect 0 unlink ${n0}

# Update parent directory ctime/mtime if file didn't exist.
expect 0 chown . 0 0
time=`${fstest} stat . ctime`
sleep 1
expect 0 open ${n0} O_CREAT,O_WRONLY 0644
atime=`${fstest} stat ${n0} atime`
test_check $time -lt $atime
mtime=`${fstest} stat ${n0} mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat ${n0} ctime`
test_check $time -lt $ctime
mtime=`${fstest} stat . mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat . ctime`
test_check $time -lt $ctime
expect 0 unlink ${n0}

# Don't update parent directory ctime/mtime if file existed.
expect 0 create ${n0} 0644
dmtime=`${fstest} stat . mtime`
dctime=`${fstest} stat . ctime`
sleep 1
expect 0 open ${n0} O_CREAT,O_RDONLY 0644
mtime=`${fstest} stat . mtime`
test_check $dmtime -eq $mtime
ctime=`${fstest} stat . ctime`
test_check $dctime -eq $ctime
expect 0 unlink ${n0}

echo test > ${n0}
mtime1=`${fstest} stat ${n0} mtime`
ctime1=`${fstest} stat ${n0} ctime`
sleep 1
expect 0 open ${n0} O_WRONLY,O_TRUNC
mtime2=`${fstest} stat ${n0} mtime`
test_check $mtime1 -lt $mtime2
ctime2=`${fstest} stat ${n0} ctime`
test_check $ctime1 -lt $ctime2
expect 0 unlink ${n0}

cd ${cdir}
expect 0 rmdir ${n1}
OpenPOWER on IntegriCloud