Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/copyfd.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/copyfd.c

    r1765 r2725  
    55 * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99
    1010#include "libbb.h"
    1111
    12 #if BUFSIZ < 4096
    13 #undef BUFSIZ
    14 #define BUFSIZ 4096
    15 #endif
    16 
    17 /* Used by NOFORK applets (e.g. cat) - must not use xmalloc */
    18 
     12/* Used by NOFORK applets (e.g. cat) - must not use xmalloc.
     13 * size < 0 means "ignore write errors", used by tar --to-command
     14 * size = 0 means "copy till EOF"
     15 */
    1916static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
    2017{
    2118    int status = -1;
    2219    off_t total = 0;
    23     char buffer[BUFSIZ];
     20    bool continue_on_write_error = 0;
     21#if CONFIG_FEATURE_COPYBUF_KB <= 4
     22    char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
     23    enum { buffer_size = sizeof(buffer) };
     24#else
     25    char *buffer;
     26    int buffer_size;
     27#endif
     28
     29    if (size < 0) {
     30        size = -size;
     31        continue_on_write_error = 1;
     32    }
     33
     34#if CONFIG_FEATURE_COPYBUF_KB > 4
     35    if (size > 0 && size <= 4 * 1024)
     36        goto use_small_buf;
     37    /* We want page-aligned buffer, just in case kernel is clever
     38     * and can do page-aligned io more efficiently */
     39    buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
     40            PROT_READ | PROT_WRITE,
     41            MAP_PRIVATE | MAP_ANON,
     42            /* ignored: */ -1, 0);
     43    buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
     44    if (buffer == MAP_FAILED) {
     45 use_small_buf:
     46        buffer = alloca(4 * 1024);
     47        buffer_size = 4 * 1024;
     48    }
     49#endif
    2450
    2551    if (src_fd < 0)
     
    2753
    2854    if (!size) {
    29         size = BUFSIZ;
     55        size = buffer_size;
    3056        status = 1; /* copy until eof */
    3157    }
     
    3460        ssize_t rd;
    3561
    36         rd = safe_read(src_fd, buffer, size > BUFSIZ ? BUFSIZ : size);
     62        rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size);
    3763
    3864        if (!rd) { /* eof - all done */
     
    4874            ssize_t wr = full_write(dst_fd, buffer, rd);
    4975            if (wr < rd) {
    50                 bb_perror_msg(bb_msg_write_error);
    51                 break;
     76                if (!continue_on_write_error) {
     77                    bb_perror_msg(bb_msg_write_error);
     78                    break;
     79                }
     80                dst_fd = -1;
    5281            }
    5382        }
     
    6392    }
    6493 out:
     94
     95#if CONFIG_FEATURE_COPYBUF_KB > 4
     96    if (buffer_size != 4 * 1024)
     97        munmap(buffer, buffer_size);
     98#endif
    6599    return status ? -1 : total;
    66100}
     
    68102
    69103#if 0
    70 void complain_copyfd_and_die(off_t sz)
     104void FAST_FUNC complain_copyfd_and_die(off_t sz)
    71105{
    72106    if (sz != -1)
     
    77111#endif
    78112
    79 off_t bb_copyfd_size(int fd1, int fd2, off_t size)
     113off_t FAST_FUNC bb_copyfd_size(int fd1, int fd2, off_t size)
    80114{
    81115    if (size) {
     
    85119}
    86120
    87 void bb_copyfd_exact_size(int fd1, int fd2, off_t size)
     121void FAST_FUNC bb_copyfd_exact_size(int fd1, int fd2, off_t size)
    88122{
    89123    off_t sz = bb_copyfd_size(fd1, fd2, size);
    90     if (sz == size)
     124    if (sz == (size >= 0 ? size : -size))
    91125        return;
    92126    if (sz != -1)
     
    96130}
    97131
    98 off_t bb_copyfd_eof(int fd1, int fd2)
     132off_t FAST_FUNC bb_copyfd_eof(int fd1, int fd2)
    99133{
    100134    return bb_full_fd_action(fd1, fd2, 0);
Note: See TracChangeset for help on using the changeset viewer.