2 # $FreeBSD: head/tools/regression/pjdfstest/tests/open/00.t 211352 2010-08-15 21:24:17Z pjd $
4 desc="open opens (and eventually creates) a file"
14 expect 0 mkdir ${n1} 0755
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.
24 expect 0 open ${n0} O_CREAT,O_WRONLY 0755
25 expect regular,0755 lstat ${n0} type,mode
27 expect 0 open ${n0} O_CREAT,O_WRONLY 0151
28 expect regular,0151 lstat ${n0} type,mode
30 expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
31 expect regular,0100 lstat ${n0} type,mode
33 expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
34 expect regular,0305 lstat ${n0} type,mode
36 expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
37 expect regular,0244 lstat ${n0} type,mode
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 [...]
44 expect 0 chown . 65535 65535
45 expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644
46 expect 65535,65535 lstat ${n0} uid,gid
48 expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
49 expect "65535,6553[45]" lstat ${n0} uid,gid
52 expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
53 expect "65534,6553[35]" lstat ${n0} uid,gid
56 # Update parent directory ctime/mtime if file didn't exist.
58 time=`${fstest} stat . ctime`
60 expect 0 open ${n0} O_CREAT,O_WRONLY 0644
61 atime=`${fstest} stat ${n0} atime`
62 test_check $time -lt $atime
63 mtime=`${fstest} stat ${n0} mtime`
64 test_check $time -lt $mtime
65 ctime=`${fstest} stat ${n0} ctime`
66 test_check $time -lt $ctime
67 mtime=`${fstest} stat . mtime`
68 test_check $time -lt $mtime
69 ctime=`${fstest} stat . ctime`
70 test_check $time -lt $ctime
73 # Don't update parent directory ctime/mtime if file existed.
74 expect 0 create ${n0} 0644
75 dmtime=`${fstest} stat . mtime`
76 dctime=`${fstest} stat . ctime`
78 expect 0 open ${n0} O_CREAT,O_RDONLY 0644
79 mtime=`${fstest} stat . mtime`
80 test_check $dmtime -eq $mtime
81 ctime=`${fstest} stat . ctime`
82 test_check $dctime -eq $ctime
86 expect 5 stat ${n0} size
87 mtime1=`${fstest} stat ${n0} mtime`
88 ctime1=`${fstest} stat ${n0} ctime`
90 expect 0 open ${n0} O_WRONLY,O_TRUNC
91 mtime2=`${fstest} stat ${n0} mtime`
92 test_check $mtime1 -lt $mtime2
93 ctime2=`${fstest} stat ${n0} ctime`
94 test_check $ctime1 -lt $ctime2
95 expect 0 stat ${n0} size