aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-11 21:47:23 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-11 21:47:23 +0000
commitfa1649e9ac6ec8d84f10a14f4f1e28b86645206f (patch)
tree9d2a6a659f53d7af59e3d92addef739ae9bc36e8 /archival
parentdee8587d9208e4ea5ba8f8bb73b555007529372e (diff)
downloadbusybox-w32-fa1649e9ac6ec8d84f10a14f4f1e28b86645206f.tar.gz
busybox-w32-fa1649e9ac6ec8d84f10a14f4f1e28b86645206f.tar.bz2
busybox-w32-fa1649e9ac6ec8d84f10a14f4f1e28b86645206f.zip
cpio: backport the fix for
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466771
Diffstat (limited to 'archival')
-rw-r--r--archival/cpio.c110
-rw-r--r--archival/libunarchive/get_header_cpio.c5
2 files changed, 97 insertions, 18 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index 2919ff8de..bf442d789 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -14,18 +14,6 @@
14#include "libbb.h" 14#include "libbb.h"
15#include "unarchive.h" 15#include "unarchive.h"
16 16
17enum {
18 CPIO_OPT_EXTRACT = (1 << 0),
19 CPIO_OPT_TEST = (1 << 1),
20 CPIO_OPT_UNCONDITIONAL = (1 << 2),
21 CPIO_OPT_VERBOSE = (1 << 3),
22 CPIO_OPT_FILE = (1 << 4),
23 CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
24 CPIO_OPT_PRESERVE_MTIME = (1 << 6),
25 CPIO_OPT_CREATE = (1 << 7),
26 CPIO_OPT_FORMAT = (1 << 8),
27};
28
29#if ENABLE_FEATURE_CPIO_O 17#if ENABLE_FEATURE_CPIO_O
30static off_t cpio_pad4(off_t size) 18static off_t cpio_pad4(off_t size)
31{ 19{
@@ -190,21 +178,108 @@ static int cpio_o(void)
190} 178}
191#endif 179#endif
192 180
181/* GNU cpio (GNU cpio) 2.9 help (abridged):
182
183 Main operation mode:
184 -i, --extract Extract files from an archive
185 -o, --create Create the archive
186 -p, --pass-through Copy-pass mode (was ist das?!)
187 -t, --list List the archive
188
189 Operation modifiers valid in any mode:
190 --block-size=SIZE I/O block size = SIZE * 512 bytes
191 -B I/O block size = 5120 bytes
192 -c Use the old portable (ASCII) archive format
193 -C, --io-size=NUMBER I/O block size to the given NUMBER bytes
194 -f, --nonmatching Only copy files that do not match given pattern
195 -F, --file=FILE Use FILE instead of standard input or output
196 -H, --format=FORMAT Use given archive FORMAT
197 -M, --message=STRING Print STRING when the end of a volume of the
198 backup media is reached
199 -n, --numeric-uid-gid If -v, show numeric UID and GID
200 --quiet Do not print the number of blocks copied
201 --rsh-command=COMMAND Use remote COMMAND instead of rsh
202 -v, --verbose Verbosely list the files processed
203 -V, --dot Print a "." for each file processed
204 -W, --warning=FLAG Control warning display: 'none','truncate','all';
205 multiple options accumulate
206
207 Operation modifiers valid only in --extract mode:
208 -b, --swap Swap both halfwords of words and bytes of
209 halfwords in the data (equivalent to -sS)
210 -r, --rename Interactively rename files
211 -s, --swap-bytes Swap the bytes of each halfword in the files
212 -S, --swap-halfwords Swap the halfwords of each word (4 bytes)
213 --to-stdout Extract files to standard output
214 -E, --pattern-file=FILE Read additional patterns specifying filenames to
215 extract or list from FILE
216 --only-verify-crc Verify CRC's, don't actually extract the files
217
218 Operation modifiers valid only in --create mode:
219 -A, --append Append to an existing archive
220 -O FILE File to use instead of standard output
221
222 Operation modifiers valid only in --pass-through mode:
223 -l, --link Link files instead of copying them, when possible
224
225 Operation modifiers valid in --extract and --create modes:
226 --absolute-filenames Do not strip file system prefix components from
227 the file names
228 --no-absolute-filenames Create all files relative to the current dir
229
230 Operation modifiers valid in --create and --pass-through modes:
231 -0, --null A list of filenames is terminated by a NUL
232 -a, --reset-access-time Reset the access times of files after reading them
233 -I FILE File to use instead of standard input
234 -L, --dereference Dereference symbolic links (copy the files
235 that they point to instead of copying the links)
236 -R, --owner=[USER][:.][GROUP] Set owner of created files
237
238 Operation modifiers valid in --extract and --pass-through modes:
239 -d, --make-directories Create leading directories where needed
240 -m, --preserve-modification-time
241 Retain previous file modification times when
242 creating files
243 --no-preserve-owner Do not change the ownership of the files
244 --sparse Write files with blocks of zeros as sparse files
245 -u, --unconditional Replace all files unconditionally
246 */
247
193int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 248int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
194int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv) 249int cpio_main(int argc UNUSED_PARAM, char **argv)
195{ 250{
196 archive_handle_t *archive_handle; 251 archive_handle_t *archive_handle;
197 char *cpio_filename; 252 char *cpio_filename;
253 USE_FEATURE_CPIO_O(const char *cpio_fmt = "";)
254 unsigned opt;
255 enum {
256 CPIO_OPT_EXTRACT = (1 << 0),
257 CPIO_OPT_TEST = (1 << 1),
258 CPIO_OPT_UNCONDITIONAL = (1 << 2),
259 CPIO_OPT_VERBOSE = (1 << 3),
260 CPIO_OPT_FILE = (1 << 4),
261 CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
262 CPIO_OPT_PRESERVE_MTIME = (1 << 6),
263 CPIO_OPT_CREATE = (1 << 7),
264 CPIO_OPT_FORMAT = (1 << 8),
265 };
266
267#if ENABLE_GETOPT_LONG && ENABLE_DESKTOP
268 applet_long_options =
269 "extract\0" No_argument "i"
270 "list\0" No_argument "t"
198#if ENABLE_FEATURE_CPIO_O 271#if ENABLE_FEATURE_CPIO_O
199 const char *cpio_fmt = ""; 272 "create\0" No_argument "o"
273 "format\0" Required_argument "H"
274#endif
275 ;
200#endif 276#endif
201 unsigned opt;
202 277
203 /* Initialize */ 278 /* Initialize */
204 archive_handle = init_handle(); 279 archive_handle = init_handle();
205 archive_handle->src_fd = STDIN_FILENO; 280 archive_handle->src_fd = STDIN_FILENO;
206 archive_handle->seek = seek_by_read; 281 archive_handle->seek = seek_by_read;
207 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; 282 archive_handle->flags = ARCHIVE_EXTRACT_NEWER;
208 283
209#if ENABLE_FEATURE_CPIO_O 284#if ENABLE_FEATURE_CPIO_O
210 opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt); 285 opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
@@ -258,6 +333,9 @@ int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
258 if (opt & CPIO_OPT_CREATE_LEADING_DIR) { 333 if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
259 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS; 334 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
260 } 335 }
336 if (opt & CPIO_OPT_PRESERVE_MTIME) {
337 archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
338 }
261 339
262 while (*argv) { 340 while (*argv) {
263 archive_handle->filter = filter_accept_list; 341 archive_handle->filter = filter_accept_list;
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index b97b53b20..0b9d385c1 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -7,8 +7,8 @@
7#include "libbb.h" 7#include "libbb.h"
8#include "unarchive.h" 8#include "unarchive.h"
9 9
10typedef struct hardlinks_s { 10typedef struct hardlinks_t {
11 struct hardlinks_s *next; 11 struct hardlinks_t *next;
12 int inode; /* TODO: must match maj/min too! */ 12 int inode; /* TODO: must match maj/min too! */
13 int mode ; 13 int mode ;
14 int mtime; /* These three are useful only in corner case */ 14 int mtime; /* These three are useful only in corner case */
@@ -144,6 +144,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
144 free(make_me); 144 free(make_me);
145 goto next_link; 145 goto next_link;
146 } 146 }
147 cur = cur->next;
147 } 148 }
148 /* Oops... no file with such inode was created... do it now 149 /* Oops... no file with such inode was created... do it now
149 * (happens when hardlinked files are empty (zero length)) */ 150 * (happens when hardlinked files are empty (zero length)) */