]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/pjdfstest/tests/open/00.t
dts: Update our copy to Linux 4.17
[FreeBSD/FreeBSD.git] / contrib / pjdfstest / tests / open / 00.t
1 #!/bin/sh
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 $
4
5 desc="open opens (and eventually creates) a file"
6
7 dir=`dirname $0`
8 . ${dir}/../misc.sh
9
10 echo "1..47"
11
12 n0=`namegen`
13 n1=`namegen`
14
15 expect 0 mkdir ${n1} 0755
16 cdir=`pwd`
17 cd ${n1}
18
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
27 expect 0 unlink ${n0}
28 expect 0 open ${n0} O_CREAT,O_WRONLY 0151
29 expect regular,0151 lstat ${n0} type,mode
30 expect 0 unlink ${n0}
31 expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151
32 expect regular,0100 lstat ${n0} type,mode
33 expect 0 unlink ${n0}
34 expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345
35 expect regular,0305 lstat ${n0} type,mode
36 expect 0 unlink ${n0}
37 expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345
38 expect regular,0244 lstat ${n0} type,mode
39 expect 0 unlink ${n0}
40
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
48 expect 0 unlink ${n0}
49 expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644
50 expect "65535,6553[45]" lstat ${n0} uid,gid
51 expect 0 unlink ${n0}
52 expect 0 chmod . 0777
53 expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644
54 expect "65534,6553[35]" lstat ${n0} uid,gid
55 expect 0 unlink ${n0}
56
57 # Update parent directory ctime/mtime if file didn't exist.
58 expect 0 chown . 0 0
59 time=`${fstest} stat . ctime`
60 sleep 1
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
72 expect 0 unlink ${n0}
73
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`
78 sleep 1
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
84 expect 0 unlink ${n0}
85
86 echo test > ${n0}
87 expect 5 stat ${n0} size
88 mtime1=`${fstest} stat ${n0} mtime`
89 ctime1=`${fstest} stat ${n0} ctime`
90 sleep 1
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
97 expect 0 unlink ${n0}
98
99 cd ${cdir}
100 expect 0 rmdir ${n1}