From: paulr Date: Tue, 13 Jul 2010 03:52:53 +0000 (+1000) Subject: blah di blah X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=b2a5bc95c526835f139a0f3d8856e58d7009a02b;p=php-bacula-disk-changer.git blah di blah --- diff --git a/bin/pbdc.php b/bin/pbdc.php index 8c67315..f447768 100644 --- a/bin/pbdc.php +++ b/bin/pbdc.php @@ -223,6 +223,47 @@ function check_init($changer) return true; } +function disk_get_size($file, $realname="") +{ + global $BASE_DATA, $BASE_LIB, $BACULA_USER, $argv; + + check_init_and_fail($argv[1]); + + $changer = $argv[1]; + + error_reporting(E_ALL); + + $dh = opendir("/dev/disk/by-uuid"); + $amdir = conf_getVal($changer, "automountdir"); + + $ts = 0; + + $parsed = false; + if(file_exists("/$amdir/$file/.")) { + $cmd = "/bin/df -k /$amdir/$file/. |/usr/bin/tail -1 |/usr/bin/awk '{ print $4 }'"; + $pl = popen($cmd, "r"); + if($pl) { + $f = fread($pl, 1024); + echo "cmd: $cmd\nf: $f\n"; + $ts = (int)($f); + if($ts > 1) $parsed = true; + pclose($pl); + } + } + + if(!$parsed && $realname != "") { + $fh = fopen("/sys/class/block/$realname/size", "r"); + $lk = ((int)(fgets($fh))); + $ts = ($lk/1024)*512; + fclose($fh); + + } + + $realsize = (int)(($ts/1024)/1024); + + return $realsize; +} + function add_disk() { // disks get inited by going to /changer_dir/disk_uuid/ then: @@ -231,7 +272,10 @@ function add_disk() check_init_and_fail($argv[1]); + $changer = $argv[1]; + $dh = opendir("/dev/disk/by-uuid"); + $amdir = conf_getVal($changer, "automountdir"); $disk = ""; $i = 0; @@ -240,18 +284,15 @@ function add_disk() if($file != "." && $file != "..") { $st = stat("/dev/disk/by-uuid/".$file); $realname = basename(readlink("/dev/disk/by-uuid/".$file)); + $realsize = disk_get_size($file, $realname); - // now get the size - $fh = fopen("/sys/class/block/$realname/size", "r"); - $rl = fgets($fh); - fclose($fh); - $realsize = (int)(((($rl/1024)*512)/1024)/1024); - + // now get the size, first lets try and parse df output echo "disk $i: /dev/$realname or /dev/disk/by-uuid/$file of size ".$realsize."gb\n"; $disk[$i]["real"] = "/dev/$realname"; $disk[$i]["syml"] = "/dev/disk/by-uuid/".$file; $disk[$i]["size"] = $realsize; $i++; + } } diff --git a/install.sh b/install.sh index e4e2d29..da6d193 100644 --- a/install.sh +++ b/install.sh @@ -31,4 +31,5 @@ EOF cp -rp bin/* $install_base/bin cp -rp lib/* $install_base/lib -chown -R $user_id $install_base \ No newline at end of file +chown -R $user_id $install_base +chmod 755 $install_base/bin/* \ No newline at end of file