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