summaryrefslogtreecommitdiff
path: root/bin/mv
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-03-01 20:43:52 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-03-01 20:43:52 +0000
commit5d7140eb9da85ee5546dd59af1bf35505158814d (patch)
tree72a1b900f7125358e95fb23297c370123786095f /bin/mv
parent2adc03d82fb53f88fe7e8d5a308882bd53d7432f (diff)
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.
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/mv.c20
1 files 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 <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
+#include <sys/mount.h>
#include <err.h>
#include <errno.h>
@@ -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);
}