summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpio/bsdcpio.17
-rw-r--r--cpio/test/test_basic.c2
-rw-r--r--libarchive/archive_read_set_options.39
-rw-r--r--libarchive/archive_write_format.38
-rw-r--r--libarchive/archive_write_set_options.312
-rw-r--r--libarchive/cpio.5200
-rw-r--r--libarchive/libarchive-formats.537
-rw-r--r--libarchive/test/test_write_format_cpio.c10
8 files changed, 199 insertions, 86 deletions
diff --git a/cpio/bsdcpio.1 b/cpio/bsdcpio.1
index 514c1a2c..01b508e1 100644
--- a/cpio/bsdcpio.1
+++ b/cpio/bsdcpio.1
@@ -82,6 +82,13 @@ all operating modes.
.It Fl 0 , Fl Fl null
Read filenames separated by NUL characters instead of newlines.
This is necessary if any of the filenames being read might contain newlines.
+.It Fl 6 , Fl Fl pwb
+When reading a binary format archive, assume it's the earlier one,
+from the PWB variant of 6th Edition UNIX.
+When writing a cpio archive, use the PWB format.
+.It Fl 7 , Fl Fl binary
+(o mode only)
+When writing a cpio archive, use the (newer, non-PWB) binary format.
.It Fl A
(o mode only)
Append to the specified archive.
diff --git a/cpio/test/test_basic.c b/cpio/test/test_basic.c
index b7162534..3d7d86a0 100644
--- a/cpio/test/test_basic.c
+++ b/cpio/test/test_basic.c
@@ -230,6 +230,8 @@ DEFINE_TEST(test_basic)
basic_cpio("copy_odc", "--format=odc", "", msg, msg);
basic_cpio("copy_newc", "-H newc", "", result, "2 blocks\n");
basic_cpio("copy_cpio", "-H odc", "", msg, msg);
+ msg = "1 block\n";
+ basic_cpio("copy_bin", "-H bin", "", msg, msg);
msg = canSymlink() ? "9 blocks\n" : "8 blocks\n";
basic_cpio("copy_ustar", "-H ustar", "", msg, msg);
diff --git a/libarchive/archive_read_set_options.3 b/libarchive/archive_read_set_options.3
index 78d99999..b2db4cbc 100644
--- a/libarchive/archive_read_set_options.3
+++ b/libarchive/archive_read_set_options.3
@@ -188,9 +188,18 @@ used when translating file names.
.El
.It Format cpio
.Bl -tag -compact -width indent
+.It Cm compat-2x
+Libarchive 2.x incorrectly encoded Unicode filenames on
+some platforms.
+This option mimics the libarchive 2.x filename handling
+so that such archives can be read correctly.
.It Cm hdrcharset
The value is used as a character set name that will be
used when translating file names.
+.It Cm pwb
+When reading a binary CPIO archive, assume that it is
+in the original PWB cpio format, and handle file mode
+bits accordingly. The default is to assume v7 format.
.El
.It Format iso9660
.Bl -tag -compact -width indent
diff --git a/libarchive/archive_write_format.3 b/libarchive/archive_write_format.3
index 994e41f2..653089f7 100644
--- a/libarchive/archive_write_format.3
+++ b/libarchive/archive_write_format.3
@@ -35,8 +35,10 @@
.Nm archive_write_set_format_ar_svr4 ,
.Nm archive_write_set_format_by_name ,
.Nm archive_write_set_format_cpio ,
+.Nm archive_write_set_format_cpio_bin ,
.Nm archive_write_set_format_cpio_newc ,
.Nm archive_write_set_format_cpio_odc ,
+.Nm archive_write_set_format_cpio_pwb ,
.Nm archive_write_set_format_filter_by_ext ,
.Nm archive_write_set_format_filter_by_ext_def ,
.Nm archive_write_set_format_gnutar ,
@@ -74,10 +76,14 @@ Streaming Archive Library (libarchive, -larchive)
.Ft int
.Fn archive_write_set_format_cpio "struct archive *"
.Ft int
+.Fn archive_write_set_format_cpio_bin "struct archive *"
+.Ft int
.Fn archive_write_set_format_cpio_newc "struct archive *"
.Ft int
.Fn archive_write_set_format_cpio_odc "struct archive *"
.Ft int
+.Fn archive_write_set_format_cpio_pwb "struct archive *"
+.Ft int
.Fn archive_write_set_format_filter_by_ext "struct archive *" "const char *filename"
.Ft int
.Fn archive_write_set_format_filter_by_ext_def "struct archive *" "const char *filename" "const char *def_ext"
@@ -132,8 +138,10 @@ Supported extensions: .7z, .zip, .jar, .cpio, .iso, .a, .ar, .tar, .tgz, .tar.gz
.Fn archive_write_set_format_ar_bsd
.Fn archive_write_set_format_ar_svr4
.Fn archive_write_set_format_cpio
+.Fn archive_write_set_format_cpio_bin
.Fn archive_write_set_format_cpio_newc
.Fn archive_write_set_format_cpio_odc
+.Fn archive_write_set_format_cpio_pwb
.Fn archive_write_set_format_gnutar
.Fn archive_write_set_format_iso9660
.Fn archive_write_set_format_mtree
diff --git a/libarchive/archive_write_set_options.3 b/libarchive/archive_write_set_options.3
index e1079a81..dd573588 100644
--- a/libarchive/archive_write_set_options.3
+++ b/libarchive/archive_write_set_options.3
@@ -279,6 +279,12 @@ Values between 0 and 9 are supported.
The interpretation of the compression level depends on the chosen
compression method.
.El
+.It Format bin
+.Bl -tag -compact -width indent
+.It Cm hdrcharset
+The value is used as a character set name that will be
+used when translating file names.
+.El
.It Format gnutar
.Bl -tag -compact -width indent
.It Cm hdrcharset
@@ -519,6 +525,12 @@ used when translating file names.
The value is used as a character set name that will be
used when translating file names.
.El
+.It Format pwb
+.Bl -tag -compact -width indent
+.It Cm hdrcharset
+The value is used as a character set name that will be
+used when translating file names.
+.El
.It Format pax
.Bl -tag -compact -width indent
.It Cm hdrcharset
diff --git a/libarchive/cpio.5 b/libarchive/cpio.5
index a91f0c59..9fb9b06b 100644
--- a/libarchive/cpio.5
+++ b/libarchive/cpio.5
@@ -56,40 +56,44 @@ The end of the archive is indicated by a special record with
the pathname
.Dq TRAILER!!! .
.Ss PWB format
-XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
-.Ss Old Binary Format
-The old binary
+The PWB binary
.Nm
-format stores numbers as 2-byte and 4-byte binary values.
+format is the original format, when cpio was introduced as part of the
+Programmer's Work Bench system, a variant of 6th Edition UNIX. It
+stores numbers as 2-byte and 4-byte binary values.
Each entry begins with a header in the following format:
+.Pp
.Bd -literal -offset indent
-struct header_old_cpio {
- unsigned short c_magic;
- unsigned short c_dev;
- unsigned short c_ino;
- unsigned short c_mode;
- unsigned short c_uid;
- unsigned short c_gid;
- unsigned short c_nlink;
- unsigned short c_rdev;
- unsigned short c_mtime[2];
- unsigned short c_namesize;
- unsigned short c_filesize[2];
+struct header_pwb_cpio {
+ short h_magic;
+ short h_dev;
+ short h_ino;
+ short h_mode;
+ short h_uid;
+ short h_gid;
+ short h_nlink;
+ short h_majmin;
+ long h_mtime;
+ short h_namesize;
+ long h_filesize;
};
.Ed
.Pp
The
-.Va unsigned short
-fields here are 16-bit integer values; the
-.Va unsigned int
-fields are 32-bit integer values.
-The fields are as follows
+.Va short
+fields here are 16-bit integer values, while the
+.Va long
+fields are 32 bit integers. Since PWB UNIX, like the 6th Edition UNIX
+it was based on, only ran on PDP-11 computers, they
+are in PDP-endian format, which has little-endian shorts, and
+big-endian longs. That is, the long integer whose hexadecimal
+representation is 0x12345678 would be stored in four successive bytes
+as 0x34, 0x12, 0x78, 0x56.
+The fields are as follows:
.Bl -tag -width indent
-.It Va magic
+.It Va h_magic
The integer value octal 070707.
-This value can be used to determine whether this archive is
-written with little-endian or big-endian integers.
-.It Va dev , Va ino
+.It Va h_dev , Va h_ino
The device and inode numbers from the disk.
These are used by programs that read
.Nm
@@ -97,78 +101,138 @@ archives to determine when two entries refer to the same file.
Programs that synthesize
.Nm
archives should be careful to set these to distinct values for each entry.
-.It Va mode
-The mode specifies both the regular permissions and the file type.
-It consists of several bit fields as follows:
+.It Va h_mode
+The mode specifies both the regular permissions and the file type, and
+it also holds a couple of bits that are irrelevant to the cpio format,
+because the field is actually a raw copy of the mode field in the inode
+representing the file. These are the IALLOC flag, which shows that
+the inode entry is in use, and the ILARG flag, which shows that the
+file it represents is large enough to have indirect blocks pointers in
+the inode.
+The mode is decoded as follows:
+.Pp
.Bl -tag -width "MMMMMMM" -compact
-.It 0170000
-This masks the file type bits.
-.It 0140000
-File type value for sockets.
-.It 0120000
-File type value for symbolic links.
-For symbolic links, the link body is stored as file data.
.It 0100000
-File type value for regular files.
+IALLOC flag - irrelevant to cpio.
.It 0060000
-File type value for block special devices.
+This masks the file type bits.
.It 0040000
File type value for directories.
.It 0020000
File type value for character special devices.
+.It 0060000
+File type value for block special devices.
.It 0010000
-File type value for named pipes or FIFOs.
+ILARG flag - irrelevant to cpio.
.It 0004000
SUID bit.
.It 0002000
SGID bit.
.It 0001000
Sticky bit.
-On some systems, this modifies the behavior of executables and/or directories.
.It 0000777
The lower 9 bits specify read/write/execute permissions
for world, group, and user following standard POSIX conventions.
.El
-.It Va uid , Va gid
+.It Va h_uid , Va h_gid
The numeric user id and group id of the owner.
-.It Va nlink
+.It Va h_nlink
The number of links to this file.
Directories always have a value of at least two here.
Note that hardlinked files include file data with every copy in the archive.
-.It Va rdev
+.It Va h_majmin
For block special and character special entries,
-this field contains the associated device number.
+this field contains the associated device number, with the major
+number in the high byte, and the minor number in the low byte.
For all other entry types, it should be set to zero by writers
and ignored by readers.
-.It Va mtime
+.It Va h_mtime
Modification time of the file, indicated as the number
of seconds since the start of the epoch,
00:00:00 UTC January 1, 1970.
-The four-byte integer is stored with the most-significant 16 bits first
-followed by the least-significant 16 bits.
-Each of the two 16 bit values are stored in machine-native byte order.
-.It Va namesize
+.It Va h_namesize
The number of bytes in the pathname that follows the header.
This count includes the trailing NUL byte.
-.It Va filesize
-The size of the file.
-Note that this archive format is limited to
-four gigabyte file sizes.
-See
-.Va mtime
-above for a description of the storage of four-byte integers.
+.It Va h_filesize
+The size of the file. Note that this archive format is limited to 16
+megabyte file sizes, because PWB UNIX, like 6th Edition, only used
+an unsigned 24 bit integer for the file size internally.
.El
.Pp
The pathname immediately follows the fixed header.
-If the
-.Cm namesize
+If
+.Cm h_namesize
is odd, an additional NUL byte is added after the pathname.
-The file data is then appended, padded with NUL
-bytes to an even length.
+The file data is then appended, again with an additional NUL
+appended if needed to get the next header at an even offset.
.Pp
Hardlinked files are not given special treatment;
the full file contents are included with each copy of the
file.
+.Ss New Binary Format
+The new binary
+.Nm
+format showed up when cpio was adopted into late 7th Edition UNIX.
+It is exactly like the PWB binary format, described above, except for
+three changes:
+.Pp
+First, UNIX now ran on more than one hardware type, so the endianness
+of 16 bit integers must be determined by observing the magic number at
+the start of the header. The 32 bit integers are still always stored
+with the most significant word first, though, so each of those two, in
+the struct shown above, was stored as an array of two 16 bit integers,
+in the traditional order. Those 16 bit integers, like all the others
+in the struct, were accessed using a macro that byte swapped them if
+necessary.
+.Pp
+Next, 7th Edition had more file types to store, and the IALLOC and ILARG
+flag bits were re-purposed to accomodate these. The revised use of the
+various bits is as follows:
+.Pp
+.Bl -tag -width "MMMMMMM" -compact
+.It 0170000
+This masks the file type bits.
+.It 0140000
+File type value for sockets.
+.It 0120000
+File type value for symbolic links.
+For symbolic links, the link body is stored as file data.
+.It 0100000
+File type value for regular files.
+.It 0060000
+File type value for block special devices.
+.It 0040000
+File type value for directories.
+.It 0020000
+File type value for character special devices.
+.It 0010000
+File type value for named pipes or FIFOs.
+.It 0004000
+SUID bit.
+.It 0002000
+SGID bit.
+.It 0001000
+Sticky bit.
+.It 0000777
+The lower 9 bits specify read/write/execute permissions
+for world, group, and user following standard POSIX conventions.
+.El
+.Pp
+Finally, the file size field now represents a signed 32 bit integer in
+the underlying file system, so the maximum file size has increased to
+2 gigabytes.
+.Pp
+Note that there is no obvious way to tell which of the two binary
+formats an archive uses, other than to see which one makes more
+sense. The typical error scenario is that a PWB format archive
+unpacked as if it were in the new format will create named sockets
+instead of directories, and then fail to unpack files that should
+go in those directories. Running
+.Va bsdcpio -itv
+on an unknown archive will make it obvious which it is: if it's
+PWB format, directories will be listed with an 's' instead of
+a 'd' as the first character of the mode string, and the larger
+files will have a '?' in that position.
.Ss Portable ASCII Format
.St -susv2
standardized an ASCII variant that is portable across all
@@ -180,6 +244,7 @@ format or as the
format.
It stores the same numeric fields as the old binary format, but
represents them as 6-character or 11-character octal values.
+.Pp
.Bd -literal -offset indent
struct cpio_odc_header {
char c_magic[6];
@@ -196,9 +261,9 @@ struct cpio_odc_header {
};
.Ed
.Pp
-The fields are identical to those in the old binary format.
+The fields are identical to those in the new binary format.
The name and file body follow the fixed header.
-Unlike the old binary format, there is no additional padding
+Unlike the binary formats, there is no additional padding
after the pathname or file contents.
If the files being archived are themselves entirely ASCII, then
the resulting archive will be entirely ASCII, except for the
@@ -207,6 +272,7 @@ NUL byte that terminates the name field.
The "new" ASCII format uses 8-byte hexadecimal fields for
all numbers and separates device numbers into separate fields
for major and minor numbers.
+.Pp
.Bd -literal -offset indent
struct cpio_newc_header {
char c_magic[6];
@@ -227,7 +293,7 @@ struct cpio_newc_header {
.Ed
.Pp
Except as specified below, the fields here match those specified
-for the old binary format above.
+for the new binary format above.
.Bl -tag -width indent
.It Va magic
The string
@@ -288,9 +354,9 @@ while working in AT&T's Unix Support Group.
It appeared in 1977 as part of PWB/UNIX 1.0, the
.Dq Programmer's Work Bench
derived from
-.At v6
+.At 6th Edition UNIX
that was used internally at AT&T.
-Both the old binary and old character formats were in use
+Both the new binary and old character formats were in use
by 1980, according to the System III source released
by SCO under their
.Dq Ancient Unix
@@ -304,9 +370,9 @@ The
format is mis-named, as it uses a simple checksum and
not a cyclic redundancy check.
.Pp
-The old binary format is limited to 16 bits for user id,
-group id, device, and inode numbers.
-It is limited to 4 gigabyte file sizes.
+The binary formats are limited to 16 bits for user id, group id,
+device, and inode numbers. They are limited to 16 megabyte and 2
+gigabyte file sizes for the older and newer variants, respectively.
.Pp
The old ASCII format is limited to 18 bits for
the user id, group id, device, and inode numbers.
diff --git a/libarchive/libarchive-formats.5 b/libarchive/libarchive-formats.5
index 62359ddc..5a118ff5 100644
--- a/libarchive/libarchive-formats.5
+++ b/libarchive/libarchive-formats.5
@@ -201,28 +201,27 @@ POSIX.1-2001 extended the ustar format to create the
.Dq pax interchange
format.
.Ss Cpio Formats
-The libarchive library can read a number of common cpio variants and can write
-.Dq odc
-and
-.Dq newc
-format archives.
-A cpio archive stores each entry as a fixed-size header followed
-by a variable-length filename and variable-length data.
-Unlike the tar format, the cpio format does only minimal padding
-of the header or file data.
-There are several cpio variants, which differ primarily in
-how they store the initial header: some store the values as
-octal or hexadecimal numbers in ASCII, others as binary values of
-varying byte order and length.
+The libarchive library can read and write a number of common cpio
+variants. A cpio archive stores each entry as a fixed-size header
+followed by a variable-length filename and variable-length data.
+Unlike the tar format, the cpio format does only minimal padding of
+the header or file data. There are several cpio variants, which
+differ primarily in how they store the initial header: some store the
+values as octal or hexadecimal numbers in ASCII, others as binary
+values of varying byte order and length.
.Bl -tag -width indent
.It Cm binary
-The libarchive library transparently reads both big-endian and little-endian
-variants of the original binary cpio format.
-This format used 32-bit binary values for file size and mtime,
-and 16-bit binary values for the other fields.
+The libarchive library transparently reads both big-endian and
+little-endian variants of the the two binary cpio formats; the
+original one from PWB/UNIX, and the later, more widely used, variant.
+This format used 32-bit binary values for file size and mtime, and
+16-bit binary values for the other fields. The formats support only
+the file types present in UNIX at the time of their creation. File
+sizes are limited to 24 bits in the PWB format, because of the limits
+of the file system, and to 31 bits in the newer binary format, where
+signed 32 bit longs were used.
.It Cm odc
-The libarchive library can both read and write this
-POSIX-standard format, which is officially known as the
+This is the POSIX standardized format, which is officially known as the
.Dq cpio interchange format
or the
.Dq octet-oriented cpio archive format
diff --git a/libarchive/test/test_write_format_cpio.c b/libarchive/test/test_write_format_cpio.c
index 18707031..d5df8a8c 100644
--- a/libarchive/test/test_write_format_cpio.c
+++ b/libarchive/test/test_write_format_cpio.c
@@ -273,6 +273,8 @@ test_big_entries(int (*set_format)(struct archive *), int64_t size, int expected
DEFINE_TEST(test_write_format_cpio)
{
+ int64_t size_16m = ((int64_t)1) << 24;
+ int64_t size_2g = ((int64_t)1) << 31;
int64_t size_4g = ((int64_t)1) << 32;
int64_t size_8g = ((int64_t)1) << 33;
@@ -287,4 +289,12 @@ DEFINE_TEST(test_write_format_cpio)
size_4g - 1, ARCHIVE_OK);
test_big_entries(archive_write_set_format_cpio_newc,
size_4g, ARCHIVE_FAILED);
+ test_big_entries(archive_write_set_format_cpio_bin,
+ size_2g - 1, ARCHIVE_OK);
+ test_big_entries(archive_write_set_format_cpio_bin,
+ size_2g, ARCHIVE_FAILED);
+ test_big_entries(archive_write_set_format_cpio_pwb,
+ size_16m - 1, ARCHIVE_OK);
+ test_big_entries(archive_write_set_format_cpio_pwb,
+ size_16m, ARCHIVE_FAILED);
}