View Single Post
Old 10-18-2003, 08:08 PM  
romracer
Junior Member
 
Join Date: Oct 2003
Posts: 25
Default a fix for freespace

The ioDiskSpace.exe that comes with dZSbot (or was it with ioftpd, I don't remember) doesn't properly calculate space for all drives, most notably network drives. I have a drive that is mounted as 1.73TB but the diskspace program only reports around 680GB. This of course makes !free not work properly on the bot, or to at least print out the wrong info. My solution was to modify the script to use a different binary. Here's how I did it.

First you'll need http://www.geocities.com/urifrid/lport.zip. Most notably, you want the df.exe file from it.

Second, you'll want to use:

Code:
set binary(DF)		        "D:/ioFTPD/scripts/bin/df.exe"
in your bot .tcl file. Of course change it to match the path you placed that file in.

Third you'll want to change the devices() list to include a trailing slash (remember to escape it) on your drive letters. ie,

Code:
set device(2)		"F:\\ ARCHIVE"
And lastly, you'll want to replace your proc show_free with mine. I've included it here.

Code:
proc show_free { nick uhost hand chan arg } {
	global binary announce device disable sections
	if { $disable(FREE) == 1 } {return}
	set arg [string tolower $arg]
	set total_freespace 0
	set total_space 0
	set scheck "$sections ALL"
	if { $arg == "" || [string match -nocase *$arg* $scheck] == 0 } {
		set output $announce(DEFAULT)
		set output [replacevar $output "%msg" "Available sections are: $sections"]
		set output [basicreplace $output "FREE"]
		sndall "DEFAULT" "$output or ALL"
		return
	} elseif { $arg == "all" } {
		set output $announce(DEFAULT)
		for {set i 0} {$i < $device(TOTAL)} {incr i} {
			foreach line [split [exec $binary(DF) "-m"] "\n"] {
#				putlog "DEBUG>>> line = $line"
#				if { [string match [lindex $line 0] [string toupper [lindex $device($i) 0]]] == 1 } { }
				if { [lindex [split $line] 0] == [string toupper [lindex [split $device($i)] 0]] } {	
					
					# set thisfree [lindex $line 6]
					# set thistotal [lindex $line 5]
					set thisfree [lindex $line [expr [llength $line] - 2]]
					set thistotal [lindex $line [expr [llength $line] - 3]]
					set thisfree [string range $thisfree 0 [expr [string length $thisfree] - 3]]
					set thistotal [string range $thistotal 0 [expr [string length $thistotal] - 3]]
#					putlog "DEBUG>>> thisfree = $thisfree"
#					putlog "DEBUG>>> thistotal = $thistotal"

					append devices "\[[lrange [split $device($i)] 1 end]: %bold[format %.2f [expr $thisfree/1024]]%bold/[format %.2f [expr $thistotal.0/1024]] GB\] - "
					set total_freespace [expr $total_freespace + [expr $thisfree.0/1024]]
					set total_space [expr $total_space + [expr $thistotal.0/1024]]
				}
			}
		}
		append devices "TOTAL: %bold[format %.2f $total_freespace]%bold/[format %.2f $total_space] GB"
		set output [replacevar $output "%msg" $devices]
		set output [basicreplace $output "FREE"]
		sndall "DEFAULT" $output
	} else {
		set output $announce(DEFAULT)
		for {set i 0} {$i < $device(TOTAL)} {incr i} {
			if { [string match -nocase *$arg* [split $device($i)]] == 1 } {
				set result [lindex [split $device($i)] 0]
			}
		}
#		putlog "DEBUG>>> result = $result"
#		foreach line [split [exec $binary(DF) $result] "\n"] { }
		foreach line [split [exec $binary(DF) "-m"] "\n"] {
			if { [lindex [split $line] 0] == [string toupper $result] } {
				set thisfree [lindex $line [expr [llength $line] - 2]]
				set thistotal [lindex $line [expr [llength $line] - 3]]
				set thisfree [string range $thisfree 0 [expr [string length $thisfree] - 3]]
				set thistotal [string range $thistotal 0 [expr [string length $thistotal] - 3]]

				set devices "\[[string toupper $arg]: %bold[format %.2f [expr $thisfree/1024]]%bold/[format %.2f [expr $thistotal/1024]] GB\]"
			}
		}
		set output [replacevar $output "%msg" $devices]
		set output [basicreplace $output "FREE"]
		sndall "DEFAULT" $output
	}
}
I think that should about do it. I don't remember changing anything else though I might have. If this mod doesn't work someone let me know. You can find me on irc. One thing you'll notice is that %free space is missing when you do !free <section>. I just didn't feel like modifying that portion of code as I don't really care about %free. You can add it back if you want.

Many, many thanks go to a friend who modified the code to look for free space and total space in different columns in the output. And also for making it deal with spaces in volume label names. Never would have done it without.

Hope you guys like this and find it useful. I sure did. I've also included a a zip file with the df.exe file and my show_free proc in a text file if it makes it easier for you guys.
Attached Files
File Type: zip show_free.zip (16.2 KB, 24 views)
romracer is offline   Reply With Quote