2 # vim: filetype=sh noexpandtab ts=8 sw=8
3 # $FreeBSD: head/tools/regression/pjdfstest/tests/open/00.t 211352 2010-08-15 21:24:17Z pjd $
5 desc="open opens (and eventually creates) a file"
15 expect 0 mkdir ${n1} 0755
19 # POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the access
20 # permission bits of the file mode shall be set to the value of the third
21 # argument taken as type mode_t modified as follows: a bitwise AND is performed
22 # on the file-mode bits and the corresponding bits in the complement of the
23 # process' file mode creation mask. Thus, all bits in the file mode whose
24 # corresponding bit in the file mode creation mask is set are cleared.
25 expect 0 open ${n0} O_CREAT,O_WRONLY 0755
26 expect regular,0755 lstat ${n0} type,mode
28 expect 0 open ${n0} O_CREAT,O_WRONLY 0151
29 expect regular,0151 lstat ${n0} type,mode
31 expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
32 expect regular,0100 lstat ${n0} type,mode
34 expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
35 expect regular,0305 lstat ${n0} type,mode
37 expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
38 expect regular,0244 lstat ${n0} type,mode
41 # POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the user ID
42 # of the file shall be set to the effective user ID of the process; the group ID
43 # of the file shall be set to the group ID of the file's parent directory or to
44 # the effective group ID of the process [...]
45 expect 0 chown . 65535 65535
46 expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
47 expect 65535,65535 lstat ${n0} uid,gid
49 expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
50 expect "65535,6553[45]" lstat ${n0} uid,gid
53 expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
54 expect "65534,6553[35]" lstat ${n0} uid,gid
57 # Update parent directory ctime/mtime if file didn't exist.
59 time=`${fstest} stat . ctime`
61 expect 0 open ${n0} O_CREAT,O_WRONLY 0644
62 atime=`${fstest} stat ${n0} atime`
63 test_check $time -lt $atime
64 mtime=`${fstest} stat ${n0} mtime`
65 test_check $time -lt $mtime
66 ctime=`${fstest} stat ${n0} ctime`
67 test_check $time -lt $ctime
68 mtime=`${fstest} stat . mtime`
69 test_check $time -lt $mtime
70 ctime=`${fstest} stat . ctime`
71 test_check $time -lt $ctime
74 # Don't update parent directory ctime/mtime if file existed.
75 expect 0 create ${n0} 0644
76 dmtime=`${fstest} stat . mtime`
77 dctime=`${fstest} stat . ctime`
79 expect 0 open ${n0} O_CREAT,O_RDONLY 0644
80 mtime=`${fstest} stat . mtime`
81 test_check $dmtime -eq $mtime
82 ctime=`${fstest} stat . ctime`
83 test_check $dctime -eq $ctime
87 expect 5 stat ${n0} size
88 mtime1=`${fstest} stat ${n0} mtime`
89 ctime1=`${fstest} stat ${n0} ctime`
91 expect 0 open ${n0} O_WRONLY,O_TRUNC
92 mtime2=`${fstest} stat ${n0} mtime`
93 test_check $mtime1 -lt $mtime2
94 ctime2=`${fstest} stat ${n0} ctime`
95 test_check $ctime1 -lt $ctime2
96 expect 0 stat ${n0} size