Commit Graph

70 Commits

Author SHA1 Message Date
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Bryan Drewery
724fd44827 Cleanup some style(9) issues.
- Whitespace.
- Comments.
- Wrap long lines.

MFC after:	2 weeks
X-MFC-with:	r284105,r284106
Sponsored by:	EMC / Isilon Storage Division
2015-06-08 19:24:18 +00:00
Bryan Drewery
7ea2450f42 Implement '-s' to copy as symlink, similar to the current -l link(2) handling.
This is also implemented in at least GNU coreutils cp.

While here also improve the '-l' handling to not open(2) the source file as
it does not actually need the descriptor.

Sponsored by:	EMC / Isilon Storage Division
2015-06-07 06:30:25 +00:00
Bryan Drewery
14376e1f21 Cleanup some indentation issues. 2015-06-07 03:49:41 +00:00
Jilles Tjoelker
347b9f6de0 cp,mv: Use futimens() instead of utimensat() if possible. 2015-03-23 17:35:05 +00:00
Jilles Tjoelker
5faf2ae160 cp,mv,touch: Set timestamps with nanosecond precision.
This uses utimensat().
2015-01-24 13:50:13 +00:00
Mark Johnston
111a5d7c78 Return with an error from copy_link(), copy_fifo() and copy_special() if
the -n option is specified and the destination file exists.

PR:		bin/174489
Approved by:	rstone (co-mentor)
MFC after:	2 weeks
2013-01-27 05:59:28 +00:00
David E. O'Brien
e4573a9a7b Return "failure" as we do for 'cp -i' and a "n" answer.
Otherwise with '-v' we print out the file name as if it was copied:
   /tmp/2gb-card/M0132.CTG not overwritten
   /mnt/DCIM/CANONMSC/M0132.CTG -> /tmp/2gb-card/M0132.CTG
2013-01-23 02:06:20 +00:00
Ed Schouten
99742a231f Change all our own code to use st_*tim instead of st_*timespec.
Also remove some local patches to diff(1) which are now unneeded.
2010-03-28 13:16:08 +00:00
Gavin Atkinson
f815125fbc Implement an "-x" option to cp(1), for compatibility with Linux and
feature parity with du(1) and similar:  When set, cp(1) will not traverse
mount points.

Initial patch by:       Graham J Lee   leeg teaching.physics.ox.ac.uk

PR:		bin/88056
Initial patch by: Graham J Lee   leeg teaching.physics.ox.ac.uk
Approved by:	ed (mentor)
MFC after:	1 month
2010-01-17 09:37:31 +00:00
Edward Tomasz Napierala
2689ba2720 Add NFSv4 ACL support to cp(1) and fix a few memory leaks.
Note that this changes error reporting behaviour somewhat - before,
no error was reported if ACL couldn't be copied because the target
filesystem doesn't support ACLs.  Now, it will be reported - of course,
only if there actually is an ACL to copy.

Reviewed by:	rwatson
2009-09-02 08:08:57 +00:00
Jilles Tjoelker
f2db75739c Preserve file flags on symlinks in cp -Rp.
This reported ENOSYS before.

PR:		bin/111226 (part of)
Submitted by:	Martin Kammerhofer
Approved by:	ed (mentor)
MFC after:	3 weeks
2009-05-30 10:36:14 +00:00
Ivan Voras
e9cbc9a770 Teach cat(1) and cp(1) to use a larger buffer if enough memory is present
in the system. A simple heuristics is used to detect what is "enough"
memory: if number of physmem pages is greater than 32k (equalling 128 MB
on machines with 4 kB pages).

Typical immediate result of these changes is reduction in context switches
and the goal is to increase efficiency by using large buffers:
before: /usr/bin/time -hlp cat file1 > file2
...
       163  voluntary context switches
     11194  involuntary context switches
after: /usr/bin/time -hlp ./cat file1 > file2
...
       417  voluntary context switches
       272  involuntary context switches

Reviewed by:    hackers@ (no objections to earlier version of cat patch)
Approved by:    gnn (mentor)
MFC after:      4 months
2008-10-30 14:05:57 +00:00
Diomidis Spinellis
cce2092c73 Add fallback when mmap fails on regular files. Some filesystems,
like smbnetfs, do not support mmap.

