Verify that the last component of the mount point path exists and is

a directory - allows for better error reporting.
This commit is contained in:
David Greenman 1995-02-15 14:20:50 +00:00
parent b019cc8f8e
commit 8a978495e7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=6441
2 changed files with 22 additions and 2 deletions

View File

@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
@ -245,6 +247,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
const char *vfstype, *spec, *name, *options, *mntopts;
int flags;
{
struct stat sb;
/* List of directories containing mount_xxx subcommands. */
static const char *edirs[] = {
_PATH_SBIN,
@ -257,10 +261,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
int argc, i, status;
char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
if (realpath(name, mntpath) == NULL) {
if ((realpath(name, mntpath) != NULL) && (stat(mntpath, &sb) == NULL)) {
if ((sb.st_mode & S_IFDIR) == 0) {
warnx("%s: Not a directory", mntpath);
return (1);
}
} else {
warn("%s", mntpath);
return (1);
}
if (mntopts == NULL)
mntopts = "";

View File

@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
@ -245,6 +247,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
const char *vfstype, *spec, *name, *options, *mntopts;
int flags;
{
struct stat sb;
/* List of directories containing mount_xxx subcommands. */
static const char *edirs[] = {
_PATH_SBIN,
@ -257,10 +261,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
int argc, i, status;
char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
if (realpath(name, mntpath) == NULL) {
if ((realpath(name, mntpath) != NULL) && (stat(mntpath, &sb) == NULL)) {
if ((sb.st_mode & S_IFDIR) == 0) {
warnx("%s: Not a directory", mntpath);
return (1);
}
} else {
warn("%s", mntpath);
return (1);
}
if (mntopts == NULL)
mntopts = "";