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 # Sets and prints the attributes of a file.
  30 #
  31 
  32 if { $argc != 2 } {
  33     puts "Usage: $argv0 <hostname> <filepath>"
  34     puts "       note: <filepath> must be full path and writable."
  35     exit
  36 }
  37 
  38 set host [ lindex $argv 0 ]
  39 set path [ path2comp [lindex $argv 1] "/" ]
  40 set attrs {size mode owner owner_group time_access time_modify}
  41 
  42 #connect -t udp -p 9999 $host
  43 connect $host
  44 
  45 
  46 # call the above function to create a test file
  47 set dfh [ get_fh $path ]
  48 if {$dfh == ""} {
  49         puts stderr "ERROR: dirpath=($path) not found."
  50         return 1
  51 }
  52 
  53 # Create a new file to be used for attribute manipulation
  54 set fname "Tfile.[pid]"
  55 set verifier "[clock seconds]"
  56 set owner "owner[pid]"
  57 set res [compound {Setclientid $verifier $owner {0 0 0}}]
  58 if {$status != "OK"} {
  59         puts "ERROR: cannot set clientid."
  60         puts "Res: $res"
  61         return 2
  62 }
  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 if {$status != "OK"} {
  69         puts "ERROR: cannot confirm clientid."
  70         puts "Res: $res"
  71         return 2
  72 }
  73 # Now try to create (open_type=1) the $fname under $dfh 
  74 set oseqid 1
  75 set otype 1
  76 set oclaim 0
  77 set res [compound {Putfh $dfh; Open $oseqid 3 0 {$clientid $owner} \
  78         {$otype 0 {{mode 0640}}} {$oclaim $fname}; Getfh}]
  79 if {$status != "OK"} {
  80         puts "ERROR: Unable to create ($fname) with Open."
  81         puts "Res: $res"
  82         return 3
  83 }
  84 set cl [clock seconds]
  85 set open_sid [lindex [lindex $res 1] 2]
  86 set rflags [lindex [lindex $res 1] 4] 
  87 set nfh [lindex [lindex $res 2] 2]
  88 incr oseqid
  89 # do open_confirm if needed, e.g. rflags==OPEN4_RESULT_CONFIRM=2
  90 if {[expr $rflags & 2] == 2} {
  91         set tag "OPEN_CONFIRM"
  92         set res [compound {Putfh $nfh; Open_confirm $open_sid $oseqid}]
  93         if {$status != "OK"} {
  94                 puts "ERROR: unable to confirm created file $fname."
  95                 puts "Res: $res"
  96                 return 3
  97         }
  98         set open_sid [lindex [lindex $res 1] 2]
  99         incr oseqid
 100 }
 101 
 102 # Generate a compound request to obtain the attributes for the path.
 103 set res [compound { Putfh $nfh; Getattr $attrs }]
 104 if {$status != "OK"} {
 105         puts "ERROR compound{ Getattr } return status=$status"
 106         puts "Res: $res"
 107         return 4
 108 }
 109 
 110 puts "Attributes Before Setattr (at [clock format $cl]): "
 111 prn_attrs [lindex [lindex $res 1] 2]
 112 
 113 puts "Now sleep for 30 seconds ..."
 114 exec sleep 30
 115 set nta "[expr [clock seconds] - 218] 0"
 116 
 117 # Generate a compound request to change the attributes
 118 set res [compound { Putfh $nfh;
 119         Setattr $open_sid {{size 8888} {mode 0765} {time_access_set {$nta}} };
 120         Getattr $attrs; }]
 121 if {$status != "OK"} {
 122         puts "ERROR compound{ Setattr } return status=$status"
 123         puts "Res: $res"
 124 #       return 5
 125 }
 126 
 127 set ncl [clock seconds]
 128 puts "New attributes after Setattr (at [clock format $ncl]): "
 129 prn_attrs [lindex [lindex $res 2] 2]
 130 
 131 set res [compound {Putfh $nfh; Close $oseqid $open_sid; 
 132         Putfh $dfh; Remove $fname}]
 133 if {$status != "OK"} {
 134         puts stderr "ERROR: Close/Remove failed."
 135         puts "Res: $res"
 136         return 6
 137 }
 138 
 139 disconnect 
 140 exit 0