1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 LINK operation test - negative tests
  27 
  28 # include all test enironment
  29 source LINK.env
  30 
  31 # connect to the test server
  32 Connect
  33 
  34 # setting local variables
  35 set TNAME $argv0
  36 set bfh [get_fh "$BASEDIRS"]
  37 set ffh [get_fh "$BASEDIRS $env(TEXTFILE)"]
  38 
  39 
  40 # Start testing
  41 # --------------------------------------------------------------
  42 # a: try to Link while source obj is removed, expect ENOENT
  43 set expcode "NOENT"
  44 set ASSERTION "try to Link while source obj is removed, expect $expcode"
  45 putmsg stdout 0 "$TNAME{a}: $ASSERTION"
  46 set tag "$TNAME{a}"
  47 set newf "Link-F.[pid]"
  48 set nffh [creatv4_file [file join $BASEDIR $newf]]
  49 if { $nffh != $NULL } {
  50     # now the link test:
  51     set res [compound {Putfh $nffh; Savefh;
  52         Putfh $bfh; Remove $newf; Link "L.new"; Getfh}]
  53     ckres "Link" $status $expcode $res $PASS
  54 } else {
  55     putmsg stderr 0 "\t Test UNINITIATED: unable to create temp file."
  56     set cont "false"
  57 }
  58 
  59 
  60 # b: try to Link while target dir is removed, expect STALE
  61 set expcode "STALE"
  62 set ASSERTION "try to Link while target dir is removed, expect $expcode"
  63 putmsg stdout 0 "$TNAME{b}: $ASSERTION"
  64 set tag "$TNAME{b}"
  65 set tmpd "tmp.[pid]"
  66 set res [compound {Putfh $bfh; Create $tmpd {{mode 0751}} d; Getfh}]
  67 set tfh [lindex [lindex $res 2] 2]
  68 check_op "Putfh $bfh; Remove $tmpd" "OK" "UNINITIATED"
  69 set res [compound {Putfh $bfh; Lookup "$env(TEXTFILE)"; Savefh;
  70         Putfh $tfh; Link newl2b}]
  71 ckres "Link" $status $expcode $res $PASS
  72 
  73 
  74 # c: Link with newname has zero length, expect INVAL
  75 set expcode "INVAL"
  76 set ASSERTION "Link with newname has zero length, expect $expcode"
  77 putmsg stdout 0 "$TNAME{c}: $ASSERTION"
  78 set tag "$TNAME{c}"
  79 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
  80         Putfh $bfh; Link ""}]
  81 set cont [ckres "Link" $status $expcode $res $FAIL]
  82 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
  83 linkcnt_equal $lcnt1 $ffh $cont $PASS
  84 
  85 
  86 # d: Link with newname is not UTF-8, expect INVAL
  87 set expcode "INVAL"
  88 set ASSERTION "Link with newname is not UTF-8, expect $expcode"
  89 #putmsg stdout 0 "$TNAME{d}: $ASSERTION"
  90 set tag "$TNAME{c}"
  91 #puts "\t Test UNTESTED: XXX how to create non-UTF-8 compliance name??\n"
  92 
  93 
  94 # e: Link with newname set to ".", expect INVAL|OK
  95 set expcode "INVAL|OK"
  96 set ASSERTION "Link with newname set to '.', expect $expcode"
  97 putmsg stdout 0 "$TNAME{e}: $ASSERTION"
  98 set tag "$TNAME{e}"
  99 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
 100         Putfh $bfh; Link "."}]
 101 set cont [ckres "Link" $status $expcode $res $FAIL]
 102 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 103 linkcnt_equal $lcnt1 $ffh $cont $PASS
 104 
 105 
 106 # f: Link with newname set to "..", expect INVAL|OK
 107 set expcode "INVAL|OK"
 108 set ASSERTION "Link with newname set to '..', expect $expcode"
 109 putmsg stdout 0 "$TNAME{f}: $ASSERTION"
 110 set tag "$TNAME{f}"
 111 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
 112         Putfh $bfh; Link ".."}]
 113 set cont [ckres "Link" $status $expcode $res $FAIL]
 114 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 115 linkcnt_equal $lcnt1 $ffh $cont $PASS
 116 
 117 
 118 # g: Link with newname included path delimiter, expect INVAL
 119 set expcode "INVAL"
 120 set ASSERTION "Link with newname included path delimiter, expect $expcode"
 121 putmsg stdout 0 "$TNAME{g}: $ASSERTION"
 122 set tag "$TNAME{g}"
 123 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
 124         Putfh $bfh; Link "new-$DELM-link"}]
 125 set cont [ckres "Link" $status $expcode $res $FAIL]
 126 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 127 linkcnt_equal $lcnt1 $ffh $cont $PASS
 128 
 129 
 130 # i: Link with newname longer than maxname, expect NAMETOOLONG
 131 set expcode "NAMETOOLONG"
 132 set ASSERTION "Link with newname longer than maxname, expect $expcode"
 133 putmsg stdout 0 "$TNAME{i}: $ASSERTION"
 134 set tag "$TNAME{i}"
 135 set nli [set_maxname $bfh]
 136 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
 137         Putfh $bfh; Link $nli}]
 138 set cont [ckres "Link" $status $expcode $res $FAIL]
 139 if {[string equal $cont "false"] && $DEBUG} {
 140         putmsg stderr 1 "\t   length of newname = ([string length $nli])"
 141 }
 142 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 143 linkcnt_equal $lcnt1 $ffh $cont $PASS
 144 
 145 
 146 # m: Link across filesystems, expect XDEV
 147 set expcode "XDEV"
 148 set ASSERTION "Link to a file across filesystem, expect $expcode"
 149 putmsg stdout 0 "$TNAME{m}: $ASSERTION"
 150 set tag "$TNAME{m}"
 151 set xfh [get_fh [path2comp $env(SSPCDIR) $DELM]]
 152 set res [compound {Putfh $ffh; Getattr numlinks; Savefh;
 153         Putfh $xfh; Link "err-link"}]
 154 set cont [ckres "Link" $status $expcode $res $FAIL]
 155 set lcnt1 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 156 linkcnt_equal $lcnt1 $ffh $cont $PASS
 157 
 158 
 159 # n: make a Link in ROFS, expect ROFS
 160 set expcode "ROFS"
 161 set ASSERTION "make a Link to a ReadOnly filesystem, expect $expcode"
 162 putmsg stdout 0 "$TNAME{n}: $ASSERTION"
 163 set tag "$TNAME{n}"
 164 set rofh [get_fh [path2comp $env(ROFSDIR) $DELM]]
 165 set res [compound {Putfh $rofh; Lookup $env(RWFILE); Getattr numlinks;
 166         Getfh; Savefh; Putfh $rofh; Link "err-rolink"}]
 167 set cont [ckres "Link" $status $expcode $res $FAIL]
 168 set lcnt1 [lindex [lindex [lindex [lindex $res 2] 2] 0] 1]
 169 set rffh [lindex [lindex $res 3] 2]
 170 linkcnt_equal $lcnt1 $rffh $cont $PASS
 171 
 172 # p: newname is already a hardlink to source, expect EXIST (issue 130)
 173 set expcode "EXIST"
 174 set ASSERTION "newname is already a hardlink to source, expect $expcode"
 175 putmsg stdout 0 "$TNAME{p}: $ASSERTION"
 176 set tag "$TNAME{p}"
 177 set newln "newln.[pid]"
 178 set res [compound {Putfh $bfh; Lookup $env(RWFILE); Savefh;
 179         Putfh $bfh; Link $newln}]
 180 if { [ckres "Link1" $status "OK" $res $FAIL] == "true" } {
 181         # try to link again, should fail w/EXIST
 182         set res [compound {Putfh $bfh; Lookup $env(RWFILE); Getattr numlinks;
 183                 Getfh; Savefh; Putfh $bfh; Link $newln}]
 184         set cont [ckres "Link" $status $expcode $res $FAIL]
 185         # and make sure link-count was not increased w/this failure
 186         set lcnt1 [lindex [lindex [lindex [lindex $res 2] 2] 0] 1]
 187         set newfh [lindex [lindex $res 3] 2]
 188         linkcnt_equal $lcnt1 $newfh $cont $PASS
 189         # Cleanup: remove the created link
 190         compound {Putfh $bfh; Remove $newln}
 191 }
 192 
 193 
 194 # --------------------------------------------------------------
 195 # disconnect and exit
 196 set tag ""
 197 Disconnect
 198 exit $PASS