1271294Sngie#!/bin/sh
2271294Sngie# $FreeBSD: head/tools/regression/pjdfstest/tests/open/00.t 211352 2010-08-15 21:24:17Z pjd $
3271294Sngie
4271294Sngiedesc="open opens (and eventually creates) a file"
5271294Sngie
6271294Sngiedir=`dirname $0`
7271294Sngie. ${dir}/../misc.sh
8271294Sngie
9271294Sngieecho "1..47"
10271294Sngie
11271294Sngien0=`namegen`
12271294Sngien1=`namegen`
13271294Sngie
14271294Sngieexpect 0 mkdir ${n1} 0755
15271294Sngiecdir=`pwd`
16271294Sngiecd ${n1}
17271294Sngie
18271294Sngie# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the access
19271294Sngie# permission bits of the file mode shall be set to the value of the third
20271294Sngie# argument taken as type mode_t modified as follows: a bitwise AND is performed
21271294Sngie# on the file-mode bits and the corresponding bits in the complement of the
22271294Sngie# process' file mode creation mask. Thus, all bits in the file mode whose
23271294Sngie# corresponding bit in the file mode creation mask is set are cleared.
24271294Sngieexpect 0 open ${n0} O_CREAT,O_WRONLY 0755
25271294Sngieexpect regular,0755 lstat ${n0} type,mode
26271294Sngieexpect 0 unlink ${n0}
27271294Sngieexpect 0 open ${n0} O_CREAT,O_WRONLY 0151
28271294Sngieexpect regular,0151 lstat ${n0} type,mode
29271294Sngieexpect 0 unlink ${n0}
30271294Sngieexpect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
31271294Sngieexpect regular,0100 lstat ${n0} type,mode
32271294Sngieexpect 0 unlink ${n0}
33271294Sngieexpect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
34271294Sngieexpect regular,0305 lstat ${n0} type,mode
35271294Sngieexpect 0 unlink ${n0}
36271294Sngieexpect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
37271294Sngieexpect regular,0244 lstat ${n0} type,mode
38271294Sngieexpect 0 unlink ${n0}
39271294Sngie
40271294Sngie# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the user ID
41271294Sngie# of the file shall be set to the effective user ID of the process; the group ID
42271294Sngie# of the file shall be set to the group ID of the file's parent directory or to
43271294Sngie# the effective group ID of the process [...]
44271294Sngieexpect 0 chown . 65535 65535
45271294Sngieexpect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
46271294Sngieexpect 65535,65535 lstat ${n0} uid,gid
47271294Sngieexpect 0 unlink ${n0}
48271294Sngieexpect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
49271294Sngieexpect "65535,6553[45]" lstat ${n0} uid,gid
50271294Sngieexpect 0 unlink ${n0}
51271294Sngieexpect 0 chmod . 0777
52271294Sngieexpect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
53271294Sngieexpect "65534,6553[35]" lstat ${n0} uid,gid
54271294Sngieexpect 0 unlink ${n0}
55271294Sngie
56271294Sngie# Update parent directory ctime/mtime if file didn't exist.
57271294Sngieexpect 0 chown . 0 0
58271294Sngietime=`${fstest} stat . ctime`
59271294Sngiesleep 1
60271294Sngieexpect 0 open ${n0} O_CREAT,O_WRONLY 0644
61271294Sngieatime=`${fstest} stat ${n0} atime`
62271294Sngietest_check $time -lt $atime
63271294Sngiemtime=`${fstest} stat ${n0} mtime`
64271294Sngietest_check $time -lt $mtime
65271294Sngiectime=`${fstest} stat ${n0} ctime`
66271294Sngietest_check $time -lt $ctime
67271294Sngiemtime=`${fstest} stat . mtime`
68271294Sngietest_check $time -lt $mtime
69271294Sngiectime=`${fstest} stat . ctime`
70271294Sngietest_check $time -lt $ctime
71271294Sngieexpect 0 unlink ${n0}
72271294Sngie
73271294Sngie# Don't update parent directory ctime/mtime if file existed.
74271294Sngieexpect 0 create ${n0} 0644
75271294Sngiedmtime=`${fstest} stat . mtime`
76271294Sngiedctime=`${fstest} stat . ctime`
77271294Sngiesleep 1
78271294Sngieexpect 0 open ${n0} O_CREAT,O_RDONLY 0644
79271294Sngiemtime=`${fstest} stat . mtime`
80271294Sngietest_check $dmtime -eq $mtime
81271294Sngiectime=`${fstest} stat . ctime`
82271294Sngietest_check $dctime -eq $ctime
83271294Sngieexpect 0 unlink ${n0}
84271294Sngie
85271294Sngieecho test > ${n0}
86271294Sngieexpect 5 stat ${n0} size
87271294Sngiemtime1=`${fstest} stat ${n0} mtime`
88271294Sngiectime1=`${fstest} stat ${n0} ctime`
89271294Sngiesleep 1
90271294Sngieexpect 0 open ${n0} O_WRONLY,O_TRUNC
91271294Sngiemtime2=`${fstest} stat ${n0} mtime`
92271294Sngietest_check $mtime1 -lt $mtime2
93271294Sngiectime2=`${fstest} stat ${n0} ctime`
94271294Sngietest_check $ctime1 -lt $ctime2
95271294Sngieexpect 0 stat ${n0} size
96271294Sngieexpect 0 unlink ${n0}
97271294Sngie
98271294Sngiecd ${cdir}
99271294Sngieexpect 0 rmdir ${n1}
100