summaryrefslogtreecommitdiffstats
path: root/bin/mv
diff options
context:
space:
mode:
authorivoras <ivoras@FreeBSD.org>2011-10-03 21:48:10 +0000
committerivoras <ivoras@FreeBSD.org>2011-10-03 21:48:10 +0000
commitf56505c86d32bde303be9651532141d81eb66f72 (patch)
tree1633b0d616a34d8594baab2da2f0cd925535c051 /bin/mv
parent073a0c270491411548461e8859b26b7010c397c6 (diff)
downloadFreeBSD-src-f56505c86d32bde303be9651532141d81eb66f72.zip
FreeBSD-src-f56505c86d32bde303be9651532141d81eb66f72.tar.gz
Don't chop IO into small pieces, follow cp(1) and just use MAXPHYS.
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/mv.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 1f98f94..67108f7 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -260,40 +260,34 @@ static int
fastcopy(const char *from, const char *to, struct stat *sbp)
{
struct timeval tval[2];
- static u_int blen;
- static char *bp;
+ static u_int blen = MAXPHYS;
+ static char *bp = NULL;
mode_t oldmode;
int nread, from_fd, to_fd;
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
- warn("%s", from);
+ warn("fastcopy: open() failed (from): %s", from);
return (1);
}
- if (blen < sbp->st_blksize) {
- if (bp != NULL)
- free(bp);
- if ((bp = malloc((size_t)sbp->st_blksize)) == NULL) {
- blen = 0;
- warnx("malloc failed");
- return (1);
- }
- blen = sbp->st_blksize;
+ if (bp == NULL && (bp = malloc((size_t)blen)) == NULL) {
+ warnx("malloc(%u) failed", blen);
+ return (1);
}
while ((to_fd =
open(to, O_CREAT | O_EXCL | O_TRUNC | O_WRONLY, 0)) < 0) {
if (errno == EEXIST && unlink(to) == 0)
continue;
- warn("%s", to);
+ warn("fastcopy: open() failed (to): %s", to);
(void)close(from_fd);
return (1);
}
while ((nread = read(from_fd, bp, (size_t)blen)) > 0)
if (write(to_fd, bp, (size_t)nread) != nread) {
- warn("%s", to);
+ warn("fastcopy: write() failed: %s", to);
goto err;
}
if (nread < 0) {
- warn("%s", from);
+ warn("fastcopy: read() failed: %s", from);
err: if (unlink(to))
warn("%s: remove", to);
(void)close(from_fd);
OpenPOWER on IntegriCloud