diff options
author | fishsoupisgood <github@madingley.org> | 2019-04-29 01:17:54 +0100 |
---|---|---|
committer | fishsoupisgood <github@madingley.org> | 2019-05-27 03:43:43 +0100 |
commit | 3f2546b2ef55b661fd8dd69682b38992225e86f6 (patch) | |
tree | 65ca85f13617aee1dce474596800950f266a456c /roms/ipxe/src/util/padimg.pl | |
download | qemu-master.tar.gz qemu-master.tar.bz2 qemu-master.zip |
Diffstat (limited to 'roms/ipxe/src/util/padimg.pl')
-rwxr-xr-x | roms/ipxe/src/util/padimg.pl | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/roms/ipxe/src/util/padimg.pl b/roms/ipxe/src/util/padimg.pl new file mode 100755 index 00000000..4421aaf4 --- /dev/null +++ b/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 ); +} |