Reported by:	Harti Brandt
MFC after:	1 month
2008-10-27 15:21:15 +00:00
Edward Tomasz Napierala
70583fbb77 Remove redundant close(2).
Submitted by:	kensmith
Approved by:	rwatson (mentor)
2008-09-09 12:31:42 +00:00
Edward Tomasz Napierala
2aafc4d48c Fix ACL preservation, apparently broken in 1.47.
Approved by:	rwatson
MFC after:	3 weeks
2008-08-07 07:29:26 +00:00
John Baldwin
d140946cf3 Add an '-a' option which is identical to specifying '-RpP' for
compatibility with other implementations.

MFC after:	1 month
2008-03-10 19:58:41 +00:00
Maxim Konovalov
9bdb7f2e54 o Style(9).
Submitted by:	bde
2006-10-07 12:14:50 +00:00
Maxim Konovalov
eb82e1a1f8 o Avoid division by zero.
o Place error checking code near to the syscall.

Submitted by:	bde
2006-10-07 12:11:21 +00:00
Maxim Konovalov
6a861e9bfb o Hold copied bytes counter in off_t. This prevents statistics
displayed by SIGINFO handler from overflow.

PR:		bin/104039
Submitted by:	Geoffrey Giesemann
MFC after:	2 weeks
2006-10-06 08:30:33 +00:00
Ruslan Ermilov
cbae88b901 - Fix options order.
- Touch manpage's document date.
2006-08-25 09:58:13 +00:00
Ruslan Ermilov
d9c7237d04 Remove a stray -a option that probably sneaked in from julian's
attempt to enter append mode twice in vi(1).  :-)
2006-08-25 09:42:16 +00:00
Julian Elischer
6fa363774d Add an option to allow copying of a hierarchy while linking he regular files.
Bikeshedded to death on: hackers
Submitted by:andersonatcenttech.com
MFC in: 1 month
2006-08-24 20:45:38 +00:00
Christian S.J. Peron
9b4261c9b4 Attempt to complete the userspace integration of POSIX.1e extended ACLs.
This includes adding support for ACLs into cp(1) and mv(1) userspace
utilities.

For mv(1), if _PC_ACL_EXTENDED is in effect for the source AND destination
operands, the destination file's ACLs shall reflect the source.

For cp(1), if _PC_ACL_EXTENDED is in effect for both source and destination
operands, and -p has been specified, the ACLs from the source shall be
preserved on the destination.

MFC after:	1 month
2005-09-05 04:36:08 +00:00
Ruslan Ermilov
a89237ae95 Sync program's usage() with manpage's SYNOPSIS. 2005-02-09 17:37:39 +00:00
Tim J. Robbins
7807cb2439 Plug file descriptor leak in implementation of -n option. 2004-06-05 02:32:21 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Alan Cox
b9e25f436b Don't mmap(2) and munmap(2) zero-length files.
Submitted by:	Wiktor Niesiobedzki <bsd@w.evip.pl>
2003-11-13 05:26:55 +00:00
John-Mark Gurney
a6b05ab6ea support saving both user/group and permissions on symlinks (from PR)
also fix a slight bogon that assumed an fd of 0 was not valid.  Changed
it to be -1.

