History log of /freebsd-current/bin/mv/mv.c
Revision Date Author Comments
# 428f86fd 16-Mar-2024 Ricardo Branco <rbranco@suse.de>

mv: Set file flags after setting file times

Some file flags prevent modification of file times, so they should be
set later. This matches NetBSD's behaviour.

Reviewed by: markj
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/1138


# ebb1fe40 26-Dec-2023 Zhan-Wei <david5061@gapp.nthu.edu.tw>

mv: Improve comment

Fix typo/grammar error: Use the singlar verb ending on exists.

Event: Advanced UNIX Programming Course (Fall23) at NTHU.
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/940


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

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 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 script.

Sponsored by: Netflix


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

Remove $FreeBSD$: one-line .c pattern

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


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

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


# 8dd8cd00 24-May-2016 Don Lewis <truckman@FreeBSD.org>

Close from_fd if malloc() fails to avoid a file descriptor leak.

Reported by: Coverity
CID: 1007203
MFC after: 1 week


# 7bb3697b 28-Jun-2015 Jilles Tjoelker <jilles@FreeBSD.org>

mv: Improve message when moving two or more files to non-directory.

The message text is from cp, which has had a nicer message for this since
2007 (PR bin/50656).

As with cp, the exit status changes from 64 to 1.

PR: 201083
MFC after: 1 week


# 347b9f6d 23-Mar-2015 Jilles Tjoelker <jilles@FreeBSD.org>

cp,mv: Use futimens() instead of utimensat() if possible.


# 5faf2ae1 24-Jan-2015 Jilles Tjoelker <jilles@FreeBSD.org>

cp,mv,touch: Set timestamps with nanosecond precision.

This uses utimensat().


# c15455fe 01-Jul-2014 Xin LI <delphij@FreeBSD.org>

Check if fchflags() is needed by fstat'ing before and check
the results.

Reviewed by: jilles
X-MFC-With: r267977


# e6683f19 27-Jun-2014 Xin LI <delphij@FreeBSD.org>

Always set UF_ARCHIVE on target (because they are by definition new files
and should be archived) and ignore error when we can't set it (e.g. NFS).

Reviewed by: ken
MFC after: 2 weeks


# b4b2596b 21-Mar-2013 Pawel Jakub Dawidek <pjd@FreeBSD.org>

- Make 'flags' argument to chflags(2), fchflags(2) and lchflags(2) of type
u_long. Before this change it was of type int for syscalls, but prototypes
in sys/stat.h and documentation for chflags(2) and fchflags(2) (but not
for lchflags(2)) stated that it was u_long. Now some related functions
use u_long type for flags (strtofflags(3), fflagstostr(3)).
- Make path argument of type 'const char *' for consistency.

Discussed on: arch
Sponsored by: The FreeBSD Foundation


# b7d1b371 15-Nov-2012 Eitan Adler <eadler@FreeBSD.org>

Follow the behavior as specified in POSIX:

if (exists AND (NOT f_option) AND
((not_writable AND input_is_terminal) OR i_option))
prompt

in particular, add the test for input_is_terminal

PR: bin/173039
Submitted by: Mark Johnston <markjdb@gmail.com>
Approved by: cperciva
MFC after: 3 days


# 6ce6b6c1 31-Aug-2012 John Baldwin <jhb@FreeBSD.org>

Add a -h flag similar to the -h flag for ln to force mv(1) to treat a
symbolic link to a directory for the target as a symbolic link instead of
a directory. This makes it possible to atomically update a symbolic
link using rename().

Reviewed by: gj
MFC after: 2 weeks


# f9d4afb4 31-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Put some static keywords in the source code.

For these simple utilities, it doesn't harm to make all global variables
static. In fact, this allows the compiler to perform better forms of
optimisation and analysis.


# a23ffe96 03-Oct-2011 Ivan Voras <ivoras@FreeBSD.org>

Don't chop IO into small pieces, follow cp(1) and just use MAXPHYS.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# e0649d28 30-Jan-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

MFC r196841:

Add NFSv4 ACL support to mv(1).


# 62efc229 04-Sep-2009 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add NFSv4 ACL support to mv(1).

Reviewed by: rwatson


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 95aaf2e8 18-Jul-2008 Xin LI <delphij@FreeBSD.org>

Staticify symbols that will not be used in other
places.


# 961fdc4f 27-Dec-2007 Diomidis Spinellis <dds@FreeBSD.org>

- Roll-back attempts to mimic rename(2) atomicity introduced in 1.47,
and follow the letter of the POSIX specification.

- Moving a directory to an existing non-empty directory will now fail,
as required.

