source: branches/stable/mindi-busybox/archival/bbunzip.c

Last change on this file was 1770, checked in by Bruno Cornec, 13 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

  • Property svn:eol-style set to native
File size: 8.0 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 *  Common code for gunzip-like applets
4 *
5 *  Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */
7
8#include "libbb.h"
9#include "unarchive.h"
10
11enum {
12    OPT_STDOUT = 0x1,
13    OPT_FORCE = 0x2,
14/* gunzip only: */
15    OPT_VERBOSE = 0x4,
16    OPT_DECOMPRESS = 0x8,
17    OPT_TEST = 0x10,
18};
19
20static
21int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
22{
23    int fd = open3_or_warn(filename, flags, mode);
24    if (fd < 0) {
25        return 1;
26    }
27    xmove_fd(fd, to_fd);
28    return 0;
29}
30
31int bbunpack(char **argv,
32    char* (*make_new_name)(char *filename),
33    USE_DESKTOP(long long) int (*unpacker)(void)
34)
35{
36    struct stat stat_buf;
37    USE_DESKTOP(long long) int status;
38    char *filename, *new_name;
39    smallint exitcode = 0;
40
41    do {
42        /* NB: new_name is *maybe* malloc'ed! */
43        new_name = NULL;
44        filename = *argv; /* can be NULL - 'streaming' bunzip2 */
45
46        if (filename && LONE_DASH(filename))
47            filename = NULL;
48
49        /* Open src */
50        if (filename) {
51            if (stat(filename, &stat_buf) != 0) {
52                bb_perror_msg("%s", filename);
53 err:
54                exitcode = 1;
55                goto free_name;
56            }
57            if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
58                goto err;
59        }
60
61        /* Special cases: test, stdout */
62        if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
63            if (option_mask32 & OPT_TEST)
64                if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
65                    goto err;
66            filename = NULL;
67        }
68
69        /* Open dst if we are going to unpack to file */
70        if (filename) {
71            new_name = make_new_name(filename);
72            if (!new_name) {
73                bb_error_msg("%s: unknown suffix - ignored", filename);
74                goto err;
75            }
76            /* O_EXCL: "real" bunzip2 doesn't overwrite files */
77            /* GNU gunzip goes not bail out, but goes to next file */
78            if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
79                    stat_buf.st_mode))
80                goto err;
81        }
82
83        /* Check that the input is sane */
84        if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
85            bb_error_msg_and_die("compressed data not read from terminal, "
86                    "use -f to force it");
87        }
88
89        status = unpacker();
90        if (status < 0)
91            exitcode = 1;
92
93        if (filename) {
94            char *del = new_name;
95            if (status >= 0) {
96                /* TODO: restore user/group/times here? */
97                /* Delete _compressed_ file */
98                del = filename;
99                /* restore extension (unless tgz -> tar case) */
100                if (new_name == filename)
101                    filename[strlen(filename)] = '.';
102            }
103            xunlink(del);
104
105#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
106            /* Extreme bloat for gunzip compat */
107            if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
108                fprintf(stderr, "%s: %u%% - replaced with %s\n",
109                    filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
110            }
111#endif
112
113 free_name:
114            if (new_name != filename)
115                free(new_name);
116        }
117    } while (*argv && *++argv);
118
119    return exitcode;
120}
121
122#if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS
123
124static
125char* make_new_name_generic(char *filename, const char *expected_ext)
126{
127    char *extension = strrchr(filename, '.');
128    if (!extension || strcmp(extension + 1, expected_ext) != 0) {
129        /* Mimic GNU gunzip - "real" bunzip2 tries to */
130        /* unpack file anyway, to file.out */
131        return NULL;
132    }
133    *extension = '\0';
134    return filename;
135}
136
137#endif
138
139
140/*
141 *  Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
142 *  Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
143 *
144 *  Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
145 */
146
147#if ENABLE_BUNZIP2
148
149static
150char* make_new_name_bunzip2(char *filename)
151{
152    return make_new_name_generic(filename, "bz2");
153}
154
155static
156USE_DESKTOP(long long) int unpack_bunzip2(void)
157{
158    return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
159}
160
161int bunzip2_main(int argc, char **argv);
162int bunzip2_main(int argc, char **argv)
163{
164    getopt32(argv, "cf");
165    argv += optind;
166    if (applet_name[2] == 'c')
167        option_mask32 |= OPT_STDOUT;
168
169    return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2);
170}
171
172#endif
173
174
175/*
176 * Gzip implementation for busybox
177 *
178 * Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
179 *
180 * Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
181 * based on gzip sources
182 *
183 * Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
184 * well as stdin/stdout, and to generally behave itself wrt command line
185 * handling.
186 *
187 * General cleanup to better adhere to the style guide and make use of standard
188 * busybox functions by Glenn McGrath <bug1@iinet.net.au>
189 *
190 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
191 *
192 * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
193 * Copyright (C) 1992-1993 Jean-loup Gailly
194 * The unzip code was written and put in the public domain by Mark Adler.
195 * Portions of the lzw code are derived from the public domain 'compress'
196 * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
197 * Ken Turkowski, Dave Mack and Peter Jannesen.
198 *
199 * See the license_msg below and the file COPYING for the software license.
200 * See the file algorithm.doc for the compression algorithms and file formats.
201 */
202
203#if ENABLE_GUNZIP
204
205static
206char* make_new_name_gunzip(char *filename)
207{
208    char *extension = strrchr(filename, '.');
209
210    if (!extension)
211        return NULL;
212
213    extension++;
214    if (strcmp(extension, "tgz" + 1) == 0
215#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
216     || strcmp(extension, "Z") == 0
217#endif
218    ) {
219        extension[-1] = '\0';
220    } else if (strcmp(extension, "tgz") == 0) {
221        filename = xstrdup(filename);
222        extension = strrchr(filename, '.');
223        extension[2] = 'a';
224        extension[3] = 'r';
225    } else {
226        return NULL;
227    }
228    return filename;
229}
230
231static
232USE_DESKTOP(long long) int unpack_gunzip(void)
233{
234    USE_DESKTOP(long long) int status = -1;
235
236    /* do the decompression, and cleanup */
237    if (xread_char(STDIN_FILENO) == 0x1f) {
238        unsigned char magic2;
239
240        magic2 = xread_char(STDIN_FILENO);
241        if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
242            status = uncompress(STDIN_FILENO, STDOUT_FILENO);
243        } else if (magic2 == 0x8b) {
244            check_header_gzip_or_die(STDIN_FILENO);
245            status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
246        } else {
247            goto bad_magic;
248        }
249        if (status < 0) {
250            bb_error_msg("error inflating");
251        }
252    } else {
253 bad_magic:
254        bb_error_msg("invalid magic");
255        /* status is still == -1 */
256    }
257    return status;
258}
259
260int gunzip_main(int argc, char **argv);
261int gunzip_main(int argc, char **argv)
262{
263    getopt32(argv, "cfvdt");
264    argv += optind;
265    /* if called as zcat */
266    if (applet_name[1] == 'c')
267        option_mask32 |= OPT_STDOUT;
268
269    return bbunpack(argv, make_new_name_gunzip, unpack_gunzip);
270}
271
272#endif
273
274
275/*
276 * Small lzma deflate implementation.
277 * Copyright (C) 2006  Aurelien Jacobs <aurel@gnuage.org>
278 *
279 * Based on bunzip.c from busybox
280 *
281 * Licensed under GPL v2, see file LICENSE in this tarball for details.
282 */
283
284#if ENABLE_UNLZMA
285
286static
287char* make_new_name_unlzma(char *filename)
288{
289    return make_new_name_generic(filename, "lzma");
290}
291
292static
293USE_DESKTOP(long long) int unpack_unlzma(void)
294{
295    return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
296}
297
298int unlzma_main(int argc, char **argv);
299int unlzma_main(int argc, char **argv)
300{
301    getopt32(argv, "cf");
302    argv += optind;
303    /* lzmacat? */
304    if (applet_name[4] == 'c')
305        option_mask32 |= OPT_STDOUT;
306
307    return bbunpack(argv, make_new_name_unlzma, unpack_unlzma);
308}
309
310#endif
311
312
313/*
314 *  Uncompress applet for busybox (c) 2002 Glenn McGrath
315 *
316 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
317 */
318
319#if ENABLE_UNCOMPRESS
320
321static
322char* make_new_name_uncompress(char *filename)
323{
324    return make_new_name_generic(filename, "Z");
325}
326
327static
328USE_DESKTOP(long long) int unpack_uncompress(void)
329{
330    USE_DESKTOP(long long) int status = -1;
331
332    if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
333        bb_error_msg("invalid magic");
334    } else {
335        status = uncompress(STDIN_FILENO, STDOUT_FILENO);
336    }
337    return status;
338}
339
340int uncompress_main(int argc, char **argv);
341int uncompress_main(int argc, char **argv)
342{
343    getopt32(argv, "cf");
344    argv += optind;
345
346    return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);
347}
348
349#endif
Note: See TracBrowser for help on using the repository browser.