blah di blah
authorpaulr <me@pjr.cc>
Tue, 13 Jul 2010 03:52:53 +0000 (13:52 +1000)
committerpaulr <me@pjr.cc>
Tue, 13 Jul 2010 03:52:53 +0000 (13:52 +1000)
bin/pbdc.php
install.sh

index 8c67315..f447768 100644 (file)
@@ -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++;
+                       
                }
        }
        
index e4e2d29..da6d193 100644 (file)
@@ -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