History log of /src/bin/cp/utils.c (Results 1 – 25 of 346)
Revision Date Author Comments
# 7aa30669 11-Feb-2026 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Expect EINTR while copying

Both copy_file_range() and copy_fallback() can be interrupted before
they have read anything at all, in which case they return -1 and set
errno to EINTR. If that happ

cp: Expect EINTR while copying

Both copy_file_range() and copy_fallback() can be interrupted before
they have read anything at all, in which case they return -1 and set
errno to EINTR. If that happens, we should retry, not fail.

PR: 293028
MFC after: 1 week
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D55167

show more ...


# c3efa16d 09-Jul-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Add GNU-compatible long options.

While here, fully switch boolean variables from int to bool, and clean
up the manual page a little.

Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential R

cp: Add GNU-compatible long options.

While here, fully switch boolean variables from int to bool, and clean
up the manual page a little.

Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D51213

show more ...


# 0e0df1fc 23-Jun-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Fix improper use of O_PATH.

This does not appear to make any practical difference at the moment, but
technically `O_PATH` means “I'm not going to use this descriptor for any
other purposes than

cp: Fix improper use of O_PATH.

This does not appear to make any practical difference at the moment, but
technically `O_PATH` means “I'm not going to use this descriptor for any
other purposes than vnode lookups”, so using it to read the directory's
ACLs is improper and might fail in the future.

Fixes: 82fc0d09e8625
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D50984

show more ...


# b3fe9014 15-May-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Avoid prepending ./ in file-to-file case.

* Make to.base large enough to hold a trailing separator.
* Remove the separator from warning and error messages.
* In the FILE_TO_FILE case, leave to.b

cp: Avoid prepending ./ in file-to-file case.

* Make to.base large enough to hold a trailing separator.
* Remove the separator from warning and error messages.
* In the FILE_TO_FILE case, leave to.base empty.
* In the FILE_TO_DIR and DIR_TO_DNE cases, append a separator to
to.base once we've (optionally created and) opened it.
* Thus, in the file-to-file case, we print an empty string followed by
to.path, while in all other cases, to.base already contains the
necessary separator.

This fixes failures in tests that used cp and expected a specific
error message and were surprised to see "./" pop up.

Fixes: 82fc0d09e862
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D50357

show more ...


# 82fc0d09 06-May-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Partly restore symlink folllowing.

* As a general rule, follow symbolic links in the destination as long
as the target is within the destination hierarchy.
* As a special case, allow the desti

cp: Partly restore symlink folllowing.

* As a general rule, follow symbolic links in the destination as long
as the target is within the destination hierarchy.
* As a special case, allow the destination itself to be a symbolic
link, and even a dead one (in which case we create the target).
* The file-to-file case remains unrestricted.

Currently, if a symlink we aren't allowed to follow is encountered,
cp will behave just like it would if the file was not writable. We
should consider whether it would be better to replace the offending
link instead.

Fixes: 0729d1e8fd90
MFC after: never
Relnotes: yes
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D50093

show more ...


# 3d7c8f08 16-May-2024 Pierre Pronchery <pierre@freebsdfoundation.org>

cp: avoid a resource leak

In copy_file(), make sure the from_fd file descriptor is closed even
when the operation failed early.

Reported by: Coverity Scan
CID: 1545036
Sponsored by: The FreeBSD Fo

cp: avoid a resource leak

In copy_file(), make sure the from_fd file descriptor is closed even
when the operation failed early.

Reported by: Coverity Scan
CID: 1545036
Sponsored by: The FreeBSD Foundation

Reviewed by: imp, emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/1238

show more ...


# 9075d4cf 17-Apr-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Additional sanity check.

Once we've successfully opened the file we've been asked to copy, check
that it's of the same type as FTS told us it was.

MFC after: 1 week
Sponsored by: Klara, Inc.
Re

cp: Additional sanity check.

Once we've successfully opened the file we've been asked to copy, check
that it's of the same type as FTS told us it was.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude, markj
Differential Revision: https://reviews.freebsd.org/D44806

show more ...


# 8b864151 13-Feb-2024 Collin Funk <collin.funk1@gmail.com>

cp: Remove useless ssize_t cast

