CVS commit: src/bin/cp
Module Name:src Committed By: andvar Date: Fri Jun 7 21:01:00 UTC 2024 Modified Files: src/bin/cp: cp.c Log Message: s/concatentation/concatenation/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.62 src/bin/cp/cp.c:1.63 --- src/bin/cp/cp.c:1.62 Fri May 22 14:54:30 2020 +++ src/bin/cp/cp.c Fri Jun 7 21:01:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $ */ +/* $NetBSD: cp.c,v 1.63 2024/06/07 21:01:00 andvar Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.63 2024/06/07 21:01:00 andvar Exp $"); #endif #endif /* not lint */ @@ -375,7 +375,7 @@ copy(char *argv[], enum op type, int fts * is the case where the target exists. * * Also, check for "..". This is for correct path - * concatentation for paths ending in "..", e.g. + * concatenation for paths ending in "..", e.g. * cp -R .. /tmp * Paths ending in ".." are changed to ".". This is * tricky, but seems the easiest way to fix the problem.
CVS commit: src/bin/cp
Module Name:src Committed By: andvar Date: Fri Jun 7 21:01:00 UTC 2024 Modified Files: src/bin/cp: cp.c Log Message: s/concatentation/concatenation/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Mon Jan 15 17:41:06 UTC 2024 Modified Files: src/bin/cp: utils.c Log Message: PR/57857: Ricardo Branco: Always copy regular files, even if they appear to be zero-sized. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.49 src/bin/cp/utils.c:1.50 --- src/bin/cp/utils.c:1.49 Sun May 17 19:34:11 2020 +++ src/bin/cp/utils.c Mon Jan 15 12:41:06 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.49 2020/05/17 23:34:11 christos Exp $ */ +/* $NetBSD: utils.c,v 1.50 2024/01/15 17:41:06 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.49 2020/05/17 23:34:11 christos Exp $"); +__RCSID("$NetBSD: utils.c,v 1.50 2024/01/15 17:41:06 christos Exp $"); #endif #endif /* not lint */ @@ -179,10 +179,10 @@ copy_file(FTSENT *entp, int dne) rval = 0; /* - * There's no reason to do anything other than close the file - * now if it's regular and empty, so let's not bother. + * We always copy regular files, even if they appear to be 0-sized + * because kernfs and procfs don't return file sizes. */ - bool need_copy = !S_ISREG(fs->st_mode) || fs->st_size > 0; + bool need_copy = S_ISREG(fs->st_mode) || fs->st_size > 0; struct finfo fi;
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Mon Jan 15 17:41:06 UTC 2024 Modified Files: src/bin/cp: utils.c Log Message: PR/57857: Ricardo Branco: Always copy regular files, even if they appear to be zero-sized. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Fri May 22 14:54:30 UTC 2020 Modified Files: src/bin/cp: cp.c Log Message: fix reversed test. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Fri May 22 14:54:30 UTC 2020 Modified Files: src/bin/cp: cp.c Log Message: fix reversed test. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.61 src/bin/cp/cp.c:1.62 --- src/bin/cp/cp.c:1.61 Sun May 17 19:34:11 2020 +++ src/bin/cp/cp.c Fri May 22 10:54:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.61 2020/05/17 23:34:11 christos Exp $ */ +/* $NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.61 2020/05/17 23:34:11 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $"); #endif #endif /* not lint */ @@ -517,7 +517,7 @@ copy(char *argv[], enum op type, int fts this_failed = any_failed = 1; #endif } -if (this_failed && (dne = popdne())) +if (!this_failed && (dne = popdne())) (void)chmod(to.p_path, curr->fts_statp->st_mode); }
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Mon Sep 23 18:01:09 UTC 2019 Modified Files: src/bin/cp: utils.c Log Message: PR/54564: Jan Schaumann: cp of a fifo yields an empty file Don't short-circuit 0 sized stat entries if they don't belong to regular files. Also don't try to mmap non-regular files. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Mon Sep 23 18:01:09 UTC 2019 Modified Files: src/bin/cp: utils.c Log Message: PR/54564: Jan Schaumann: cp of a fifo yields an empty file Don't short-circuit 0 sized stat entries if they don't belong to regular files. Also don't try to mmap non-regular files. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.46 src/bin/cp/utils.c:1.47 --- src/bin/cp/utils.c:1.46 Tue Jul 17 09:04:58 2018 +++ src/bin/cp/utils.c Mon Sep 23 14:01:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $ */ +/* $NetBSD: utils.c,v 1.47 2019/09/23 18:01:09 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); +__RCSID("$NetBSD: utils.c,v 1.47 2019/09/23 18:01:09 christos Exp $"); #endif #endif /* not lint */ @@ -174,87 +174,83 @@ copy_file(FTSENT *entp, int dne) rval = 0; - /* + /* * There's no reason to do anything other than close the file - * now if it's empty, so let's not bother. + * now if it's regular and empty, so let's not bother. */ - if (fs->st_size > 0) { - struct finfo fi; - - fi.from = entp->fts_path; - fi.to = to.p_path; - fi.size = fs->st_size; - - /* - * Mmap and write if less than 8M (the limit is so - * we don't totally trash memory on big files). - * This is really a minor hack, but it wins some CPU back. - */ - bool use_read; + bool need_copy = !S_ISREG(fs->st_mode) || fs->st_size > 0; - use_read = true; - if (fs->st_size <= MMAP_MAX_SIZE) { - size_t fsize = (size_t)fs->st_size; - p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, - from_fd, (off_t)0); - if (p != MAP_FAILED) { -size_t remainder; - -use_read = false; - -(void) madvise(p, (size_t)fs->st_size, - MADV_SEQUENTIAL); - -/* - * Write out the data in small chunks to - * avoid locking the output file for a - * long time if the reading the data from - * the source is slow. - */ -remainder = fsize; -do { - ssize_t chunk; - - chunk = (remainder > MMAP_MAX_WRITE) ? - MMAP_MAX_WRITE : remainder; - if (write(to_fd, [fsize - remainder], - chunk) != chunk) { - warn("%s", to.p_path); - rval = 1; - break; - } - remainder -= chunk; - ptotal += chunk; - if (pinfo) - progress(, ptotal); -} while (remainder > 0); + struct finfo fi; -if (munmap(p, fsize) < 0) { - warn("%s", entp->fts_path); - rval = 1; -} - } - } + fi.from = entp->fts_path; + fi.to = to.p_path; + fi.size = fs->st_size; - if (use_read) { - while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { -wcount = write(to_fd, buf, (size_t)rcount); -if (rcount != wcount || wcount == -1) { + /* + * Mmap and write if less than 8M (the limit is so + * we don't totally trash memory on big files). + * This is really a minor hack, but it wins some CPU back. + */ + if (S_ISREG(fs->st_mode) && fs->st_size && fs->st_size <= MMAP_MAX_SIZE) { + size_t fsize = (size_t)fs->st_size; + p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, + from_fd, (off_t)0); + if (p != MAP_FAILED) { + size_t remainder; + + need_copy = false; + + (void) madvise(p, (size_t)fs->st_size, MADV_SEQUENTIAL); + + /* + * Write out the data in small chunks to + * avoid locking the output file for a + * long time if the reading the data from + * the source is slow. + */ + remainder = fsize; + do { +ssize_t chunk; + +chunk = (remainder > MMAP_MAX_WRITE) ? +MMAP_MAX_WRITE : remainder; +if (write(to_fd, [fsize - remainder], +chunk) != chunk) { warn("%s", to.p_path); rval = 1; break; } -ptotal += wcount; +remainder -= chunk; +ptotal += chunk; if (pinfo) progress(, ptotal); - } - if (rcount < 0) { + } while (remainder > 0); + + if (munmap(p, fsize) < 0) { warn("%s", entp->fts_path); rval = 1; } } } + if (need_copy) { + while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { + wcount = write(to_fd, buf, (size_t)rcount); + if (rcount != wcount || wcount == -1) { +warn("%s", to.p_path); +rval = 1; +break; + } + ptotal += wcount; + if (pinfo) +progress(, ptotal); + } + if (rcount < 0) { + warn("%s", entp->fts_path); + rval = 1; + } + } + if (pflag && (fcpxattr(from_fd, to_fd) != 0)) warn("%s: error copying extended attributes", to.p_path);
CVS commit: src/bin/cp
Module Name:src Committed By: gutteridge Date: Sun Dec 23 01:29:23 UTC 2018 Modified Files: src/bin/cp: cp.1 Log Message: Clarify a sentence about the error handling of cp(1)'s -p option. Addresses PR bin/40336. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.45 src/bin/cp/cp.1:1.46 --- src/bin/cp/cp.1:1.45 Thu Aug 11 00:17:23 2016 +++ src/bin/cp/cp.1 Sun Dec 23 01:29:23 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.45 2016/08/11 00:17:23 sevan Exp $ +.\" $NetBSD: cp.1,v 1.46 2018/12/23 01:29:23 gutteridge Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd August 11, 2016 +.Dd December 22, 2018 .Dt CP 1 .Os .Sh NAME @@ -120,8 +120,9 @@ to preserve in the copy as many of the m file flags, file mode, user ID, group ID, and extended attributes, as allowed by permissions. .Pp -If the user ID and group ID cannot be preserved, no error message -is displayed and the exit value is not altered. +If the user ID and group ID cannot be preserved due to insufficient +permissions, no error message is displayed and the exit value is not +altered. .Pp If the source file has its set user ID bit on and the user ID cannot be preserved, the set user ID bit is not preserved
CVS commit: src/bin/cp
Module Name:src Committed By: gutteridge Date: Sun Dec 23 01:29:23 UTC 2018 Modified Files: src/bin/cp: cp.1 Log Message: Clarify a sentence about the error handling of cp(1)'s -p option. Addresses PR bin/40336. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Tue Jul 17 13:04:58 UTC 2018 Modified Files: src/bin/cp: utils.c Log Message: Re-order the code to short circuit all the opens and closes if linking. Discussed on tech-userlevel and agreed to by christos@. Testing suggests an order of magnitude improvement when linking. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.45 src/bin/cp/utils.c:1.46 --- src/bin/cp/utils.c:1.45 Mon Feb 29 04:22:21 2016 +++ src/bin/cp/utils.c Tue Jul 17 13:04:58 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $ */ +/* $NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $"); +__RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); #endif #endif /* not lint */ @@ -99,7 +99,17 @@ copy_file(FTSENT *entp, int dne) int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; off_t ptotal = 0; - + + /* if hard linking then simply link and return */ + if (lflag) { + (void)unlink(to.p_path); + if (link(entp->fts_path, to.p_path)) { + warn("%s", to.p_path); + return (1); + } + return (0); + } + if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); return (1); @@ -164,18 +174,6 @@ copy_file(FTSENT *entp, int dne) rval = 0; - /* if hard linking then simply close the open fds, link and return */ - if (lflag) { - (void)close(from_fd); - (void)close(to_fd); - (void)unlink(to.p_path); - if (link(entp->fts_path, to.p_path)) { - warn("%s", to.p_path); - return (1); - } - return (0); - } - /* * There's no reason to do anything other than close the file * now if it's empty, so let's not bother.
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Tue Jul 17 13:04:58 UTC 2018 Modified Files: src/bin/cp: utils.c Log Message: Re-order the code to short circuit all the opens and closes if linking. Discussed on tech-userlevel and agreed to by christos@. Testing suggests an order of magnitude improvement when linking. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: sevan Date: Thu Aug 11 00:17:23 UTC 2016 Modified Files: src/bin/cp: cp.1 Log Message: Document the version cp first appeared. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: sevan Date: Thu Aug 11 00:17:23 UTC 2016 Modified Files: src/bin/cp: cp.1 Log Message: Document the version cp first appeared. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.44 src/bin/cp/cp.1:1.45 --- src/bin/cp/cp.1:1.44 Sun Jun 28 16:22:54 2015 +++ src/bin/cp/cp.1 Thu Aug 11 00:17:23 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.44 2015/06/28 16:22:54 wiz Exp $ +.\" $NetBSD: cp.1,v 1.45 2016/08/11 00:17:23 sevan Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd March 25, 2012 +.Dd August 11, 2016 .Dt CP 1 .Os .Sh NAME @@ -255,3 +255,8 @@ The .Fl v option is an extension to .St -p1003.2 . +.Sh HISTORY +A +.Nm +utility appeared in +.At v1 .
CVS commit: src/bin/cp
Module Name:src Committed By: uwe Date: Sat Mar 5 19:48:56 UTC 2016 Modified Files: src/bin/cp: cp.c Log Message: The '-i' flag should work regardless of whether the standard input is a terminal. The Open Group notes this historic behavior and correctly notes that it doesn't make much sense. Note also, that mv(1) has always respected its '-i' regardless of whether the standard input is a terminal. >From Timo Buhrmester. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: uwe Date: Sat Mar 5 19:48:56 UTC 2016 Modified Files: src/bin/cp: cp.c Log Message: The '-i' flag should work regardless of whether the standard input is a terminal. The Open Group notes this historic behavior and correctly notes that it doesn't make much sense. Note also, that mv(1) has always respected its '-i' regardless of whether the standard input is a terminal. >From Timo Buhrmester. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.58 src/bin/cp/cp.c:1.59 --- src/bin/cp/cp.c:1.58 Wed Jan 4 15:58:37 2012 +++ src/bin/cp/cp.c Sat Mar 5 19:48:55 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */ +/* $NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $"); #endif #endif /* not lint */ @@ -145,7 +145,7 @@ main(int argc, char *argv[]) iflag = 0; break; case 'i': - iflag = isatty(fileno(stdin)); + iflag = 1; fflag = 0; break; case 'l':
CVS commit: src/bin/cp
Module Name:src Committed By: mrg Date: Mon Feb 29 04:22:21 UTC 2016 Modified Files: src/bin/cp: utils.c Log Message: for display in the (post) SIGINFO handler use off_t not size_t for file sizes. fixes incorrect reporting errors on 32 bit platforms with >4GB file sizes. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.44 src/bin/cp/utils.c:1.45 --- src/bin/cp/utils.c:1.44 Tue Mar 3 00:20:38 2015 +++ src/bin/cp/utils.c Mon Feb 29 04:22:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $ */ +/* $NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $"); +__RCSID("$NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $"); #endif #endif /* not lint */ @@ -77,17 +77,18 @@ set_utimes(const char *file, struct stat struct finfo { const char *from; const char *to; - size_t size; + off_t size; }; static void -progress(const struct finfo *fi, size_t written) +progress(const struct finfo *fi, off_t written) { int pcent = (int)((100.0 * written) / fi->size); pinfo = 0; - (void)fprintf(stderr, "%s => %s %zu/%zu bytes %d%% written\n", - fi->from, fi->to, written, fi->size, pcent); + (void)fprintf(stderr, "%s => %s %llu/%llu bytes %d%% written\n", + fi->from, fi->to, (unsigned long long)written, + (unsigned long long)fi->size, pcent); } int @@ -97,7 +98,7 @@ copy_file(FTSENT *entp, int dne) struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; - size_t ptotal = 0; + off_t ptotal = 0; if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); @@ -184,7 +185,7 @@ copy_file(FTSENT *entp, int dne) fi.from = entp->fts_path; fi.to = to.p_path; - fi.size = (size_t)fs->st_size; + fi.size = fs->st_size; /* * Mmap and write if less than 8M (the limit is so
CVS commit: src/bin/cp
Module Name:src Committed By: mrg Date: Mon Feb 29 04:22:21 UTC 2016 Modified Files: src/bin/cp: utils.c Log Message: for display in the (post) SIGINFO handler use off_t not size_t for file sizes. fixes incorrect reporting errors on 32 bit platforms with >4GB file sizes. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Jun 28 16:22:54 UTC 2015 Modified Files: src/bin/cp: cp.1 Log Message: Add serial comma, use upper case for abbreviation, and remove apostrophe for plural. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.43 src/bin/cp/cp.1:1.44 --- src/bin/cp/cp.1:1.43 Tue Dec 17 09:54:08 2013 +++ src/bin/cp/cp.1 Sun Jun 28 16:22:54 2015 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.43 2013/12/17 09:54:08 apb Exp $ +.\ $NetBSD: cp.1,v 1.44 2015/06/28 16:22:54 wiz Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -225,8 +225,8 @@ utility had a .Fl r option. This implementation supports that option, however, its use is strongly -discouraged, as it does not correctly copy special files, symbolic links -or fifo's. +discouraged, as it does not correctly copy special files, symbolic links, +or FIFOs. .Sh SEE ALSO .Xr mv 1 , .Xr pax 1 ,
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Jun 28 16:22:54 UTC 2015 Modified Files: src/bin/cp: cp.1 Log Message: Add serial comma, use upper case for abbreviation, and remove apostrophe for plural. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: enami Date: Tue Mar 3 00:20:38 UTC 2015 Modified Files: src/bin/cp: utils.c Log Message: Fix the name of failed function in warning message. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.43 src/bin/cp/utils.c:1.44 --- src/bin/cp/utils.c:1.43 Mon Mar 2 03:17:24 2015 +++ src/bin/cp/utils.c Tue Mar 3 00:20:38 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.43 2015/03/02 03:17:24 enami Exp $ */ +/* $NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.43 2015/03/02 03:17:24 enami Exp $); +__RCSID($NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $); #endif #endif /* not lint */ @@ -68,7 +68,7 @@ set_utimes(const char *file, struct stat ts[1] = fs-st_mtimespec; if (lutimens(file, ts)) { - warn(lutimes: %s, file); + warn(lutimens: %s, file); return (1); } return (0);
CVS commit: src/bin/cp
Module Name:src Committed By: enami Date: Tue Mar 3 00:20:38 UTC 2015 Modified Files: src/bin/cp: utils.c Log Message: Fix the name of failed function in warning message. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Dec 11 06:00:11 UTC 2013 Modified Files: src/bin/cp: utils.c Log Message: Remove entirely bogus /* NOTREACHED */ annotation. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.41 src/bin/cp/utils.c:1.42 --- src/bin/cp/utils.c:1.41 Wed Jan 4 15:58:37 2012 +++ src/bin/cp/utils.c Wed Dec 11 06:00:11 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */ +/* $NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $); +__RCSID($NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $); #endif #endif /* not lint */ @@ -174,7 +174,6 @@ copy_file(FTSENT *entp, int dne) } return (0); } - /* NOTREACHED */ /* * There's no reason to do anything other than close the file
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Dec 11 06:00:11 UTC 2013 Modified Files: src/bin/cp: utils.c Log Message: Remove entirely bogus /* NOTREACHED */ annotation. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Mar 25 22:37:08 UTC 2012 Modified Files: src/bin/cp: cp.1 Log Message: From patch by Bug Hunting: - bump the manpage's date (because of the next change); - note that cp(1) does not preserve hard links (even with `-R'), and refer to pax(1) there as well as in the `SEE ALSO' section for such functionality (this change is based upon a similar note in FreeBSD's version of the manpage); - change a wording, for more overall consistency. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.41 src/bin/cp/cp.1:1.42 --- src/bin/cp/cp.1:1.41 Wed Aug 3 15:44:15 2011 +++ src/bin/cp/cp.1 Sun Mar 25 22:37:08 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.41 2011/08/03 15:44:15 dholland Exp $ +.\ $NetBSD: cp.1,v 1.42 2012/03/25 22:37:08 wiz Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\ .\ @(#)cp.1 8.3 (Berkeley) 4/18/94 .\ -.Dd August 3, 2011 +.Dd March 25, 2012 .Dt CP 1 .Os .Sh NAME @@ -151,8 +151,15 @@ followed, and for to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process's umask. +.Pp +Note that +.Nm +copies hard linked files as separate files. +If you need to preserve hard links, consider using a utility like +.Xr pax 1 +instead. .It Fl v -Cause +Causes .Nm to be verbose, showing files as they are copied. .El @@ -219,6 +226,7 @@ discouraged, as it does not correctly co or fifo's. .Sh SEE ALSO .Xr mv 1 , +.Xr pax 1 , .Xr rcp 1 , .Xr umask 2 , .Xr fts 3 ,
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Wed Jan 4 15:58:37 UTC 2012 Modified Files: src/bin/cp: cp.c extern.h utils.c Log Message: Add siginfo support from Daniel Loffgren. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/bin/cp/cp.c cvs rdiff -u -r1.16 -r1.17 src/bin/cp/extern.h cvs rdiff -u -r1.40 -r1.41 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.57 src/bin/cp/cp.c:1.58 --- src/bin/cp/cp.c:1.57 Thu Aug 18 04:11:58 2011 +++ src/bin/cp/cp.c Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $ */ +/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = @(#)cp.c 8.5 (Berkeley) 4/29/95; #else -__RCSID($NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $); +__RCSID($NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $); #endif #endif /* not lint */ @@ -70,6 +70,7 @@ __RCSID($NetBSD: cp.c,v 1.57 2011/08/18 #include errno.h #include fts.h #include locale.h +#include signal.h #include stdlib.h #include stdio.h #include string.h @@ -88,11 +89,18 @@ PATH_T to = { .p_end = to.p_path, .targe uid_t myuid; int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag; mode_t myumask; +sig_atomic_t pinfo; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; -int main(int, char *[]); -int copy(char *[], enum op, int); +static int copy(char *[], enum op, int); + +static void +progress(int sig __unused) +{ + + pinfo++; +} int main(int argc, char *argv[]) @@ -210,6 +218,8 @@ main(int argc, char *argv[]) /* Set end of argument list for fts(3). */ argv[argc] = NULL; + (void)signal(SIGINFO, progress); + /* * Cp has two distinct cases: * @@ -310,7 +320,7 @@ popdne(void) return rv; } -int +static int copy(char *argv[], enum op type, int fts_options) { struct stat to_stat; Index: src/bin/cp/extern.h diff -u src/bin/cp/extern.h:1.16 src/bin/cp/extern.h:1.17 --- src/bin/cp/extern.h:1.16 Sun Feb 6 07:37:49 2011 +++ src/bin/cp/extern.h Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.16 2011/02/06 12:37:49 darcy Exp $ */ +/* $NetBSD: extern.h,v 1.17 2012/01/04 15:58:37 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -44,6 +44,7 @@ extern PATH_T to; extern uid_t myuid; extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; extern mode_t myumask; +extern sig_atomic_t pinfo; #include sys/cdefs.h Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.40 src/bin/cp/utils.c:1.41 --- src/bin/cp/utils.c:1.40 Wed Aug 3 00:11:15 2011 +++ src/bin/cp/utils.c Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $ */ +/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $); +__RCSID($NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $); #endif #endif /* not lint */ @@ -74,6 +74,22 @@ set_utimes(const char *file, struct stat return (0); } +struct finfo { + const char *from; + const char *to; + size_t size; +}; + +static void +progress(const struct finfo *fi, size_t written) +{ + int pcent = (int)((100.0 * written) / fi-size); + + pinfo = 0; + (void)fprintf(stderr, %s = %s %zu/%zu bytes %d%% written\n, + fi-from, fi-to, written, fi-size, pcent); +} + int copy_file(FTSENT *entp, int dne) { @@ -81,6 +97,7 @@ copy_file(FTSENT *entp, int dne) struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; + size_t ptotal = 0; if ((from_fd = open(entp-fts_path, O_RDONLY, 0)) == -1) { warn(%s, entp-fts_path); @@ -164,6 +181,12 @@ copy_file(FTSENT *entp, int dne) * now if it's empty, so let's not bother. */ if (fs-st_size 0) { + struct finfo fi; + + fi.from = entp-fts_path; + fi.to = to.p_path; + fi.size = (size_t)fs-st_size; + /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). @@ -203,6 +226,9 @@ copy_file(FTSENT *entp, int dne) break; } remainder -= chunk; + ptotal += chunk; + if (pinfo) + progress(fi, ptotal); } while (remainder 0); if (munmap(p, fsize) 0) { @@ -220,6 +246,9 @@ copy_file(FTSENT *entp, int dne) rval = 1; break; } +ptotal += wcount; +if (pinfo) + progress(fi, ptotal); } if (rcount 0) { warn(%s, entp-fts_path);
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Wed Jan 4 15:58:37 UTC 2012 Modified Files: src/bin/cp: cp.c extern.h utils.c Log Message: Add siginfo support from Daniel Loffgren. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/bin/cp/cp.c cvs rdiff -u -r1.16 -r1.17 src/bin/cp/extern.h cvs rdiff -u -r1.40 -r1.41 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Thu Aug 18 08:11:59 UTC 2011 Modified Files: src/bin/cp: cp.c Log Message: Remove warning about system extended attributes that cannot be copied, since it will always be displayed when an unprivilegied user moves files across filesystems (mv(1) uses cp -p in that case). After all, there is no warning that we loose a setuid bit during a move or copy, so this makes sense. Fixes bin/45259 To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.56 src/bin/cp/cp.c:1.57 --- src/bin/cp/cp.c:1.56 Wed Aug 3 04:11:15 2011 +++ src/bin/cp/cp.c Thu Aug 18 08:11:58 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $ */ +/* $NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = @(#)cp.c 8.5 (Berkeley) 4/29/95; #else -__RCSID($NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $); +__RCSID($NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $); #endif #endif /* not lint */ @@ -197,13 +197,6 @@ myumask = umask(0); (void)umask(myumask); - /* - * Warn that system extended attributes will not be preserved - * if not root - */ - if ((myuid != 0) pflag) - warnx(system extended attribute will not be preserved); - /* Save the target base in to. */ target = argv[--argc]; if (strlcpy(to.p_path, target, sizeof(to.p_path)) = sizeof(to.p_path))
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Thu Aug 18 08:11:59 UTC 2011 Modified Files: src/bin/cp: cp.c Log Message: Remove warning about system extended attributes that cannot be copied, since it will always be displayed when an unprivilegied user moves files across filesystems (mv(1) uses cp -p in that case). After all, there is no warning that we loose a setuid bit during a move or copy, so this makes sense. Fixes bin/45259 To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Wed Aug 3 12:55:03 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: iExplain what happens to extended attriutes when -p is used. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.38 src/bin/cp/cp.1:1.39 --- src/bin/cp/cp.1:1.38 Sat Apr 2 08:38:56 2011 +++ src/bin/cp/cp.1 Wed Aug 3 12:55:03 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.38 2011/04/02 08:38:56 mbalmer Exp $ +.\ $NetBSD: cp.1,v 1.39 2011/08/03 12:55:03 manu Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -117,7 +117,8 @@ Causes .Nm to preserve in the copy as many of the modification time, access time, -file flags, file mode, user ID, and group ID as allowed by permissions. +file flags, file mode, user ID, group ID, and extended attributes, +as allowed by permissions. .Pp If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered. @@ -132,6 +133,13 @@ and either the user ID or group ID cannot be preserved, neither the set user ID or set group ID bits are preserved in the copy's permissions. +.Pp +Extended attributes from all accessible namespaces are copied, the +others being ignored. If an error occur during the copy, a message is +displayed and +.Nm cp +skips +the other extended attributes for the file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Wed Aug 3 14:02:59 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: New sentence, new line. Remove trailing whitespace. Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.39 src/bin/cp/cp.1:1.40 --- src/bin/cp/cp.1:1.39 Wed Aug 3 12:55:03 2011 +++ src/bin/cp/cp.1 Wed Aug 3 14:02:59 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.39 2011/08/03 12:55:03 manu Exp $ +.\ $NetBSD: cp.1,v 1.40 2011/08/03 14:02:59 wiz Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\ .\ @(#)cp.1 8.3 (Berkeley) 4/18/94 .\ -.Dd April 2, 2011 +.Dd August 3, 2011 .Dt CP 1 .Os .Sh NAME @@ -135,11 +135,10 @@ permissions. .Pp Extended attributes from all accessible namespaces are copied, the -others being ignored. If an error occur during the copy, a message is -displayed and +others being ignored. +If an error occur during the copy, a message is displayed and .Nm cp -skips -the other extended attributes for the file. +skips the other extended attributes for the file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Aug 3 15:44:15 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Adjust wording of previous and fix a couple grammar slipups/typos. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.40 src/bin/cp/cp.1:1.41 --- src/bin/cp/cp.1:1.40 Wed Aug 3 14:02:59 2011 +++ src/bin/cp/cp.1 Wed Aug 3 15:44:15 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.40 2011/08/03 14:02:59 wiz Exp $ +.\ $NetBSD: cp.1,v 1.41 2011/08/03 15:44:15 dholland Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -134,11 +134,11 @@ the set user ID or set group ID bits are preserved in the copy's permissions. .Pp -Extended attributes from all accessible namespaces are copied, the -others being ignored. -If an error occur during the copy, a message is displayed and -.Nm cp -skips the other extended attributes for the file. +Extended attributes from all accessible namespaces are copied; +others are ignored. +If an error occurs during this copy, a message is displayed and +.Nm +skips the other extended attributes for that file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Wed Aug 3 12:55:03 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: iExplain what happens to extended attriutes when -p is used. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Wed Aug 3 14:02:59 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: New sentence, new line. Remove trailing whitespace. Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Aug 3 15:44:15 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Adjust wording of previous and fix a couple grammar slipups/typos. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Sun Feb 6 12:37:49 UTC 2011 Modified Files: src/bin/cp: cp.1 cp.c extern.h utils.c Log Message: Add -l option to copy a tree as links. Non-standard option similar to Gnutools cp(1) Approved by core. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/cp.1 cvs rdiff -u -r1.54 -r1.55 src/bin/cp/cp.c cvs rdiff -u -r1.15 -r1.16 src/bin/cp/extern.h cvs rdiff -u -r1.38 -r1.39 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.35 src/bin/cp/cp.1:1.36 --- src/bin/cp/cp.1:1.35 Mon Jan 24 07:22:57 2011 +++ src/bin/cp/cp.1 Sun Feb 6 12:37:48 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.35 2011/01/24 07:22:57 wiz Exp $ +.\ $NetBSD: cp.1,v 1.36 2011/02/06 12:37:48 darcy Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\ .\ @(#)cp.1 8.3 (Berkeley) 4/18/94 .\ -.Dd December 21, 2010 +.Dd February 6, 2010 .Dt CP 1 .Os .Sh NAME @@ -45,7 +45,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl aNpv +.Op Fl alNpv .Ar source_file target_file .Nm cp .Oo @@ -53,7 +53,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl aNpv +.Op Fl alNpv .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the @@ -104,6 +104,9 @@ If the .Fl R option is specified, all symbolic links are followed. +.It Fl l +Create hard links to regular files in a hierarchy instead of copying. +The -l option is expected to behave similar to cp(1) in GNU coreutils. .It Fl N When used with .Fl p , Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.54 src/bin/cp/cp.c:1.55 --- src/bin/cp/cp.c:1.54 Tue Dec 21 20:56:01 2010 +++ src/bin/cp/cp.c Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $ */ +/* $NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = @(#)cp.c 8.5 (Berkeley) 4/29/95; #else -__RCSID($NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $); +__RCSID($NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $); #endif #endif /* not lint */ @@ -86,7 +86,7 @@ PATH_T to = { .p_end = to.p_path, .target_end = empty }; uid_t myuid; -int Hflag, Lflag, Rflag, Pflag, fflag, iflag, pflag, rflag, vflag, Nflag; +int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag; mode_t myumask; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; @@ -106,7 +106,7 @@ (void)setlocale(LC_ALL, ); Hflag = Lflag = Pflag = Rflag = 0; - while ((ch = getopt(argc, argv, HLNPRfaiprv)) != -1) + while ((ch = getopt(argc, argv, HLNPRfailprv)) != -1) switch (ch) { case 'H': Hflag = 1; @@ -140,6 +140,9 @@ iflag = isatty(fileno(stdin)); fflag = 0; break; + case 'l': + lflag = 1; + break; case 'p': pflag = 1; break; Index: src/bin/cp/extern.h diff -u src/bin/cp/extern.h:1.15 src/bin/cp/extern.h:1.16 --- src/bin/cp/extern.h:1.15 Sun Jul 16 16:22:24 2006 +++ src/bin/cp/extern.h Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.15 2006/07/16 16:22:24 jschauma Exp $ */ +/* $NetBSD: extern.h,v 1.16 2011/02/06 12:37:49 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -42,7 +42,7 @@ extern PATH_T to; extern uid_t myuid; -extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, pflag, Nflag; +extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; extern mode_t myumask; #include sys/cdefs.h Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.38 src/bin/cp/utils.c:1.39 --- src/bin/cp/utils.c:1.38 Tue Jan 4 10:35:10 2011 +++ src/bin/cp/utils.c Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $ */ +/* $NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $); +__RCSID($NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $); #endif #endif /* not lint */ @@ -145,11 +145,23 @@ rval = 0; + /* if hard linking then simply close the open fds, link and return */ + if (lflag) { + (void)close(from_fd); + (void)close(to_fd); + (void)unlink(to.p_path); + if (link(entp-fts_path, to.p_path)) { + warn(%s, to.p_path); + return (1); + } + return (0); + } + /* NOTREACHED */ + /* * There's no reason to do anything other than close the file * now if it's empty, so let's not bother. */ - if (fs-st_size 0) { /* * Mmap and write if less than 8M (the limit is so @@ -215,8 +227,9 @@ } } + (void)close(from_fd); + if (rval == 1) { - (void)close(from_fd); (void)close(to_fd);
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Feb 6 12:49:33 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Put -l compatibility note in STANDARDS section. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.36 src/bin/cp/cp.1:1.37 --- src/bin/cp/cp.1:1.36 Sun Feb 6 12:37:48 2011 +++ src/bin/cp/cp.1 Sun Feb 6 12:49:32 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.36 2011/02/06 12:37:48 darcy Exp $ +.\ $NetBSD: cp.1,v 1.37 2011/02/06 12:49:32 wiz Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -106,7 +106,6 @@ option is specified, all symbolic links are followed. .It Fl l Create hard links to regular files in a hierarchy instead of copying. -The -l option is expected to behave similar to cp(1) in GNU coreutils. .It Fl N When used with .Fl p , @@ -226,8 +225,10 @@ .Pp The .Fl a -is a non-standard extension. -It is intended to be compatible with the same option which +and +.Fl l +flags are non-standard extensions. +They are intended to be compatible with the same options which other implementations, namely GNU coreutils and .Fx , of this utility have.
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Sun Feb 6 12:37:49 UTC 2011 Modified Files: src/bin/cp: cp.1 cp.c extern.h utils.c Log Message: Add -l option to copy a tree as links. Non-standard option similar to Gnutools cp(1) Approved by core. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/cp.1 cvs rdiff -u -r1.54 -r1.55 src/bin/cp/cp.c cvs rdiff -u -r1.15 -r1.16 src/bin/cp/extern.h cvs rdiff -u -r1.38 -r1.39 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Feb 6 12:49:33 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Put -l compatibility note in STANDARDS section. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Mon Jan 24 07:22:57 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Use Fx. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.34 src/bin/cp/cp.1:1.35 --- src/bin/cp/cp.1:1.34 Mon Jan 24 02:44:22 2011 +++ src/bin/cp/cp.1 Mon Jan 24 07:22:57 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.34 2011/01/24 02:44:22 yamt Exp $ +.\ $NetBSD: cp.1,v 1.35 2011/01/24 07:22:57 wiz Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -225,7 +225,8 @@ .Fl a is a non-standard extension. It is intended to be compatible with the same option which -other implementations, namely GNU coreutils and FreeBSD, +other implementations, namely GNU coreutils and +.Fx , of this utility have. .Pp The
CVS commit: src/bin/cp
Module Name:src Committed By: yamt Date: Mon Jan 24 02:44:22 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: document what -a is for To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Mon Jan 24 07:22:57 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Use Fx. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Tue Jan 4 10:35:10 UTC 2011 Modified Files: src/bin/cp: utils.c Log Message: Fix fd leak in error case. Found by cppcheck. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/bin/cp
On Tue, 21 Dec 2010, Christos Zoulas wrote: Modified Files: src/bin/cp: cp.1 cp.c utils.c Log Message: Add -a archive flag. from Aleksey Cheusov Please add a note under STANDARDS in the man page saying that -a is non-standard. --apb (Alan Barrett)
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Wed Dec 22 05:46:26 UTC 2010 Modified Files: src/bin/cp: cp.1 Log Message: Say that -a is non-standard and -P is the default. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.31 src/bin/cp/cp.1:1.32 --- src/bin/cp/cp.1:1.31 Tue Dec 21 15:56:01 2010 +++ src/bin/cp/cp.1 Wed Dec 22 00:46:25 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: cp.1,v 1.31 2010/12/21 20:56:01 christos Exp $ +.\ $NetBSD: cp.1,v 1.32 2010/12/22 05:46:25 christos Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -110,6 +110,7 @@ don't copy file flags. .It Fl P No symbolic links are followed. +This is the default. .It Fl p Causes .Nm @@ -219,6 +220,9 @@ utility is expected to be .St -p1003.2 compatible. +The +.Fl a +is a non-standard extension. .Pp The .Fl v
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Tue Dec 21 20:56:01 UTC 2010 Modified Files: src/bin/cp: cp.1 cp.c utils.c Log Message: Add -a archive flag. from Aleksey Cheusov To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/bin/cp/cp.1 cvs rdiff -u -r1.53 -r1.54 src/bin/cp/cp.c cvs rdiff -u -r1.36 -r1.37 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 05:49:11PM +0100, David Laight wrote: No, since in general the file is also being extended (certainly in this case it is) it also has to lock the file size, and that's going to deny stat() until it's done. A stat request during a write can safely return the old size. Yes it can, if it has it. Hence multiversion... -- David A. Holland dholl...@netbsd.org
Re: CVS commit: src/bin/cp
On Sun, Oct 24, 2010 at 10:56:40PM +, David Holland wrote: Anyway, ISTM that writing from the mmap buffer in say 64K chunks would retain nearly all the advantages and get rid of the latency problem. The way the code is currently written it only uses mmap(2) for files smaller than 8MB anyway. Your suggested change would require more work than reducing the size of the mapped memory. There is also the problem that the overhead per call to mmap(2) or munmap(2) is high on some platforms, IIRC alpha is one of them. Changing the code as you suggested above might therefore impact performance on some ports. Kind regards -- Matthias Scheler http://zhadum.org.uk/
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 08:52:43AM +0100, Matthias Scheler wrote: On Sun, Oct 24, 2010 at 10:56:40PM +, David Holland wrote: Anyway, ISTM that writing from the mmap buffer in say 64K chunks would retain nearly all the advantages and get rid of the latency problem. The way the code is currently written it only uses mmap(2) for files smaller than 8MB anyway. Your suggested change would require more work than reducing the size of the mapped memory. Forget that, I misunderstood what you said. We can still use one mmap(2) but should write out that memory with multile write(2) system calls. Kind regards -- Matthias Scheler http://zhadum.org.uk/
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 11:17:22AM +0200, Juergen Hannken-Illjes wrote: On Sun, Oct 24, 2010 at 05:21:06AM +, David Holland wrote: On Fri, Oct 22, 2010 at 05:56:06PM +, Antti Kantee wrote: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to tstile (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. Wouldn't it be better to just ratchet back the block size to something like 64K that happens faster? Or first fault the mapped region instead of madvise() like: Do we implement MADV_WILLNEED? Joerg
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 06:30:54PM +0200, Joerg Sonnenberger wrote: On Mon, Oct 25, 2010 at 11:17:22AM +0200, Juergen Hannken-Illjes wrote: On Sun, Oct 24, 2010 at 05:21:06AM +, David Holland wrote: On Fri, Oct 22, 2010 at 05:56:06PM +, Antti Kantee wrote: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to tstile (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. Wouldn't it be better to just ratchet back the block size to something like 64K that happens faster? Or first fault the mapped region instead of madvise() like: Do we implement MADV_WILLNEED? According to the man page This WILL NOT fault pages in from backing store. -- Juergen Hannken-Illjes - hann...@eis.cs.tu-bs.de - TU Braunschweig (Germany)
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 11:17:22AM +0200, Juergen Hannken-Illjes wrote: On Sun, Oct 24, 2010 at 05:21:06AM +, David Holland wrote: On Fri, Oct 22, 2010 at 05:56:06PM +, Antti Kantee wrote: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to tstile (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. Wouldn't it be better to just ratchet back the block size to something like 64K that happens faster? Or first fault the mapped region instead of madvise() like: int pgsz = getpagesize(); char *q; volatile char c; for (q = p; q p+fs-st_size; q += pgsz) c = *q; That won't really help - the pages could easily be discarded almost immediately - eg in order to fault in a later page. David -- David Laight: da...@l8s.co.uk
Re: CVS commit: src/bin/cp
On Sun, Oct 24, 2010 at 10:56:40PM +, David Holland wrote: I think write() only needs to lock the the file enough to ensure that the file offset is correct. No, since in general the file is also being extended (certainly in this case it is) it also has to lock the file size, and that's going to deny stat() until it's done. A stat request during a write can safely return the old size. David -- David Laight: da...@l8s.co.uk
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 06:41:11PM +0200, Juergen Hannken-Illjes wrote: Do we implement MADV_WILLNEED? According to the man page This WILL NOT fault pages in from backing store. The version of the man page I have says It might or might not fault pages in from backing store. Joerg
re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 08:52:43AM +0100, Matthias Scheler wrote: On Sun, Oct 24, 2010 at 10:56:40PM +, David Holland wrote: Anyway, ISTM that writing from the mmap buffer in say 64K chunks would retain nearly all the advantages and get rid of the latency problem. The way the code is currently written it only uses mmap(2) for files smaller than 8MB anyway. Your suggested change would require more work than reducing the size of the mapped memory. Forget that, I misunderstood what you said. We can still use one mmap(2) but should write out that memory with multile write(2) system calls. FWIW, bozohttpd defaults to mapping upto 64MB regions and writing out up to 64KB at a time. .mrg.
Re: CVS commit: src/bin/cp
On Mon, Oct 25, 2010 at 06:46:36PM +0200, Joerg Sonnenberger wrote: On Mon, Oct 25, 2010 at 06:41:11PM +0200, Juergen Hannken-Illjes wrote: Do we implement MADV_WILLNEED? According to the man page This WILL NOT fault pages in from backing store. The version of the man page I have says It might or might not fault pages in from backing store. Mine was 5.0.2, yours looks more -current :-) -- Juergen Hannken-Illjes - hann...@eis.cs.tu-bs.de - TU Braunschweig (Germany)
Re: CVS commit: src/bin/cp
On Tue, Oct 26, 2010 at 05:05:28AM +1100, matthew green wrote: On Mon, Oct 25, 2010 at 08:52:43AM +0100, Matthias Scheler wrote: On Sun, Oct 24, 2010 at 10:56:40PM +, David Holland wrote: Anyway, ISTM that writing from the mmap buffer in say 64K chunks would retain nearly all the advantages and get rid of the latency problem. The way the code is currently written it only uses mmap(2) for files smaller than 8MB anyway. Your suggested change would require more work than reducing the size of the mapped memory. Forget that, I misunderstood what you said. We can still use one mmap(2) but should write out that memory with multile write(2) system calls. FWIW, bozohttpd defaults to mapping upto 64MB regions and writing out up to 64KB at a time. cp(1) now maps a region upto 8MB and writes it out in chunks of at most 64KB. Kind regards -- Matthias Scheler http://zhadum.org.uk/
CVS commit: src/bin/cp
Module Name:src Committed By: tron Date: Mon Oct 25 08:19:47 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Re-enable support for reading files smaller of at most 8MB via mmap(2). Write out the mmap-ed data in small chunks to avoid locking the output file for a long time. Suggested by David Holland on source-changes-d mailing list. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.35 src/bin/cp/utils.c:1.36 --- src/bin/cp/utils.c:1.35 Fri Oct 22 17:56:06 2010 +++ src/bin/cp/utils.c Mon Oct 25 08:19:47 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $ */ +/* $NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $); +__RCSID($NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $); #endif #endif /* not lint */ @@ -47,6 +47,7 @@ #include errno.h #include fcntl.h #include fts.h +#include stdbool.h #include stdio.h #include stdlib.h #include string.h @@ -54,6 +55,9 @@ #include extern.h +#define MMAP_MAX_SIZE (8 * 1048576) +#define MMAP_MAX_WRITE (64 * 1024) + int set_utimes(const char *file, struct stat *fs) { @@ -75,6 +79,7 @@ static char buf[MAXBSIZE]; struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; + char *p; if ((from_fd = open(entp-fts_path, O_RDONLY, 0)) == -1) { warn(%s, entp-fts_path); @@ -145,47 +150,55 @@ */ if (fs-st_size 0) { - - /* - * Disable use of mmap. With the current vnode locking - * scheme it has a very annoying property: if the source - * media is slow (like a slow network), the target file - * will be locked for the duration of the entire max 8MB - * write and cause processes attempting to e.g. stat() it - * to tstile. Revisit when vnode locking gets a little - * smarter. - */ -#ifdef VNODE_LOCKING_IS_SMARTER_NOW /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). * This is really a minor hack, but it wins some CPU back. */ + bool use_read; - if (fs-st_size = 8 * 1048576) { + use_read = true; + if (fs-st_size = MMAP_MAX_SIZE) { size_t fsize = (size_t)fs-st_size; - char *p; - p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, from_fd, (off_t)0); - if (p == MAP_FAILED) { -goto mmap_failed; - } else { + if (p != MAP_FAILED) { +size_t remainder; + +use_read = false; + (void) madvise(p, (size_t)fs-st_size, MADV_SEQUENTIAL); -if (write(to_fd, p, fsize) != -fs-st_size) { - warn(%s, to.p_path); - rval = 1; -} + +/* + * Write out the data in small chunks to + * avoid locking the output file for a + * long time if the reading the data from + * the source is slow. + */ +remainder = fsize; +do { + ssize_t chunk; + + chunk = (remainder MMAP_MAX_WRITE) ? + MMAP_MAX_WRITE : remainder; + if (write(to_fd, p[fsize - remainder], + chunk) != chunk) { + warn(%s, to.p_path); + rval = 1; + break; + } + remainder -= chunk; +} while (remainder 0); + if (munmap(p, fsize) 0) { warn(%s, entp-fts_path); rval = 1; } } - } else { -mmap_failed: -#endif + } + + if (use_read) { while ((rcount = read(from_fd, buf, MAXBSIZE)) 0) { wcount = write(to_fd, buf, (size_t)rcount); if (rcount != wcount || wcount == -1) { @@ -198,9 +211,7 @@ warn(%s, entp-fts_path); rval = 1; } -#ifdef VNODE_LOCKING_IS_SMARTER_NOW } -#endif } if (rval == 1) {
CVS commit: src/bin/cp
Module Name:src Committed By: tron Date: Mon Oct 25 08:19:47 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Re-enable support for reading files smaller of at most 8MB via mmap(2). Write out the mmap-ed data in small chunks to avoid locking the output file for a long time. Suggested by David Holland on source-changes-d mailing list. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/bin/cp
(adding tech-kern because this seems likely to become lengthy; if following up please drop source-changes-d) On Sun, Oct 24, 2010 at 11:30:43AM +0100, David Laight wrote: [mmap mode disabled in cp due to long vnode lock waits] Because individual write() calls are supposed to be atomic, I don't think there is such a thing as a locking improvement that'll help with this behavior. :-/ I think write() only needs to lock the the file enough to ensure that the file offset is correct. No, since in general the file is also being extended (certainly in this case it is) it also has to lock the file size, and that's going to deny stat() until it's done. Possibly the written range needs locking against other accesses - but I think the app is supposed to use file locking for that No, the reason single syscalls are atomic is specifically so apps don't have to use file locking for simple cases, like e.g. writing lines to log files. (and mmap will always be non-atomic w.r.t. write). Yes, but the mmap in this case is for reading. (what the code in cp does is map the source and then write to the destination file from the mapped region) Actually if 2 writes are issued for the same part of a file, the kernel can act as if they were requested in either order - since the app(s) cannot know the order the calls would be made in! As long as nothing else happens in between that establishes an ordering, yes. Which means it could just sleep the 2nd write until the first terminates! Yes indeed, that's what locks do :-) Writes with O_APPEND (and writes that extend the file) are more problematical since you cant allow a second such write to start until the first has completed - for instance it might try to read from an unmapped user-space address and return a short length. Right. Except I guess going to some kind of multiversion model for vnodes. Don't you just need 2 locks? One for locking the data areas, and the other for the file data itself. Nope. Or at least, that doesn't fix the objectionable behavior. Because you need to lock the file size, if you want stat() to be able to complete while the operation is in progress you need to be able to let stat() read a version of the file size from before the operation began. One can do multiversion schemes in the kernel; apparently it's neither as ghastly or as expensive as one would think. See for example the transactional Linux paper from SOSP 2009. But it'd be a pretty big hacking job to do it in NetBSD. Anyway, ISTM that writing from the mmap buffer in say 64K chunks would retain nearly all the advantages and get rid of the latency problem. -- David A. Holland dholl...@netbsd.org
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Fri Oct 22 17:56:06 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to tstile (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. chs ok (although he would rather see vnode locking improvements, but that's a slightly larger project) To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.34 src/bin/cp/utils.c:1.35 --- src/bin/cp/utils.c:1.34 Fri Oct 26 16:21:25 2007 +++ src/bin/cp/utils.c Fri Oct 22 17:56:06 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.34 2007/10/26 16:21:25 hira Exp $ */ +/* $NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = @(#)utils.c 8.3 (Berkeley) 4/1/94; #else -__RCSID($NetBSD: utils.c,v 1.34 2007/10/26 16:21:25 hira Exp $); +__RCSID($NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $); #endif #endif /* not lint */ @@ -75,7 +75,6 @@ static char buf[MAXBSIZE]; struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; - char *p; if ((from_fd = open(entp-fts_path, O_RDONLY, 0)) == -1) { warn(%s, entp-fts_path); @@ -147,6 +146,16 @@ if (fs-st_size 0) { + /* + * Disable use of mmap. With the current vnode locking + * scheme it has a very annoying property: if the source + * media is slow (like a slow network), the target file + * will be locked for the duration of the entire max 8MB + * write and cause processes attempting to e.g. stat() it + * to tstile. Revisit when vnode locking gets a little + * smarter. + */ +#ifdef VNODE_LOCKING_IS_SMARTER_NOW /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). @@ -155,6 +164,8 @@ if (fs-st_size = 8 * 1048576) { size_t fsize = (size_t)fs-st_size; + char *p; + p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, from_fd, (off_t)0); if (p == MAP_FAILED) { @@ -174,6 +185,7 @@ } } else { mmap_failed: +#endif while ((rcount = read(from_fd, buf, MAXBSIZE)) 0) { wcount = write(to_fd, buf, (size_t)rcount); if (rcount != wcount || wcount == -1) { @@ -186,7 +198,9 @@ warn(%s, entp-fts_path); rval = 1; } +#ifdef VNODE_LOCKING_IS_SMARTER_NOW } +#endif } if (rval == 1) {
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Fri Oct 22 17:56:06 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to tstile (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. chs ok (although he would rather see vnode locking improvements, but that's a slightly larger project) To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Thu Oct 8 20:36:41 UTC 2009 Modified Files: src/bin/cp: cp.c Log Message: Fix the dne handling and chmod behaviour properly: values of dne need to be on a stack instead of being a single variable since directories are processed depth-first. Otherwise dne randomly depends on the previously processed entry. This fixes both chmod of non-created directories (they used to be chmod'd even when not created if their last child element did not exist in the target subtree) and a foo exists bug exposed by my last commit which removed directory sorting. all regression tests passed To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.52 src/bin/cp/cp.c:1.53 --- src/bin/cp/cp.c:1.52 Tue Sep 29 13:30:17 2009 +++ src/bin/cp/cp.c Thu Oct 8 20:36:41 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $ */ +/* $NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = @(#)cp.c 8.5 (Berkeley) 4/29/95; #else -__RCSID($NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $); +__RCSID($NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $); #endif #endif /* not lint */ @@ -65,6 +65,7 @@ #include sys/param.h #include sys/stat.h +#include assert.h #include err.h #include errno.h #include fts.h @@ -280,6 +281,26 @@ /* NOTREACHED */ } +static int dnestack[MAXPATHLEN]; /* unlikely we'll have more nested dirs */ +static ssize_t dnesp; +static void +pushdne(int dne) +{ + + dnestack[dnesp++] = dne; + assert(dnesp MAXPATHLEN); +} + +static int +popdne(void) +{ + int rv; + + rv = dnestack[--dnesp]; + assert(dnesp = 0); + return rv; +} + int copy(char *argv[], enum op type, int fts_options) { @@ -291,7 +312,6 @@ size_t nlen; char *p, *target_mid; - dne = 0; base = 0; /* XXX gcc -Wuninitialized (see comment below) */ if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL) @@ -398,8 +418,7 @@ this_failed = any_failed = 1; continue; } - if (!S_ISDIR(curr-fts_statp-st_mode)) -dne = 0; + dne = 0; } switch (curr-fts_statp-st_mode S_IFMT) { @@ -439,6 +458,7 @@ * 555) and not causing a permissions race. If the * umask blocks owner writes, we fail.. */ +pushdne(dne); if (dne) { if (mkdir(to.p_path, curr-fts_statp-st_mode | S_IRWXU) 0) @@ -462,16 +482,9 @@ */ if (pflag setfile(curr-fts_statp, 0)) this_failed = any_failed = 1; -else if (dne) +else if ((dne = popdne())) (void)chmod(to.p_path, curr-fts_statp-st_mode); - -/* - * Since this is the second pass, we already - * noted (and acted on) the existence of the - * directory. - */ -dne = 0; } else {
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Tue Sep 29 13:30:17 UTC 2009 Modified Files: src/bin/cp: cp.c Log Message: Remove fts sorting. It was originally put there to copy files before directories since files (usually) are in the same cylinder group and subdirectories aren't. However, this mostly changed with the new ffs dirpref algorithm in 2001. No sorting has two effects: 1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build objdir to tmpfs is 7% faster after the change) 2) source file parameters no longer get randomly shuffled due to fts doing an unstable sort of them. this means that cp 1 2 3 4 dest/ will copy the files in that order instead of e.g. 3 4 1 2. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.51 src/bin/cp/cp.c:1.52 --- src/bin/cp/cp.c:1.51 Sun Jul 20 00:52:39 2008 +++ src/bin/cp/cp.c Tue Sep 29 13:30:17 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $ */ +/* $NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = @(#)cp.c 8.5 (Berkeley) 4/29/95; #else -__RCSID($NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $); +__RCSID($NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $); #endif #endif /* not lint */ @@ -92,7 +92,6 @@ int main(int, char *[]); int copy(char *[], enum op, int); -int mastercmp(const FTSENT **, const FTSENT **); int main(int argc, char *argv[]) @@ -295,7 +294,7 @@ dne = 0; base = 0; /* XXX gcc -Wuninitialized (see comment below) */ - if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) + if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL) err(EXIT_FAILURE, %s, argv[0]); /* NOTREACHED */ for (any_failed = 0; (curr = fts_read(ftsp)) != NULL;) { @@ -515,29 +514,3 @@ (void)fts_close(ftsp); return (any_failed); } - -/* - * mastercmp -- - * The comparison function for the copy order. The order is to copy - * non-directory files before directory files. The reason for this - * is because files tend to be in the same cylinder group as their - * parent directory, whereas directories tend not to be. Copying the - * files first reduces seeking. - */ -int -mastercmp(const FTSENT **a, const FTSENT **b) -{ - int a_info, b_info; - - a_info = (*a)-fts_info; - if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR) - return (0); - b_info = (*b)-fts_info; - if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR) - return (0); - if (a_info == FTS_D) - return (-1); - if (b_info == FTS_D) - return (1); - return (0); -}