1166065Spjd#!/bin/sh
2166065Spjd# $FreeBSD$
3166065Spjd
4166065Spjddesc="open opens (and eventually creates) a file"
5166065Spjd
6166065Spjddir=`dirname $0`
7166065Spjd. ${dir}/../misc.sh
8166065Spjd
9166232Spjdecho "1..47"
10166065Spjd
11166065Spjdn0=`namegen`
12166065Spjdn1=`namegen`
13166065Spjd
14166065Spjdexpect 0 mkdir ${n1} 0755
15166065Spjdcdir=`pwd`
16166065Spjdcd ${n1}
17166065Spjd
18166232Spjd# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the access
19166232Spjd# permission bits of the file mode shall be set to the value of the third
20166232Spjd# argument taken as type mode_t modified as follows: a bitwise AND is performed
21166232Spjd# on the file-mode bits and the corresponding bits in the complement of the
22166232Spjd# process' file mode creation mask. Thus, all bits in the file mode whose
23166232Spjd# corresponding bit in the file mode creation mask is set are cleared.
24166065Spjdexpect 0 open ${n0} O_CREAT,O_WRONLY 0755
25166065Spjdexpect regular,0755 lstat ${n0} type,mode
26166065Spjdexpect 0 unlink ${n0}
27166065Spjdexpect 0 open ${n0} O_CREAT,O_WRONLY 0151
28166065Spjdexpect regular,0151 lstat ${n0} type,mode
29166065Spjdexpect 0 unlink ${n0}
30166065Spjdexpect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
31166065Spjdexpect regular,0100 lstat ${n0} type,mode
32166065Spjdexpect 0 unlink ${n0}
33166065Spjdexpect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
34166065Spjdexpect regular,0305 lstat ${n0} type,mode
35166065Spjdexpect 0 unlink ${n0}
36166065Spjdexpect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
37166065Spjdexpect regular,0244 lstat ${n0} type,mode
38166065Spjdexpect 0 unlink ${n0}
39166065Spjd
40166232Spjd# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the user ID
41166232Spjd# of the file shall be set to the effective user ID of the process; the group ID
42166232Spjd# of the file shall be set to the group ID of the file's parent directory or to
43166232Spjd# the effective group ID of the process [...]
44166065Spjdexpect 0 chown . 65535 65535
45166065Spjdexpect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
46166065Spjdexpect 65535,65535 lstat ${n0} uid,gid
47166065Spjdexpect 0 unlink ${n0}
48166065Spjdexpect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
49166232Spjdexpect "65535,6553[45]" lstat ${n0} uid,gid
50166065Spjdexpect 0 unlink ${n0}
51166065Spjdexpect 0 chmod . 0777
52166065Spjdexpect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
53166232Spjdexpect "65534,6553[35]" lstat ${n0} uid,gid
54166065Spjdexpect 0 unlink ${n0}
55166065Spjd
56166065Spjd# Update parent directory ctime/mtime if file didn't exist.
57166065Spjdexpect 0 chown . 0 0
58166065Spjdtime=`${fstest} stat . ctime`
59166065Spjdsleep 1
60166065Spjdexpect 0 open ${n0} O_CREAT,O_WRONLY 0644
61166065Spjdatime=`${fstest} stat ${n0} atime`
62166065Spjdtest_check $time -lt $atime
63166065Spjdmtime=`${fstest} stat ${n0} mtime`
64166065Spjdtest_check $time -lt $mtime
65166065Spjdctime=`${fstest} stat ${n0} ctime`
66166065Spjdtest_check $time -lt $ctime
67166065Spjdmtime=`${fstest} stat . mtime`
68166065Spjdtest_check $time -lt $mtime
69166065Spjdctime=`${fstest} stat . ctime`
70166065Spjdtest_check $time -lt $ctime
71166065Spjdexpect 0 unlink ${n0}
72166065Spjd
73166065Spjd# Don't update parent directory ctime/mtime if file existed.
74166065Spjdexpect 0 create ${n0} 0644
75166065Spjddmtime=`${fstest} stat . mtime`
76166065Spjddctime=`${fstest} stat . ctime`
77166065Spjdsleep 1
78166065Spjdexpect 0 open ${n0} O_CREAT,O_RDONLY 0644
79166065Spjdmtime=`${fstest} stat . mtime`
80166065Spjdtest_check $dmtime -eq $mtime
81166065Spjdctime=`${fstest} stat . ctime`
82166065Spjdtest_check $dctime -eq $ctime
83166065Spjdexpect 0 unlink ${n0}
84166065Spjd
85166065Spjdecho test > ${n0}
86166232Spjdexpect 5 stat ${n0} size
87166065Spjdmtime1=`${fstest} stat ${n0} mtime`
88166065Spjdctime1=`${fstest} stat ${n0} ctime`
89166065Spjdsleep 1
90166065Spjdexpect 0 open ${n0} O_WRONLY,O_TRUNC
91166065Spjdmtime2=`${fstest} stat ${n0} mtime`
92166065Spjdtest_check $mtime1 -lt $mtime2
93166065Spjdctime2=`${fstest} stat ${n0} ctime`
94166065Spjdtest_check $ctime1 -lt $ctime2
95166232Spjdexpect 0 stat ${n0} size
96166065Spjdexpect 0 unlink ${n0}
97166065Spjd
98166065Spjdcd ${cdir}
99166065Spjdexpect 0 rmdir ${n1}
100