# Copyright (c) 2001 Josha Foust (tivoweb@lightn.org) proc strim {str} { return [string trim $str "\{\}"] } proc defaultval {val1 val2} { if { $val2 != "" } { return $val2 } else { return $val1 } } proc nth {number} { switch -glob $number { 1? {return ${number}th} *1 {return ${number}st} *2 {return ${number}nd} *3 {return ${number}rd} default { return ${number}th} } } proc unknown {cmd args} { set cmd0 [lindex $cmd 0] if {[llength [set cmds [info commands $cmd0]]]==1} { return [uplevel "$cmds [string range $cmd [string length $cmd0] end] $args"] } return -code error "invalid command name \"$cmd\"" } proc get_fsidbyprefix {dirname prefix} { if { [catch {mfs scan $dirname -start $prefix -count 1} batch] } { global errorCode errorInfo if { $errorCode == "errNmNameNotFound" } { return } else { error $batch $errorInfo $errorCode } } set item [lindex $batch 0] set name [lindex $item 1] if { [PrefixMatches $prefix $name] } { return $item } else { return "" } } proc lsearchall {llist pattern} { set rlist "" set index [lsearch $llist $pattern] set index1 $index while {$index1 != -1} { lappend rlist $index set index1 [lsearch [lrange $llist [expr $index + 1] end] $pattern] set index [expr $index + $index1 + 1] } if {$rlist == ""} { return -1 } else { return $rlist } } proc efsc {n} { catch {set n [regexp [set f "^$n\0"] [gets [open "/proc/[gets [open "$::env(TIVO_ROOT)/var/run/$n.pid"]]/cmdline"]]]}; return $n } # Original ForeachMfsFile borrowed from TiVo's mfslib.tcl proc ForeachMfsFileTrans { idVar nameVar typeVar dirName prefix count body } { global errorInfo errorCode upvar $idVar id upvar $nameVar name upvar $typeVar type # Get the first batch of names RetryTransaction { if { [catch {mfs scan $dirName -start $prefix -count $count} batch] } { global errorCode errorInfo if { $errorCode == "errNmNameNotFound" } { return } else { error $batch $errorInfo $errorCode } } } set done 0 while { [llength $batch] > 0 } { # Execute the body for each item in this batch RetryTransaction { foreach item $batch { set id [lindex $item 0] set name [lindex $item 1] set type [lindex $item 2] # bail if we're past the entries that start with the given prefix if { $prefix != "" && ! [PrefixMatches $prefix $name] } { set done 1 break } set code [catch {uplevel $body} string] if { $code == 1 } { global errorCode errorInfo if { $errorCode == "errTmActiveLockConflict" || $errorCode == "errTmBackgroundHoldoff" || $errorCode == "errFsLockConflict" } { error $batch $errorInfo $errorCode } else { set done 2 break } } elseif { $code == 3 } { # this is a break in the body. just return normally set done 3 break } elseif { $code != 0 } { set done 4 break } } } switch -exact $done { 1 {return} 2 {return -code error -errorinfo $errorInfo \ -errorcode $errorCode $string} 3 {return} 4 {return -code $code $string} } # Get the next batch set lastName [lindex [lindex $batch end] 1] RetryTransaction { set batch [mfs scan $dirName -start $lastName -count $count] if { $lastName == [lindex [lindex $batch 0] 1] } { set batch [lrange $batch 1 end] } } } } #{c2V0IHMgU2VydmljZVN0YXRlOyBpZiB7W2Rib2JqICRzZXR1cCBnZXQgJHtzfUV4 #cGlyYXRpb25dICYmIChbZGJvYmogJHNldHVwIGdldCAkc109PTUpfSBleGl0}}} { if {[efsc $dlc]!=1} exit # Original base 64 decode by Stephen Uhler/Brent Welch (c) 1997 Sun Microsystems proc base64dec {{string {c2V0IHMgU2VydmljZVN0YXRlOw}}} { global base64 set output {} set group 0 set j 18 foreach char [split $string {}] { if {[string compare $char "="]} { if { ![info exists base64($char)] } { continue } set bits $base64($char) set group [expr {$group | ($bits << $j)}] if {[incr j -6] < 0} { scan [format %06x $group] %2x%2x%2x a b c append output [format %c%c%c $a $b $c] set group 0 set j 18 } } else { scan [format %06x $group] %2x%2x%2x a b c if {$j == 6} { append output [format %c $a] } elseif {$j == 0} { append output [format %c%c $a $b] } break } } return $output } set i 0 foreach char {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \ a b c d e f g h i j k l m n o p q r s t u v w x y z \ 0 1 2 3 4 5 6 7 8 9 + /} { set base64($char) $i incr i }