Both wcount and wresid are ssize_t so this cast is not needed. Just
remove it so the code is easier to read.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Revi

cp: Remove useless ssize_t cast

Both wcount and wresid are ssize_t so this cast is not needed. Just
remove it so the code is easier to read.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Reviewed by: emaste, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/1116

show more ...


# 38509270 14-Dec-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Further simplify the core logic.

If the destination file exists but we decide unlink it, set the dne
flag. This means we don't need to re-check the conditions that would
have caused us to delet

cp: Further simplify the core logic.

If the destination file exists but we decide unlink it, set the dne
flag. This means we don't need to re-check the conditions that would
have caused us to delete the file when we later need to decide whether
to create or replace it.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43064

show more ...


# d002316f 13-Dec-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Refactor the core logic.

Rewrite `copy_file()` so the lflag and sflag are handled as early as
possible instead of constantly checking that they're not set and then
handling them at the end. Thi

cp: Refactor the core logic.

Rewrite `copy_file()` so the lflag and sflag are handled as early as
possible instead of constantly checking that they're not set and then
handling them at the end. This also opens the door to changing the
failure logic at some future point (for instance, we might decide to
fall back to copying if `errno` indicates that the file system does not
support links).

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43055

show more ...


# 3e7e3b5b 07-Dec-2023 Warner Losh <imp@FreeBSD.org>

cp: Don't warn for chflags() failing with EOPNOTSUPP if flags == 0

From NetBSD's utils.c 1.5 importing importing BSDI change, with light
formatting changes:
Author: cgd <cgd@NetBSD.org>
Date

cp: Don't warn for chflags() failing with EOPNOTSUPP if flags == 0

From NetBSD's utils.c 1.5 importing importing BSDI change, with light
formatting changes:
Author: cgd <cgd@NetBSD.org>
Date: Wed Feb 26 14:40:51 1997 +0000

Patch from BSDI (via Keith Bostic):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)

CVS Info: utils.c 1.6

Obtained from: NetBSD
Sponsored by: Netflix

Differential Revision: https://reviews.freebsd.org/D42674

show more ...


# 5a52e3d0 07-Dec-2023 Warner Losh <imp@FreeBSD.org>

cp: Add -N flag, inspired by NetBSD's similar flag

Add -N to supress copying of file flags when -p is specified (explicitly
or implicitly). Often times we don't care about the flags or wish to be
ab

cp: Add -N flag, inspired by NetBSD's similar flag

Add -N to supress copying of file flags when -p is specified (explicitly
or implicitly). Often times we don't care about the flags or wish to be
able to copy to NFS, and this comes in handy for that. FreeBSD's and
NetBSD's cp are somewhat different, so I had to reimplement all but one
of the patch hunks...

Obtained from: NetBSD (cp.1 1.25, cp.c 1.37, utils.c 1.28 by elad)
Sponsored by: Netflix

Differential Revision: https://reviews.freebsd.org/D42673

show more ...


# e043f372 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remov

bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix

show more ...


# 90aea514 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl s

bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# c5b5f2d8 24-Apr-2023 Mateusz Guzik <mjg@FreeBSD.org>

cp: Revert "If copy_file_range(2) fails with EXDEV, use fall-back."

This reverts commit 64333654908153cd8e2dcb408c57cc3e3c4f29af.

The error is not valid per api contract, it showed up as a regressi

cp: Revert "If copy_file_range(2) fails with EXDEV, use fall-back."

This reverts commit 64333654908153cd8e2dcb408c57cc3e3c4f29af.

The error is not valid per api contract, it showed up as a regression
after 15f0b8c309dea1dcb14d3e374686576ff68ac43f

