Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Jul 2005 14:43:59 +0200 (CEST)
From:      Mikolaj Rydzewski <miki@ma.krakow.pl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/84298: [patch] allow mount(8) to recognize relative pathnames as mountpoints
Message-ID:  <200507291243.j6TChxb7078431@k2.ma.krakow.pl>
Resent-Message-ID: <200507291250.j6TCoJdt095834@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         84298
>Category:       bin
>Synopsis:       [patch] allow mount(8) to recognize relative pathnames as mountpoints
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 29 12:50:19 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Mikolaj Rydzewski
>Release:        FreeBSD 5.4-RELEASE-p5 i386
>Organization:
>Environment:
System: FreeBSD k2.ma.krakow.pl 5.4-RELEASE-p5 FreeBSD 5.4-RELEASE-p5 #3: Tue Jul 26 13:11:08 CEST 2005 miki@k2.ma.krakow.pl:/usr/src/sys/i386/compile/K2 i386


>Description:
	Current version of mount(8) requires to specify absolute mountpoint
	pathname. Let's assume one has some mountpoints located in /mnt:
	/mnt/cdrom, /mnt/floppy, /mnt/usb
	It should be possible to call mount(8) like this:
	mount cdrom (assuming the current directory is /mnt). It has
	more practical impact when system is configured to allow non-root
	users to mount (cdroms, usb sticks) to mountpoints in their home
	directories. It's much more flexible to run mount ~/usb than 
	mount /home/<username>/usb.
	And last but not least ;-) mount(8) is supposed to behave in such
	way - there's a correct call to realpath(3), but infortunately
	previous function checks mountpoint validity without using
	realpath(3) call.
	So my patch just polishes existing code.
>How-To-Repeat:
	Try to mount a filesystem using non absolute path name - an error
	will occur.
>Fix:
	Apply attached patch.

--- mount_patch begins here ---
diff -Nru sbin/mount.old/getmntopts.c sbin/mount/getmntopts.c
--- sbin/mount.old/getmntopts.c	Fri Jul 29 13:55:33 2005
+++ sbin/mount/getmntopts.c	Fri Jul 29 14:08:03 2005
@@ -140,3 +140,18 @@
 	} else
 		errx(EX_USAGE, "%s: %s", resolved, strerror(errno));
 }
+
+const char *
+getrealpath(path, resolved)
+	const char *path;
+	char *resolved;
+{
+	struct stat sb;
+
+	if (realpath(path, resolved) != NULL
+		&& stat(resolved, &sb) == 0
+		&& S_ISDIR(sb.st_mode))
+		return resolved;
+
+	return path;
+}
diff -Nru sbin/mount.old/mntopts.h sbin/mount/mntopts.h
--- sbin/mount.old/mntopts.h	Fri Jul 29 13:55:33 2005
+++ sbin/mount/mntopts.h	Fri Jul 29 14:07:15 2005
@@ -91,4 +91,5 @@
 void getmntopts(const char *, const struct mntopt *, int *, int *);
 void rmslashes(char *, char *);
 void checkpath(const char *, char resolved_path[]);
+const char* getrealpath(const char *, char resolved_path[]);
 extern int getmnt_silent;
diff -Nru sbin/mount.old/mount.c sbin/mount/mount.c
--- sbin/mount.old/mount.c	Fri Jul 29 13:55:33 2005
+++ sbin/mount/mount.c	Fri Jul 29 14:12:42 2005
@@ -126,13 +126,14 @@
 	int argc;
 	char * const argv[];
 {
-	const char *mntfromname, **vfslist, *vfstype;
+	const char *mntfromname, **vfslist, *vfstype, *mntpath_ptr;
 	struct fstab *fs;
 	struct statfs *mntbuf;
 	FILE *mountdfp;
 	pid_t pid;
 	int all, ch, i, init_flags, mntsize, rval, have_fstab;
 	char *cp, *ep, *options;
+	char mntpath[PATH_MAX];
 
 	all = init_flags = 0;
 	options = NULL;
@@ -271,8 +272,9 @@
 			    mntbuf->f_mntonname, init_flags, options, 0);
 			break;
 		}
-		if ((fs = getfsfile(*argv)) == NULL &&
-		    (fs = getfsspec(*argv)) == NULL)
+		mntpath_ptr = getrealpath(*argv, mntpath);
+		if ((fs = getfsfile(mntpath_ptr)) == NULL &&
+		    (fs = getfsspec(mntpath_ptr)) == NULL)
 			errx(1, "%s: unknown special file or file system",
 			    *argv);
 		if (BADTYPE(fs->fs_type))
--- mount_patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507291243.j6TChxb7078431>