xref: /freebsd/contrib/pjdfstest/tests/open/00.t (revision c6db8143eda5c775467145ac73e8ebec47afdd8f)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/open/00.t 211352 2010-08-15 21:24:17Z pjd $
3
4desc="open opens (and eventually creates) a file"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..47"
10
11n0=`namegen`
12n1=`namegen`
13
14expect 0 mkdir ${n1} 0755
15cdir=`pwd`
16cd ${n1}
17
18# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the access
19# permission bits of the file mode shall be set to the value of the third
20# argument taken as type mode_t modified as follows: a bitwise AND is performed
21# on the file-mode bits and the corresponding bits in the complement of the
22# process' file mode creation mask. Thus, all bits in the file mode whose
23# corresponding bit in the file mode creation mask is set are cleared.
24expect 0 open ${n0} O_CREAT,O_WRONLY 0755
25expect regular,0755 lstat ${n0} type,mode
26expect 0 unlink ${n0}
27expect 0 open ${n0} O_CREAT,O_WRONLY 0151
28expect regular,0151 lstat ${n0} type,mode
29expect 0 unlink ${n0}
30expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
31expect regular,0100 lstat ${n0} type,mode
32expect 0 unlink ${n0}
33expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
34expect regular,0305 lstat ${n0} type,mode
35expect 0 unlink ${n0}
36expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
37expect regular,0244 lstat ${n0} type,mode
38expect 0 unlink ${n0}
39
40# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the user ID
41# of the file shall be set to the effective user ID of the process; the group ID
42# of the file shall be set to the group ID of the file's parent directory or to
43# the effective group ID of the process [...]
44expect 0 chown . 65535 65535
45expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
46expect 65535,65535 lstat ${n0} uid,gid
47expect 0 unlink ${n0}
48expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
49expect "65535,6553[45]" lstat ${n0} uid,gid
50expect 0 unlink ${n0}
51expect 0 chmod . 0777
52expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
53expect "65534,6553[35]" lstat ${n0} uid,gid
54expect 0 unlink ${n0}
55
56# Update parent directory ctime/mtime if file didn't exist.
57expect 0 chown . 0 0
58time=`${fstest} stat . ctime`
59sleep 1
60expect 0 open ${n0} O_CREAT,O_WRONLY 0644
61atime=`${fstest} stat ${n0} atime`
62test_check $time -lt $atime
63mtime=`${fstest} stat ${n0} mtime`
64test_check $time -lt $mtime
65ctime=`${fstest} stat ${n0} ctime`
66test_check $time -lt $ctime
67mtime=`${fstest} stat . mtime`
68test_check $time -lt $mtime
69ctime=`${fstest} stat . ctime`
70test_check $time -lt $ctime
71expect 0 unlink ${n0}
72
73# Don't update parent directory ctime/mtime if file existed.
74expect 0 create ${n0} 0644
75dmtime=`${fstest} stat . mtime`
76dctime=`${fstest} stat . ctime`
77sleep 1
78expect 0 open ${n0} O_CREAT,O_RDONLY 0644
79mtime=`${fstest} stat . mtime`
80test_check $dmtime -eq $mtime
81ctime=`${fstest} stat . ctime`
82test_check $dctime -eq $ctime
83expect 0 unlink ${n0}
84
85echo test > ${n0}
86expect 5 stat ${n0} size
87mtime1=`${fstest} stat ${n0} mtime`
88ctime1=`${fstest} stat ${n0} ctime`
89sleep 1
90expect 0 open ${n0} O_WRONLY,O_TRUNC
91mtime2=`${fstest} stat ${n0} mtime`
92test_check $mtime1 -lt $mtime2
93ctime2=`${fstest} stat ${n0} ctime`
94test_check $ctime1 -lt $ctime2
95expect 0 stat ${n0} size
96expect 0 unlink ${n0}
97
98cd ${cdir}
99expect 0 rmdir ${n1}
100