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 # Read a directory, print each entry with attributes
  30 #
  31 
  32 if { $argc != 2 } {
  33     puts "Usage: $argv0 <hostname> <pathname>"
  34     exit
  35 }
  36 
  37 set host [ lindex $argv 0 ]
  38 set path [ path2comp [lindex $argv 1] "/" ]
  39 
  40 connect $host
  41 
  42 set cookie 0
  43 set eof false
  44 
  45 while {$eof != "true"} {
  46 
  47     set result [compound {
  48         Putrootfh
  49         foreach c $path {Lookup $c}
  50         Readdir $cookie 0 1024 1024 { size type time_modify }
  51     }]
  52 
  53     if {$status != "OK"} {
  54         puts $status
  55         exit
  56     }
  57 
  58     # Get the readdir result from the compound result
  59 
  60     set readdirres [ lindex $result end ]
  61 
  62 
  63     # Get the eof flag from the directory result
  64 
  65     set eof [ lindex $readdirres 4 ]
  66     if { $eof != "true" } { 
  67         # Then also need to get its cookie to read more
  68         set dlist [ lindex $readdirres 3 ]
  69         set cookie [ lindex [ lindex $dlist [expr [llength $dlist] -1]] 0]
  70     }
  71 
  72     # Now extract the directory listing itself
  73 
  74     set dirlist [ lindex $readdirres 3 ]
  75 
  76     # Print each entry with its attributes in the whole
  77     # directory in sorted order.
  78 
  79     prn_dirlist [ lsort -index 1 $dirlist ]
  80 }
  81 
  82 disconnect
  83 exit 0