PR:		bin/25017
Submitted by:	Martin Kammerhofer
2003-06-22 07:02:17 +00:00
Matthew N. Dodd
00d321a2b3 Add a SIGINFO handler. 2003-04-07 11:00:56 +00:00
Mark Murray
ba8acd9de2 Constify and staticify for lint. 2002-10-18 14:45:00 +00:00
Mark Murray
13fcef50d0 Fix some easy WARNS. 2002-07-31 16:52:16 +00:00
Johan Karlsson
786c276fe4 Add the -n option, which automatically answers "no" to the overwrite question.
PR:		7828
Suggested by:	Daniel O'Connor <doconnor@gsoft.com.au>
Approved by:	sheldonh (mentor)
MFC after:	2 weeks
2002-07-23 00:42:56 +00:00
Mark Murray
7ede89e44b Fix some low-hanging lint-fruit: endianness and staticness warnings. 2002-07-03 16:35:20 +00:00
David E. O'Brien
5eb43ac2f7 Consistently use __FBSDID 2002-06-30 05:13:54 +00:00
Mark Murray
8bd08b5fac Fix warnings inspired by lint, a commercial lint and WARNS=4. 2002-02-22 21:24:14 +00:00
Warner Losh
5dce647c1b Modernization effort for bin/c*:
o __P has been reoved
  o Old-style K&R declarations have been converted to new C89 style
  o register has been removed
  o prototype for main() has been removed (gcc3 makes it an error)
  o int main(int argc, char *argv[]) is the preferred main definition.
  o Attempt to not break style(9) conformance for declarations more than
    they already are.

  Approved by: arch@, new style(9)
2002-02-02 06:15:22 +00:00
Stephen McKay
048e497627 Typo in warning message (chown should be chmod). 2001-12-11 13:14:15 +00:00
Dag-Erling Smørgrav
26f6b0fbe8 Add more headers that are required with -fno-builtin (stdlib and strings) 2001-06-19 15:41:57 +00:00
Bruce Evans
e1d071dbfd Removed the broken code which claimed to lose the set[ug]id bits in
the !(pflag && setfile()) case for regular files unless the copy is
owned by the same user and group.  These bits have already been lost
(or never gained) in the correct way.  The code didn't actually lose
the bits; it depended on them being lost already (apparently in all
cases) and attempted to gain them as necessary, but it often gained
them (and sometimes collateral bits) when wrong:
- pflag && setfile() == 0 case (i.e., for a successful cp -p):
  setfile() copies all the attributes as correctly as possible (as
  specified by POSIX), and we sometimes messed up the up the mode by
  setting it again.  Also, if the file is immutable, then setting the
  mode again gave spurious errors (PR 20646).
- !pflag case.  If the target is created, POSIX requires it to not
  have the set[ug]id bits, but we sometimes copied them from the source.
  If the target already exists, POSIX requires its mode to be unchanged,
  but we sometimes copied the whole mode from the source.

PR:		20646
MFC after:	4 weeks
2001-06-11 13:57:54 +00:00
Warner Losh
34f9c106b9 Migrate from using MAXPATHLEN to MAX_PATH. Use strlcpy to copy the
strings.
2001-05-16 19:10:40 +00:00
Garrett Wollman
eb2fc78027 Don't depend on <sys/stat.h> bogusly including <sys/time.h> (and thereby
<time.h>).
2000-10-10 01:50:26 +00:00
Michael Haro
127432d7e2 fix cp -vi bug
Submitted by:	Dan Papasian (bugg_ on irc)
2000-01-23 03:04:49 +00:00
Michael Haro
fcb2f1b389 brucify and move printf() to catch cases of special files 1999-08-29 07:58:19 +00:00
Peter Wemm
2a4562393f $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
Michael Haro
4506e9078e Add a verbose mode to show what files are being copied.
Idea taken from obrien.

Reviewed by:	obrien
1999-08-26 02:44:56 +00:00
Kris Kennaway
46be34b902 Various spelling/formatting changes.
Submitted by: Philippe Charnier <charnier@xp11.frmug.org>
1999-05-08 10:22:15 +00:00
Warner Losh
426e9c1dcc First set of fixes to keep egcs happy. These include {} around single
statement if blocks[*] when the else could be ambiguous, not defaulting
to int type and removal of some unused variables.

[*] This is explicitly allowed by style(9) when the single statement
spans more than one line.

Reviewed by: obrien, chuckr
1999-04-25 21:13:34 +00:00
Bruce Evans
40fc4ee2de Don't use mmap() for non-regular files, since st_size is only meaningful
for regular files.  This fixes recent breakage of cp'ing from /dev/zero.
/dev/zero doesn't support mmap(), but the device driver mmap routines are
not called for mapping 0 bytes, so the error was not detected.  mmap()
can't even be used for cp'ing special files that support mmap(), since
there is general way to determine the file size.
1998-11-18 11:47:45 +00:00