#! /usr/bin/perl -w

$device = shift or die("Usage: reverse_dev <dev_path> <step>\n");
$step = shift or die("Usage: reverse_dev <dev_path> <step>\n");

open(IN, "/sbin/blockdev --getsize $device |") 
    or die("couldn't run blockdev\n");
$dev_size = <IN>;
close(IN);

chomp($dev_size);
$dev_size--;

# round down dev size to the lower step
$dev_size = int($dev_size / $step);
$dev_size *= $step;

$start = 0;
for ($i = 0; $i < $dev_size; $i += $step) {
    $rstart = $dev_size - ($start + $step);
    print "$start $step linear $device $rstart\n";
    $start += $step;
}
