From 0e5b10c1f9d3a91db880f4eca5fce8d2f42e7111 Mon Sep 17 00:00:00 2001 From: millert Date: Sat, 1 Mar 1997 20:43:51 +0000 Subject: [PATCH] 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. --- bin/mv/mv.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/mv/mv.c b/bin/mv/mv.c index d2bc283cb85..9e089da3f5d 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mv.c,v 1.6 1997/02/02 10:16:58 tholo Exp $ */ +/* $OpenBSD: mv.c,v 1.7 1997/03/01 20:43:51 millert Exp $ */ /* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: mv.c,v 1.6 1997/02/02 10:16:58 tholo Exp $"; +static char rcsid[] = "$OpenBSD: mv.c,v 1.7 1997/03/01 20:43:51 millert Exp $"; #endif #endif /* not lint */ @@ -55,6 +55,7 @@ static char rcsid[] = "$OpenBSD: mv.c,v 1.6 1997/02/02 10:16:58 tholo Exp $"; #include #include #include +#include #include #include @@ -199,7 +200,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); } -- 2.20.1