- Improve consistency and remove some style bugs of earlier versions.

This version passes all tests of tools/regression/bin/mv/regress.sh 1.6

Reviewed by: bde
MFC after: 1 month


# 3db8241b 17-Dec-2007 Diomidis Spinellis <dds@FreeBSD.org>

Calling any function from vfork other than exec* and _exit yields
undefined behavior.

Noted by: alfred


# 2ec43f35 16-Dec-2007 Diomidis Spinellis <dds@FreeBSD.org>

Eliminate gcc "variable clobbered" warnings by declaring the variables
living across the vfork as volatile.

Noted by: kan


# 3a44a288 16-Dec-2007 Diomidis Spinellis <dds@FreeBSD.org>

When moving a directory across devices to a place where a directory
with the same name exists, delete that directory first, before performing
the copy. This ensures that mv(1) across devices follows the semantics
of rename(2), as required by POSIX.

This change could introduce the potential of data loss, even if the
copy fails, violating the atomicity properties of rename(2). This is
(mostly) mitigated by first renaming the destination and obliterating
it only after a succesfull copy.

The above logic also led to the introduction of code that will cleanup
the results of a partial copy, if a cross-device copy fails.

PR: bin/118367
MFC after: 1 month


# 9b4261c9 04-Sep-2005 Christian S.J. Peron <csjp@FreeBSD.org>

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


# 8835fa27 19-May-2005 Maxime Henrion <mux@FreeBSD.org>

Correct a few places where we called warn() when warnx() should have
been used.

Submitted by: "Liam J. Foy" <liamfoy@sepulcrum.org>
Obtained from: DragonFlyBSD


# 9ddb49cb 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/*- or .\"- or #- to begin license clauses.


# 6195fb41 06-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 3184e921 21-Mar-2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>

When symbolic link is pointed onto a mount point, it can't be moved
to a different file system.
Patch in PR was incorrect.

PR: bin/64430
Submitted by: Samuel Tardieu
MFC after: 3 days


# 8d5c19ff 05-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Centralize _PATH_* definitions.

Submitted by: Tim Kientzle <kientzle@acm.org> (embellished by me)


# 09a80d48 01-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Quiet warnings about copyright[].


# 0f7109e8 09-Jul-2002 Johan Karlsson <johan@FreeBSD.org>

Update usage for the addition of -n in rev 1.35 of mv.c.

Approved by: obrien, sheldonh (mentor).


# 9a81395d 15-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

When trying to emulate a cross-device move operation with cp and rm, add
a "--" argument after the options so filenames with leading dashes are
handled correctly.

PR: 39318
Submitted by: Serge van den Boom <svdb@stack.nl>
MFC after: 1 week


# 71e092d1 17-May-2002 Juli Mallett <jmallett@FreeBSD.org>

Remove local definition of _PATH_CP, and use <paths.h>, _PATH_CP is in the
CURRENT <paths.h>.


# 0302f42b 22-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Update SCM ID.


# dce742c5 22-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Add the -n option, which automatically answers "no" to the overwrite question.


# 4b23bd7c 22-Feb-2002 Mark Murray <markm@FreeBSD.org>

Warnings fixes.


# fc69394f 13-Feb-2002 Warner Losh <imp@FreeBSD.org>

Move user_from_uid to pwd.h
Move group_from_gid to grp.h
Remove from stdlib.h
Make the prototypes match the code
Fix rm and mv to include new files.

NetBSD has these defined in those files, and others too that I've not
done.

Approved by: terminal room kabal
Reviewed by: jhb, phk


# b75c7687 02-Feb-2002 Warner Losh <imp@FreeBSD.org>

missed a few registers


# 46251dde 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

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.


# 7bc6d015 09-Jul-2001 Brian Somers <brian@FreeBSD.org>

Fix the type of the NULL arg to execl()

Idea from: Theo de Raadt <deraadt@openbsd.org>


# 422a64ea 29-May-2001 Warner Losh <imp@FreeBSD.org>

Use PATH_MAX in preference to MAXPATHLEN.


# 29e13abe 19-May-2001 Kris Kennaway <kris@FreeBSD.org>

Silence WARNS=2 and BDECFLAGS on alpha and i386, except for mode_t
warnings.

MFC after: 1 week


# f698dde9 20-Jul-2000 SADA Kenji <sada@FreeBSD.org>

Don't emit a warning message if fchflags() returns EOPNOTSUPP

Requested by: FUJISHIMA Satsuki <k5@cheerful.com>
Obtained from: OpenBSD


