copy.c revision 553acb7b6b8d4f16a4747b1f978e8b7888fbfb2c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/sendfile.h>
#include "util.h"
#include "copy.h"
bool try_sendfile = true;
for (;;) {
ssize_t n;
if (max_bytes <= 0)
return -EFBIG;
}
/* First try sendfile(), unless we already tried */
if (try_sendfile) {
if (n < 0) {
return -errno;
try_sendfile = false;
/* use fallback below */
} else if (n == 0) /* EOF */
break;
else if (n > 0)
/* Succcess! */
goto next;
}
/* As a fallback just copy bits by hand */
{
char buf[m];
int r;
if (n < 0)
return -errno;
if (n == 0) /* EOF */
break;
if (r < 0)
return r;
}
next:
max_bytes -= n;
}
}
return 0;
}
static int fd_copy_symlink(int df, const char *from, const struct stat *st, int dt, const char *to) {
int r;
if (r < 0)
return r;
return -errno;
return -errno;
return 0;
}
static int fd_copy_regular(int df, const char *from, const struct stat *st, int dt, const char *to) {
int r, q;
if (fdf < 0)
return -errno;
if (fdt < 0)
return -errno;
if (r < 0) {
return r;
}
r = -errno;
r = -errno;
fdt = -1;
if (q < 0) {
r = -errno;
}
return r;
}
int r;
if (r < 0)
return -errno;
r = -errno;
r = -errno;
return r;
}
int r;
if (r < 0)
return -errno;
r = -errno;
r = -errno;
return r;
}
static int fd_copy_directory(int df, const char *from, const struct stat *st, int dt, const char *to, dev_t original_device, bool merge) {
bool created;
int r;
if (fdf < 0)
return -errno;
if (!d)
return -errno;
fdf = -1;
if (r >= 0)
created = true;
created = false;
else
return -errno;
if (fdt < 0)
return -errno;
r = 0;
if (created) {
r = -errno;
r = -errno;
}
int q;
r = -errno;
continue;
}
continue;
else
q = -ENOTSUP;
q = 0;
if (q < 0)
r = q;
}
return r;
}
return -errno;
else
return -ENOTSUP;
}
if (fdf < 0)
return -errno;
}
int fdt, r;
if (fdt < 0)
return -errno;
if (r < 0) {
return r;
}
return -errno;
}
return 0;
}