1 /* vi: set sw=4 ts=4: */
3 * Mini cpio implementation for busybox
5 * Copyright (C) 2001 by Glenn McGrath
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 * Only supports new ASCII and CRC formats
18 #include "unarchive.h"
21 #define CPIO_OPT_EXTRACT 0x01
22 #define CPIO_OPT_TEST 0x02
23 #define CPIO_OPT_UNCONDITIONAL 0x04
24 #define CPIO_OPT_VERBOSE 0x08
25 #define CPIO_OPT_FILE 0x10
26 #define CPIO_OPT_CREATE_LEADING_DIR 0x20
27 #define CPIO_OPT_PRESERVE_MTIME 0x40
29 int cpio_main(int argc, char **argv);
30 int cpio_main(int argc, char **argv)
32 archive_handle_t *archive_handle;
33 char *cpio_filename = NULL;
37 archive_handle = init_handle();
38 archive_handle->src_fd = STDIN_FILENO;
39 archive_handle->seek = seek_by_read;
40 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
42 opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
44 /* One of either extract or test options must be given */
45 if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
49 if (opt & CPIO_OPT_TEST) {
50 /* if both extract and test options are given, ignore extract option */
51 if (opt & CPIO_OPT_EXTRACT) {
52 opt &= ~CPIO_OPT_EXTRACT;
54 archive_handle->action_header = header_list;
56 if (opt & CPIO_OPT_EXTRACT) {
57 archive_handle->action_data = data_extract_all;
59 if (opt & CPIO_OPT_UNCONDITIONAL) {
60 archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
61 archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
63 if (opt & CPIO_OPT_VERBOSE) {
64 if (archive_handle->action_header == header_list) {
65 archive_handle->action_header = header_verbose_list;
67 archive_handle->action_header = header_list;
70 if (cpio_filename) { /* CPIO_OPT_FILE */
71 archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
72 archive_handle->seek = seek_by_jump;
74 if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
75 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
78 while (optind < argc) {
79 archive_handle->filter = filter_accept_list;
80 llist_add_to(&(archive_handle->accept), argv[optind]);
84 while (get_header_cpio(archive_handle) == EXIT_SUCCESS);