1#!/bin/sh 2# $FreeBSD: head/tools/regression/pjdfstest/tests/link/00.t 211352 2010-08-15 21:24:17Z pjd $ 3 4desc="link creates hardlinks" 5 6dir=`dirname $0` 7. ${dir}/../misc.sh 8 9echo "1..202" 10 11n0=`namegen` 12n1=`namegen` 13n2=`namegen` 14n3=`namegen` 15 16expect 0 mkdir ${n3} 0755 17cdir=`pwd` 18cd ${n3} 19 20for type in regular fifo block char socket; do 21 create_file ${type} ${n0} 22 expect ${type},1 lstat ${n0} type,nlink 23 24 expect 0 link ${n0} ${n1} 25 expect ${type},2 lstat ${n0} type,nlink 26 expect ${type},2 lstat ${n1} type,nlink 27 28 expect 0 link ${n1} ${n2} 29 expect ${type},3 lstat ${n0} type,nlink 30 expect ${type},3 lstat ${n1} type,nlink 31 expect ${type},3 lstat ${n2} type,nlink 32 33 expect 0 chmod ${n1} 0201 34 expect 0 chown ${n1} 65534 65533 35 36 expect ${type},0201,3,65534,65533 lstat ${n0} type,mode,nlink,uid,gid 37 expect ${type},0201,3,65534,65533 lstat ${n1} type,mode,nlink,uid,gid 38 expect ${type},0201,3,65534,65533 lstat ${n2} type,mode,nlink,uid,gid 39 40 expect 0 unlink ${n0} 41 expect ENOENT lstat ${n0} type,mode,nlink,uid,gid 42 expect ${type},0201,2,65534,65533 lstat ${n1} type,mode,nlink,uid,gid 43 expect ${type},0201,2,65534,65533 lstat ${n2} type,mode,nlink,uid,gid 44 45 expect 0 unlink ${n2} 46 expect ENOENT lstat ${n0} type,mode,nlink,uid,gid 47 expect ${type},0201,1,65534,65533 lstat ${n1} type,mode,nlink,uid,gid 48 expect ENOENT lstat ${n2} type,mode,nlink,uid,gid 49 50 expect 0 unlink ${n1} 51 expect ENOENT lstat ${n0} type,mode,nlink,uid,gid 52 expect ENOENT lstat ${n1} type,mode,nlink,uid,gid 53 expect ENOENT lstat ${n2} type,mode,nlink,uid,gid 54done 55 56# successful link(2) updates ctime. 57for type in regular fifo block char socket; do 58 create_file ${type} ${n0} 59 ctime1=`${fstest} stat ${n0} ctime` 60 dctime1=`${fstest} stat . ctime` 61 dmtime1=`${fstest} stat . mtime` 62 sleep 1 63 expect 0 link ${n0} ${n1} 64 ctime2=`${fstest} stat ${n0} ctime` 65 test_check $ctime1 -lt $ctime2 66 dctime2=`${fstest} stat . ctime` 67 test_check $dctime1 -lt $dctime2 68 dmtime2=`${fstest} stat . mtime` 69 test_check $dctime1 -lt $dmtime2 70 expect 0 unlink ${n0} 71 expect 0 unlink ${n1} 72done 73 74# unsuccessful link(2) does not update ctime. 75for type in regular fifo block char socket; do 76 create_file ${type} ${n0} 77 expect 0 -- chown ${n0} 65534 -1 78 ctime1=`${fstest} stat ${n0} ctime` 79 dctime1=`${fstest} stat . ctime` 80 dmtime1=`${fstest} stat . mtime` 81 sleep 1 82 expect EACCES -u 65534 link ${n0} ${n1} 83 ctime2=`${fstest} stat ${n0} ctime` 84 test_check $ctime1 -eq $ctime2 85 dctime2=`${fstest} stat . ctime` 86 test_check $dctime1 -eq $dctime2 87 dmtime2=`${fstest} stat . mtime` 88 test_check $dctime1 -eq $dmtime2 89 expect 0 unlink ${n0} 90done 91 92cd ${cdir} 93expect 0 rmdir ${n3} 94