diff options
author | 2015-08-28 09:58:54 +0800 | |
---|---|---|
committer | 2015-09-01 12:44:00 +0800 | |
commit | e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch) | |
tree | 66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/ipxe/src/util/padimg.pl | |
parent | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff) |
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/ipxe/src/util/padimg.pl')
-rwxr-xr-x | qemu/roms/ipxe/src/util/padimg.pl | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/qemu/roms/ipxe/src/util/padimg.pl b/qemu/roms/ipxe/src/util/padimg.pl new file mode 100755 index 000000000..4421aaf4b --- /dev/null +++ b/qemu/roms/ipxe/src/util/padimg.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use Getopt::Long; +use Fcntl; + +my $verbosity = 0; +my $blksize = 512; +my $byte = 0; + +my %opts = ( + 'verbose|v+' => sub { $verbosity++; }, + 'quiet|q+' => sub { $verbosity--; }, + 'blksize|s=o' => sub { $blksize = $_[1]; }, + 'byte|b=o' => sub { $byte = $_[1]; }, +); + +Getopt::Long::Configure ( 'bundling', 'auto_abbrev' ); +GetOptions ( %opts ) or die "Could not parse command-line options\n"; + +while ( my $filename = shift ) { + die "$filename is not a file\n" unless -f $filename; + my $oldsize = -s $filename; + my $padsize = ( ( -$oldsize ) % $blksize ); + my $newsize = ( $oldsize + $padsize ); + next unless $padsize; + if ( $verbosity >= 1 ) { + printf "Padding %s from %d to %d bytes with %d x 0x%02x\n", + $filename, $oldsize, $newsize, $padsize, $byte; + } + if ( $byte ) { + sysopen ( my $fh, $filename, ( O_WRONLY | O_APPEND ) ) + or die "Could not open $filename for appending: $!\n"; + syswrite $fh, ( chr ( $byte ) x $padsize ) + or die "Could not append to $filename: $!\n"; + close ( $fh ); + } else { + truncate $filename, $newsize + or die "Could not resize $filename: $!\n"; + } + die "Failed to pad $filename\n" + unless ( ( ( -s $filename ) % $blksize ) == 0 ); +} |