Last active
August 29, 2015 14:10
-
-
Save windwiny/f47a628781853629bffa to your computer and use it in GitHub Desktop.
Revisions
-
windwiny renamed this gist
Dec 8, 2014 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,9 +10,8 @@ def sect2chs sec return "" if sec == 0 c = sec / (255*63) sec = sec % (255*63) h = sec / 63 s = sec % 63 + 1 "#{c}/#{h}/#{s}" end -
windwiny created this gist
Dec 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ =begin fdisk -l output sector to CHS =end def sect2chs sec sec = sec.to_i return "" if sec == 0 c = sec / (255*63) sec = sec % (255*63) h = sec / 255 sec = sec % 255 s = sec / 63 + 1 "#{c}/#{h}/#{s}" end def secs2sz size sz = size.to_i return "" if sz == 0 sz /= 2 if sz > 1024*1024 "#{sz/1024/1025}GB" elsif sz > 1024 "#{sz/1024}MB" else "#{sz}KB" end end DATA.each_line do |l| l.strip! break if l.empty? dev, startp, endp, size = l.split v1 = sect2chs(startp) v2 = sect2chs(endp) sz = secs2sz(size) puts %{#{dev} #{'%12s' % startp} #{'%12s' % endp} |#{'%15s' % v1} #{'%15s' % v2} #{sz}} end __END__