diff options
author | Martin Matuška <martin@matuska.org> | 2021-05-10 21:05:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 21:05:00 +0200 |
commit | 942cd1a5e1ce4e1450cecafa2674f71aea0263a4 (patch) | |
tree | 2081dadf55b7e79b89783ac1d32048ad6fa0f2ea /cpio | |
parent | 34040a1532e718ff109f43bf489825e1aa09e542 (diff) | |
parent | fe9d6e6c2e515e0b10bbecb793ca2c4f27c367b9 (diff) | |
download | libarchive-942cd1a5e1ce4e1450cecafa2674f71aea0263a4.tar.gz |
Merge pull request #1502 from tih/cpio-bin-formats
Support for PWB and v7 binary cpio formats
Diffstat (limited to 'cpio')
-rw-r--r-- | cpio/bsdcpio.1 | 7 | ||||
-rw-r--r-- | cpio/cmdline.c | 4 | ||||
-rw-r--r-- | cpio/cpio.c | 23 | ||||
-rw-r--r-- | cpio/cpio.h | 1 | ||||
-rw-r--r-- | cpio/test/test_basic.c | 2 |
5 files changed, 30 insertions, 7 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/cmdline.c b/cpio/cmdline.c index c8fc30ea..2683524e 100644 --- a/cpio/cmdline.c +++ b/cpio/cmdline.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cmdline.c,v 1.5 2008/12/06 07:30:40 kientzl /* * Short options for cpio. Please keep this sorted. */ -static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz"; +static const char *short_options = "067AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz"; /* * Long options for cpio. Please keep this sorted. @@ -62,6 +62,7 @@ static const struct option { int equivalent; /* Equivalent short option. */ } cpio_longopts[] = { { "b64encode", 0, OPTION_B64ENCODE }, + { "binary", 0, '7' }, { "create", 0, 'o' }, { "dereference", 0, 'L' }, { "dot", 0, 'V' }, @@ -86,6 +87,7 @@ static const struct option { { "pass-through", 0, 'p' }, { "preserve-modification-time", 0, 'm' }, { "preserve-owner", 0, OPTION_PRESERVE_OWNER }, + { "pwb", 0, '6' }, { "quiet", 0, OPTION_QUIET }, { "unconditional", 0, 'u' }, { "uuencode", 0, OPTION_UUENCODE }, diff --git a/cpio/cpio.c b/cpio/cpio.c index c15ee525..68a6301a 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -192,6 +192,12 @@ main(int argc, char *argv[]) case '0': /* GNU convention: --null, -0 */ cpio->option_null = 1; break; + case '6': /* in/out: assume/create 6th edition (PWB) format */ + cpio->option_pwb = 1; + break; + case '7': /* out: create archive using 7th Edition binary format */ + cpio->format = "bin"; + break; case 'A': /* NetBSD/OpenBSD */ cpio->option_append = 1; break; @@ -400,11 +406,12 @@ main(int argc, char *argv[]) switch (cpio->mode) { case 'o': - /* TODO: Implement old binary format in libarchive, - use that here. */ - if (cpio->format == NULL) - cpio->format = "odc"; /* Default format */ - + if (cpio->format == NULL) { + if (cpio->option_pwb) + cpio->format = "pwb"; + else + cpio->format = "cpio"; + } mode_out(cpio); break; case 'i': @@ -462,7 +469,7 @@ static const char *long_help_msg = " -v Verbose filenames -V one dot per file\n" "Create: %p -o [options] < [list of files] > [archive]\n" " -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma\n" - " --format {odc|newc|ustar} Select archive format\n" + " --format {pwb|bin|odc|newc|ustar} Select archive format\n" "List: %p -it < [archive]\n" "Extract: %p -i [options] < [archive]\n"; @@ -970,6 +977,8 @@ mode_in(struct cpio *cpio) lafe_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_filter_all(a); archive_read_support_format_all(a); + if (cpio->option_pwb) + archive_read_set_options(a, "pwb"); if (cpio->passphrase != NULL) r = archive_read_add_passphrase(a, cpio->passphrase); else @@ -1080,6 +1089,8 @@ mode_list(struct cpio *cpio) lafe_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_filter_all(a); archive_read_support_format_all(a); + if (cpio->option_pwb) + archive_read_set_options(a, "pwb"); if (cpio->passphrase != NULL) r = archive_read_add_passphrase(a, cpio->passphrase); else diff --git a/cpio/cpio.h b/cpio/cpio.h index 8e7cc5fd..a71b6649 100644 --- a/cpio/cpio.h +++ b/cpio/cpio.h @@ -62,6 +62,7 @@ struct cpio { int option_list; /* -t */ char option_null; /* --null */ int option_numeric_uid_gid; /* -n */ + int option_pwb; /* -6 */ int option_rename; /* -r */ char *destdir; size_t destdir_len; 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); |