diff options
author | eivind <eivind@FreeBSD.org> | 1997-12-10 17:52:49 +0000 |
---|---|---|
committer | eivind <eivind@FreeBSD.org> | 1997-12-10 17:52:49 +0000 |
commit | 02f883b4a2faad20fec2877ff8ad2df37f9e31c1 (patch) | |
tree | c19b28480f7fc2c4a893af89298dbb020621fd3e /bin | |
parent | 9c8df1263b66f0e424093443f3e6a9f02e909d7d (diff) | |
download | FreeBSD-src-02f883b4a2faad20fec2877ff8ad2df37f9e31c1.zip FreeBSD-src-02f883b4a2faad20fec2877ff8ad2df37f9e31c1.tar.gz |
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>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/mv/mv.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c index ac53e11..e30b16e 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: mv.c,v 1.15 1997/10/04 13:02:06 wosch Exp $ + * $Id: mv.c,v 1.16 1997/10/26 10:33:02 helbig Exp $ */ #ifndef lint @@ -50,6 +50,7 @@ static char const sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; #include <sys/time.h> #include <sys/wait.h> #include <sys/stat.h> +#include <sys/mount.h> #include <err.h> #include <errno.h> @@ -184,7 +185,20 @@ do_move(from, to) if (!rename(from, to)) return (0); - if (errno != EXDEV) { + if (errno == EXDEV) { + struct statfs sfs; + char path[MAXPATHLEN]; + + /* Can't mv(1) a mount point. */ + if (realpath(from, path) == NULL) { + warnx("cannot resolve %s: %s", from, path); + return (1); + } + if (!statfs(path, &sfs) && !strcmp(path, sfs.f_mntonname)) { + warnx("cannot rename a mount point"); + return (1); + } + } else { warn("rename %s to %s", from, to); return (1); } |