eyesis4pi_interface.php 4.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
*!***************************************************************************
*! FILE NAME  : eyesis4pi_interface.php
*! DESCRIPTION: command interface for the eyesis4pi gui
*! Copyright (C) 2016 Elphel, Inc.
*! --------------------------------------------------------------------------
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! --------------------------------------------------------------------------
*/

23
include 'include/elphel_functions_include.php';
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
24

25 26 27 28 29 30
$cmd = "donothing";
if (isset($_GET['cmd']))
  $cmd = $_GET['cmd'];
else if (isset($argv[1]))
  $cmd = $argv[1];

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
31
#hardcoded for eyesis4pi
32 33
$symlink = "/www/pages/ssd";
$mountpoint = "/mnt/sda1";
34

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
35
$camogmdisk = "/home/root/camogm.disk";
36 37 38 39 40 41 42 43 44 45
$nandbootpath = "/tmp/rootfs.ro";

if (is_dir($nandbootpath)) $camogmdisk = $nandbootpath.$camogmdisk; 

$sysfs_lba_path = "/sys/devices/soc0/amba@0/80000000.elphel-ahci/";

$file_lba_start = $sysfs_lba_path."lba_start";
$file_lba_current = $sysfs_lba_path."lba_current";
$file_lba_end = $sysfs_lba_path."lba_end";

46 47
switch($cmd){
  case "symlink":
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
48 49
    if (is_link($symlink)) die("already exists");
    die(symlink($mountpoint,$symlink));
50
    break;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
51
  case "free_space":
52
    //sda1
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
53 54 55 56
    if (is_dir($mountpoint)){
      $sda1 = round(disk_free_space($mountpoint)/1024/1024/1024,2);
      $sda1 .= "G";
    }
57
    
58
    
59
    //sda2
60 61 62 63 64 65 66 67 68 69 70 71
    $lba_start = 0;
    $lba_current = 0;
    $lba_end = 0;
    
    if (is_file($file_lba_start))   $lba_start   = intval(trim(file_get_contents($file_lba_start)));
    if (is_file($file_lba_current)) $lba_current = intval(trim(file_get_contents($file_lba_current)));
    if (is_file($file_lba_end))     $lba_end     = intval(trim(file_get_contents($file_lba_end)));
    
    if (($lba_start!=0)&&($lba_current!=0)&&($lba_end!=0)){
    	$size = ($lba_end - $lba_current)/2/1024/1024;
    	$sda2 = round($size,2);
    	$sda2 .= "G";
72
    }else{
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    	// camogm.disk not found
    	if (!is_file($camogmdisk)){
    		$devices = get_raw_dev();
    		foreach($devices as $device=>$size){
    			//size in MB
    			if ($device=="/dev/sda2") {
    				$sda2 = round($size/1048576,2);
    				$sda2 .= "G";
    			}
    		}
    	}else{
    		//read camogm.disk file
    		$content = file_get_contents($camogmdisk);
    		$content = trim(preg_replace('/\n|\t{2,}/',"\t",$content));
    		$content_arr = explode("\t",$content);
    		
    		if (count($content_arr)>=8){
    			$device = $content_arr[4];
    			$lba_current = $content_arr[6];
    			$lba_end = $content_arr[7];
    			$size = ($lba_end - $lba_current)/2/1024/1024;
    			$sda2 = round($size,2);
    			$sda2 .= "G";
    		}else{    		
	    		//tmp
	    		$devices = get_raw_dev();
	    		foreach($devices as $device=>$size){
	    			//size in MB
	    			if ($device=="/dev/sda2") {
	    				$sda2 = round($size/1048576,2);
	    				$sda2 .= "G";
	    			}
	    		}
    		}
    	}
108
    }
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
109
    respond_xml("{$sda1} {$sda2}");
110
    break;
111
    
112 113 114 115 116 117 118
  case "reset_camogm_fastrec":
  	//remove file
  	if (is_file($camogmdisk)){
  		unlink($camogmdisk);
  	}
  	file_put_contents($file_lba_current,file_get_contents($file_lba_start));
  	print("reset fastrec: ok");
119 120
    break;
  case "free_space_bkp":
121
    // results are in GB
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
122
    // /dev/sda2 is not a mountpoint but a device because it does not have a file system
123
    $res = 0;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
124 125 126 127 128
    if ($_GET['mountpoint']=="/dev/sda2"){
      //root@elphel393:~# cat /home/root/camogm.disk
      //Device          Start LBA       Current LBA     End LBA
      ///dev/sda2       195334335       545641716       976768065
      if (!is_file($camogmdisk)){
129 130 131 132 133
        $devices = get_raw_dev();
        foreach($devices as $device=>$size){
          //size in MB
          if ($device=="/dev/sda2") $res = round($size/1048576,2);
        }
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
134
      }else{
135 136
        //read camogm.disk file
        $res = 10;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
137
      }
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
138
    }else{
139
      if (is_dir($mountpoint)) $res = round(disk_free_space($mountpoint)/1024/1024/1024,2);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
140
    }
141
    respond_xml($res);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
142
    break;
143
  default:
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
144
    print("nothing has been done");
145 146 147
}
  
?>