blob: beee83d310b5b52b387c0befbe6f9501bf6fcd7b [file] [log] [blame]
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Mini cpio implementation for busybox
4 *
5 * Copyright (C) 2001 by Glenn McGrath
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Limitations:
22 * Doesn't check CRC's
23 * Only supports new ASCII and CRC formats
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000024 *
25 */
26#include <fcntl.h>
27#include <getopt.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
Glenn L McGrathef0eab52001-10-25 14:49:48 +000031#include "unarchive.h"
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000032#include "busybox.h"
33
34extern int cpio_main(int argc, char **argv)
35{
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000036 archive_handle_t *archive_handle;
37 int opt;
38
39 /* Initialise */
40 archive_handle = init_handle();
41 archive_handle->src_fd = fileno(stdin);
Glenn L McGrath237ae422002-11-03 14:05:15 +000042 archive_handle->seek = seek_by_char;
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000043 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
44
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000045 while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
46 switch (opt) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000047 case 'i': /* extract */
48 archive_handle->action_data = data_extract_all;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000049 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000050 case 'd': /* create _leading_ directories */
51 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000052 break;
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000053#if 0
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000054 case 'm': /* preserve modification time */
55 archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000056 break;
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000057#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000058 case 'v': /* verbosly list files */
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000059 if (archive_handle->action_header == header_list) {
60 archive_handle->action_header = header_verbose_list;
61 } else {
62 archive_handle->action_header = header_list;
63 }
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000064 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000065 case 'u': /* unconditional */
66 archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000067 archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000068 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000069 case 't': /* list files */
Glenn L McGrath4cee66d2003-08-28 19:12:23 +000070 if (archive_handle->action_header == header_list) {
71 archive_handle->action_header = header_verbose_list;
72 } else {
73 archive_handle->action_header = header_list;
74 }
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000075 break;
76 case 'F':
Manuel Novoa III cad53642003-03-19 09:13:01 +000077 archive_handle->src_fd = bb_xopen(optarg, O_RDONLY);
Glenn L McGrath237ae422002-11-03 14:05:15 +000078 archive_handle->seek = seek_by_jump;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000079 break;
80 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +000081 bb_show_usage();
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000082 }
83 }
84
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000085 while (optind < argc) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000086 archive_handle->filter = filter_accept_list;
Glenn L McGrath66125c82002-12-08 00:54:33 +000087 archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000088 optind++;
89 }
90
Glenn L McGrathb72a7352002-12-10 00:17:22 +000091 while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000092
93 return(EXIT_SUCCESS);
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000094}