Example #1
0
function get_partition_info($device, $reload = FALSE)
{
    global $_ENV, $paths;
    $disk = array();
    $attrs = isset($_ENV['DEVTYPE']) ? get_udev_info($device, $_ENV, $reload) : get_udev_info($device, NULL, $reload);
    // $GLOBALS["echo"]($attrs);
    $device = realpath($device);
    if ($attrs['DEVTYPE'] == "partition") {
        $disk['serial_short'] = isset($attrs["ID_SCSI_SERIAL"]) ? $attrs["ID_SCSI_SERIAL"] : $attrs['ID_SERIAL_SHORT'];
        $disk['serial'] = "{$attrs[ID_MODEL]}_{$disk[serial_short]}";
        $disk['device'] = $device;
        // Grab partition number
        preg_match_all("#(.*?)(\\d+\$)#", $device, $matches);
        $disk['part'] = $matches[2][0];
        $disk['disk'] = $matches[1][0];
        if (isset($attrs['ID_FS_LABEL'])) {
            $disk['label'] = safe_name($attrs['ID_FS_LABEL_ENC']);
        } else {
            if (isset($attrs['ID_VENDOR']) && isset($attrs['ID_MODEL'])) {
                $disk['label'] = sprintf("%s %s", safe_name($attrs['ID_VENDOR']), safe_name($attrs['ID_MODEL']));
            } else {
                $disk['label'] = safe_name($attrs['ID_SERIAL']);
            }
            $all_disks = array_unique(array_map(function ($ar) {
                return realpath($ar);
            }, listDir("/dev/disk/by-id")));
            $disk['label'] = count(preg_grep("%" . $matches[1][0] . "%i", $all_disks)) > 2 ? $disk['label'] . "-part" . $matches[2][0] : $disk['label'];
        }
        $disk['fstype'] = safe_name($attrs['ID_FS_TYPE']);
        $disk['fstype'] = !$disk['fstype'] && verify_precleared($disk['disk']) ? "precleared" : $disk['fstype'];
        $disk['target'] = str_replace("\\040", " ", trim(shell_exec("/bin/cat /proc/mounts 2>&1|/bin/grep {$device}|/bin/awk '{print \$2}'")));
        $disk['size'] = intval(trim(shell_exec("/sbin/blockdev --getsize64 {$device} 2>/dev/null")));
        $disk['used'] = intval(trim(shell_exec("/bin/df --output=used,source 2>/dev/null|/bin/grep -v 'Filesystem'|/bin/grep {$device}|/bin/awk '{print \$1}'"))) * 1024;
        $disk['avail'] = $disk['size'] - $disk['used'];
        if ($disk['mountpoint'] = get_config($disk['serial'], "mountpoint.{$disk[part]}")) {
            if (!$disk['mountpoint']) {
                goto empty_mountpoint;
            }
        } else {
            empty_mountpoint:
            $disk['mountpoint'] = $disk['target'] ? $disk['target'] : preg_replace("%\\s+%", "_", sprintf("%s/%s", $paths['usb_mountpoint'], $disk['label']));
        }
        $disk['owner'] = isset($_ENV['DEVTYPE']) ? "udev" : "user";
        $disk['automount'] = is_automount($disk['serial'], strpos($attrs['DEVPATH'], "usb"));
        $disk['shared'] = config_shared($disk['serial'], $disk['part'], strpos($attrs['DEVPATH'], "usb"));
        $disk['command'] = get_config($disk['serial'], "command.{$disk[part]}");
        $disk['command_bg'] = get_config($disk['serial'], "command_bg.{$disk[part]}");
        $disk['prog_name'] = basename($disk['command'], ".sh");
        $disk['logfile'] = $paths['device_log'] . $disk['prog_name'] . ".log";
        return $disk;
    }
}
function get_partition_info($device){
  global $_ENV, $paths;
  $disk = array();
  $attrs = (isset($_ENV['DEVTYPE'])) ? get_udev_info($device, $_ENV) : get_udev_info($device);
  $device = realpath($device);
  if ($attrs['DEVTYPE'] == "partition") {
    $disk['serial']       = $attrs['ID_SERIAL'];
    $disk['serial_short'] = $attrs['ID_SERIAL_SHORT'];
    $disk['device']       = $device;
    // Grab partition number
    preg_match_all("#(.*?)(\d+$)#", $device, $matches);
    $disk['part']   =  $matches[2][0];
    if (isset($attrs['ID_FS_LABEL'])){
      $disk['label'] = safe_name($attrs['ID_FS_LABEL_ENC']);
    } else {
      if (isset($attrs['ID_VENDOR']) && isset($attrs['ID_MODEL'])){
        $disk['label'] = sprintf("%s %s", safe_name($attrs['ID_VENDOR']), safe_name($attrs['ID_MODEL']));
      } else {
        $disk['label'] = safe_name($attrs['ID_SERIAL']);
      }
      $all_disks = array_unique(array_map(function($ar){return realpath($ar);},listDir("/dev/disk/by-id")));
      $disk['label']  = (count(preg_grep("%".$matches[1][0]."%i", $all_disks)) > 2) ? $disk['label']."-part".$matches[2][0] : $disk['label'];
    }
    $disk['fstype'] = safe_name($attrs['ID_FS_TYPE']);
    $disk['target'] = str_replace("\\040", " ", trim(shell_exec("cat /proc/mounts 2>&1|grep ${device}|awk '{print $2}'")));
    $disk['size']   = intval(trim(shell_exec("blockdev --getsize64 ${device} 2>/dev/null")));
    $disk['used']   = intval(trim(shell_exec("df --output=used,source 2>/dev/null|grep -v 'Filesystem'|grep ${device}|awk '{print $1}'")))*1024;
    $disk['avail']  = $disk['size'] - $disk['used'];
    if ( $disk['mountpoint'] = get_config($disk['serial'], "mountpoint.{$disk[part]}") ) {
      if (! $disk['mountpoint'] ) goto empty_mountpoint;
    } else {
      empty_mountpoint:
      $disk['mountpoint'] = $disk['target'] ? $disk['target'] : preg_replace("%\s+%", "_", sprintf("%s/%s", $paths['usb_mountpoint'], $disk['label']));
    }
    $disk['owner'] = (isset($_ENV['DEVTYPE'])) ? "udev" : "user";
    $disk['automount'] = is_automount_2($disk['serial'],strpos($attrs['DEVPATH'],"usb"));
    return $disk;
  }
}