From f029ab1ce68e1fcf4ba329a91eb3e3bbf6fd903f Mon Sep 17 00:00:00 2001 From: hummypkg Date: Wed, 28 May 2014 18:10:58 +0000 Subject: [PATCH] improve diskspace check git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1920 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- webif/lib/system.class | 77 +++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index 6477391..0a5b350 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.0.13-2 +Version: 1.0.13-3 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif-channelicons(>=1.1.11),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.13),hmt(>=1.1.14),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),mongoose diff --git a/webif/lib/system.class b/webif/lib/system.class index 2a347bd..d3185ba 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -144,18 +144,72 @@ proc {system dustbin} {{short 0}} { return "[system mediaroot]/$dustbin" } -proc {system diskspace} {} { +proc {system diskdev} {} { + switch [system model] { + HDR { set part /mnt/hd2 } + HD { set part /media/drive1 } + } + foreach line [split [\ + exec /mod/bin/busybox/df $part 2>>/dev/null] "\n\r"] { + if {[string match "/*" $line]} { + lassign [split $line] dev + break + } + } + return $dev +} + +proc {system disk} {} { + return [string range [system diskdev] 0 end-1] +} + +if {[file exists /sbin/tune2fs]} { + + # New version of diskspace functions that ignores reserved blocks. + # Only supported on firmwares with tune2fs in the root filesystem. + + require pretty_size + + proc {system diskspace} {{raw 0}} { + set dev [system diskdev] + foreach line [split [exec /sbin/tune2fs -l $dev] "\n\r"] { + lassign [split $line ":"] key val + switch $key { + "Block size" { set bsize $val } + "Block count" { set blocks $val } + "Free blocks" { set fblocks $val } + } + } + + set size $($bsize * $blocks) + set free $($bsize * $fblocks) + set used $($size - $free) + set perc $($used * 100 / $size) + set fperc $(100 - $perc) + + if {!$raw} { + set size [pretty_size $size] + set free [pretty_size $free] + set used [pretty_size $used] + } + + return [list $size $used $perc $free $fperc $dev] + } + + proc {system diskfree} {} { + return [lindex [system diskspace 1] 3] + } + +} else { + + proc {system diskspace} {} { switch [system model] { HDR { set part /mnt/hd2 } HD { set part /media/drive1 } } - set size 0 - set used 0 - set free 0 - set perc 0 - set dev 0 - foreach line [split [exec /mod/bin/busybox/df -h $part 2>>/dev/null] "\n\r"] { + foreach line [split [\ + exec /mod/bin/busybox/df -h $part 2>>/dev/null] "\n\r"] { if {[string match "/*" $line]} { regsub -all -- {[[:space:]]+} $line " " line set fields [split $line] @@ -170,13 +224,9 @@ proc {system diskspace} {} { } return [list $size $used $perc $free $fperc $dev] -} + } -proc {system disk} {} { - return [string range [lindex [system diskspace] 5] 0 end-1] -} - -proc {system diskfree} {} { + proc {system diskfree} {} { switch [system model] { HDR { set part /mnt/hd2 } HD { set part /media/drive1 } @@ -194,6 +244,7 @@ proc {system diskfree} {} { } return $free + } } proc {system busy} {} {