aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-06-04 13:15:51 -0500
committerRob Landley <rob@landley.net>2017-06-04 13:15:51 -0500
commit32550751997db5b15baca56e72c54ed8ade53bd6 (patch)
treeb4d89a5bd7287c554eb8c5635fc4ea93dcd6d28d /toys
parent51a1e91d263ad14ffd4b57ff0c22d3ff02799ceb (diff)
downloadtoybox-32550751997db5b15baca56e72c54ed8ade53bd6.tar.gz
Don't add cpio TRAILER!!! entry by default, add new --trailer option if you
want that. (This lets you concatenate cpio archives with "cat". Kernel's initramfs extractor doesn't need it.)
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/cpio.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 5524dba2..90c8107f 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -16,7 +16,7 @@
* rdevmajor rdevminor namesize check
* This is the equiavlent of mode -H newc when using GNU CPIO.
-USE_CPIO(NEWTOY(cpio, "(no-preserve-owner)mduH:p:|i|t|F:v(verbose)o|[!pio][!pot][!pF]", TOYFLAG_BIN))
+USE_CPIO(NEWTOY(cpio, "(no-preserve-owner)(trailer)mduH:p:|i|t|F:v(verbose)o|[!pio][!pot][!pF]", TOYFLAG_BIN))
config CPIO
bool "cpio"
@@ -34,6 +34,7 @@ config CPIO
-t test files (list only, stdin=archive, stdout=list of files)
-v verbose (list files during create/extract)
--no-preserve-owner (don't set ownership during extract)
+ --trailer Add legacy trailer (prevents concatenation).
*/
#define FOR_cpio
@@ -113,8 +114,8 @@ void cpio_main(void)
int test = toys.optflags & FLAG_t, err = 0;
// Read header and name.
- xreadall(afd, toybuf, 110);
- if (memcmp(toybuf, "070701", 6)) error_exit("bad cpio magic");
+ if (!(size =readall(afd, toybuf, 110))) break;
+ if (size != 110 || memcmp(toybuf, "070701", 6)) error_exit("bad header");
tofree = name = strpad(afd, x8u(toybuf+94), 110);
if (!strcmp("TRAILER!!!", name)) {
if (CFG_TOYBOX_FREE) free(tofree);
@@ -275,9 +276,11 @@ void cpio_main(void)
}
free(name);
- memset(toybuf, 0, sizeof(toybuf));
- xwrite(afd, toybuf,
- sprintf(toybuf, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0)+4);
+ if (FLAG_trailer) {
+ memset(toybuf, 0, sizeof(toybuf));
+ xwrite(afd, toybuf,
+ sprintf(toybuf, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0)+4);
+ }
}
if (TT.archive) xclose(afd);