summaryrefslogtreecommitdiff
path: root/ddp
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
commitb0a14e013b318fa87714414b8ece95780527bddf (patch)
treea9427383ab6e38a4421c9c4313043f6dfcb8e90e /ddp
Initial commit
Diffstat (limited to 'ddp')
-rwxr-xr-xddp70
1 files changed, 70 insertions, 0 deletions
diff --git a/ddp b/ddp
new file mode 100755
index 0000000..d3bddf3
--- /dev/null
+++ b/ddp
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+
+cmd = ['dd']
+countarg = nil
+
+def decr(mult)
+ return {
+ 'c' => ['c', 1],
+ 'w' => ['c', 2],
+ 'b' => ['c', 512],
+ 'kB' => ['w', 500],
+ 'K' => ['w', 512],
+ 'MB' => ['kB', 1000],
+ 'M' => ['K', 1024],
+ 'GB' => ['MB', 1000],
+ 'G' => ['M', 1024],
+ 'TB' => ['GB', 1000],
+ 'T' => ['G', 1024],
+ 'PB' => ['TB', 1000],
+ 'P' => ['T', 1024],
+ 'EB' => ['PB', 1000],
+ 'E' => ['P', 1024],
+ 'ZB' => ['EB', 1000],
+ 'Z' => ['E', 1024],
+ 'YB' => ['ZB', 1000],
+ 'Y' => ['Z', 1024],
+ }[mult]
+end
+
+def parsecount(countarg)
+ if countarg =~ /^(\d+)(c|w|b|kB|K|[MGTPEZY]B?)$/
+ if $1 == '1' then
+ unit, num = decr($2)
+ count = "count=1#{unit}"
+ seeks = (0...num).map do |i|
+ "seek=#{i}#{unit}"
+ end
+ else
+ count = "count=1#{$2}"
+ seeks = (0...($1.to_i)).map do |i|
+ "seek=#{i}#{$2}"
+ end
+ end
+ return count, seeks
+ else
+ puts "BAD COUNT"
+ exit 1
+ end
+end
+
+ARGV.each do |arg|
+ if arg =~ /count=(.*)/ then
+ countarg=$1
+ else
+ cmd << arg
+ end
+end
+
+if countarg.nil? then
+ run = cmd.join(' ')
+ puts "*** " + run
+ system(run)
+else
+ count, seeks = parsecount(countarg)
+ seeks.each do |seek|
+ run = (cmd + [seek, count]).join(' ')
+ puts "*** " + run
+ system(run)
+ end
+end