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 # TCL procedure for LINK operation testing
27
28 set DEBUG $env(DEBUG)
29
30 #---------------------------------------------------------
31 # Test procedure to verify the numlinks attribute of the file
32 # Usage: linkcnt_equal lcnt1 objfh continue-flag prn-pass
33 # lcnt1: number of numlinks use to compare
34 # objfh: the FH of the obj to be compared with
35 # cont: continue-flag (true|false) if we should continue
36 # prn: flag to indication if PASS message should be printed
37 #
38 # Return:
39 # true: if numlinks are equal
40 # false: if lcnt1 and numlinks(ckobj) are not equal, or
41 # something failed in the process.
42 #
43 proc linkcnt_equal {lcnt1 objfh cont prn} {
44 global DEBUG
45
46 # stop the verification if 'continue-flag' is FALSE
47 if {[string equal $cont "false"]} { return false }
48
49 set res [compound {Putfh $objfh; Getattr numlinks}]
50 if {"$status" != "OK"} {
51 putmsg stderr 0 "\t Test UNRESOLVED: Unable to get objfh(numlinks)"
52 putmsg stderr 1 "\t res=($res)"
53 putmsg stderr 1 " "
54 return false
55 }
56 set lcnt2 [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
57 if {$lcnt1 != $lcnt2} {
58 if {$prn == 0} {
59 # do not print error in case user want to compare with NOT-equal
60 putmsg stderr 0 "\t Test FAIL: link count are not equal."
61 putmsg stderr 1 "\t lcnt1=($lcnt1)"
62 putmsg stderr 1 "\t lcnt2=($lcnt2)"
63 putmsg stderr 1 " "
64 }
65 return false
66 } else {
67 if {$prn == 0} {
68 putmsg stdout 0 "\t Test PASS"
69 }
70 return true
71 }
72 }
73
74
75 #---------------------------------------------------------
76 # Test procedure to set maxlink to an object
77 # Usage: set_maxlink objfh ldirfh
78 # objfh: the FH of the obj to be compared with
79 # ldirfh: the FH of the directory where links to be created
80 #
81 # Return:
82 # $malx: the value of maxlink if all created successfully
83 # false: if something failed during the process.
84 #
85 proc set_maxlink {objfh ldirfh} {
86 global DEBUG
87
88 # first get the system's maxlink value
89 set res [compound {Putfh $objfh; Getattr maxlink}]
90 if {"$status" != "OK"} {
91 putmsg stderr 0 "\t Test UNRESOLVED: Unable to get objfh(maxlink)"
92 putmsg stderr 1 "\t res=($res)"
93 putmsg stderr 1 " "
94 return false
95 }
96 set maxl [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
97 set i 1
98 while {$i <= $maxl && "$status" == "OK"} {
99 set res [compound {Putfh $objfh; Savefh; Putfh $ldirfh; Link L$i}]
100 incr i
101 }
102 if {$i < $maxl && "$status" != "OK"} {
103 putmsg stderr 0 "\t Test UNRESOLVED: failed to create $maxl links"
104 putmsg stderr 1 "\t res=($res)"
105 putmsg stderr 1 " "
106 return false
107 }
108 return $maxl
109 }
110
111
112 #---------------------------------------------------------
113 # Test procedure to cleanup the links to an object
114 # Usage: cleanup_links objfh ldirfh continue-flag
115 # objfh: the FH of the obj to be compared with
116 # ldirfh: the FH of the directory where links to be created
117 # cont: continue-flag (true|false) if we should continue
118 #
119 # Return:
120 # true: maxlink removed successfully
121 # false: if something failed during the process.
122 #
123 proc cleanup_links {maxl ldirfh cont} {
124 global DEBUG
125
126 # stop the verification if 'continue-flag' is FALSE
127 if {[string equal $cont "false"]} { return false }
128
129 set i 1; set status OK
130 while {$i <= $maxl && "$status" == "OK"} {
131 set res [compound {Putfh $ldirfh; Remove L$i}]
132 incr i
133 }
134 if {$i < $maxl && "$status" != "OK"} {
135 putmsg stderr 0 "\t Test UNRESOLVED: failed to Remove $maxl links"
136 putmsg stderr 1 "\t res=($res)"
137 putmsg stderr 1 " "
138 return false
139 }
140 return true
141 }