home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/wish
- #
- # MUT written by Jesse Liley for Puppy Linux 2005
- # bugs, fixes, suggestions, email: Jesse.Liley@gmail.com
- #
- # Free software, use at own risk! LGPL, please keep comments.
- #
- # Images used taken from Mandrake Linux download 10.0 /usr/share/icons
- # So I hope they are free to distribute :-)
- #
-
- package require Tcl 8.5
-
- #Here you can set mount points that MUT will not allow to be unmounted.
- lappend NoUnmounts "/" ; # This one is a generic for any Linux, its actually quite bad to unmount this one.
- if {![file exists /etc/multisessionmediatype]} {
- # this file /etc/multisessionmediatype indicates that
- lappend NoUnmounts "/mnt/home" ; # This one is a Puppy Linux specific one, it is the container fs for pup001 file
- }
- #lappend NoUnmounts "/mnt/home" ; #add any more here, as many as you like, don't forget to uncomment.
-
- #Puppy2 very specific: never unmount anything under /initrd/
- lappend PuppyNoUnmount "/initrd/"
-
- #Here you can set devices that start out not being scanned, e.g. for if the scan time takes a while and you don't really want to wait every refresh.
- array unset NoScanMedia ;# this line defines the array.
- set NoScanMedia(fd0) "noscan" ;# floppy disk is fd0
- set NoScanMedia(fd1) "noscan" ;# second floppy disk is fd1, this is ok if one or none floppy drives in system.
- #set NoScanMedia(fd0) "noscan" ;# add others, replace fd0 with device name
-
-
-
- # Here in this function you can change the scripted events attached to MUT click actions (mounting etc...)
-
- proc trigger_external_event {event device} {
- set mounted 0
- set dev $device
- if {[info exists ::etc_fstab($dev)]} {
- set mntloc "$::etc_fstab($dev)"
- } else {
- set mntloc "/mnt/$dev"
- }
- # if we chose bad, allow fallback to some other location.
- foreach devpath [array names ::mounteds] {
- set d [lindex [split $devpath / ] end]
- set mp [lindex [split $::mounteds($devpath) | ] 0 ]
- if {$mp == $mntloc && $dev != $d} {
- set mntloc "/mnt/$dev"
- }
- }
-
- set rescan_delay 2000
- catch {
- set mntloc [lindex [split $::mounteds(/dev/$dev) |] 0]
- set mounted 1
- }
- if {$::debug} { puts "User clicked on action with device $event /dev/$dev $mntloc $mounted" }
- switch $event {
- "cdplay" { ;# Commands to open application to play audio CD
- set cdinfo ""
- catch "exec $::mut/bin/cdrominfo /dev/$dev -p" cdinfo
- if {$::debug} {puts "got cdinfo for /dev/$dev, which is $cdinfo"}
- if { [lindex [split $cdinfo '|'] 7] == "Audio" || [lindex [split $cdinfo '|'] 7] == "Mixed"} {
- catch "exec /usr/local/bin/gplaycd -c /dev/$dev &"
- }
- set rescan_delay 200
- }
- "cdmount" { ;# Commands to open application to show data files on CD
- catch "exec mkdir $mntloc"
- set fs "iso9660"
- catch "exec mount /dev/$dev $mntloc -t iso9660"
- catch "exec rox -d $mntloc"
- catch {exec "mount > /etc/mtab"}
- set rescan_delay 500
- }
- "cdunmount" {;# Commands to close application to show data files on CD
- catch "exec rox -D $mntloc"
- catch "exec fuser -k -m $mntloc"
- catch "exec umount $mntloc"
- catch {exec "mount > /etc/mtab"}
- set rescan_delay 500
- }
- "mount" { ;# Commands to open application to show data files on disk
- catch "exec mkdir $mntloc"
- set fs ""
- catch "exec $::mut/bin/guess_fstype /dev/$dev" fs
- if {$::debug} {puts "got fs for /dev/$dev, which is $fs"}
- catch "exec mount /dev/$dev $mntloc -t $fs"
- catch "exec rox -d $mntloc"
- catch {exec "mount > /etc/mtab"}
- set rescan_delay 500
- }
- "unmount" { ;# Commands to close application to show data files on disk
- if {$mounted} {
- catch "exec rox -D $mntloc"
- catch "exec fuser -k -m $mntloc"
- }
- catch "exec umount $mntloc"
- catch {exec "mount > /etc/mtab"}
- set rescan_delay 400
- }
- "gxinedvd" { ;# Launch a dvd player
- catch "exec gxine dvd:/"
- set rescan_delay 2000
- }
- "rox" { ;# Launch file browser on already mounted partition/disk/cd
- catch "exec rox -d $mntloc"
- set rescan_delay 200
- }
- "eject" { ;# Eject disc media Cdrom DVD etc..
- if {$mounted} {
- catch "exec rox -D $mntloc"
- catch "exec fuser -k -m $mntloc"
- catch "exec umount $mntloc"
- catch {exec "mount > /etc/mtab"}
- }
- catch "exec $::mut/bin/cdrominfo /dev/$dev -e"
- # This application locks up during the trayclose event, so rescan shortlyafter
- set rescan_delay 200
- }
- "trayclose" {;# Close tray holder mechanism on disc media Cdrom DVD etc..
- catch "exec $::mut/bin/cdrominfo /dev/$dev -c"
- # This application locks up during the trayclose event, so rescan shortlyafter
- set rescan_delay 200
- }
- "initrdswapoff" {;# unmount initrd swap filesystem
- catch "exec swapoff /initrd/dev/$dev"
- set rescan_delay 1000
- }
- "swapoff" {;# unmount swap filesystem
- catch "exec swapoff /dev/$dev"
- set rescan_delay 1000
- }
- "swapon" { ;# mount swap filesystem
- catch "exec swapon /dev/$dev"
- set rescan_delay 1000
- }
-
-
- "scan" { ;# Activate Mut scanning this device (it may be slow to respond)
- array unset ::NoScanMedia $dev
- if {$::debug} {puts "names NoScan [array names ::NoScanMedia]"}
- set rescan_delay 100
- }
- "noscan" { ;# Deactivate Mut scanning this device (it may be slow to respond)
- set ::NoScanMedia($dev) "noscan"
- if {$::debug} {puts "names NoScan [array names ::NoScanMedia]"}
- set rescan_delay 100
- }
- default { msg "no code to run for event \"$event\"" }
- }
- return $rescan_delay
- }
-
- # This function calculates home path of application, yay, no need to configure it :-) even if symlinked to it.
- # this is generic, it could apply to any tcl app that has an application directory structure.
- proc homepath { } {
- set cmd "pwd"
- catch $cmd this_pwd
- if {[string index $::argv0 0] == "/"} {
- set path "$::argv0"
- } else {
- set path "$this_pwd/$::argv0"
- }
- # if it is a symlink from say /usr/local/bin/mut, follow the link.
- if { [file type $path] == "link" } {
- set path "$this_pwd/[file readlink $path]"
- }
- set path "$path/.."
- set plist [split $path "/"]
- set n [llength $plist]
- for {set i 0} {$i < $n} {incr i} {
- if {[lindex $plist $i] == "."} {
- set a [expr "$i - 1" ]
- set b [expr "$i + 1" ]
- set plist [concat [lrange $plist 0 $a] [lrange $plist $b end ] ]
- incr n -1
- }
- }
- set n [llength $plist]
- set olist ""
- for {set i 0} {$i < $n} {incr i} {
- if {[lindex $plist $i] == ".."} {
- set olist [lrange $olist 0 [expr "[llength $olist]-2"]]
- } else {
- lappend olist [lindex $plist $i]
- }
- }
- set path "[join $olist "/"]/"
- return $path
- }
-
- proc in_rect {x y x1 y1 x2 y2} {
- if {$x >= $x1 && $x <= $x2 && $y >= $y1 && $y <= $y2} {return 1}
- return 0
- }
-
- proc show_icons {} {
- set wx [lindex [split [wm geometry .] "+x"] 0]
- set wy [lindex [split [wm geometry .] "+x"] 1]
- set xpos [expr "$wx - 0.5 * [image width ::img::img(tux)] -4"]
- set ypos [expr "$wy - 20"]
- .boxc create image $wx $ypos -image ::img::img(tux) -anchor se
-
- set ypos [expr "$wy - 20"]
-
-
- set xpos [expr "$wx - 0.5 * [image width ::img::img(refresh)] -4"]
- .boxc create image $xpos 16 -image ::img::img(refresh)
- }
-
- proc full_refresh_display {} {
- .boxc delete all
- array unset ::actions
- set ::infolist {}
- run_full_scan
- Show_Devices
- show_icons
- if {[file exists /proc/bus/usb/devices]} {
- set ::last_hotplug [file mtime /proc/bus/usb/devices]
- }
- }
-
- proc quick_update_display {} {
- .boxc delete all
- array unset ::actions
- set ::infolist {}
- run_quick_update
- Show_Devices
- show_icons
- }
-
- proc check_click_action {x y} {
- set done false
- set rescan_delay 2000
- foreach id [array names ::actions *] {
- set action $::actions($id)
- foreach {x1 y1 x2 y2} [lrange $action 1 4] {
- if {[in_rect $x $y $x1 $y1 $x2 $y2]} {
- #puts "event trigger [lindex $action 0] for [lindex $action 5]"
- set done true
- set rescan_delay [trigger_external_event [lindex $action 0] [lindex $action 5]]
- }
- }
- }
- if {$done == false } { after 100 full_refresh_display } else { after $rescan_delay full_refresh_display }
- }
-
- proc msg { msg } {
- tk_dialog .msg "Message Window" $msg info 0 OK
- }
-
- proc remove_empties str {
- set i 0
- set i [lsearch $str {}]
- while {$i >= 0} {
- set str [lreplace $str $i $i]
- set i [lsearch $str {}]
- }
- return $str
- }
-
- proc grab_fs_vol {fs dev} {
- set results ""
- if {[lsearch [list "iso9660" "vfat" "ext2"] $fs]=={}} {
- if {$::debug} {puts "Unknown fs $fs for grab_fs_vol"}
- return ""
- }
- catch "exec $::mut/bin/label_$fs /dev/$dev" results
- set results [lindex [split $results "\n"] 0]
- set results [string trimleft [string trimright $results]]
- return $results
- }
-
- proc majorBus__get_list {} {
- set rec false
- array unset ::majorBus
- array unset ::majorBusRev
- catch {
- set fid [open "/proc/devices" r]
- if {$::debug} {puts "in majorBus__get_list"}
- while {![eof $fid]} {
- gets $fid str
- set line [remove_empties [split $str " "]]
- if {$rec == true && [lindex $line 1] > 1} {
- set ::majorBus([lindex $line 0]) [lindex $line 1]
- set ::majorBusRev([lindex $line 1]) [lindex $line 0]
- if {$::debug} {puts " ::majorBus([lindex $line 0]) $::majorBus([lindex $line 0]) "}
- }
- if {[lindex $line 0 ] == "Block"} {set rec true}
- }
- close $fid
- }
- }
-
- # scan media or model file.
- proc scan_ide_medium {bus lun scan_me} {
- if {$bus=="" || $lun=="" || $scan_me==""} {return ""}
- set medium ""
- catch {
- set bd_fd [open "/proc/ide/$bus/$lun/$scan_me" r]
- gets $bd_fd medium
- close $bd_fd
- }
- return $medium
- }
-
- proc main_or_part {str} {
- for {set i 0} {$i < [string length $str] } {incr i} {
- if {[string index $str $i] >= "0" && [string index $str $i] <= "9"} {
- if {[string range $str $i end] >= 1 && [string range $str $i end] <= 16} {
- return part
- }
- }
- }
- return main
- }
-
- proc diskStats26__get_list {quick} {
- set rec false
- array unset ::diskStats
- catch {
- set fid [open "/proc/diskstats" r]
- if {$::debug} {puts "in diskStats26__get_list"}
- while {![eof $fid]} {
- gets $fid str
- set line [remove_empties [split $str " "]]
- foreach did $::grabdevs {
- if {[string range [lindex $line 2] 0 1] == $did} {
- set media ""
- if {$did == "fd"} {
- set media floppy
- }
- if {$did == "hd"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media [scan_ide_medium $::majorBus([lindex $line 0]) [lindex $line 2] "media"]
- } else {
- set media part
- }
- }
- if {$did == "sd"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media disk
- } else {
- set media part
- }
- }
- if {$did == "scd" || $did=="sr"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media cdrom
- } else {
- set media part
- }
- }
- set ::diskStats([lindex $line 2]) "[lindex $line 0].[lindex $line 1].$::majorBus([lindex $line 0]).$media"
- if {$::debug} {puts "set ::diskStats([lindex $line 2]) $::diskStats([lindex $line 2])"}
- }
- }
- if {[lindex $line 0 ] == "Block"} {set rec true}
- }
- close $fid
- }
- }
-
- proc diskStats24__get_list {quick} {
- set rec false
- array unset ::diskStats
- if {$::debug} {puts "in diskStats24__get_list"}
- set addfd false
- catch {
- if {$::majorBusRev(fd) >= 0} {
- set ::diskStats(fd0) "$::majorBusRev(fd).0.fd.floppy"
- if {$::debug} {puts "set ::diskStats(fd0) $::diskStats(fd0)"}
- #second floppy disk here:
- #set ::diskStats(fd1) "$::majorBusRev(fd).1.fd.floppy"
- #if {$::debug} {puts "set ::diskStats(fd1) $::diskStats(fd1)"}
- }
- }
- foreach dev [lsort [array names ::partitions]] {
- set str $::partitions($dev)
- set line [remove_empties [list [lindex $str 1] [lindex $str 2] $dev ]]
- if {[llength $line] < 3 } {continue}
- foreach did $::grabdevs {
- if {[string range [lindex $line 2] 0 1] == $did} {
- set media ""
- if {$did == "fd"} {
- set media floppy
- }
- if {$did == "hd"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media [scan_ide_medium $::majorBus([lindex $line 0]) [lindex $line 2] "media"]
- } else {
- set media part
- }
- }
- if {$did == "sd"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media disk
- } else {
- set media part
- }
- }
- if {$did == "scd" || $did=="sr"} {
- if {[main_or_part [lindex $line 2]] == "main"} {
- set media cdrom
- } else {
- set media part
- }
- }
- set ::diskStats([lindex $line 2]) "[lindex $line 0].[lindex $line 1].$::majorBus([lindex $line 0]).$media"
- if {$::debug} {puts "set ::diskStats([lindex $line 2]) $::diskStats([lindex $line 2])"}
- }
- }
- if {[lindex $line 0 ] == "Block"} {set rec true}
- }
- }
-
- proc diskStats__get_list {quick} {
- if {$::Kernel_Version=="2.4"} {diskStats24__get_list $quick}
- if {$::Kernel_Version=="2.6"} {diskStats26__get_list $quick}
- }
-
- proc partitions__get_list {} {
- array unset ::partitions
- catch {
- set fid [open "/proc/partitions" r]
- while {![eof $fid]} {
- gets $fid str
- set shortlist [remove_empties [split $str]]
- set dev [lindex $shortlist 3]
- if {[llength $str] == 4 && [lindex $str 0] > 0 && [lindex $shortlist 2] > 1 } {
- set mytimer [clock clicks -milliseconds]
- set openok true
- set catchinfo ""
- if {$::Kernel_Version=="2.4" && [string range $dev 0 1] == "sd"} {
- # Sigh, we have to force the kernel to look at the hardware:
- if {[info exists ::NoScanMedia($dev)]} {
- if {$::debug} { puts "not scan $dev"}
- } else {
- set openok false
- catch {
- if {$::debug} { puts "about to scan $dev"}
- set bd_fd [open "/dev/$dev" r]
- close $bd_fd
- set openok true
- } catchinfo
- }
- }
- if {$openok == false} {
- if {$::debug} { puts "device not working? /dev/$dev $catchinfo" }
- if {[info exists ::NoScanMedia($dev)]} {
- if {$::debug} {puts "already in NoScanMedia $::NoScanMedia($dev)"}
- } else {
- #if it exists but cannot be opened, make it a noscan object
- if {[file exists /dev/[lindex $shortlist 3] ] == 1} {
- set ::NoScanMedia([lindex $shortlist 3]) "noscan"
- }
- }
- }
- set time_length [expr "[clock clicks -milliseconds] - $mytimer"]
- if {$::debug} { puts "open scan time is $time_length 1000ths of a second, $shortlist"}
- set ::partitions([lindex $shortlist 3]) \
- [list [format "%1.1f Mb" [expr "[lindex $shortlist 2]/1000.0"]] [lindex $shortlist 0] [lindex $shortlist 1]]
- if {$::debug} {puts "set ::partitions($dev) = $::partitions($dev)"}
- }
- if {[llength $str] == 4 && [lindex $str 0] > 0 && [lindex $shortlist 2] == 1 } {
- set ::partitions($dev) "extended"
- }
- }
- close $fid
- }
-
- # we have to scan for extra devices here in kernel 2.4
- # Scan for IDE removable disc drives (cdroms)
- if {$::Kernel_Version=="2.4"} {
- set ide_devs [glob /dev/hd*]
- set ide_scan {}
- set devlist [array names ::partitions]
- foreach device $ide_devs {
- set dev [lindex [split $device / ] 2]
- set atpos [lsearch -exact $devlist $dev]
- if {$atpos < 0 && [string length $dev] == 3} {
- set found false
- set gl ""
- catch {
- set gl [split [glob "/proc/ide/ide*/$dev"] /]
- }
- array unset ::cdromMedium $dev
- if {$gl == ""} {continue}
- set info ""
- lappend ide_scan $dev
- catch { exec $::mut/bin/stat_dev /dev/$dev } info
- if {$info ==""} {continue}
- set ::partitions($dev) [concat "device" [split $info |]]
- if {$::debug} { puts "set ::partitions($dev) = $::partitions($dev)" }
- #set ::diskStats($dev) "[lindex $info 0].[lindex $info 1].sr.cdrom"
- #if {$::debug} { puts "set ::diskStats($dev) = $::diskStats($dev)" }
- }
- }
- if {$::debug} { puts "scan these devices... [lsort $ide_scan]" }
- }
- # Scan for SCSI/USB removable disc drives (cdroms)
- if {$::Kernel_Version=="2.4" || $::Kernel_Version=="2.6"} {
- set sr_devs [glob /dev/sr*]
- set sr_scan {}
- set devlist [array names ::partitions]
- foreach device $sr_devs {
- set dev [lindex [split $device / ] 2]
- set atpos [lsearch -exact $devlist $dev]
- if {$atpos < 0 && [string length $dev] == 3} {
- set found false
- set gl ""
- set cdinfo ""
- catch { exec $::mut/bin/cdrominfo /dev/$dev -p } cdinfo
- if {$cdinfo == ""} {continue}
- set info [split $cdinfo |]
- if {[llength $info ] < 10} {continue}
- lappend sr_scan $dev
- catch { exec $::mut/bin/stat_dev /dev/$dev } info
- set ::partitions($dev) [concat "device" [split $info |]]
- if {$::debug} { puts "set ::partitions($dev) = $::partitions($dev)" }
- }
- }
- if {$::debug} { puts "scan these devices... [lsort $sr_scan]" }
- }
- }
-
- proc device_nodes__scan_for_make_additional {} {
- foreach name [lsort [array names ::partitions]] {
- if {[lsearch -exact $::existing_nodes $name] >= 0} {continue}
- set info ""
- catch { exec $::mut/bin/stat_dev /dev/$name } info
- set info [split $info |]
- if {[lindex $info 0]>0 && [llength $info] ==2} {
- lappend ::existing_nodes $name
- } else {
- if {$::debug} {puts "ADDME $name info $info"}
- if {$::debug} {puts "makedevs /dev/$name b [lindex $::partitions($name) 1] [lindex $::partitions($name) 2] 0 16 s" }
- catch "exec makedevs /dev/$name b [lindex $::partitions($name) 1] [lindex $::partitions($name) 2] 0 16 s " ex_info
- if {$::debug} {puts "execute info $ex_info" }
- }
- }
- if {$::debug} {puts "devnodes include $::existing_nodes"}
- }
-
- proc cdromMedium_get_list {quick} {
- if {$quick=="true"} {return}
- array unset ::cdromMedium
- foreach dev [array names ::diskStats] {
- set ds [split $::diskStats($dev) '.']
- if {[lindex $ds 3] =="cdrom"} {
- catch "exec $::mut/bin/cdrominfo /dev/$dev -p" cdinfo
- set ::cdromMedium($dev) $cdinfo
- if {$::debug} {puts "set ::cdromMedium($dev) which is $cdinfo"}
- }
- }
- }
-
- proc additional_scan_for {mnt} {
- catch { exec $::mut/bin/stat_dev /dev/$mnt } info
- set m [lindex [split $info |] 0]
- set s [lindex [split $info |] 1]
- if {$m !="" && $s!= ""} {
- foreach dev [array names ::diskStats] {
- if {$m == [lindex [split $::diskStats($dev) .] 0] &&
- $s == [lindex [split $::diskStats($dev) .] 1]} {
- if {$dev !="" && $mnt !=""} {
- set ::etc_fstab($dev) "/mnt/$mnt"
- if {$::debug} {puts "set ::etc_fstab($dev) = $::etc_fstab($dev)"}
- return
- }
- }
- }
- }
- }
-
- proc etc_fstab__get_list {} {
- if {$::debug} {puts "in etc_fstab__get_list"}
- array unset ::etc_fstab
- catch {
- set fid [open "/etc/fstab" r]
- while {![eof $fid]} {
- gets $fid str
- set sl [remove_empties [split $str]]
- set dev [lindex $sl 0]
- set mnt [lindex $sl 1]
- set dev [lindex [remove_empties [split $dev /]] end]
- if { $dev != "" &&
- $dev != "none" &&
- $dev != "tmpfs" &&
- $dev != "rootfs" &&
- $dev != "loop"} {
- if {$dev !="" && $mnt !=""} {
- set ::etc_fstab($dev) "$mnt"
- if {$::debug} {puts "set ::etc_fstab($dev) = $::etc_fstab($dev)"}
- }
- }
- }
- }
- close $fid
- additional_scan_for dvd
- additional_scan_for cdrom
-
- # Multisession DVD/CD should get mounted at /mnt/home if possible
- set myhome /mnt/myhome
- if {[file exists /etc/multisessionmediatype]} {
- set cdburnerdrive ""
- if {[file exists /etc/cdburnerdrive ]} {
- catch {
- set fid [open /etc/cdburnerdrive r]
- gets $fid cdburnerdrive
- close $fid
- }
- }
- if {$cdburnerdrive != ""} {
- set do_set true
- catch {
- if {$::etc_fstab($cdburnerdrive) == $myhome } {
- set do_set false
- }
- }
- if {$do_set} {
- set ::etc_fstab($cdburnerdrive) $myhome
- if {$::debug} {puts "set ::etc_fstab($cdburnerdrive) = $::etc_fstab($cdburnerdrive)"}
- }
- }
- }
- }
-
- proc mounteds__get_list {} {
- if {$::debug} {puts "in mounteds__get_list"}
-
- set fs_list ""
- catch "exec mount" fs_list
- foreach line [split $fs_list '\n'] {
- set sl [remove_empties [split $line]]
- set dev [lindex $sl 0]
- set mnt [lindex $sl 2]
- if { [string compare -length 4 $dev "/dev"] == 0} {
- set ::mounteds($dev) "$mnt|[join [lrange $sl 4 end ] |]"
- if {$::debug} { puts " ::mounteds($dev) = $::mounteds($dev)"}
- }
- }
-
- # Kernel 2.6 swaps:
- # Filename Type Size Used Priority
- # /dev/hda8 partition 682720 0 -1
-
-
- catch {
- set fid [open "/proc/swaps" r]
- while {![eof $fid]} {
- gets $fid str
- set sl [remove_empties [split $str]]
- set swap [lindex $sl 0]
- if { [string compare -length 4 $swap "/dev"] == 0} {
- set ::mounteds($swap) "swap|swap|"
- if {$::debug} { puts " ::mounteds($swap) = $::mounteds($swap)"}
- }
- if { [string compare -length 11 $swap "/initrd/dev"] == 0} {
- set swap [string range $swap 7 end]
- set ::mounteds($swap) "initrdswap|initrdswap|"
- if {$::debug} { puts " ::mounteds($swap) = $::mounteds($swap)"}
- }
- }
- close $fid
- }
- }
-
- proc real_permit_unmount {mnt} {
- if {[llength [lsearch -inline -all -exact $::NoUnmounts $mnt]] > 0} { return false }
- foreach m $::PuppyNoUnmount {
- if {[string match "$m*" $mnt] == 1} { return false }
- }
- return true
- }
-
- proc permit_unmount {mnt} {
- set r [real_permit_unmount $mnt]
- if {$::debug} { puts " unmountable $mnt $r "}
- return $r
- }
-
-
- # dmesg example:
- # sd 6:0:0:0: Attached scsi removable disk sdb
-
-
- proc scsi_host_to_sd_location {} {
- array unset ::scsi_drvr
- array unset ::scsi_node
- set info ""
- catch { exec dmesg -s 65535 } info
- #puts " dmesg length [llength $info] "
- set lines [split $info \n]
- foreach line $lines {
- set sl [remove_empties [split $line]]
- if {[string range [lindex $sl 0] 0 3] == "scsi"} {
- set n [string range [lindex $sl 0] 4 end]
- #puts "scsi$n has driver: [lrange $sl 2 end]"
- if {[join [lrange $sl 2 end]] == "SCSI emulation for USB Mass Storage devices"} {
- set ::scsi_drvr($n) "usb_storage"
- } else {
- set ::scsi_drvr($n) [lrange $sl 2 end]
- }
- }
- if {[lindex $sl 0] == "sd"} {
- if {[lindex $sl 2] == "Attached"} {
- if {[lindex $sl 3] == "scsi"} {
- if {[lindex $sl 4] == "removable"} {
- set n [lindex [split [lindex $sl 1] :] 0]
- #puts "scsi$n == [lindex $sl 6] "
- set ::scsi_node([lindex $sl 6]) $n
- }
- if {[lindex $sl 4] == "disk"} {
- set n [lindex [split [lindex $sl 1] :] 0]
- #puts "scsi$n == [lindex $sl 5] "
- set ::scsi_node([lindex $sl 5]) $n
- }
- }
- }
- }
- }
-
- #Jun 15 03:21:33 (none) user.info kernel: scsi2 : sata_nv
- #Jun 15 03:21:33 (none) user.info kernel: scsi3 : sata_nv
- #Jun 15 03:21:33 (none) user.notice kernel: sd 2:0:0:0: Attached scsi disk sda
- #Jun 14 19:22:26 (none) user.info kernel: scsi4 : SCSI emulation for USB Mass Storage devices
- #Jun 14 19:22:26 (none) user.info kernel: scsi5 : SCSI emulation for USB Mass Storage devices
- #Jun 14 19:22:31 (none) user.notice kernel: sd 4:0:0:0: Attached scsi removable disk sdb
- #Jun 14 19:22:31 (none) user.notice kernel: sd 4:0:0:1: Attached scsi removable disk sdc
- #Jun 14 19:22:31 (none) user.notice kernel: sd 4:0:0:2: Attached scsi removable disk sdd
- #Jun 14 19:22:31 (none) user.notice kernel: sd 4:0:0:3: Attached scsi removable disk sde
- #Jun 14 19:22:31 (none) user.notice kernel: sd 5:0:0:0: Attached scsi removable disk sdf
- #Jun 14 19:22:31 (none) user.notice kernel: sd 5:0:0:1: Attached scsi removable disk sdg
- #Jun 15 03:21:33 (none) user.notice kernel: sd 2:0:0:0: Attached scsi disk sda
-
-
- set fid [open "/var/log/messages" r]
- while {![eof $fid]} {
- gets $fid str
- set sl [remove_empties [split $str]]
- if {[lindex $sl 4] == "user.info"} {
- if {[lindex $sl 5] == "kernel:"} {
- #puts "[string range [lindex $sl 6] 0 3]"
- if {[string range [lindex $sl 6] 0 3] == "scsi"} {
- set n [string range [lindex $sl 6] 4 end]
- #puts "scsi$n has driver: [lrange $sl 8 end]"
- if {[join [lrange $sl 8 end]] == "SCSI emulation for USB Mass Storage devices"} {
- set ::scsi_drvr($n) "usb_storage"
- } else {
- set ::scsi_drvr($n) [lrange $sl 8 end]
- }
- }
- }
- }
- if {[lindex $sl 6] == "sd"} {
- if {[lindex $sl 8] == "Attached"} {
- if {[lindex $sl 9] == "scsi"} {
- if {[lindex $sl 10] == "removable"} {
- set n [lindex [split [lindex $sl 7] :] 0]
- #puts "scsi$n == [lindex $sl 12] "
- set ::scsi_node([lindex $sl 12]) $n
- }
- if {[lindex $sl 10] == "disk"} {
- set n [lindex [split [lindex $sl 7] :] 0]
- #puts "scsi$n == [lindex $sl 11] "
- set ::scsi_node([lindex $sl 11]) $n
- }
- }
- }
- }
-
- }
- close $fid
- }
-
- proc scsi_or_usb_grabinfos {} {
- array unset ::scsi_N
-
- array unset scsi_ctrlr
-
- catch {
- set fid [open "/proc/scsi/scsi" r]
- set host_n ""
- set vend ""
- set modl ""
- while {![eof $fid]} {
- gets $fid str
- set sl [remove_empties [split $str]]
- if {[lindex $sl 0] == "Host:"} {
- set host_n [string map {scsi {}} [lindex $sl 1]]
- set scsi_ctrlr($host_n) "Present"
- }
- if {[lindex $sl 0] == "Vendor:"} {
- set m_at [lsearch $sl "Model:"]
- set r_at [lsearch $sl "Rev:"]
- set vend ""
- set modl ""
- if {0 != [expr $m_at-1]} {
- set vend [join [lrange $sl 1 [expr $m_at-1]]]
- }
- if {$m_at != [expr $r_at-1]} {
- set modl [join [lrange $sl [expr $m_at+1] [expr $r_at-1]]]
- }
- }
- if {[lindex $sl 0] == "Type:"} {
- set r_at [lsearch $sl "ANSI"]
- set type ""
- if {0 != [expr $m_at-1]} {
- set type [join [lrange $sl 1 [expr $r_at-1]]]
- }
- set ::scsi_N($host_n) "$vend|$modl|$type"
- if {$::debug} { puts " ::scsi_N($host_n) = $vend|$modl|$type"}
- }
- }
- close $fid
- }
-
- catch {
- foreach ctrlr [array names scsi_ctrlr] {
- set hostis "scsi"
- catch {
- if {[string match -nocase *usb* $::scsi_drvr($ctrlr)] == 1} {
- set hostis "usb"
- }
- }
- catch {
- set fid [open "/proc/scsi/usb-storage/$ctrlr" r]
- while {![eof $fid]} {
- gets $fid str
- set hostis "usb"
- }
- close $fid
- }
-
- catch {
- if {[string match -nocase *sata* $::scsi_drvr($ctrlr)] == 1} {
- set hostis "sata"
- }
- }
- set vend [lindex [split $::scsi_N($ctrlr) |] 0]
- if {$vend == "ATA"} {
- set hostis "sata"
- }
- #puts "scsi$ctrlr Host is really $hostis"
- set info $::scsi_N($ctrlr)
- set ::scsi_N($ctrlr) "$hostis|$info"
- }
- }
- }
-
-
- proc mainDeviceList__derive {} {
- set dev_list [lsort -dictionary [array names ::diskStats]]
- if {$::debug} {puts "$$ dev_list $dev_list"}
- set omit_parts "false"
- foreach dev $dev_list {
-
- if {[string match "$omit_parts*" $dev] == 1} {
- continue;
- }
- set omit_parts "false"
-
- set ds [split $::diskStats($dev) .]
- set dev_type [lindex $ds 3]
- set icon ""
- set fs ""
- set part ""
- set mnt ""
- set vol ""
- set hw_name ""
- set gui_cmds ""
- catch {set part [lindex $::partitions($dev) 0] }
- catch {set mnt [lindex [split $::mounteds(/dev/$dev) |] 0] }
- catch {set fs [lindex [split $::mounteds(/dev/$dev) |] 1] }
- if {$part == "extended"} { continue }
- set noscan false
- switch $dev_type {
- floppy {
- set fdinfo ""
- catch " exec $::mut/bin/fdinfo /dev/$dev" fdinfo
- if {[llength [split $fdinfo |]]>3} {
- set fdx [lindex [split $fdinfo |] 1]
- if {$fdx != 5} { set fdx 3 }
- set icon "fd$fdx"
- }
- catch {
- if {$::NoScanMedia($dev)=="noscan"} { set noscan true }
- }
- }
- disk {
- set icon "disk"
- set noscan true
- if {[lindex $ds 2] == "sd" } {
- catch {
- set ctrlr $::scsi_node($dev)
- set ctrlr_info [split $::scsi_N($ctrlr) |]
- set hw_name [lindex $ctrlr_info 2]
- set icon "[lindex $ctrlr_info 0]disk"
- #set driver $::scsi_drvr($ctrlr)
- }
-
- #Here We check for SuperFloppy format:
- if {$part != "extended"} {
- set fsinfo ""
- catch "exec $::mut/bin/guess_fstype /dev/$dev" fsinfo
- if {$fsinfo != ""} {set fs $fsinfo}
- if {[lindex [split $fsinfo] 0] == "unknown"} {set fs ""}
- if {$fs != ""} {
- set parts 0
- set unknownparts 0
- foreach d $dev_list {
- if {[string match "$dev*" $d]==1} {
- if {$d != $dev} {
- set fsinfo ""
- catch "exec $::mut/bin/guess_fstype /dev/$d" fsinfo
- if {$fsinfo == "unknown"} { incr unknownparts }
- incr parts
- }
- }
- }
- if {$parts == $unknownparts} {
- set noscan false
- set dev_type superfloppy
- set omit_parts "$dev"
- } else {
- set fs ""
- }
- }
- }
- } else {
- if {[string range [lindex $ds 2] 0 2] == "ide" } {
- set hw_name [scan_ide_medium [lindex $ds 2] $dev model]
- }
- }
- }
- part {
- set icon "none"
- set noscan false
- if {$fs == "" && $part != "extended"} {
- set fsinfo ""
- catch "exec $::mut/bin/guess_fstype /dev/$dev" fsinfo
- if {$fsinfo != ""} {set fs $fsinfo}
- }
- }
- cdrom {
- set cdinfo [split $::cdromMedium($dev) |]
- set dt [lindex $cdinfo 1]
- set ty [lindex $cdinfo 2]
- set ok1 "false"; set ok2 "false"
- set noscan true
- if {$dt=="DVD"} {set dt dvd ; set ok2 true}
- if {$dt=="CD"} {set dt cd ; set ok2 true}
- if {$ty=="R&W"} {set ty raw ; set ok1 true}
- if {$ty=="RO"} {set ty ro ; set ok1 true}
- if {$ok1 && $ok2} {set icon "$dt$ty"} else {set icon "cdhuh"}
- if {[lindex $cdinfo 4]=="SW_CLOSE" && [lindex $cdinfo 6]== "open" } {
- lappend gui_cmds cd_tray_close
- if { $::Kernel_Version=="2.4" } {
- lappend gui_cmds cd_disc_eject
- }
- }
-
- if {[lindex $cdinfo 5]=="SW_OPEN" && [lindex $cdinfo 6]== "closed"} {
- lappend gui_cmds cd_disc_eject
- }
- if {[lindex $cdinfo 7] == "Audio" || [lindex $cdinfo 7] == "Mixed"} {
- if { [lindex $cdinfo 8] > 0 } {
- set fs [lindex $cdinfo 7]; set vol "[lindex $cdinfo 8] tracks"
- lappend gui_cmds cd_play_audio
- }
- }
- if {[lindex $cdinfo 7] == "Data" || [lindex $cdinfo 7] == "Mixed"} {
- if {$dt=="dvd"} {lappend gui_cmds gxine_dvd_play}
- if { [lindex $cdinfo 9] > 0 } {
- set fs [lindex $cdinfo 7];
- set vol [grab_fs_vol iso9660 $dev]
- if {$mnt == ""} {lappend gui_cmds cd_disk_mount}
- if {$mnt != ""} {lappend gui_cmds cd_disk_unmount}
- }
- }
- if {[string range [lindex $ds 2] 0 2] == "ide" } {
- set hw_name [scan_ide_medium [lindex $ds 2] $dev model]
- }
-
- }
- default { if {$::debug} {puts "Unknown device type $dev_type on $dev"} }
- }
- if {$fs=="" && $noscan==false && $part!="extended"} {
- set fsinfo ""
- catch "exec $::mut/bin/guess_fstype /dev/$dev" fsinfo
- if {$fsinfo != ""} {set fs $fsinfo}
- if {$fs == "unknown"} { set fs "" }
- }
-
- if {$vol=="" && $noscan==false} {
- if {$fs == "unknown"} { set fs "" }
- if {$fs == "iso9660" && $vol==""} { set vol [grab_fs_vol iso9660 $dev] }
- if {$fs == "vfat"} { set vol [grab_fs_vol vfat $dev] }
- if {$fs == "ext2"} { set vol [grab_fs_vol ext2 $dev] }
- }
- if {$dev_type == "floppy"} {
- if {$noscan} {
- set part "unknown"
- lappend gui_cmds scan
- } else {
- lappend gui_cmds dev_part_info
- if {$part == "" && $fs!=""} {
- set part "Disc"
- if {$mnt == ""} {
- lappend gui_cmds dev_mount
- }
- } else {
- set part "No Disc"
- }
- lappend gui_cmds noscan
- }
- if {$mnt != ""} {
- lappend gui_cmds dev_rox
- if {[permit_unmount $mnt]} {
- lappend gui_cmds dev_unmount
- }
- lappend gui_cmds dev_part_mnt
- }
- }
- if {$dev_type == "superfloppy"} {
- lappend gui_cmds dev_part_info
- if {$mnt == ""} {
- lappend gui_cmds dev_mount
- } else {
- lappend gui_cmds dev_rox
- if {[permit_unmount $mnt]} {
- lappend gui_cmds dev_unmount
- }
- lappend gui_cmds dev_part_mnt
- }
- }
-
- if {$::debug} {puts "test $dev|$icon|$hw_name|$part|$mnt|$fs|$vol|[join $gui_cmds ,]|$dev_type|" }
-
- if {$icon=="none" && ($part =="" || $fs=="") && $mnt == "" && $vol == "" && [llength $gui_cmds] ==0} {continue}
-
- if {[llength $gui_cmds] ==0 && [string length $dev]==3 && [llength [lsearch -all $dev_list $dev*]] == 1 } {continue}
- lappend ::infolist "$dev|$icon|$hw_name|$part|$mnt|$fs|$vol|[join $gui_cmds ,]|$dev_type|"
- if {$::debug} {puts "::infolist [lindex $::infolist end]"}
- }
- }
-
- proc grab_block_devices {{quick false}} {
- majorBus__get_list
- partitions__get_list
- device_nodes__scan_for_make_additional
- diskStats__get_list quick
- cdromMedium_get_list quick
- etc_fstab__get_list
- mounteds__get_list
- scsi_host_to_sd_location
- scsi_or_usb_grabinfos
- mainDeviceList__derive
- }
-
- proc run_full_scan {} {
- array unset ::partitions
- array unset ::mounteds
-
- #scan hardware
- grab_block_devices true
- }
-
- proc run_quick_update {} {
- array unset ::partitions
- array unset ::mounteds
-
- #scan hardware
- grab_block_devices
-
- }
-
- proc usb_autoscan {{how refresh}} {
- if {[file exists /proc/bus/usb/devices]} {
- if {$how == "on"} {
- if {$::debug} {puts "usb_autoscan $how"}
- full_refresh_display
- after 2000 usb_autoscan refresh2000
- set ::Program_Initialized true
- return
- }
- set hotplug [file mtime /proc/bus/usb/devices]
- if {$hotplug != $::last_hotplug} {
- if {$::debug} {puts "usb_autoscan $how now=$hotplug last=$::last_hotplug"}
- after 1000 full_refresh_display
- after 1500 usb_autoscan refresh1500
- } else {
- after 200 usb_autoscan refresh200
- }
- }
- }
-
- # we tend to get lots of window updates all in a row, so we skip all but last in a short time to update window.
- # this saves on rattelling the floppy drive to bits :)
- proc rearrange {{how Unknown}} {
- #puts [wm geometry .]
- if {$how == "config"} {
- incr ::Stack_rearrange
- if {$::debug} {puts "rearrange $how $::Stack_rearrange"}
- after 30 rearrange delayed
- }
- if {$how == "delayed"} {
- incr ::Stack_rearrange -1
- if {$::debug} {puts "rearrange $how $::Stack_rearrange"}
- if {$::Stack_rearrange == 0 && $::Program_Initialized == true} { full_refresh_display }
- }
- }
-
- proc Create_Display {} {
- wm title . "Media Utility Tool $::Version"
-
- frame .box
-
- label .status_bar -text "MUT $::Version, written by Jesse Liley for Puppy Linux 2005."
- pack .status_bar -in . -side bottom -fill x
-
- canvas .boxc -width 180 -height 350 -bd 0 -bg gray50 -highlightthickness 0
-
- pack .box -in . -fill both -expand yes
- pack .boxc -in .box -fill both -expand yes
-
- bind .boxc <Button-1> { check_click_action %x %y }
-
- # Mouse Wheel scrolling.
- # bind .boxc <Button-4> { .boxc yview scroll -3 units }
- # bind .boxc <Button-5> { .boxc yview scroll 3 units }
-
-
- bind . <Configure> "rearrange config"
- }
-
- proc set_box_trigger {itm dev y1 x1 width colour tex act} {
- upvar 1 $itm n
- set y2 [expr "11 + $y1"]
- set x2 [expr "$x1 + $width"]
- .boxc create rectangle $x1 $y1 $x2 $y2 -outline $colour
- .boxc create text [expr "$x1 + 4"] $y1 -anchor nw -text $tex -fill $colour -font {Helvetica -10 bold}
- set ::actions($n) [list $act $x1 $y1 $x2 $y2 $dev]
- if {$::debug} {puts "actions($n) = [list $act $x1 $y1 $x2 $y2 $dev]" }
- incr n
- }
-
- proc max {a b} {
- if {$a > $b} {return $a}
- return $b
- }
-
- set ::clr(mount) "LightBlue"
-
- proc Show_Devices {} {
- set index 1
- set n_itm 1
- set ypos 5
- set nextdev_ypos $ypos
- set start_horizontal_pos 50
-
- foreach str $::infolist {
- set l ".l$index"
- set info [split $str "|"]
- set xpos 110
-
- set dev [lindex $info 0]
- set icon [lindex $info 1]
- set hw_name [lindex $info 2]
- set part [lindex $info 3]
- set mnt [lindex $info 4]
- set fs [lindex $info 5]
- set vol [lindex $info 6]
- set guicmds [split [lindex $info 7] ,]
- set dev_type [lindex $info 8]
-
- if {$icon!="" && $icon!="none"} { # only devices have icons at this point
- set ypos [max $ypos $nextdev_ypos]
- set xpos 3
- set tex "$dev :: $hw_name"
- .boxc create image $xpos $ypos -anchor nw -image ::img::img($icon)
- set xpos [expr "$xpos + [image width ::img::img($icon)] + 3" ]
- .boxc create text $xpos $ypos -anchor nw -text $tex -fill White -font {Helvetica -10 bold }
- incr ypos 14
- incr xpos 5
-
- foreach cmd $guicmds {
- switch $cmd {
- gxine_dvd_play {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 57 Cyan "GxineDVD" "gxinedvd"
- incr xpos 57
- }
- dev_part_mnt {
- if {$mnt != "" } {
- .boxc create text $xpos [expr "$ypos + 4"] -anchor nw -text "$mnt" -fill $::clr(mount) -font {Courier -10 bold}
- incr xpos [expr " 7 * [string length $mnt]"]
- }
- }
- dev_part_info {
- set d [lindex [split $dev '/'] end]
- set d [string trim $d "abcdefghijklmnopqrstuvwxyz/"]
- set tex "[string toupper $d] $fs"
- set v "$vol"
- incr xpos 8
- .boxc create text [expr "$xpos"] [expr "$ypos +4"] -anchor nw -text "$vol." -fill White -font {Courier -10 }
- .boxc create text [expr "$xpos-8"] [expr "$ypos -3"] -anchor nw -text $tex -fill #dfdfdf -font {Courier -10 }
-
-
- incr xpos [max [expr " 5 * [string length $tex]"] [expr "5+ 6 * [string length $v]"] ]
-
- set tex "$fs:$part"
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text "$part" -fill black -font {Helvetica -10 bold }
- incr xpos [expr " 6 * [string length $part]"]
- }
- dev_rox {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 25 LightGoldenrod "Rox" "rox"
- incr xpos 25
- }
- dev_unmount {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 50 PeachPuff "UnMount" "unmount"
- incr xpos 50
- }
- dev_mount {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 37 pink "Mount" "mount"
- incr xpos 37
- }
- scan {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 29 Yellow "Scan" "scan"
- incr xpos 29
- }
- noscan {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 43 Yellow "NoScan" "noscan"
- incr xpos 43
- }
- cd_disk_mount {
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 37 pink "Mount" "cdmount"
- incr xpos 37
- if {$fs == "Mixed" || $fs=="Data"} {
- incr xpos 5
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text $vol -fill black -font {Helvetica -10 bold }
- incr xpos 27
- }
- }
- cd_disk_unmount {
- incr xpos 5
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 25 LightGoldenrod "Rox" "rox"
- incr xpos 25
- incr xpos 5
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 50 PeachPuff "UnMount" "cdunmount"
- incr xpos 50
- if {$fs == "Mixed" || $fs=="Data"} {
- incr xpos 6
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text $vol -fill black -font {Helvetica -10 bold }
- incr xpos [expr " 7 * [string length $vol] + 4"]
-
- incr xpos 5
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text "$mnt" -fill $::clr(mount) -font {Courier -10 bold}
- incr xpos [expr " 7 * [string length $mnt]"]
- }
- }
- cd_play_audio {
- incr xpos 6
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 56 cyan "CD Player" "cdplay"
- incr xpos 56
- }
- cd_disc_eject {
- incr xpos 6
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 30 SpringGreen "Eject" "eject"
- incr xpos 30
-
- incr xpos 6
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text $fs -fill black -font {Helvetica -10 bold }
- incr xpos 25
- }
- cd_tray_close {
- incr xpos 6
- set_box_trigger n_itm $dev [expr "2 + $ypos"] $xpos 35 tan "Close" "trayclose"
- incr xpos 35
- }
- default { if {$::debug} {puts "Unhandled cmd $cmd"} }
- }
- incr xpos 4
- }
- set nextdev_ypos [expr "26 + $ypos"]
- }
-
- set xpos $start_horizontal_pos
-
- if { $dev_type == "part" } {
- set d [lindex [split $dev '/'] end]
- set d [string trim $d "abcdefghijklmnopqrstuvwxyz/"]
- set tex "[string toupper $d] $fs"
-
- .boxc create text [expr "$xpos"] [expr "$ypos +4"] -anchor nw -text "$vol." -fill White -font {Courier -10 }
- .boxc create text [expr "$xpos-8"] [expr "$ypos -3"] -anchor nw -text $tex -fill #dfdfdf -font {Courier -10 }
- incr xpos 120
- .boxc create text $xpos $ypos -anchor ne -text $part -font {Helvetica -10}
-
- if {$mnt != "" && $fs != "Audio"} {
- if {$mnt != "" && $fs != "swap" && $fs != "initrdswap"} {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 26 LightGoldenrod "Rox" "rox"
- incr xpos 26
- }
- if {$mnt != ""} {
- if {$fs != "swap" && $fs != "initrdswap" &&[permit_unmount $mnt]} {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 49 PeachPuff "Unmount" "unmount"
- incr xpos 49
- }
- incr xpos 5
- .boxc create text $xpos [expr "2 + $ypos"] -anchor nw -text "$mnt" -fill $::clr(mount) -font {Courier -10 bold}
- incr xpos [expr " 7 * [string length $mnt]"]
- }
- if {$fs == "swap"} {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 51 blue "Swap Off" "swapoff"
- incr xpos 51
- }
- if {$fs == "initrdswap"} {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 51 blue "Swap Off" "initrdswapoff"
- incr xpos 51
- }
- } elseif { $fs == "Audio" } {
-
- } elseif { $fs != "" && $fs != "unknown" && $part != ""} {
- if { $fs == "swap" } {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 56 SkyBlue "Use Swap" "swapon"
- incr xpos 56
- } else {
- if {$mnt == ""} {
- incr xpos 5
- set_box_trigger n_itm $dev $ypos $xpos 37 pink "Mount" "mount"
- incr xpos 37
- }
- }
- }
- incr ypos 19
- set nextdev_ypos [max [expr "10 + $ypos"] $nextdev_ypos]
- }
- incr index
- }
-
- }
-
-
-
- ## Initialise global variables here:
-
- set Version "0.0.9b"; # Version Number
- set mut [homepath]; # Home path to app directory, Now done automatically! :-)
- set debug 0; # Choose output of debugging information, output is to stdout
- set last_hotplug 0; # USB SCSI hotplug last refresh info, for hot [un]plug scanning.
- set Kernel_Version ""
- set Program_Initialized false; # Make start quicker.
-
- # get the Kernel version.
- proc get_kv {} {
- set ::Kernel_Version "Unknown"
- catch {
- set fid [open "/proc/version" r]
- while {![eof $fid]} {
- gets $fid str
- set ::Kernel_Version "[string range [lindex [split $str] 2] 0 2]"
- break;
- }
- close $fid
- }
- }
- get_kv
-
- ## global variables used to describe attached hardware:
-
-
- array unset partitions ; # List of info from /proc/partitions
- array unset mounteds ; # List of info from /proc/mounts
- array unset actions ; # "click actions" value is a list of {action minx miny maxx maxy}
- set Stack_rearrange 0 ; # Stack the window rearrange events
- array unset etc_fstab ; # save info from /etc/fstab file.
- array unset cdromMedium ; # List of info from bin/cdrominfo about cdrom drives in system
- array unset diskStats ; # info about block devices in system
- set grabdevs {fd hd sd scd sr} ; # list of device types to scan in /proc/diskstats & /proc/partitions
- set existing_nodes "" ; # Keep track of nodes that exist in /dev directory.
- array unset majorBus ; # block device info from /proc/devices
- array unset majorBusRev ; # reverse lookup of majorBus, not always best to use! heh :)
- set infolist ""; # The list of displayed devices & partitions.
-
- ## Process command line arguments, debuging flag only at this point
-
- if {$argc > 0} {
- for {set i 0} {$i < $argc} {incr i} {
- set sw [string trimleft [lindex $argv $i] "- "]
- switch $sw {
- "d" {set debug 1 ; puts "debugging on"}
- "debug" {set debug 1 ; puts "debugging on"}
- default {}
- }
- }
- }
-
- ## Load Images for display:
- image create photo ::img::img(fd3) -file "$mut/icon/fd3.ppm"
- image create photo ::img::img(fd5) -file "$mut/icon/fd5.ppm"
- image create photo ::img::img(cdhuh) -file "$mut/icon/cdhuh.ppm"
- image create photo ::img::img(cdro) -file "$mut/icon/cd-ro.ppm"
- image create photo ::img::img(cdraw) -file "$mut/icon/cd-raw.ppm"
- image create photo ::img::img(dvdro) -file "$mut/icon/dvd-ro.ppm"
- image create photo ::img::img(dvdraw) -file "$mut/icon/dvd-raw.ppm"
- image create photo ::img::img(disk) -file "$mut/icon/disk.ppm"
- image create photo ::img::img(scsidisk) -file "$mut/icon/scsidisk.ppm"
- image create photo ::img::img(satadisk) -file "$mut/icon/satadisk.ppm"
- image create photo ::img::img(usbdisk) -file "$mut/icon/usbdisk.ppm"
- image create photo ::img::img(zip) -file "$mut/icon/zip.ppm"
- ## These two images are the screen tattoos
- image create photo ::img::img(refresh) -file "$mut/icon/refresh.ppm"
- image create photo ::img::img(tux) -file "$mut/icon/tux.ppm"
-
-
- # set transparency on tattoos
- catch {
- foreach img [list "tux" "refresh"] {
- set width [image width ::img::img($img)]
- set height [image height ::img::img($img)]
- for {set x 0} {$x < $width} {incr x} {
- for {set y 0} {$y < $height} {incr y} {
- #set c [lindex $data [incr ndx]]
- set c [::img::img($img) get $x $y ]
- if {[lindex $c 0] == 127 && [lindex $c 1] == 127 && [lindex $c 2] == 127} {
- ::img::img($img) transparency set $x $y 1
- }
- }
- }
- }
- }
-
-
- ## MUT version information
-
- if {$debug} {puts "'MUT version $::Version' on a $::Kernel_Version kernel, bugs, fixes, suggestions, email: Jesse.Liley@gmail.com"}
- if {$::debug} { puts " unmountables are $NoUnmounts $PuppyNoUnmount"}
- proc kick_off_autoscan {} {
- if {[file exists /proc/bus/usb/devices]} {
- usb_autoscan on
- } else {
- full_refresh_display
- }
- }
-
- ## Kick off the application, get it running:
-
- catch { exec $mut/bin/load_drivers.sh }
- Create_Display
- after 2500 kick_off_autoscan
- if {$debug} {puts "Program started"}
-