blob: 111807c433c143caa1b6798701520d1179bbf2eb [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 McGrath7ca04f32002-09-25 02:47:48 +000043 archive_handle->action_header = header_list;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000044
45 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 McGrath7ca04f32002-09-25 02:47:48 +000053 case 'm': /* preserve modification time */
54 archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000055 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000056 case 'v': /* verbosly list files */
57 archive_handle->action_header = header_verbose_list;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000058 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000059 case 'u': /* unconditional */
60 archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000061 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000062 case 't': /* list files */
63 archive_handle->action_header = header_list;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000064 break;
65 case 'F':
Manuel Novoa III cad53642003-03-19 09:13:01 +000066 archive_handle->src_fd = bb_xopen(optarg, O_RDONLY);
Glenn L McGrath237ae422002-11-03 14:05:15 +000067 archive_handle->seek = seek_by_jump;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000068 break;
69 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +000070 bb_show_usage();
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000071 }
72 }
73
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000074 while (optind < argc) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000075 archive_handle->filter = filter_accept_list;
Glenn L McGrath66125c82002-12-08 00:54:33 +000076 archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000077 optind++;
78 }
79
Glenn L McGrathb72a7352002-12-10 00:17:22 +000080 while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000081
82 return(EXIT_SUCCESS);
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000083}
84