Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/cpio.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/archival/cpio.c

    r3232 r3621  
    1010 * Doesn't check CRC's
    1111 * Only supports new ASCII and CRC formats
    12  *
    1312 */
    1413#include "libbb.h"
     14#include "common_bufsiz.h"
    1515#include "bb_archive.h"
    1616
     17//config:config CPIO
     18//config:   bool "cpio"
     19//config:   default y
     20//config:   help
     21//config:     cpio is an archival utility program used to create, modify, and
     22//config:     extract contents from archives.
     23//config:     cpio has 110 bytes of overheads for every stored file.
     24//config:
     25//config:     This implementation of cpio can extract cpio archives created in the
     26//config:     "newc" or "crc" format, it cannot create or modify them.
     27//config:
     28//config:     Unless you have a specific application which requires cpio, you
     29//config:     should probably say N here.
     30//config:
     31//config:config FEATURE_CPIO_O
     32//config:   bool "Support for archive creation"
     33//config:   default y
     34//config:   depends on CPIO
     35//config:   help
     36//config:     This implementation of cpio can create cpio archives in the "newc"
     37//config:     format only.
     38//config:
     39//config:config FEATURE_CPIO_P
     40//config:   bool "Support for passthrough mode"
     41//config:   default y
     42//config:   depends on FEATURE_CPIO_O
     43//config:   help
     44//config:     Passthrough mode. Rarely used.
     45
     46//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
     47//kbuild:lib-$(CONFIG_CPIO) += cpio.o
     48
    1749//usage:#define cpio_trivial_usage
    18 //usage:       "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
     50//usage:       "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
    1951//usage:       " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
    2052//usage:       " [EXTR_FILE]..."
     
    3567//usage:     "\n    -p DIR  Copy files to DIR"
    3668//usage:    )
     69//usage:     "\nOptions:"
    3770//usage:     "\n    -d  Make leading directories"
    3871//usage:     "\n    -m  Preserve mtime"
     
    4073//usage:     "\n    -u  Overwrite"
    4174//usage:     "\n    -F FILE Input (-t,-i,-p) or output (-o) file"
     75//usage:     "\n    -R USER[:GRP]   Set owner of created files"
    4276//usage:    IF_FEATURE_CPIO_O(
    4377//usage:     "\n    -H newc Archive format"
     
    99133  -L, --dereference          Dereference symbolic links (copy the files
    100134                             that they point to instead of copying the links)
    101   -R, --owner=[USER][:.][GROUP] Set owner of created files
     135  -R, --owner=[USER][:.][GRP] Set owner of created files
    102136
    103137 Options valid in --extract and --pass-through modes:
     
    119153    OPT_DEREF              = (1 << 7),
    120154    OPT_FILE               = (1 << 8),
    121     OPTBIT_FILE = 8,
     155    OPT_OWNER              = (1 << 9),
     156    OPTBIT_OWNER = 9,
    122157    IF_FEATURE_CPIO_O(OPTBIT_CREATE     ,)
    123158    IF_FEATURE_CPIO_O(OPTBIT_FORMAT     ,)
     
    132167};
    133168
    134 #define OPTION_STR "it0uvdmLF:"
     169#define OPTION_STR "it0uvdmLF:R:"
     170
     171struct globals {
     172    struct bb_uidgid_t owner_ugid;
     173} FIX_ALIASING;
     174#define G (*(struct globals*)bb_common_bufsiz1)
     175void BUG_cpio_globals_too_big(void);
     176#define INIT_G() do { \
     177    setup_common_bufsiz(); \
     178    G.owner_ugid.uid = -1L; \
     179    G.owner_ugid.gid = -1L; \
     180} while (0)
    135181
    136182#if ENABLE_FEATURE_CPIO_O
     
    150196static NOINLINE int cpio_o(void)
    151197{
    152     static const char trailer[] ALIGN1 = "TRAILER!!!";
    153198    struct name_s {
    154199        struct name_s *next;
     
    191236                bb_simple_perror_msg_and_die(name);
    192237            }
     238
     239            if (G.owner_ugid.uid != (uid_t)-1L)
     240                st.st_uid = G.owner_ugid.uid;
     241            if (G.owner_ugid.gid != (gid_t)-1L)
     242                st.st_gid = G.owner_ugid.gid;
    193243
    194244            if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
     
    226276                continue;
    227277            }
    228 
    229278        } else { /* line == NULL: EOF */
    230279 next_link:
     
    245294                /* If no (more) hardlinks to output,
    246295                 * output "trailer" entry */
    247                 name = trailer;
     296                name = cpio_TRAILER;
    248297                /* st.st_size == 0 is a must, but for uniformity
    249298                 * in the output, we zero out everything */
     
    293342
    294343        if (!line) {
    295             if (name != trailer)
     344            if (name != cpio_TRAILER)
    296345                goto next_link;
    297346            /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
     
    309358    archive_handle_t *archive_handle;
    310359    char *cpio_filename;
     360    char *cpio_owner;
    311361    IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
    312362    unsigned opt;
     
    323373#endif
    324374#endif
     375        "owner\0"        Required_argument "R"
    325376        "verbose\0"      No_argument       "v"
    326377        "quiet\0"        No_argument       "\xff"
     
    329380#endif
    330381
     382    INIT_G();
    331383    archive_handle = init_handle();
    332384    /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
     
    339391
    340392#if !ENABLE_FEATURE_CPIO_O
    341     opt = getopt32(argv, OPTION_STR, &cpio_filename);
     393    opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
     394#else
     395    opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
     396               &cpio_filename, &cpio_owner, &cpio_fmt);
     397#endif
    342398    argv += optind;
     399    if (opt & OPT_OWNER) { /* -R */
     400        parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
     401        archive_handle->cpio__owner = G.owner_ugid;
     402    }
     403#if !ENABLE_FEATURE_CPIO_O
    343404    if (opt & OPT_FILE) { /* -F */
    344405        xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
    345406    }
    346407#else
    347     opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
    348     argv += optind;
    349408    if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
    350409        xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
Note: See TracChangeset for help on using the changeset viewer.