1 #!nfsh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Simple script to test open of a file with and without creation,
30 # non-claimed, non-checked and with the current user and process
31 # number as the owner ID
32 #
33
34 if { $argc != 2 } {
35 puts "Usage: $argv0 <hostname> <pathname>"
36 puts " <pathname>: full path dir name to create test file."
37 exit 1
38 }
39
40 # set host and file pathname (original)
41 set host [ lindex $argv 0 ]
42 set path [ path2comp [lindex $argv 1] "/" ]
43 set fname "nfile.[pid]"
44
45 # connect to the server
46 connect $host
47
48 # get dir file handle
49 set dfh [get_fh $path]
50 if {$dfh == ""} {
51 puts stderr "ERROR: pathname=($path) not found."
52 return 1
53 }
54
55 # negotiate the cleintid
56 # set unique clientid and verifier
57 set verifier "[clock seconds]"
58 set owner "owner[pid]"
59
60 set res [compound {Setclientid $verifier $owner {0 0 0}}]
61 puts "\nSetclientid $verifier $owner ..."
62 puts "Res: $res"
63 set clientid [lindex [lindex [lindex $res 0] 2] 0]
64 set cid_verifier [lindex [lindex [lindex $res 0] 2] 1]
65
66 # confirm clientid
67 set res [compound {Setclientid_confirm $clientid $cid_verifier}]
68 puts "\nSetclientid_confirm $clientid $cid_verifier ..."
69 puts "Res: $res"
70
71 # Now try to create (open_type=1) a new test file under $path with Open op
72 set oseqid 1
73 set otype 1
74 set mode 0664
75 set oclaim 0
76 set tag "OPEN1"
77 set res [compound {Putfh $dfh;
78 Open $oseqid 3 0 {$clientid $owner} \
79 {$otype 0 {{mode $mode} {size 0}}} {$oclaim $fname};
80 Getfh; Getattr {mode size}}]
81 puts "\nTEST #1: Open to create $fname ..."
82 puts -nonewline " Open $oseqid 3 0 {$clientid $owner}"
83 puts " {$otype 0 {{mode $mode} {size 0}}} {$oclaim $fname}"
84 puts "Res: $res"
85 if {$status != "OK"} {
86 puts stderr "ERROR: Unable to create ($fname) with Open."
87 return 2
88 }
89 # store the needed open info
90 set open_sid [lindex [lindex $res 1] 2]
91 set rflags [lindex [lindex $res 1] 4]
92 set nfh [lindex [lindex $res 2] 2]
93 set attr [lindex [lindex $res 3] 2]
94
95 # do open_confirm if needed, e.g. rflags==OPEN4_RESULT_CONFIRM=2
96 if {[expr $rflags & 2] == 2} {
97 set tag "OPEN_CONFIRM"
98 incr oseqid
99 set res [compound {Putfh $nfh; Open_confirm "$open_sid" $oseqid}]
100 puts "\nOpen_confirm ($open_sid) $oseqid ..."
101 puts "Res: $res"
102 if {$status != "OK"} {
103 puts stderr "ERROR: unable to confirm created file $fname."
104 return 2
105 }
106 set open_sid [lindex [lindex $res 1] 2]
107 }
108
109 # then close this file
110 incr oseqid
111 set tag "CLOSE1"
112 set res [compound {Putfh $nfh; Close $oseqid $open_sid}]
113 puts "\nNow Close the created file: Close $oseqid ($open_sid) ..."
114 puts "Res: $res"
115 if {$status != "OK"} {
116 puts stderr "ERROR: Close OPEN/create failed."
117 return 2
118 }
119
120 #check if the file is really there
121 if [catch {set fh [get_fh "$path $fname"]} file_here ] {
122 puts stderr "ERROR: File in <path/$fname> must exist at this point."
123 return 1
124 }
125
126 # try open without create on the same file
127 set otype 0
128 set tag "OPEN2"
129 incr oseqid
130 set res [compound {Putfh $dfh;
131 Open $oseqid 3 0 {$clientid $owner} \
132 {$otype 0 {{mode $mode}}} {$oclaim $fname}; Getfh}]
133 puts "\n\nTEST #2: Open with/non-CREATE $fname ..."
134 puts -nonewline " Open $oseqid 3 0 {$clientid $owner}"
135 puts " {$otype 0 {{mode $mode} {size 1025}}} {$oclaim $fname}"
136 puts "Res: $res"
137 if {$status != "OK"} {
138 puts stderr "ERROR: Can not open file $fname under $path"
139 return 3
140 }
141 # store the needed open info
142 set open_sid2 [lindex [lindex $res 1] 2]
143 set rflags [lindex [lindex $res 1] 4]
144 set nfh2 [lindex [lindex $res 2] 2]
145
146 # do open_confirm if needed, e.g. rflags==OPEN4_RESULT_CONFIRM=2
147 if {[expr $rflags & 2] == 2} {
148 incr oseqid
149 puts "\nOpen_confirm ($open_sid2) $oseqid ..."
150 set res [compound {Putfh $nfh; Open_confirm "$open_sid2" $oseqid}]
151 puts "Res: $res"
152 if {$status != "OK"} {
153 puts stderr "ERROR: unable to confirm with open-non-create."
154 return 2
155 }
156 set open_sid2 [lindex [lindex $res 1] 2]
157 }
158
159 set tag "CLOSE2"
160 incr oseqid
161 set res [compound {Putfh $nfh; Close $oseqid $open_sid2}]
162 puts "\nNow Close non-create file: Close $oseqid ($open_sid2) ..."
163 puts "Res: $res"
164 if {$status != "OK"} {
165 puts stderr "ERROR: Final close2 failed."
166 return 2
167 }
168
169
170 # If we get here, test is good; thus remove the created file
171 set res [compound {Putfh $dfh; Remove $fname}]
172 puts "\nFinally Remove $fname ..."
173 puts "Res: $res"
174 if {$status != "OK"} {
175 puts stderr "ERROR: Can not remove file $fname under $path"
176 return 3
177 }
178
179 disconnect
180 exit 0