#!/ldcg/bin/tclsh

##******************************************************************
##
## This is a utility for dumping the mount points use by LDAS and
##   the i/o characteristics to be used
##
## Calling convention:
##
##    mountDump
##
##******************************************************************

set auto_path "/ldas/lib $auto_path"

set ::API frame

##---------------------------------------------------------------
## Load in resource files
##   diskcache - needed for ::MOUNT_PT
##   frame     - needed for ::DEVICE_IO_CONFIGURATION
##---------------------------------------------------------------
foreach file {LDASapi.rsc \
		  diskcacheAPI/LDASdiskcache.rsc \
		  frameAPI/LDASframe.rsc } {
    foreach dir {/ldas_outgoing /ldas/lib} {
	if { [file exists "$dir/$file"] } {
	    source "$dir/$file"
	    break
	}
    }
}

##---------------------------------------------------------------
## Load in the different packages required. Each package
## supplies extentions to TCL that are either used directly or
## indirectly by this script
##---------------------------------------------------------------
package require genericAPI
package require frameAPI

proc help { args } {
     set    err "\n\nmountDump usage:\n\n"
     append err "     mountDump\n\n"
     puts stderr $err
     exit
}

proc truefalse { bool } {
    if { $bool } {
	return "true"
    }
    return "false"
}

# :TODO: If any options are passed on the command line, print help message
# :TODO:   and exit

if { ! [ info exists ::DEVICE_IO_CONFIGURATION ] } {
    # Reestablish the variable
    set ::DEVICE_IO_CONFIGURATION [ list ]
}
ResetDeviceIOConfiguration $::DEVICE_IO_CONFIGURATION

##---------------------------------------------------------------
## Loop over the entries in ::MOUNT_PT
##---------------------------------------------------------------
set fmt "%10s %10d %10s %s"
regsub -all {d} $fmt {s} title_fmt
puts [format  $title_fmt "mmapped" "buf size" "fstype" "mount point"]
foreach mntpt $::MOUNT_PT {
    #------------------------------------------------------------
    # Query the frameAPI on how it will handle this request
    #------------------------------------------------------------
    set config [split [GetDeviceIOConfiguration $mntpt] { }]
    if {[llength $config] < 4} {
	lappend config "unknown"
    }
    puts [format $fmt \
	      [truefalse [lindex $config 2]] \
	      [lindex $config 1 ] \
	      [lindex $config 3 ] \
	      [lindex $config 0]]
}


exit
