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 5desc="open opens (and eventually creates) a file" 6 7dir=`dirname $0` 8. ${dir}/../misc.sh 9 10echo "1..47" 11 12n0=`namegen` 13n1=`namegen` 14 15expect 0 mkdir ${n1} 0755 16cdir=`pwd` 17cd ${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. 25expect 0 open ${n0} O_CREAT,O_WRONLY 0755 26expect regular,0755 lstat ${n0} type,mode 27expect 0 unlink ${n0} 28expect 0 open ${n0} O_CREAT,O_WRONLY 0151 29expect regular,0151 lstat ${n0} type,mode 30expect 0 unlink ${n0} 31expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151 32expect regular,0100 lstat ${n0} type,mode 33expect 0 unlink ${n0} 34expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345 35expect regular,0305 lstat ${n0} type,mode 36expect 0 unlink ${n0} 37expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345 38expect regular,0244 lstat ${n0} type,mode 39expect 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 [...] 45expect 0 chown . 65535 65535 46expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644 47expect 65535,65535 lstat ${n0} uid,gid 48expect 0 unlink ${n0} 49expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644 50expect "65535,6553[45]" lstat ${n0} uid,gid 51expect 0 unlink ${n0} 52expect 0 chmod . 0777 53expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644 54expect "65534,6553[35]" lstat ${n0} uid,gid 55expect 0 unlink ${n0} 56 57# Update parent directory ctime/mtime if file didn't exist. 58expect 0 chown . 0 0 59time=`${fstest} stat . ctime` 60sleep 1 61expect 0 open ${n0} O_CREAT,O_WRONLY 0644 62atime=`${fstest} stat ${n0} atime` 63test_check $time -lt $atime 64mtime=`${fstest} stat ${n0} mtime` 65test_check $time -lt $mtime 66ctime=`${fstest} stat ${n0} ctime` 67test_check $time -lt $ctime 68mtime=`${fstest} stat . mtime` 69test_check $time -lt $mtime 70ctime=`${fstest} stat . ctime` 71test_check $time -lt $ctime 72expect 0 unlink ${n0} 73 74# Don't update parent directory ctime/mtime if file existed. 75expect 0 create ${n0} 0644 76dmtime=`${fstest} stat . mtime` 77dctime=`${fstest} stat . ctime` 78sleep 1 79expect 0 open ${n0} O_CREAT,O_RDONLY 0644 80mtime=`${fstest} stat . mtime` 81test_check $dmtime -eq $mtime 82ctime=`${fstest} stat . ctime` 83test_check $dctime -eq $ctime 84expect 0 unlink ${n0} 85 86echo test > ${n0} 87expect 5 stat ${n0} size 88mtime1=`${fstest} stat ${n0} mtime` 89ctime1=`${fstest} stat ${n0} ctime` 90sleep 1 91expect 0 open ${n0} O_WRONLY,O_TRUNC 92mtime2=`${fstest} stat ${n0} mtime` 93test_check $mtime1 -lt $mtime2 94ctime2=`${fstest} stat ${n0} ctime` 95test_check $ctime1 -lt $ctime2 96expect 0 stat ${n0} size 97expect 0 unlink ${n0} 98 99cd ${cdir} 100expect 0 rmdir ${n1} 101