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