#!/usr/bin/perl -w use strict; use warnings; use Fcntl; if ($#ARGV != 1) { die "$0 converts a vtar to a tar file\n" . "usage: $0 "; } my ($src, $dst) = @ARGV; open(SRC, $src) || die "$src: $!"; binmode SRC; my $boundary = ""; for (my $i = 0; $i < 512 * 8; $i++) { vec($boundary, $i, 1) = 0; } my @entries; for (;;) { my $entry; read(SRC, $entry, 512); last if ($entry eq $boundary); push @entries, $entry; } my $pos = $#entries * 512 + 1024; open(DST, ">$dst") || die "$dst: $!"; binmode DST; foreach my $entry(@entries) { print DST $entry; my $size = int((oct(substr($entry, 124, 12)) + 511) / 512) * 512; if ($size) { seek(SRC, $pos, Fcntl::SEEK_SET); my $buf; read(SRC, $buf, $size); print DST $buf; $pos += $size; } } print DST substr($boundary, 0, 512 - ($pos % 512)) if ($pos % 512); print DST $boundary; print DST $boundary; close(DST); close(SRC);