Mark Watts <[EMAIL PROTECTED]> wrote:

> Any chance 'df' could be patched to display the partition name and the
> sizing info all on the same line?
> 
>  It was fine when you just had /dev/hda, but when you have 
> /dev/ide/host0/bus0/target0/lun0/part1/cow4/banana3  it all gets a tad
> messy.

Another solution could be a small script that converts "long device
names" to small ones, using informations from /proc/partitions.

I join to the mail a portion of php script that does this task.
I think it could adapted easily to other more common script languages
(a Perl Guru should write that in a few lines...)

Usage: pc df
(or alias dfs='pc df')

-- 
Vincent Palatin
#!/usr/bin/php
<?php

$partitions="/proc/partitions";

//return "classic" device name corresponding to device major & minor numbers
function olddevicename($major,$minor) {
  switch($major) {
    case 3:
      $devname="dev/hd".($minor&64?'b':'a').($minor&63);
      break;
    case 22:
      $devname="dev/hd".($minor&64?'d':'c').($minor&63);
      break;
    case 33:
      $devname="dev/hd".($minor&64?'f':'e').($minor&63);
      break;
    case 34:
      $devname="dev/hd".($minor&64?'h':'g').($minor&63);
      break;
    case 8:
      $devname="dev/sd".chr(($minor>>4)+ord('a')).($minor&15);
      break;
    default:
      $devname="unknown";
  }
  //if it's a disk (not a partition) => remove trailing zero
  return trim($devname,"0");
}

//read /proc/partitions entries
function readPartitions() {
  $equiv=array();
  $fp = fopen("/proc/partitions","r") or die("unable to open : /proc/partitions\n");
  fgets($fp); fgets($fp);
  while (!feof($fp)) {
    list($major,$minor,$blocks,$partname,$remain) = split("[ \t\n]+",trim(fgets($fp)),5);
    $dev=olddevicename($major,$minor);
    if ($dev!="unknown") $equiv[$partname]=$dev;
  }
  fclose($fp);
  return($equiv);
}

$equiv=readPartitions();
exec(implode(" ",array_slice($_SERVER['argv'],1)),$retour);
echo(strtr(implode("\n",$retour),$equiv)."\n");

?>

Reply via email to