15f0b8c309dea1dc ("zfs: merge openzfs/zfs@9cd71c860 (master)") and was
subsequently in d012836fb6165494 ("zfs: fix up EXDEV handling for
clone_range").

Sponsored by: Rubicon Communications, LLC ("Netgate")

show more ...


# 64333654 04-Apr-2023 Poul-Henning Kamp <phk@FreeBSD.org>

If copy_file_range(2) fails with EXDEV, use fall-back.


# cb96a0ef 03-Feb-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Minor code cleanup.

* Fix includes in utils.c, cf. style(9).
* Fix type mismatch: readlink(2) returns ssize_t, not int.
* It is not necessary to set errno to 0 as fts_read(3) already does it.

M

cp: Minor code cleanup.

* Fix includes in utils.c, cf. style(9).
* Fix type mismatch: readlink(2) returns ssize_t, not int.
* It is not necessary to set errno to 0 as fts_read(3) already does it.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D38369

show more ...


# 6c85042a 01-Feb-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Simplify the common case.

* The allocated buffer is only used in the fallback case, so move it
there. The argument for passing it in from the caller was that if
malloc(3) were to fail, we'd

cp: Simplify the common case.

* The allocated buffer is only used in the fallback case, so move it
there. The argument for passing it in from the caller was that if
malloc(3) were to fail, we'd want it to fail before we started
copying anything, but firstly, it was already not in the right place
to ensure that, and secondly, malloc(3) never fails (except in very
contrived circumstances, such as an unreasonable RLIMIT_AS or
RLIMIT_DATA).

* Remove the mmap(2) option. It is almost never beneficial,
especially when the alternative is copy_file_range(2), and it adds
needless complexity and indentation.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: rmacklem, mav
Differential Revision: https://reviews.freebsd.org/D38291

show more ...


# 35b7759c 30-Aug-2022 Alexander Motin <mav@FreeBSD.org>

cp: Fix build without VM_AND_BUFFER_CACHE_SYNCHRONIZED.

It allows to not use mmap() for small files, which is not helpful
in case of ZFS. Should be no functional change.

MFC after: 1 week


# 45b252fc 26-Jan-2021 Baptiste Daroussin <bapt@FreeBSD.org>

cp: fix indentation

No functional changes


# c98a764c 03-Jan-2021 Rick Macklem <rmacklem@FreeBSD.org>

cp(1): fix performance issue for large non-sparse file copies

PR252358 reported a serious performance problem when
copying a large non-sparse file on a UFS file system.
This problem seems to have be

cp(1): fix performance issue for large non-sparse file copies

PR252358 reported a serious performance problem when
copying a large non-sparse file on a UFS file system.
This problem seems to have been caused by a large
number of SEEK_HOLE operations, with one done
for each copy_file_range(2) call.

This patch modifies cp(1) to use a large (SSIZE_MAX)
len argument, reducing the number of system calls
and resolving the performance issue.

While here, convert the type of the "rcount" from "int"
to "ssize_t" so that it is consistent with that returned
by both read(2) and copy_file_range(2).

PR: 252358
Reviewed by: asomers
Differential Revision: https://reviews.freebsd.org/D27937

show more ...


# 1ea95ba2 11-Sep-2020 Alan Somers <asomers@FreeBSD.org>

cp: fall back to read/write if copy_file_range fails

Even though copy_file_range has a file-system agnostic version, it still
fails on devfs (perhaps because the file descriptor is non-seekable?) In

cp: fall back to read/write if copy_file_range fails

Even though copy_file_range has a file-system agnostic version, it still
fails on devfs (perhaps because the file descriptor is non-seekable?) In
that case, fallback to old-fashioned read/write. Fixes
"cp /dev/null /tmp/null"

PR: 249248
Reported by: Michael Butler
Reviewed by: mjg
MFC-With: 365549
Differential Revision: https://reviews.freebsd.org/D26395

show more ...


# c01816a9 10-Sep-2020 Alan Somers <asomers@FreeBSD.org>

cp: use copy_file_range(2)

This has three advantages over write(2)/read(2):

* Fewer context switches and data copies
* Mostly preserves a file's sparseness
* On some file systems (currently NFS 4.2

cp: use copy_file_range(2)

This has three advantages over write(2)/read(2):

* Fewer context switches and data copies
* Mostly preserves a file's sparseness
* On some file systems (currently NFS 4.2) the file system will perform the
copy in an especially efficient way.

Reviewed by: rmacklem
MFC after: 2 weeks
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D26377

show more ...


# c3efa16d 09-Jul-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

cp: Add GNU-compatible long options.

While here, fully switch boolean variables from int to bool, and clean
up the manual page a little.

Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential R

cp: Add GNU-compatible long options.

While here, fully switch boolean variables from int to bool, and clean
up the manual page a little.

Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D51213

show more ...


12345678910>>...14