# 3c2ddcf5 15-Jul-2000 SADA Kenji <sada@FreeBSD.org>

To make inherit file flags when mv(1) moves file between directories
on different file systems.

PR: bin/12375
Submitted by: Takashi SHIRAI <shirai@nintendo.co.jp>
No response by: steve
No problem with: building 5-current world


# a95d6fda 11-Jul-2000 David Malone <dwmalone@FreeBSD.org>

Use lstat(2) instead of stat(2) when deciding if we should fastcopy
a file. This fixes moving symlinks across partitions.

PR: 17847
Reviewed by: bde


# 46fedeb0 29-Aug-1999 Michael Haro <mharo@FreeBSD.org>

add verbose flag


# 2a456239 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 1fd98d7d 13-Oct-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Calls one or more of malloc(), warn(), err(), syslog(), execlp() or
execvp() in the child branch of a vfork(). Changed to use fork()
instead.

Some of these (mv, find, apply, xargs) might benefit greatly from
being rewritten to use vfork() properly.

PR: Loosely related to bin/8252
Approved by: jkh and bde


# fe6f0b08 28-Jun-1998 Bruce Evans <bde@FreeBSD.org>

Fixed printf format errors.


# 8a20f85c 08-Jun-1998 Warner Losh <imp@FreeBSD.org>

Make sure we don't overflow the path buffer. Exit if we do.
Obtained from or inspired by: A similar change in OpenBSD by theo


# 191b38b5 25-May-1998 Steve Price <steve@FreeBSD.org>

Don't append a '/' to the destination directory if there
is already one there.

PR: 3025


# c9a8d1f4 15-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm. Add rcsid.


# a33d9e66 10-Dec-1997 Eivind Eklund <eivind@FreeBSD.org>

Merge from OpenBSD:
> Error out if someone tries to mv a mount point. Old behavior was to
> move all files contained in the mounted filesystem to the dest. dir
> which could be quite nasty. Personally, I think rename(2) should
> return EPERM or EINVAL instead of EXDEV.

Obtained from: OpenBSD mv.c rev 1.6 by Todd Miller <millert@openbsd.org>


# af6ff028 26-Oct-1997 Wolfgang Helbig <helbig@FreeBSD.org>

Synchronize usage() and man page.
Pointed out by bde.


# ae691257 04-Oct-1997 Wolfram Schneider <wosch@FreeBSD.org>

mv(1) is too silent if used with the option -i. It should
print which input mv(1) expect (y/n) and print a warning if the
file was not overwritten.


# fee9ad97 28-Sep-1997 Wolfram Schneider <wosch@FreeBSD.org>

Endless loop.

$ touch from to
$ echo -n loop | mv -i from to
overwrite to?
^C


# 93ef08af 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 03001f57 08-Mar-1997 Guido van Rooij <guido@FreeBSD.org>

Make mv more robust. A race has been fixed, as well as an extra warning
added when sbits are cleared.
Fixes PR 1351 and 1377 (I hope).


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 78b09ffe 13-Dec-1996 Steve Price <steve@FreeBSD.org>

-Wall cleaning.


# aa055148 29-Feb-1996 Wolfram Schneider <wosch@FreeBSD.org>

delete unused label endarg
correct indent of last new code
fix usage string, option -f before option -i (alphabetic order)


# 5fd463ac 20-Feb-1996 Wolfram Schneider <wosch@FreeBSD.org>

option -f and -i are exclusive (Posix)
respond `Y' is equal to `y'
update usage string
prompt only if source exist


# 91e94a1d 18-Feb-1996 Paul Traina <pst@FreeBSD.org>

-- is implemented in getopt(3)
-? is an unnecessary case statement and not useful


# d7e0e5ca 18-Feb-1996 Wolfram Schneider <wosch@FreeBSD.org>

delete my last commit
Submitted by: pst, ache


# 1efb053d 18-Feb-1996 Wolfram Schneider <wosch@FreeBSD.org>

option -f and -i are exclusive
all flag variables initialized with zero
respond `Y' is equal to `y'
update usage string
prompt only if source exist

ignore -i option if file descriptor stdin not refers to a valid
terminal type device


# 27e79e1d 07-Oct-1995 Bruce Evans <bde@FreeBSD.org>

Handle trailing slashes in source filenames correctly. E.g., rewrite
`mv foo/ ../..' to `mv foo/ ../../foo/', not to `mv foo/ ../../'. The
latter caused a panic. Before the trailing slash changes in the kernel,
the trailing slashes caused the rename() for this mv to fail earlier, so
there was no panic in 2.0.

Fixes part of PR 760.


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources