This manual is for Tarlz (version 0.9, 22 January 2019).
Copyright © 2013-2019 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy, distribute and modify it.
Tarlz is a combined implementation of the tar archiver and the lzip compressor. By default tarlz creates, lists and extracts archives in a simplified posix pax format compressed with lzip on a per file basis. Each tar member is compressed in its own lzip member, as well as the end-of-file blocks. This method adds an indexed lzip layer on top of the tar archive, making it possible to decode the archive safely in parallel. The resulting multimember tar.lz archive is fully backward compatible with standard tar tools like GNU tar, which treat it like any other tar.lz archive. Tarlz can append files to the end of such compressed archives.
Tarlz can create tar archives with four levels of compression granularity; per file, per directory, appendable solid, and solid.
Of course, compressing each file (or each directory) individually is less efficient than compressing the whole tar archive, but it has the following advantages:
--keep-damagedcan be used to recover as much data as possible from each damaged member, and lziprecover can be used to recover some of the damaged members.
Tarlz protects the extended records with a CRC in a way compatible with standard tar tools. See crc32.
Tarlz does not understand other tar formats like 'gnu', 'oldgnu', 'star' or 'v7'.
The format for running tarlz is:
tarlz [options] [files]
On archive creation or appending, tarlz removes leading and trailing slashes from filenames, as well as filename prefixes containing a '..' component. On extraction, archive members containing a '..' component are skipped. Tarlz detects when the archive being created or enlarged is among the files to be dumped, appended or concatenated, and skips it.
On extraction and listing, tarlz removes leading './' strings from
member names in the archive or given in the command line, so that
tarlz -xf foo ./bar baz extracts members 'bar' and
'./baz' from archive 'foo'.
tarlz supports the following options:
-Coption in the command line is significant; it will change the current working directory for the following files until a new
-Coption appears in the command line. When extracting, all the
-Coptions are executed in sequence before starting the extraction. Listing ignores any
-Coptions specified. dir is relative to the then current working directory, perhaps changed by a previous
Note that the number of usable threads is limited during decompression to
the number of lzip members in the tar.lz archive, which you can find by
lzip -lv archive.tar.lz.
-0 .. -9
--create, don't compress the created tar archive. Create an uncompressed tar archive instead.
Exit status: 0 for a normal exit, 1 for environmental problems (file not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid input file, 3 for an internal consistency error (eg, bug) which caused tarlz to panic.
In the diagram below, a box like this:
+---+ | | <-- the vertical bars might be missing +---+
represents one byte; a box like this:
+==============+ | | +==============+
represents a variable number of bytes or a fixed but large number of bytes (for example 512).
A tar.lz file consists of a series of lzip members (compressed data sets). The members simply appear one after another in the file, with no additional information before, between, or after them.
Each lzip member contains one or more tar members in a simplified posix pax interchange format; the only pax typeflag value supported by tarlz (in addition to the typeflag values defined by the ustar format) is 'x'. The pax format is an extension on top of the ustar format that removes the size limitations of the ustar format.
Each tar member contains one file archived, and is represented by the following sequence:
Each tar member must be contiguously stored in a lzip member for the
parallel decoding operations like
--list to work. If any tar member
is split over two or more lzip members, the archive must be decoded
sequentially. See Multi-threaded tar.
At the end of the archive file there are two 512-byte blocks filled with binary zeros, interpreted as an end-of-archive indicator. These EOF blocks are either compressed in a separate lzip member or compressed along with the tar members contained in the last lzip member.
The diagram below shows the correspondence between each tar member (formed by one or two headers plus optional data) in the tar archive and each lzip member in the resulting multimember tar.lz archive:
tar +========+======+=================+===============+========+======+========+ | header | data | extended header | extended data | header | data | EOF | +========+======+=================+===============+========+======+========+ tar.lz +===============+=================================================+========+ | member | member | member | +===============+=================================================+========+
The pax header block is identical to the ustar header block described below except that the typeflag has the value 'x' (extended). The size field is the size of the extended header data in bytes. Most other fields in the pax header block are zeroed on archive creation to prevent trouble if the archive is read by an ustar tool, and are ignored by tarlz on archive extraction. See flawed-compat.
The pax extended header data consists of one or more records, each of
them constructed as follows:
"%d %s=%s\n", <length>, <keyword>, <value>
The <length>, <blank>, <keyword>, <equals-sign>, and <newline> in the record must be limited to the portable character set. The <length> field contains the decimal length of the record in bytes, including the trailing <newline>. The <value> field is stored as-is, without conversion to UTF-8 nor any other transformation.
These are the <keyword> fields currently supported by tarlz:
The ustar header block has a length of 512 bytes and is structured as shown in the following table. All lengths and offsets are in decimal.
|Field Name||Offset||Length (in bytes)
All characters in the header block are coded using the ISO/IEC 646:1991 (ASCII) standard, except in fields storing names for files, users, and groups. For maximum portability between implementations, names should only contain characters from the portable filename character set. But if an implementation supports the use of characters outside of '/' and the portable filename character set in names for files, users, and groups, tarlz will use the byte values in these names unmodified.
The fields name, linkname, and prefix are null-terminated character strings except when all characters in the array contain non-null characters including the last character.
The name and the prefix fields produce the pathname of the file. A new pathname is formed, if prefix is not an empty string (its first character is not null), by concatenating prefix (up to the first null character), a <slash> character, and name; otherwise, name is used alone. In either case, name is terminated at the first null character. If prefix begins with a null character, it is ignored. In this manner, pathnames of at most 256 characters can be supported. If a pathname does not fit in the space provided, an extended record is used to store the pathname.
The linkname field does not use the prefix to produce a pathname. If the linkname does not fit in the 100 characters provided, an extended record is used to store the linkname.
The mode field provides 12 access permission bits. The following table shows the symbolic name of each bit and its octal value:
|Bit Name||Value||Bit Name||Value||Bit Name||Value
The uid and gid fields are the user and group ID of the owner and group of the file, respectively.
The size field contains the octal representation of the size of the file in bytes. If the typeflag field specifies a file of type '0' (regular file) or '7' (high performance regular file), the number of logical records following the header is (size / 512) rounded to the next integer. For all other values of typeflag, tarlz either sets the size field to 0 or ignores it, and does not store or expect any logical records following the header. If the file size is larger than 8_589_934_591 bytes (octal 77777777777), an extended record is used to store the file size.
The mtime field contains the octal representation of the modification time of the file at the time it was archived, obtained from the stat() function.
The chksum field contains the octal representation of the value of the simple sum of all bytes in the header logical record. Each byte in the header is treated as an unsigned value. When calculating the checksum, the chksum field is treated as if it were all <space> characters.
The typeflag field contains a single character specifying the type of file archived:
The magic field contains the ASCII null-terminated string "ustar". The version field contains the characters "00" (0x30,0x30). The fields uname, and gname are null-terminated character strings except when all characters in the array contain non-null characters including the last character. Each numeric field contains a leading space- or zero-filled, optionally null-terminated octal number using digits from the ISO/IEC 646:1991 (ASCII) standard. Tarlz is able to decode numeric fields 1 byte larger than standard ustar by not requiring a terminating null character.
Tarlz is meant to reliably detect invalid or corrupt metadata during extraction and to not create safety risks in the archives it creates. In order to achieve these goals, tarlz makes some changes to the variant of the pax format that it uses. This chapter describes these changes and the concrete reasons to implement them.
The posix pax format has a serious flaw. The metadata stored in pax extended records are not protected by any kind of check sequence. Corruption in a long filename may cause the extraction of the file in the wrong place without warning. Corruption in a large file size may cause the truncation of the file or the appending of garbage to the file, both followed by a spurious warning about a corrupt header far from the place of the undetected corruption.
Metadata like filename and file size must be always protected in an archive format because of the adverse effects of undetected corruption in them, potentially much worse that undetected corruption in the data. Even more so in the case of pax because the amount of metadata it stores is potentially large, making undetected corruption more probable.
Because of the above, tarlz protects the extended records with a CRC in a way compatible with standard tar tools. See key_crc32.
In order to allow the extraction of pax archives by a tar utility conforming to the POSIX-2:1993 standard, POSIX.1-2008 recommends selecting extended header field values that allow such tar to create a regular file containing the extended header records as data. This approach is broken because if the extended header is needed because of a long filename, the name and prefix fields will be unable to contain the full pathname of the file. Therefore the files corresponding to both the extended header and the overridden ustar header will be extracted using truncated filenames, perhaps overwriting existing files or directories. It may be a security risk to extract a file with a truncated filename.
To avoid this problem, tarlz writes extended headers with all fields zeroed except size, chksum, typeflag, magic and version. This prevents old tar programs from extracting the extended records as a file in the wrong place. Tarlz also sets to zero those fields of the ustar header overridden by extended records.
If the extended header is needed because of a file size larger than 8 GiB, the size field will be unable to contain the full size of the file. Therefore the file may be partially extracted, and the tool will issue a spurious warning about a corrupt header at the point where it thinks the file ends. Setting to zero the overridden size in the ustar header at least prevents the partial extraction and makes obvious that the file has been truncated.
The tarlz format is mainly ustar. Extended pax headers are used only when needed because the length of a filename or link name, or the size of a file exceed the limits of the ustar format. Adding extended headers to each member just to record subsecond timestamps seems wasteful for a backup format.
There is no portable way to tell what charset a text string is coded into. Therefore, tarlz stores all fields representing text strings as-is, without conversion to UTF-8 nor any other transformation. This prevents accidental double UTF-8 conversions. If the need arises this behavior will be adjusted with a command line option in the future.
Safely decoding an arbitrary tar archive in parallel is impossible. For example, if a tar archive containing another tar archive is decoded starting from some position other than the beginning, there is no way to know if the first header found there belongs to the outer tar archive or to the inner tar archive. Tar is a format inherently serial; it was designed for tapes.
In the case of compressed tar archives, the start of each compressed block determines one point through which the tar archive can be decoded in parallel. Therefore, in tar.lz archives the decoding operations can't be parallelized if the tar members are not aligned with the lzip members. Tar archives compressed with plzip can't be decoded in parallel because tar and plzip do not have a way to align both sets of members. Certainly one can decompress one such archive with a multi-threaded tool like plzip, but the increase in speed is not as large as it could be because plzip must serialize the decompressed data and pass them to tar, which decodes them sequentially, one tar member at a time.
On the other hand, if the tar.lz archive is created with a tool like tarlz, which can guarantee the alignment between tar members and lzip members because it controls both archiving and compression, then the lzip format becomes an indexed layer on top of the tar archive which makes possible decoding it safely in parallel.
Tarlz is able to automatically decode aligned and unaligned multimember
tar.lz archives, keeping backwards compatibility. If tarlz finds a member
misalignment during multi-threaded decoding, it switches to single-threaded
mode and continues decoding the archive. Currently only the
option is able to do multi-threaded decoding.
If the files in the archive are large, multi-threaded
--list on a
regular tar.lz archive can be hundreds of times faster than sequential
--list because, in addition to using several processors, it only
needs to decompress part of each lzip member. See the following example
listing the Silesia corpus on a dual core machine:
tarlz -9 -cf silesia.tar.lz silesia time lzip -cd silesia.tar.lz | tar -tf - (5.032s) time plzip -cd silesia.tar.lz | tar -tf - (3.256s) time tarlz -tf silesia.tar.lz (0.020s)
Example 1: Create a multimember compressed archive 'archive.tar.lz' containing files 'a', 'b' and 'c'.
tarlz -cf archive.tar.lz a b c
Example 2: Append files 'd' and 'e' to the multimember compressed archive 'archive.tar.lz'.
tarlz -rf archive.tar.lz d e
Example 3: Create a solidly compressed appendable archive 'archive.tar.lz' containing files 'a', 'b' and 'c'. Then append files 'd' and 'e' to the archive.
tarlz --asolid -cf archive.tar.lz a b c tarlz --asolid -rf archive.tar.lz d e
Example 4: Create a compressed appendable archive containing directories 'dir1', 'dir2' and 'dir3' with a separate lzip member per directory. Then append files 'a', 'b', 'c', 'd' and 'e' to the archive, all of them contained in a single lzip member. The resulting archive 'archive.tar.lz' contains 5 lzip members (including the EOF member).
tarlz --dsolid -cf archive.tar.lz dir1 dir2 dir3 tarlz --asolid -rf archive.tar.lz a b c d e
Example 5: Create a solidly compressed archive 'archive.tar.lz' containing files 'a', 'b' and 'c'. Note that no more files can be later appended to the archive.
tarlz --solid -cf archive.tar.lz a b c
Example 6: Extract all files from archive 'archive.tar.lz'.
tarlz -xf archive.tar.lz
Example 7: Extract files 'a' and 'c' from archive 'archive.tar.lz'.
tarlz -xf archive.tar.lz a c
Example 8: Copy the contents of directory 'sourcedir' to the directory 'targetdir'.
tarlz -C sourcedir -c . | tarlz -C targetdir -x
There are probably bugs in tarlz. There are certainly errors and omissions in this manual. If you report them, they will get fixed. If you don't, no one will ever know about them and they will remain unfixed for all eternity, if not longer.
If you find a bug in tarlz, please send electronic mail to
firstname.lastname@example.org. Include the version number, which you can
find by running