[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Mini cpio implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2001 by Glenn McGrath
|
---|
| 6 | *
|
---|
[1770] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
[821] | 8 | *
|
---|
| 9 | * Limitations:
|
---|
| 10 | * Doesn't check CRC's
|
---|
| 11 | * Only supports new ASCII and CRC formats
|
---|
| 12 | *
|
---|
| 13 | */
|
---|
[1770] | 14 | #include "libbb.h"
|
---|
[821] | 15 | #include "unarchive.h"
|
---|
| 16 |
|
---|
[1770] | 17 | #define CPIO_OPT_EXTRACT 0x01
|
---|
| 18 | #define CPIO_OPT_TEST 0x02
|
---|
| 19 | #define CPIO_OPT_UNCONDITIONAL 0x04
|
---|
| 20 | #define CPIO_OPT_VERBOSE 0x08
|
---|
| 21 | #define CPIO_OPT_FILE 0x10
|
---|
| 22 | #define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
---|
| 23 | #define CPIO_OPT_PRESERVE_MTIME 0x40
|
---|
[821] | 24 |
|
---|
[1770] | 25 | int cpio_main(int argc, char **argv);
|
---|
[821] | 26 | int cpio_main(int argc, char **argv)
|
---|
| 27 | {
|
---|
| 28 | archive_handle_t *archive_handle;
|
---|
| 29 | char *cpio_filename = NULL;
|
---|
[1770] | 30 | unsigned opt;
|
---|
[821] | 31 |
|
---|
| 32 | /* Initialise */
|
---|
| 33 | archive_handle = init_handle();
|
---|
| 34 | archive_handle->src_fd = STDIN_FILENO;
|
---|
[1770] | 35 | archive_handle->seek = seek_by_read;
|
---|
[821] | 36 | archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
---|
| 37 |
|
---|
[1770] | 38 | opt = getopt32(argv, "ituvF:dm", &cpio_filename);
|
---|
[821] | 39 |
|
---|
| 40 | /* One of either extract or test options must be given */
|
---|
| 41 | if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
---|
| 42 | bb_show_usage();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | if (opt & CPIO_OPT_TEST) {
|
---|
| 46 | /* if both extract and test options are given, ignore extract option */
|
---|
| 47 | if (opt & CPIO_OPT_EXTRACT) {
|
---|
| 48 | opt &= ~CPIO_OPT_EXTRACT;
|
---|
| 49 | }
|
---|
| 50 | archive_handle->action_header = header_list;
|
---|
| 51 | }
|
---|
| 52 | if (opt & CPIO_OPT_EXTRACT) {
|
---|
| 53 | archive_handle->action_data = data_extract_all;
|
---|
| 54 | }
|
---|
| 55 | if (opt & CPIO_OPT_UNCONDITIONAL) {
|
---|
| 56 | archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
---|
| 57 | archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
|
---|
| 58 | }
|
---|
| 59 | if (opt & CPIO_OPT_VERBOSE) {
|
---|
| 60 | if (archive_handle->action_header == header_list) {
|
---|
| 61 | archive_handle->action_header = header_verbose_list;
|
---|
| 62 | } else {
|
---|
| 63 | archive_handle->action_header = header_list;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | if (cpio_filename) { /* CPIO_OPT_FILE */
|
---|
[1770] | 67 | archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
|
---|
[821] | 68 | archive_handle->seek = seek_by_jump;
|
---|
| 69 | }
|
---|
| 70 | if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
---|
| 71 | archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | while (optind < argc) {
|
---|
| 75 | archive_handle->filter = filter_accept_list;
|
---|
| 76 | llist_add_to(&(archive_handle->accept), argv[optind]);
|
---|
| 77 | optind++;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
---|
| 81 |
|
---|
[1770] | 82 | return EXIT_SUCCESS;
|
---|
[821] | 83 | }
|
---|