source: MondoRescue/branches/3.2/mindi-busybox/archival/rpm2cpio.c@ 3232

Last change on this file since 3232 was 3232, checked in by Bruno Cornec, 10 years ago
  • Update mindi-busybox to 1.21.1
File size: 2.3 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * Mini rpm2cpio implementation for busybox
4 *
5 * Copyright (C) 2001 by Laurence Anderson
6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
[3232]9
10//usage:#define rpm2cpio_trivial_usage
11//usage: "package.rpm"
12//usage:#define rpm2cpio_full_usage "\n\n"
13//usage: "Output a cpio archive of the rpm file"
14
[1765]15#include "libbb.h"
[3232]16#include "bb_archive.h"
[2725]17#include "rpm.h"
[821]18
[2725]19enum { rpm_fd = STDIN_FILENO };
[821]20
[2725]21static unsigned skip_header(void)
[821]22{
23 struct rpm_header header;
[2725]24 unsigned len;
[821]25
[2725]26 xread(rpm_fd, &header, sizeof(header));
27// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
28// bb_error_msg_and_die("invalid RPM header magic");
29// }
30// if (header.version != 1) {
31// bb_error_msg_and_die("unsupported RPM header version");
32// }
33 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
34 bb_error_msg_and_die("invalid RPM header magic or unsupported version");
35 // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
[821]36 }
[2725]37
38 /* Seek past index entries, and past store */
39 len = 16 * ntohl(header.entries) + ntohl(header.size);
40 seek_by_jump(rpm_fd, len);
41
42 return sizeof(header) + len;
[821]43}
44
45/* No getopt required */
[2725]46int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
[821]48{
49 struct rpm_lead lead;
[2725]50 unsigned pos;
[821]51
[2725]52 if (argv[1]) {
53 xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
[821]54 }
[2725]55 xread(rpm_fd, &lead, sizeof(lead));
[821]56
[2725]57 /* Just check the magic, the rest is irrelevant */
58 if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
59 bb_error_msg_and_die("invalid RPM magic");
[821]60 }
61
[2725]62 /* Skip the signature header, align to 8 bytes */
63 pos = skip_header();
64 seek_by_jump(rpm_fd, (-(int)pos) & 7);
[821]65
66 /* Skip the main header */
[2725]67 skip_header();
[821]68
[3232]69 //if (SEAMLESS_COMPRESSION)
70 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */
71 // signal(SIGCHLD, check_errors_in_children);
72
[2725]73 /* This works, but doesn't report uncompress errors (they happen in child) */
[3232]74 setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
[2725]75 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
76 bb_error_msg_and_die("error unpacking");
77
78 if (ENABLE_FEATURE_CLEAN_UP) {
79 close(rpm_fd);
[821]80 }
81
[3232]82 if (SEAMLESS_COMPRESSION) {
83 check_errors_in_children(0);
84 return bb_got_signal;
85 }
86 return EXIT_SUCCESS;
[821]87}
Note: See TracBrowser for help on using the repository browser.